private void Another_Material_btn_Click(object sender, EventArgs e) { if (objCheckEntry.checkValidStockEntry(txt_materialType.Text, lblMaterialType.Text, txt_Quantity.Text, lbl_quantity.Text, txt_unitCost.Text, lbl_unitCost.Text, txt_TotalCost.Text, lbl_totalCost.Text, txt_Defected.Text, lbl_defected.Text, txt_DateAcq.Text, lbl_dateAcq.Text, txt_dateUsed.Text, lbl_dateUsed.Text, objStock)) { try { stocks.Add(objStock); objDatabaseManager.InsertToStockTable(stocks); txt_materialType.SelectedIndex = -1; ResetDTP(); txt_Defected.Value = 0; txt_Quantity.Value = 0; txt_TotalCost.Value = 0; txt_unitCost.Value = 0; objStock = new Stock(); } catch (Exception err) { MessageBox.Show("Error: " + err); } this.Hide(); stocks.Clear(); } }
private void ConfirmGrid_btn_Click(object sender, EventArgs e) { //Add a new stock if the Item ID is empty if (string.IsNullOrEmpty(ItemIDGrid_box.Text.ToString())) { try { objCheckEntry.checkValidStockEntry(txtMaterialType.Text, lblMaterialType.Text, quantityGrid_box.Text, lblQuantity.Text, unitCostGrid_box.Text, lblUnitCost.Text, totalCostGrid_box.Text, lblTotalCost.Text, amtDefectedGrid_box.Text, lblDefects.Text, dateAcquiredGrid_box.Text, lblDateAcq.Text, dateUsedGrid_box.Text, lblDateUsed.Text, objStock); objDatabaseManager.InsertStock(txtMaterialType.Text, quantityGrid_box.Text, unitCostGrid_box.Text, totalCostGrid_box.Text, dateAcquiredGrid_box.Text, dateUsedGrid_box.Text, amtDefectedGrid_box.Text); loadStocks(); } catch (Exception) { MessageBox.Show("Error adding stock to Stock table."); } } //Update existing stock based on the ID entered in the Item ID field if (!string.IsNullOrEmpty(ItemIDGrid_box.Text.ToString())) { try { objCheckEntry.checkValidStockEntry(txtMaterialType.Text, lblMaterialType.Text, quantityGrid_box.Text, lblQuantity.Text, unitCostGrid_box.Text, lblUnitCost.Text, totalCostGrid_box.Text, lblTotalCost.Text, amtDefectedGrid_box.Text, lblDefects.Text, dateAcquiredGrid_box.Text, lblDateAcq.Text, dateUsedGrid_box.Text, lblDateUsed.Text, objStock); int key = Int32.Parse(ItemIDGrid_box.Text); objDatabaseManager.UpdateStock(key, txtMaterialType.Text, quantityGrid_box.Text, unitCostGrid_box.Text, totalCostGrid_box.Text, dateAcquiredGrid_box.Text, dateUsedGrid_box.Text, amtDefectedGrid_box.Text); MessageBox.Show("Item number " + ItemIDGrid_box.Text + " (" + txtMaterialType.Text + ") was updated in the database."); } catch (Exception) { MessageBox.Show("Error updating stock in the Stock database table."); } loadStocks(); } }