// Event handler for Remove button click private void removeItemBtn_Click(object sender, EventArgs e) { // Creating lists strMatsBeingRemoved = new List <String>(); matsUpdatedQuantity = new List <RawMaterial>(); if (dbTools.CheckMat(txtName.Text).Equals(true)) // Checking if the material exists in the database { RawMaterial tempMaterial = dbTools.GetRawMaterial(txtName.Text); // Getting the raw material object with the given name from the database int newQuantity = tempMaterial.quantity - int.Parse(txtQuantity.Text); // Calculating the new quantity after subtracting the amount being taken out // NO DUPLICATE ENTRIES // Quantity cannot be negative after subtracting if (newQuantity > 0) { tempMaterial.quantity = int.Parse(txtQuantity.Text); // Setting the object quantity to what the user inputs matsQuantityToRemove.Add(tempMaterial); // Adding material to a list of raw material objects with the user inputted quantity newMaterial = new RawMaterial(tempMaterial.rawMaterialName, newQuantity); // What we want the product to be after making changes matsUpdatedQuantity.Add(newMaterial); // Adding that to a list to track its quantity rawMatsView.Items.Clear(); // Clearing list view // Format each material to display in list views foreach (RawMaterial mat in matsQuantityToRemove) { string s = mat.quantity.ToString() + "x " + mat.rawMaterialName; // Format to display -> (quantity)x (name) strMatsBeingRemoved.Add(s); rawMatsView.Items.Add(s); } // Clear text fields txtName.Clear(); txtQuantity.Clear(); } else { MessageBox.Show("Not enough raw materials!", "Warning!"); txtQuantity.Clear(); } } else { MessageBox.Show("Material does not exist!", "Warning!"); } }
private void changeqnt_Click(object sender, EventArgs e) { try { String MatName = itembox.Text; int Quant = int.Parse(qtnBox.Text); dbTools = new DatabaseTools(); if (dbTools.CheckMat(MatName).Equals(true)) { try { string message = "Are you sure you want to change the quantity of " + MatName + " to " + Quant + "?"; string title = "Warning!"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result = MessageBox.Show(message, title, buttons); if (result == DialogResult.Yes) { dbTools.EditQuant(MatName, Quant); dgTools.SqlCommand = "SELECT RawMaterialName, Quantity FROM RawMaterials"; // Viewing all data from RawMaterials database except the ID dgTools.RefreshDataGrid(stockDataGridView); itembox.Clear(); qtnBox.Clear(); } else { return; } } catch (Exception err) { MessageBox.Show(err.Message, "Warning!"); } } else { MessageBox.Show("This item can not be found."); } } catch (Exception err) { MessageBox.Show("Please input a value and quantity", "Warning!"); } }