private void AddButton_Click(object sender, EventArgs e) { const string errorMessage = "An item with this product code already exists.\n\nPlease enter a different product code."; _connection = DB_Connect.connect(); _connection.Open(); if (IfProductExists(_connection, PCTextBox.Text)) { MessageBox.Show(errorMessage); PCTextBox.Clear(); PCTextBox.Focus(); } else { var sqlQuery = @"INSERT INTO[Products] ([ProductCode], [ProductName], [ProductSupplier], [ProductSupplierCode], [ProductPrice], [ProductStock]) VALUES ('" + PCTextBox.Text + "', '" + PNTextBox.Text + "', '" + SNTextBox.Text + "', '" + SCTextBox.Text + "', '" + PriceTextBox.Text + "', '" + StockTextBox.Text + "')"; _command = new SqlCommand(sqlQuery, _connection); _command.ExecuteNonQuery(); ClearText(); PCTextBox.Focus(); } _connection.Close(); LoadData(); }
private void UpdateButton_Click(object sender, EventArgs e) { const string errorMessage = "An item with this product code doesn't exist.\n\nPlease enter a different product code."; _connection = DB_Connect.connect(); _connection.Open(); if (IfProductExists(_connection, PCTextBox.Text)) { var sqlQuery = @"UPDATE[Products] SET[ProductName] = '" + PNTextBox.Text + "', [ProductSupplier] = '" + SNTextBox.Text + "' , [ProductSupplierCode] = '" + SCTextBox.Text + "', [ProductPrice] = '" + PriceTextBox.Text + "', [ProductStock] = '" + StockTextBox.Text + "' WHERE[ProductCode] = '" + PCTextBox.Text + "'"; ClearText(); PCTextBox.Focus(); _command = new SqlCommand(sqlQuery, _connection); _command.ExecuteNonQuery(); } else { MessageBox.Show(errorMessage); PCTextBox.Clear(); PCTextBox.Focus(); } _connection.Close(); LoadData(); }
private void DeleteButton_Click(object sender, EventArgs e) { const string errorMessage = "This item does not exist!"; _connection = DB_Connect.connect(); if (IfProductExists(_connection, PCTextBox.Text)) { _connection.Open(); var sqlQuery = @"DELETE FROM[Products] WHERE[ProductCode] = '" + PCTextBox.Text + "'"; _command = new SqlCommand(sqlQuery, _connection); _command.ExecuteNonQuery(); _connection.Close(); } else { MessageBox.Show(errorMessage); } ClearText(); PCTextBox.Focus(); LoadData(); }