private void buttonDeleteUser_Click(object sender, EventArgs e) { var id = dataGridView1.SelectedCells[0].Value.ToString(); var dt = ConnectionUtils.ExecuteCommand($"DELETE FROM Registration WHERE Id='{id}'"); dataGridView1.DataSource = dt; ListUsersToGrid(); ShowStatusLabel($"User with id {id} was deleted"); }
private void buttonConnect_Click(object sender, EventArgs e) { var dt = ConnectionUtils.ExecuteCommand( $"SELECT * FROM Registration WHERE Username='******' AND Password='******'"); if (dt.Rows.Count > 0) { Hide(); var mdi = new MDIParent1(); mdi.Show(); } else { MessageBox.Show("Wrong username or password"); } }
private void buttonDeleteProduct_Click(object sender, EventArgs e) { var cells = dataGridView1.SelectedCells; if (cells.Count < 1) { return; } var id = dataGridView1.SelectedCells[0].Value.ToString(); var dt = ConnectionUtils.ExecuteCommand($"DELETE FROM Item WHERE Id='{id}'"); dataGridView1.DataSource = dt; ListItemsToGrid(); AppendStatusText($"Item with id {id} was deleted"); }
private void ButtonAddProduct_Click(object sender, EventArgs e) { try { ConnectionUtils.ExecuteCommand( $"INSERT INTO Item (Product, Count) VALUES ('{textBoxProduct.Text}', {numericUpDownCount.Value})"); } catch (SqlException exception) { switch (exception.Number) { case 2601: case 2627: MessageBox.Show("The e-mail address or username you entered is already in use"); break; default: MessageBox.Show($"Error while saving data\n\n{exception.Message}"); break; } return; } foreach (Control control in panel1.Controls) { switch (control) { case TextBox _: control.Text = ""; break; case NumericUpDown upDown: upDown.Value = 1; break; } } AppendStatusText("Product successfully added"); ListItemsToGrid(); }
private void buttonAddUser_Click(object sender, EventArgs e) { try { ConnectionUtils.ExecuteCommand( $"INSERT INTO Registration (Username, Password, Email, FirstName, LastName) VALUES ('{textBoxUsername.Text}', '{textBoxPassword.Text}', '{textBoxEmail.Text}', '{textBoxFirstName.Text}', '{textBoxLastName.Text}')"); } catch (SqlException exception) { switch (exception.Number) { case 2601: case 2627: MessageBox.Show("The e-mail address or username you entered is already in use"); break; default: MessageBox.Show("Error while saving data"); break; } return; } foreach (Control control in panel1.Controls) { if (control is TextBox) { control.Text = ""; } } ShowStatusLabel("User successfully added"); ListUsersToGrid(); }
private void ListUsersToGrid() { dataGridView1.DataSource = ConnectionUtils.ExecuteCommand("SELECT * FROM Registration"); }
private void ListItemsToGrid() { dataGridView1.DataSource = ConnectionUtils.ExecuteCommand("SELECT * FROM Item"); }