private void btn_Update_Click(object sender, RoutedEventArgs e) { if (!CheckValidate.checkForType(txt_Type.Text.ToString())) { MessageBox.Show("Type must be characters with start by Uppercase.", "Error!"); } if (!CheckValidate.checkForPrice(txt_Price.Text.ToString())) { MessageBox.Show("Price must be numbers, can use Comma and Decial.", "Error!"); } if (!CheckValidate.checkForInventory(txt_Inventory.Text.ToString())) { MessageBox.Show("Inventory must be natural numbers.", "Error!"); } if (CheckValidate.checkForType(txt_Type.Text.ToString()) && CheckValidate.checkForPrice(txt_Price.Text.ToString()) && CheckValidate.checkForInventory(txt_Inventory.Text.ToString())) { cmd = new SqlCommand("update tbl_product SET type = @type, description = @description, price = @price, inventory = @inventory WHERE product_id = @product_id ", sqlCon); sqlCon.Open(); cmd.Parameters.AddWithValue("@type", txt_Type.Text); cmd.Parameters.AddWithValue("@description", txt_Description.Text); cmd.Parameters.AddWithValue("@price", txt_Price.Text); cmd.Parameters.AddWithValue("@inventory", txt_Inventory.Text); cmd.Parameters.AddWithValue("@product_id", product_id); cmd.ExecuteNonQuery(); sqlCon.Close(); MessageBox.Show("Data Updated Successfully !!!", "Message"); LoadData(); RefreshTextFields(); btn_Update.IsEnabled = false; btn_Delete.IsEnabled = false; btn_Refresh.IsEnabled = false; btn_AddNew.IsEnabled = true; txt_Type.IsEnabled = true; } }
private void btn_AddNew_Click(object sender, RoutedEventArgs e) { if (!CheckValidate.checkForType(txt_Type.Text.ToString())) { MessageBox.Show("Type must be characters.", "Error!"); } if (!CheckValidate.checkForPrice(txt_Price.Text.ToString())) { MessageBox.Show("Price must be numbers, can use Comma and Decimal.", "Error!"); } if (!CheckValidate.checkForInventory(txt_Inventory.Text.ToString())) { MessageBox.Show("Inventory must be natural numbers.", "Error!"); } if (CheckValidate.checkForType(txt_Type.Text.ToString()) && CheckValidate.checkForPrice(txt_Price.Text.ToString()) && CheckValidate.checkForInventory(txt_Inventory.Text.ToString())) { cmd = new SqlCommand("INSERT INTO tbl_product(type, description, price, inventory) values(@type, @description, @price, @inventory)", sqlCon); sqlCon.Open(); cmd.Parameters.AddWithValue("@type", txt_Type.Text); cmd.Parameters.AddWithValue("@description", txt_Description.Text); cmd.Parameters.AddWithValue("@price", txt_Price.Text); cmd.Parameters.AddWithValue("@inventory", txt_Inventory.Text); cmd.ExecuteNonQuery(); sqlCon.Close(); MessageBox.Show("Data Inserted Successfully !!!", "Message"); LoadData(); RefreshTextFields(); } }