A
A
Andrey Fomin2021-01-07 22:08:24
SQL
Andrey Fomin, 2021-01-07 22:08:24

How to implement the desired operation of the interface?

Hello!
I'm making a program - like a banking client for the desktop. And during its development, several points arose that I would like to clarify:
1. There is a user form where he can enter his first and last name and then save this data to the database, but there is also a field for a photo, when the button is pressed, the explorer opens and through it in the picturebox on the form the selected image is added. How can you save an image? I read that storing images in the database is not the best option, but is it possible to store links to images and how to implement it?
2. According to the initial idea, if the user entered a first or last name and saved it in the database, then when the form is reopened, the same first and last name should appear in the same fields where they were entered. How to implement it?
3. There is a form where the user can view the history of translations. How to save the date and time in the table, and also display the entire table on the form?
4. If I entered a number in the textbox, how can I make this number count as a number, as a number?
Here is the code of the form, which I wrote about in paragraphs 1 and 2:

public FormUser()
        {
            InitializeComponent();
            
        }

        private void Upload_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            Controls.Add(pictureBox1);

            openFileDialog1.ShowDialog();

            Image image = Image.FromFile(openFileDialog1.FileName);
            pictureBox1.Image = image;
        }
        
        private void WatchHistory_Click(object sender, EventArgs e)
        {
            Hide();
            new FormHistory().Show();
        }

        private void MakePayment_Click(object sender, EventArgs e)
        {
            Hide();
            new FormPayment().Show();
        }

        private void Save_Click(object sender, EventArgs e)
        {
            if ((NameField.Text == "") && (SurnameField.Text == "") && (pictureBox1.Image == null) && (LoginField.Text == ""))
            {
                MessageBox.Show("И что мне надо сохранять, если везде пусто?!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            
            SQLiteConnection connect = new SQLiteConnection("Data source = accounts.db");
            connect.Open();
            try
            {
                SQLiteCommand command = new SQLiteCommand($"UPDATE users SET Name = '{NameField.Text}', Surname = '{SurnameField.Text}' WHERE Login = '{LoginField.Text}'", connect);
                command.ExecuteNonQuery();
            }
            finally
            {
                MessageBox.Show($"Изменения сохранены!");
                connect.Close();
            }
        }

If there are concrete examples with code, that would be great)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
oleg_ods, 2021-01-08
@a63826ndrew

1. You need to save the resulting image on the server to some folder, for example myapp/storage/images, and write the path to this image in the database ( myapp/storage/images/photo1.jpg)
2. When opening the form, check if there is db any information about this user. If there is, then fill out the form, otherwise it is empty.
3. SQL has a date data type just for storing dates. Alternatively, you can use unixtime.
4. Try to parse the entered value. Or use NumericUpDown. Or add a KeyPress event handler and check the entered character in it for the fact that it is a digit (char.IsDigit)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question