private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; int _LastNumber = 0; TLKNI_GreigeProduction GreigeP = null; if (oBtn != null && formloaded) { var ErrorM = core.returnMessage(MandatorySelected, false, MandatoryFields); if (!String.IsNullOrEmpty(ErrorM)) { MessageBox.Show(ErrorM); return; } var GrnNumber = (TLKNI_GreigeCommissionTransctions)cmbTrans.SelectedItem; using (var context = new TTI2Entities()) { TLADM_LastNumberUsed LNU = context.TLADM_LastNumberUsed.Find(2); if (LNU != null) { _LastNumber = LNU.col10; LNU.col10 += 1; } foreach (DataGridViewRow row in dataGridView1.Rows) { var Pk = (int)row.Cells[0].Value; if (Pk != 0) { var Existing = context.TLKNI_GreigeCommissionTransctions.Find(Pk); if (Existing != null) { var NewValue = (decimal)row.Cells[4].Value; if (NewValue != Existing.GreigeCom_NettWeight) { Existing.GreigeCom_NettWeight += NewValue; //Notes -- we must also now adjust the value in the GreigeProduction File //==================================================================== GreigeP = context.TLKNI_GreigeProduction.Where(x => x.GreigeP_KnitO_Fk == Pk).FirstOrDefault(); if (GreigeP != null) { GreigeP.GreigeP_weight += NewValue; GreigeP.GreigeP_weightAvail += NewValue; TLKNI_GreigeCommisionAdjustment adj = new TLKNI_GreigeCommisionAdjustment(); adj.GreigeComAJ_AjustmentNo = _LastNumber; adj.GreigeComAJ_AmtAdjusted = NewValue; adj.GreigeComAJ_AprovedBy = txtApprovedBy.Text; adj.GreigeComAJ_PieceNo_FK = (int)row.Cells[0].Value; adj.GreigeComAJ_Reasons = txtReason.Text; adj.GreigeComAJ_Strore_FK = (int)cmbStore.SelectedValue; adj.GreigeComAJ_TransDate = (DateTime)dtpTransactionDate.Value; adj.GreigeComAJ_GreigeProduction_FK = GreigeP.GreigeP_Pk; if (GrnNumber != null) { adj.GreigeComAJ_GrnNumber = GrnNumber.GreigeCom_GrnNo; } context.TLKNI_GreigeCommisionAdjustment.Add(adj); } } } } } try { context.SaveChanges(); MessageBox.Show("Data successfully saved to database"); dataGridView1.Rows.Clear(); SetUp(false); frmKnitViewRep vRep = new frmKnitViewRep(19, _LastNumber); 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); } } } }
void SetUp(bool Ind) { formloaded = false; using (var context = new TTI2Entities()) { TLADM_LastNumberUsed LNU = context.TLADM_LastNumberUsed.Find(2); if (LNU != null) { txtAdjustmentNumber.Text = "GA" + LNU.col10.ToString().PadLeft(4, '0'); } cmbTrans.DataSource = context.TLKNI_GreigeCommissionTransctions.OrderBy(x => x.GreigeCom_GrnNo).GroupBy(x => x.GreigeCom_GrnNo).Select(grp => grp.FirstOrDefault()).ToList(); cmbTrans.DisplayMember = "GreigeCom_GrnNo"; cmbTrans.ValueMember = "GreigeCom_Pk"; var dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("KNIT")).FirstOrDefault(); if (dept != null) { cmbStore.DataSource = context.TLADM_WhseStore.Where(x => x.WhStore_DepartmentFK == dept.Dep_Id).ToList(); cmbStore.DisplayMember = "WhStore_Description"; cmbStore.ValueMember = "WhStore_Id"; cmbStore.Enabled = true; } if (Ind) { oTxtA = new DataGridViewTextBoxColumn(); oTxtA.ValueType = typeof(int); oTxtA.HeaderText = "Key"; oTxtA.Visible = false; oTxtB = new DataGridViewTextBoxColumn(); oTxtB.ValueType = typeof(string); oTxtB.HeaderText = "Piece No"; oTxtB.Visible = true; oTxtB.ReadOnly = true; oTxtC = new DataGridViewTextBoxColumn(); oTxtC.ValueType = typeof(string); oTxtC.HeaderText = "Product"; oTxtC.ReadOnly = true; oTxtC.Visible = true; oTxtD = new DataGridViewTextBoxColumn(); oTxtD.ValueType = typeof(decimal); oTxtD.HeaderText = "Grade"; oTxtD.ReadOnly = true; oTxtD.Visible = true; oTxtE = new DataGridViewTextBoxColumn(); oTxtE.ValueType = typeof(decimal); oTxtE.HeaderText = "Adjusted Weight"; oTxtE.Visible = true; dataGridView1.Columns.Add(oTxtA); dataGridView1.Columns.Add(oTxtB); dataGridView1.Columns.Add(oTxtC); dataGridView1.Columns.Add(oTxtD); dataGridView1.Columns.Add(oTxtE); dataGridView1.CellContentClick += new DataGridViewCellEventHandler(Check_Changed); dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing); dataGridView1.AllowUserToAddRows = false; dataGridView1.AllowUserToOrderColumns = false; dataGridView1.AutoGenerateColumns = false; } MandatorySelected = core.PopulateArray(MandatoryFields.Length, false); } formloaded = true; }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLADM_LastNumberUsed LNU = null; TLCMT_PanelIssue pi = new TLCMT_PanelIssue(); TLCMT_PanelIssueDetail pid = new TLCMT_PanelIssueDetail(); TLCUT_CutSheetReceipt CSR = new TLCUT_CutSheetReceipt(); bool Add = false; if (oBtn != null && formloaded) { var selected = (TLADM_Departments)cmboCMTDepartment.SelectedItem; if (selected == null) { MessageBox.Show("Please select a CMT from the drop downlist"); return; } if (((TLADM_WhseStore)cmboDepartments.SelectedItem) == null) { MessageBox.Show("Please select Store from which to make an selection"); return; } using (var context = new TTI2Entities()) { int Number = Convert.ToInt32(label1.Text); pi = context.TLCMT_PanelIssue.Where(x => x.CMTPI_Number == Number).FirstOrDefault(); if (pi == null) { pi = new TLCMT_PanelIssue(); Add = true; } pi.CMTPI_Number = Number; pi.CMTPI_Date = dtpTransDate.Value; pi.CMTPI_Department_FK = selected.Dep_Id; pi.CMTPI_Closed = false; pi.CMTPI_DeliveryNumber = 0; pi.CMTPI_CutSheetSummary = false; pi.CMTPI_FromWhse_FK = ((TLADM_WhseStore)cmboDepartments.SelectedItem).WhStore_Id; var TransType = context.TLADM_TranactionType.Where(x => x.TrxT_Number == 100 && x.TrxT_Department_FK == selected.Dep_Id).FirstOrDefault(); if (TransType != null) { pi.CMTPI_TranType_FK = TransType.TrxT_Pk; } pi.CMTPI_Display = "DN -" + "0".PadLeft(4, ' ') + " - TL " + Number.ToString().PadLeft(5, '0'); if (Add) { context.TLCMT_PanelIssue.Add(pi); } if (Add && selected != null) { LNU = context.TLADM_LastNumberUsed.Where(x => x.LUN_Department_FK == selected.Dep_Id).FirstOrDefault(); if (LNU != null) { LNU.col1 += 1; } } try { context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } foreach (DataGridViewRow row in dataGridView1.Rows) { //--------------------------------------------------------------- if ((bool)row.Cells[2].Value == false) { continue; } Add = true; pid = new TLCMT_PanelIssueDetail(); if ((int)row.Cells[0].Value != 0) { var index = (int)row.Cells[0].Value; pid = context.TLCMT_PanelIssueDetail.Find(index); if (pid == null) { pid = new TLCMT_PanelIssueDetail(); } else { Add = false; } } //-------------------------------------------------------- pid.CMTPID_CutSheet_FK = (int)row.Cells[1].Value; pid.CMTPID_PI_FK = pi.CMTPI_Pk; pid.CMTPID_Receipted = false; pid.CMTPID_BIFabric = false; CSR = context.TLCUT_CutSheetReceipt.Find(pid.CMTPID_CutSheet_FK); if (CSR != null) { CSR.TLCUTSHR_Issued = true; } if (Add) { context.TLCMT_PanelIssueDetail.Add(pid); } } try { var SelectedRows = ( from Rows in dataGridView1.Rows.Cast <DataGridViewRow>() where (bool)Rows.Cells[2].Value == true select Rows).ToList(); foreach (var SelectedRow in SelectedRows) { var index = SelectedRow.Index; dataGridView1.Rows.RemoveAt(index); } context.SaveChanges(); MessageBox.Show("Data saved successfully to to database"); //This report has been housed in the the Cutting Form View Program.... Cutting.frmCutViewRep vRep = new Cutting.frmCutViewRep(12, pi.CMTPI_Pk); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(); } catch (System.Data.Entity.Validation.DbEntityValidationException en) { foreach (var eve in en.EntityValidationErrors) { MessageBox.Show("following validation errors: Type" + eve.Entry.Entity.GetType().Name.ToString() + "State " + eve.Entry.State.ToString()); foreach (var ve in eve.ValidationErrors) { MessageBox.Show("- Property" + ve.PropertyName + " Message " + ve.ErrorMessage); } } } catch (Exception ex) { var exceptionMessages = new StringBuilder(); do { exceptionMessages.Append(ex.Message); ex = ex.InnerException; }while (ex != null); MessageBox.Show(exceptionMessages.ToString()); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = (Button)sender; Boolean IsTicked; TLCSV_WhseTransfer WhseTrans = null; frmCSViewRep vRep = null; TLADM_LastNumberUsed LNU = null; if (oBtn != null && FormLoaded) { // Check that the user ie the blonde has checked at least one record //-------------------------------------------------------------------- var SingleRow = (from Rows in dataGridView1.Rows.Cast <DataGridViewRow>() where (bool)Rows.Cells[1].Value == true select Rows).FirstOrDefault(); if (SingleRow == null) { MessageBox.Show("Please select at least one record"); return; } using (var context = new TTI2Entities()) { foreach (DataGridViewRow Row in dataGridView2.Rows) { IsTicked = (bool)Row.Cells[1].Value; var Pk = (int)Row.Cells[0].Value; TLCSV_WhseTransferDetail WhseDetail = context.TLCSV_WhseTransferDetail.Find(Pk); if (!IsTicked && WhseDetail != null) { context.TLCSV_WhseTransferDetail.Remove(WhseDetail); } else if (WhseDetail != null) { if (WhseTrans == null) { WhseTrans = context.TLCSV_WhseTransfer.Find(WhseDetail.TLCSVWHTD_WhseTranfer_FK); } var SOH = context.TLCSV_StockOnHand.Find(WhseDetail.TLCSVWHTD_TLSOH_Fk); if (SOH != null && WhseTrans != null) { if (InterWhseDel && oChkConfirmation.Checked) { SOH.TLSOH_WareHouse_FK = WhseTrans.TLCSVWHT_ToWhse_Fk; SOH.TLSOH_InTransit = false; } else { if (!InterWhseDel) { SOH.TLSOH_WareHouse_FK = WhseTrans.TLCSVWHT_ToWhse_Fk; SOH.TLSOH_InTransit = false; } else { SOH.TLSOH_InTransit = true; } } } if (InterWhseDel) { WhseDetail.TLCSVWHTD_DeliveryNote = true; } else { WhseDetail.TLCSVWHTD_Receipted = true; } } } var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "CSV").FirstOrDefault(); if (Dept != null) { LNU = context.TLADM_LastNumberUsed.Where(x => x.LUN_Department_FK == Dept.Dep_Id).FirstOrDefault(); if (InterWhseDel) { WhseTrans.TLCSVWHT_DeliveryNo = LNU.col7; LNU.col7 += 1; WhseTrans.TLCSVWHT_DeliveryNote = true; WhseTrans.TLCSVWHT_Date = DateTime.Now; if (oChkConfirmation.Checked) { WhseTrans.TLCSVWHT_ReceiptNo = LNU.col8; LNU.col8 += 1; WhseTrans.TLCSVWHT_Receipted = true; WhseTrans.TLCSVWHT_Receipt_Date = DateTime.Now; } } else { WhseTrans.TLCSVWHT_ReceiptNo = LNU.col8; LNU.col8 += 1; WhseTrans.TLCSVWHT_Receipted = true; WhseTrans.TLCSVWHT_Receipt_Date = DateTime.Now; } } try { context.SaveChanges(); MessageBox.Show("data successfully saved to database"); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } if (oChkConfirmation.Checked) { InterWhseDel = false; } if (InterWhseDel) { vRep = new frmCSViewRep(19, WhseTrans.TLCSVWHT_Pk); } else { vRep = new frmCSViewRep(20, WhseTrans.TLCSVWHT_Pk); } int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); this.Close(); } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; bool lAdd = false; bool lCMT = false; bool lSuccess = true; if (oBtn != null) { using (var context = new TTI2Entities()) { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[1].Value == null) { continue; } TLADM_Departments dpt = new TLADM_Departments(); if (row.Cells[0].Value == null) { lAdd = true; } else { int pk = Convert.ToInt32(row.Cells[0].Value.ToString()); dpt = context.TLADM_Departments.Find(pk); } dpt.Dep_ShortCode = row.Cells[1].Value.ToString(); dpt.Dep_Description = row.Cells[2].Value.ToString(); dpt.Dep_UOM = Convert.ToInt32(row.Cells[3].Value.ToString()); dpt.Dep_ProductType_FK = Convert.ToInt32(row.Cells[4].Value.ToString()); if (row.Cells[5].Value == null && lAdd) { dpt.Dep_PowerN = (int)Math.Pow(2.00D, (double)row.Index); } else { dpt.Dep_PowerN = Convert.ToInt32(row.Cells[5].Value.ToString()); } if (row.Cells[6].Value != null) { if ((row.Cells[6].Value.ToString() == Boolean.TrueString)) { dpt.Dep_IsCMT = true; } } else { dpt.Dep_IsCMT = false; } if (row.Cells[7].Value != null) { if ((row.Cells[7].Value.ToString() == Boolean.TrueString)) { dpt.Dep_IsCut = true; } } else { dpt.Dep_IsCut = false; } if (lAdd) { context.TLADM_Departments.Add(dpt); } lCMT = dpt.Dep_IsCMT; try { context.SaveChanges(); // We need to add a record to the TLADM_LastNumberUsed table if (lAdd) { TLADM_LastNumberUsed LstNumberUsed = new TLADM_LastNumberUsed(); LstNumberUsed.LUN_Department_FK = dpt.Dep_Id; LstNumberUsed.col1 = 1; LstNumberUsed.col2 = 1; LstNumberUsed.col3 = 1; LstNumberUsed.col4 = 1; LstNumberUsed.col5 = 1; LstNumberUsed.col6 = 1; LstNumberUsed.col7 = 1; LstNumberUsed.col8 = 1; LstNumberUsed.col9 = 1; LstNumberUsed.col10 = 1; LstNumberUsed.col11 = 1; LstNumberUsed.col12 = 1; LstNumberUsed.col13 = 1; var LstNumber = context.TLADM_LastNumberUsed.Where(x => x.LUN_Department_FK == dpt.Dep_Id).FirstOrDefault(); if (LstNumber == null) { context.TLADM_LastNumberUsed.Add(LstNumberUsed); context.SaveChanges(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); lSuccess = false; } } } if (lSuccess) { dataGridView1.Rows.Clear(); string Mess = string.Empty; if (lCMT) { Mess = "A new CMT has just been added" + Environment.NewLine; Mess += "Please proceed to tranaction types to add a tranaction 100 to the relevant CMT's" + Environment.NewLine; Mess += "If unsure please contact system developer for assistance" + Environment.NewLine; } Mess += "Records successfully stored to database"; MessageBox.Show(Mess); } } }
private void btnSave_Click(object sender, EventArgs e) { IList <TLDYE_DyeBatch> DB = new List <TLDYE_DyeBatch>(); Button oBtn = sender as Button; TLADM_TranactionType TranType = null; TLADM_LastNumberUsed LNU = null; if (oBtn != null && formloaded) { using (var context = new TTI2Entities()) { if (_Commission) { // This is for Commission Deliveries //============================================ if (!rbCommissionDeliveriesReprint.Checked) { var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "DYE").FirstOrDefault(); if (Dept != null) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1300).FirstOrDefault(); } LNU = context.TLADM_LastNumberUsed.Find(3); if (LNU != null) { LNU.col9 += 1; } foreach (var Batch in QueryParms.DyeBatches) { var DyeBatchDetails = context.TLDYE_DyeBatchDetails.Where(x => x.DYEBD_DyeBatch_FK == Batch.DYEB_Pk).ToList(); foreach (var Detail in DyeBatchDetails) { Detail.DYEBO_CurrentStore_FK = (int)TranType.TrxT_ToWhse_FK; Detail.DYEBO_TransactionNo = TxtTransNumber.Text; Detail.DYEBO_DateSold = dtpTransDate.Value; Detail.DYEBO_Sold = true; } } try { context.SaveChanges(); MessageBox.Show("Data succesfully saved to database"); String TransNumber = TxtTransNumber.Text.Trim(); QueryParms.CommDyeing = false; StringBuilder sb = new StringBuilder(); sb.Append(richTextBox1.Text); QueryParms.Notes = sb; if (rbCommissionDyeing.Checked) { QueryParms.CommDyeing = true; } else { QueryParms.CommDyeing = false; } frmDyeViewReport vRep = new frmDyeViewReport(17, QueryParms, TransNumber); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); vRep = new frmDyeViewReport(16, QueryParms, TransNumber); h = Screen.PrimaryScreen.WorkingArea.Height; w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); frmCommissionDeliveries_Load(this, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { QueryParms.CommDyeingReprint = true; String TransNumber = string.Empty; foreach (var DBDet in QueryParms.DyeBatchDetails) { TransNumber = DBDet.DYEBO_TransactionNo; } var DyeBatches = (from DyeBatch in context.TLDYE_DyeBatch join DyeBatchDetails in context.TLDYE_DyeBatchDetails on DyeBatch.DYEB_Pk equals DyeBatchDetails.DYEBD_DyeBatch_FK where DyeBatchDetails.DYEBO_TransactionNo == TransNumber select DyeBatch).GroupBy(x => x.DYEB_BatchNo); foreach (var DBatch in DyeBatches) { var Pk = DBatch.FirstOrDefault().DYEB_Pk; QueryParms.DyeBatches.Add(repo.LoadDyeBatch(Pk)); } frmDyeViewReport vRep = new frmDyeViewReport(17, QueryParms, TransNumber); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); vRep = new frmDyeViewReport(16, QueryParms, TransNumber); h = Screen.PrimaryScreen.WorkingArea.Height; w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); frmCommissionDeliveries_Load(this, null); } } else { // This is for Fabric Sales //============================================================ QueryParms.FabricSales = true; frmDyeViewReport vRep = new frmDyeViewReport(17, QueryParms); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); vRep = new frmDyeViewReport(16, QueryParms); h = Screen.PrimaryScreen.WorkingArea.Height; w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); frmCommissionDeliveries_Load(this, null); } } } else { } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLCSV_StockOnHand SOH = null; if (oBtn != null && formloaded) { var SingleRow = (from Rows in dataGridView1.Rows.Cast <DataGridViewRow>() where (string)Rows.Cells[4].Value == String.Empty && (int)Rows.Cells[2].Value != 0 select Rows).FirstOrDefault(); if (SingleRow != null) { MessageBox.Show("There is a record with no grade assigned. Row No " + SingleRow.Index.ToString(), "error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var Total = this.dataGridView1.Rows.Cast <DataGridViewRow>() .Sum(x => Convert.ToInt32(x.Cells[2].Value.ToString())); var OriginalQty = Convert.ToInt32(txtOriginalBoxQty.Text); if (Total > OriginalQty) { MessageBox.Show("New quantity greater than original qty" + Environment.NewLine + "Please correct"); return; } if (OriginalQty - Total != 0 && !_WhseStore.WhStore_RePack) { MessageBox.Show("The total split must be equal to original qty"); return; } if (txtAuthorised.Text.Length == 0) { MessageBox.Show("Please complete the Authorised by"); return; } using (var context = new TTI2Entities()) { var MainIndex = (int)_CurrentRow.Cells[0].Value; TLADM_LastNumberUsed LNU = null; decimal number; var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("CSV")).FirstOrDefault(); if (Dept != null) { LNU = context.TLADM_LastNumberUsed.Where(x => x.LUN_Department_FK == Dept.Dep_Id).FirstOrDefault(); } SOH = context.TLCSV_StockOnHand.Find(MainIndex); foreach (DataGridViewRow row in this.dataGridView1.Rows) { if ((int)row.Cells[2].Value == 0) { continue; } TLCSV_BoxSplit BoxSplit = new TLCSV_BoxSplit(); bool Add = true; var index = 0; if (row.Cells[0].Value != null) { index = (int)row.Cells[0].Value; BoxSplit = context.TLCSV_BoxSplit.Find(index); if (BoxSplit == null) { BoxSplit = new TLCSV_BoxSplit(); } else { Add = false; } } BoxSplit.TLCMTBS_BoxNo = row.Cells[1].Value.ToString(); BoxSplit.TLCMTBS_AuthorisedBy = this.txtAuthorised.Text; BoxSplit.TLCMTBS_Completed_FK = MainIndex; BoxSplit.TLCMTBS_Grade = row.Cells[4].Value.ToString().ToUpper(); BoxSplit.TLCMTBS_Qty = (int)row.Cells[2].Value; number = Decimal.Parse(row.Cells[3].Value.ToString()); BoxSplit.TLCMTBS_Weight = number; BoxSplit.TLCMTBS_AdjustmentNo = LNU.col1; if (Add) { context.TLCSV_BoxSplit.Add(BoxSplit); } //now we need to add the box to the Stock on Hand table //------------------------------------------------------------------ if (SOH != null) { TLCSV_StockOnHand SplitB = new TLCSV_StockOnHand(); SplitB.TLSOH_BoxSelected_FK = SOH.TLSOH_BoxSelected_FK; SplitB.TLSOH_CMT_FK = SOH.TLSOH_CMT_FK; SplitB.TLSOH_Customer_Fk = SOH.TLSOH_Customer_Fk; SplitB.TLSOH_DateIntoStock = SOH.TLSOH_DateIntoStock; SplitB.TLSOH_DNListDate = SOH.TLSOH_DNListDate; SplitB.TLSOH_DNListNo = SOH.TLSOH_DNListNo; SplitB.TLSOH_MoveAdjust_FK = SOH.TLSOH_MoveAdjust_FK; SplitB.TLSOH_Movement_FK = SOH.TLSOH_Movement_FK; SplitB.TLSOH_Notes = SOH.TLSOH_Notes; SplitB.TLSOH_PastelNumber = SOH.TLSOH_PastelNumber; SplitB.TLSOH_Picked = SOH.TLSOH_Picked; SplitB.TLSOH_PickListDate = SOH.TLSOH_PickListDate; SplitB.TLSOH_PickListNo = SOH.TLSOH_PickListNo; SplitB.TLSOH_POOrder_FK = SOH.TLSOH_POOrder_FK; SplitB.TLSOH_POOrderDetail_FK = SOH.TLSOH_POOrderDetail_FK; SplitB.TLSOH_QtyAdjusted = SOH.TLSOH_QtyAdjusted; SplitB.TLSOH_Returned = SOH.TLSOH_Returned; SplitB.TLSOH_ReturnedBoxQty = SOH.TLSOH_ReturnedBoxQty; SplitB.TLSOH_ReturnedDate = SOH.TLSOH_ReturnedDate; SplitB.TLSOH_ReturnedWeight = SOH.TLSOH_ReturnedWeight; SplitB.TLSOH_ReturnNumber = SOH.TLSOH_ReturnNumber; SplitB.TLSOH_Size_FK = SOH.TLSOH_Size_FK; SplitB.TLSOH_Sold = SOH.TLSOH_Sold; SplitB.TLSOH_SoldDate = SOH.TLSOH_SoldDate; SplitB.TLSOH_Style_FK = SOH.TLSOH_Style_FK; SplitB.TLSOH_Transfered = SOH.TLSOH_Transfered; SplitB.TLSOH_TransferNotes = SOH.TLSOH_TransferNotes; SplitB.TLSOH_WareHouse_FK = SOH.TLSOH_WareHouse_FK; SplitB.TLSOH_WareHouseDeliveryNo = SOH.TLSOH_WareHouseDeliveryNo; SplitB.TLSOH_WareHousePickList = SOH.TLSOH_WareHousePickList; SplitB.TLSOH_Colour_FK = SOH.TLSOH_Colour_FK; SplitB.TLSOH_CutSheet_FK = SOH.TLSOH_CutSheet_FK; SplitB.TLSOH_BoxedQty = BoxSplit.TLCMTBS_Qty; SplitB.TLSOH_BoxNumber = BoxSplit.TLCMTBS_BoxNo; SplitB.TLSOH_Split = false; SplitB.TLSOH_Weight = number; SplitB.TLSOH_Grade = BoxSplit.TLCMTBS_Grade; if (row.Cells[5].Value != null) { SplitB.TLSOH_BoxType = (int)row.Cells[5].Value; } else { SplitB.TLSOH_BoxType = 1; } context.TLCSV_StockOnHand.Add(SplitB); } } try { if (SOH != null) { SOH.TLSOH_BoxedQty = OriginalQty - Total; if (!_WhseStore.WhStore_RePack) { SOH.TLSOH_Split = true; } else if (SOH.TLSOH_BoxedQty == 0) { SOH.TLSOH_Split = true; } } LNU.col1 += 1; context.SaveChanges(); MessageBox.Show("Data saved successfully to database"); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }