private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; bool success = true; if (oBtn != null) { var errorM = returnMessage(FldEntered); if (!String.IsNullOrEmpty(errorM)) { MessageBox.Show(errorM); return; } TLADM_WhseStore whse = new TLADM_WhseStore(); using (var context = new TTI2Entities()) { if (!addRecord) { var whseSelected = (TLADM_WhseStore)cmbWhse.SelectedItem; if (whseSelected != null) { whse = context.TLADM_WhseStore.Find(whseSelected.WhStore_Id); } } whse.WhStore_Code = txtCode.Text; whse.WhStore_Description = txtDescription.Text; //-------------------------------------------------------------------- if (rbWarehouse.Checked) { whse.WhStore_WhseOrStore = true; } else { whse.WhStore_WhseOrStore = false; } //------------------------------------------------------------------------------------------ if (rbGradeA.Checked) { whse.WhStore_GradeA = true; } else { whse.WhStore_GradeA = false; } if (rbChemicalStoreYes.Checked) { whse.WhStore_ChemicalStore = true; } else { whse.WhStore_ChemicalStore = false; } if (rbBundleStoreYes.Checked) { whse.WhStore_BundleStore = true; } else { whse.WhStore_BundleStore = false; } if (rbPanelStoreYes.Checked) { whse.WhStore_PanelStore = true; } else { whse.WhStore_PanelStore = false; } if (rbDyeKitchYes.Checked) { whse.WhStore_DyeKitchen = true; } else { whse.WhStore_DyeKitchen = false; } if (rbRepacYes.Checked) { whse.WhStore_RePack = true; } else { whse.WhStore_RePack = false; } whse.WhStore_Address1 = txtAddress1.Text; whse.WhStore_Address2 = txtAddress2.Text; whse.WhStore_Address3 = txtAddress3.Text; whse.WhStore_Address4 = txtAddress4.Text; whse.WhStore_Address5 = txtAddress5.Text; whse.WhStore_Contact = txtContact.Text; whse.WhStore_Notes = rctNotes.Text; whse.WhStore_Description = txtDescription.Text; whse.WhStore_Contact = txtContact.Text; whse.WhStore_Email = txtEMail.Text; whse.WhStore_Telephone = txtTelephone.Text; whse.WhStore_CountryOfOrigin = txtCountryOfOrigin.Text; var dept = (TLADM_Departments)cmbDepartment.SelectedItem; if (dept != null) { whse.WhStore_DepartmentFK = dept.Dep_Id; } else { whse.WhStore_DepartmentFK = 1; } var storetypes = (TLADM_StoreTypes)cmbType.SelectedItem; if (storetypes != null) { whse.WhStore_TypeFK = storetypes.StoreT_Id; } else { whse.WhStore_TypeFK = 1; } if (addRecord) { context.TLADM_WhseStore.Add(whse); } try { context.SaveChanges(); formloaded = false; cmbWhse.DataSource = context.TLADM_WhseStore.OrderBy(x => x.WhStore_Code).ToList(); cmbWhse.SelectedValue = 0; formloaded = true; Setup(false); } catch (ArgumentException ex) { MessageBox.Show(ex.Message); } catch (Exception ex) { var exceptionMessages = new StringBuilder(); do { exceptionMessages.Append(ex.Message); ex = ex.InnerException; }while (ex != null); MessageBox.Show(exceptionMessages.ToString()); success = false; } } if (success) { MessageBox.Show("Records stored to database sucessfully"); } } }
private void button1_Click(object sender, EventArgs e) { Button oBtn = sender as Button; if (oBtn != null && formloaded) { var WhseIssue = (TLADM_WhseStore)cmboIssueDepartment.SelectedItem; if (WhseIssue == null) { MessageBox.Show("Please select a Chemical Store from the list provided"); return; } var WhseReceiving = (TLADM_WhseStore)cmboReceivingDepartment.SelectedItem; if (WhseReceiving == null) { MessageBox.Show("Please select a Dye Kitchen from the list provided"); return; } using (var context = new TTI2Entities()) { var LNU = context.TLADM_LastNumberUsed.Find(3); LNU.col12 += 1; foreach (DataGridViewRow row in dataGridView1.Rows) { if (!(bool)row.Cells[1].Value) { continue; } var index = (int)row.Cells[0].Value; //--------------------------------------- // 1st decision //------------------------------------------------------- TLDYE_ConsumableSOH newSOH = new TLDYE_ConsumableSOH(); newSOH = context.TLDYE_ConsumableSOH.Where(x => x.DYCSH_WhseStore_FK == WhseReceiving.WhStore_Id && x.DYCSH_Consumable_FK == index).FirstOrDefault(); if (newSOH == null) { newSOH = new TLDYE_ConsumableSOH(); newSOH.DYCSH_StockOnHand = (decimal)row.Cells[4].Value; newSOH.DYCSH_TransNumber = -1 + LNU.col12; newSOH.DYCSH_Consumable_FK = (int)row.Cells[5].Value; newSOH.DYCSH_WhseStore_FK = WhseReceiving.WhStore_Id; newSOH.DYCSH_DyeKitchen = WhseReceiving.WhStore_DyeKitchen; context.TLDYE_ConsumableSOH.Add(newSOH); } else { newSOH.DYCSH_StockOnHand += (decimal)row.Cells[4].Value; } TLDYE_ConsumableSOH oldSOH = new TLDYE_ConsumableSOH(); oldSOH = context.TLDYE_ConsumableSOH.Find(index); if (oldSOH != null) { oldSOH.DYCSH_StockOnHand -= (Decimal)row.Cells[4].Value; } } try { context.SaveChanges(); MessageBox.Show("Data successfully saved to database"); DyeReportOptions opts = new DyeReportOptions(); opts.fromDate = DateTime.Now; opts.LNU = -1 + LNU.col12; opts.toStore = WhseReceiving.WhStore_Id; TLADM_WhseStore FromWhse = context.TLADM_WhseStore.Where(x => x.WhStore_Code.Contains("CS")).FirstOrDefault(); opts.fromStore = FromWhse.WhStore_Id; frmDyeViewReport vRep = new frmDyeViewReport(30, opts); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
public frmBoxSplitDetail(DataGridViewRow CurrentRow, TLADM_WhseStore WhseStore) { MandatoryFields = new string[][] { new string[] { "0", "A" }, new string[] { "1", "B" }, new string[] { "2", "C" }, new string[] { "3", "D" }, new string[] { "4", "E" }, new string[] { "5", "F" }, new string[] { "6", "G" }, new string[] { "7", "H" }, new string[] { "8", "I" }, new string[] { "9", "J" }, new string[] { "10", "K" } }; InitializeComponent(); _CurrentRow = CurrentRow; _WhseStore = WhseStore; txtOriginalBoxNo.Text = CurrentRow.Cells[2].Value.ToString(); txtOriginalBoxQty.Text = CurrentRow.Cells[4].Value.ToString(); oTxtA = new DataGridViewTextBoxColumn(); // 0 oTxtA.Visible = false; oTxtA.ValueType = typeof(int); dataGridView1.Columns.Add(oTxtA); oTxtB = new DataGridViewTextBoxColumn(); // 1 oTxtB.ValueType = typeof(string); oTxtB.HeaderText = "Box Number"; dataGridView1.Columns.Add(oTxtB); oTxtC = new DataGridViewTextBoxColumn(); // 2 oTxtC.ValueType = typeof(int); oTxtC.HeaderText = "Quantity"; dataGridView1.Columns.Add(oTxtC); oTxtD = new DataGridViewTextBoxColumn(); // 3 oTxtD.ValueType = typeof(int); oTxtD.HeaderText = "Weight"; dataGridView1.Columns.Add(oTxtD); oTxtE = new DataGridViewTextBoxColumn(); // 4 oTxtE.ValueType = typeof(string); oTxtE.HeaderText = "Grade"; dataGridView1.Columns.Add(oTxtE); oCmbA = new DataGridViewComboBoxColumn(); // 5 oCmbA.HeaderText = "Box Type"; oCmbA.ValueType = typeof(int); dataGridView1.Columns.Add(oCmbA); core = new Util(); dataGridView1.Focus(); formloaded = true; }