private void AddButton_Click(object sender, EventArgs e) { const string errorMessage = "A supplier with this name already exists.\n\nPlease enter a different name."; _connection = DB_Connect.connect(); _connection.Open(); if (IfSupplierExists(_connection, SNTextBox.Text)) { MessageBox.Show(errorMessage); SNTextBox.Clear(); SNTextBox.Focus(); } else { var sqlQuery = @"INSERT INTO[Suppliers] ([SupplierName], [SupplierAddress], [SupplierNumber], [SupplierEmail]) VALUES ('" + SNTextBox.Text + "', '" + SATextBox.Text + "', '" + SNUTextBox.Text + "', '" + SETextBox.Text + "')"; _command = new SqlCommand(sqlQuery, _connection); _command.ExecuteNonQuery(); ClearText(); SNTextBox.Focus(); } _connection.Close(); LoadData(); }
private void UpdateButton_Click(object sender, EventArgs e) { const string errorMessage = "A supplier with this name doesn't exist.\n\nPlease enter a different name."; _connection = DB_Connect.connect(); _connection.Open(); if (IfSupplierExists(_connection, SNTextBox.Text)) { var sqlQuery = @"UPDATE[Suppliers] SET[SupplierName] = '" + SNTextBox.Text + "', [SupplierAddress] = '" + SATextBox.Text + "' , [SupplierNumber] = '" + SNUTextBox.Text + "', [SupplierEmail] = '" + SETextBox.Text + "' WHERE[SupplierName] = '" + SNTextBox.Text + "'"; ClearText(); SNTextBox.Focus(); _command = new SqlCommand(sqlQuery, _connection); _command.ExecuteNonQuery(); } else { MessageBox.Show(errorMessage); SNTextBox.Clear(); SNTextBox.Focus(); } _connection.Close(); LoadData(); }
private void DeleteButton_Click(object sender, EventArgs e) { const string errorMessage = "This supplier does not exist!"; _connection = DB_Connect.connect(); if (IfSupplierExists(_connection, SNTextBox.Text)) { _connection.Open(); var sqlQuery = @"DELETE FROM[Suppliers] WHERE[SupplierName] = '" + SNTextBox.Text + "'"; _command = new SqlCommand(sqlQuery, _connection); _command.ExecuteNonQuery(); _connection.Close(); } else { MessageBox.Show(errorMessage); } ClearText(); SNTextBox.Focus(); LoadData(); }