private void btnSave_Click(object sender, EventArgs e) { TLSPN_CottonReceivedBales bales; Button oBtn = sender as Button; if (oBtn != null & formloaded) { if (RowsSelected != null && rbWriteOff.Checked) { var cnt = RowsSelected.Where(x => x == false).Count(); if (cnt == RowsSelected.Count()) { MessageBox.Show("Please select at least one row from the grid as shown"); return; } } var errorM = core.returnMessage(MandSelected, true, MandatoryFields); if (!string.IsNullOrEmpty(errorM)) { MessageBox.Show(errorM); return; } var LotDetails = (TLSPN_CottonTransactions)cmbLotNo.SelectedItem; //dont forget last number used //------------------------------------------- using (var context = new TTI2Entities()) { var LastNumber = context.TLADM_LastNumberUsed.Find(1); if (LastNumber != null) { LastNumber.col3 += 1; } // 0 // 1 Selected // 2 Bales Numeric // 3 MIC Decimal // 4 kgs (NETT) Decimal // 5 Staple Decimal // 6 kgs (GROSS) decimal int NoBales = 0; decimal NettMass = 0M; decimal GrossMass = 0M; var ContractDetails = (TLADM_CottonContracts)cmbContractNo.SelectedItem; foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[1].Value == null || (bool)row.Cells[1].Value == false) { continue; } NoBales += 1; NettMass += (decimal)row.Cells[4].Value; GrossMass += (decimal)row.Cells[6].Value; if (rbWriteOn.Checked) { TLSPN_CottonReceivedBales Bales = new TLSPN_CottonReceivedBales(); Bales.CotBales_BaleNo = (int)row.Cells[2].Value; Bales.CotBales_Mic = (decimal)row.Cells[3].Value; Bales.CotBales_Staple = (decimal)row.Cells[5].Value; Bales.CotBales_Weight_Nett = (decimal)row.Cells[4].Value; Bales.CotBales_LotNo = LotDetails.cotrx_LotNo; Bales.CotBales_Weight_Gross = (decimal)row.Cells[6].Value; Bales.CoBales_CottonSequence = Convert.ToInt32(txtAdjustmentNumber.Text); context.TLSPN_CottonReceivedBales.Add(Bales); } else { bales = context.TLSPN_CottonReceivedBales.Find((int)row.Cells[0].Value); if (bales != null) { if ((bool)row.Cells[1].Value == true) { bales.CoBales_CottonReturned = true; bales.CoBales_CottonSequence = Convert.ToInt32(txtAdjustmentNumber.Text); try { context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } } //---------------------------------------------------------------------------- // //------------------------------------------------------------------------------ TLSPN_CottonTransactions cotTrans = new TLSPN_CottonTransactions(); cotTrans.cotrx_TransDate = dateTimePicker1.Value; cotTrans.cotrx_ContractNo_Fk = ContractDetails.CottonCon_Pk; cotTrans.cotrx_LotNo = Convert.ToInt32(cmbLotNo.SelectedValue); cotTrans.cotrx_NetWeight = NettMass; cotTrans.cotrx_GrossWeight = GrossMass; cotTrans.cotrx_NoBales = NoBales; //cotTrans.cotrx_VehReg_FK = null; cotTrans.cotrx_WeighBridgeFull = 0; cotTrans.cotrx_WeighBridgeEmpty = 0; cotTrans.cotrx_NettPerWB = 0; cotTrans.cotrx_Return_No = Convert.ToInt32(txtAdjustmentNumber.Text); cotTrans.cotrx_Supplier_FK = ContractDetails.CottonCon_ConSupplier_FK; cotTrans.cotrx_Notes = rtbNotes.Text; //------------------------------------------------------------------------- // Consult Table TLADM_TranTypes //---------------------------------------------------------------------------- var DepDetail = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "SPIN").FirstOrDefault(); if (DepDetail != null) { var Trantype = context.TLADM_TranactionType.Where(x => x.TrxT_Number == 400 && x.TrxT_Department_FK == DepDetail.Dep_Id).FirstOrDefault(); if (Trantype != null) { cotTrans.cotrx_TranType = Trantype.TrxT_Pk; } } if (rbWriteOff.Checked) { cotTrans.cotrx_WriteOff = true; } else { cotTrans.cotrx_WriteOff = false; } //------------------------------------------------------------------------ context.TLSPN_CottonTransactions.Add(cotTrans); //----------------------------------------------------------- // //------------------------------------------------------------ string Mach_IP = Dns.GetHostEntry(Dns.GetHostName()) .AddressList.First(f => f.AddressFamily == AddressFamily.InterNetwork) .ToString(); TLADM_DailyLog DailyLog = new TLADM_DailyLog(); DailyLog.TLDL_IPAddress = Mach_IP; DailyLog.TLDL_Dept_Fk = DepDetail.Dep_Id; DailyLog.TLDL_Date = DateTime.Now; DailyLog.TLDL_TransDetail = "Cotton Adjustment"; DailyLog.TLDL_AuthorisedBy = txtAdjustmentNumber.Text; DailyLog.TLDL_Comments = txtAdjustmentNumber.Text; context.TLADM_DailyLog.Add(DailyLog); try { context.SaveChanges(); var Retno = Convert.ToInt32(txtAdjustmentNumber.Text); frmViewReport vRep = new frmViewReport(4, Retno); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); SetUp(); MessageBox.Show("Data saved to database successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { bool Update = false; Button oBtn = sender as Button; if (oBtn != null && formloaded) { var selected = (TLCUT_CutSheet)cmboCutSheet.SelectedItem; if (selected == null) { MessageBox.Show("Please select a cut sheet from the drop down list "); return; } var WhseSelected = (TLADM_WhseStore)cmboRejectStore.SelectedItem; if (WhseSelected == null) { MessageBox.Show("Please select a reject store from the drop down list"); return; } if (String.IsNullOrEmpty(txtAuthorisedBy.Text)) { MessageBox.Show("Please complete the approved by details"); return; } using (var context = new TTI2Entities()) { var CSR = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == selected.TLCutSH_Pk).FirstOrDefault(); CutReportOptions cropts = new CutReportOptions(); cropts.remarks = rtbNotes.Text; cropts.TransDate = dtpTransDate.Value; cropts.ApprovedBy = txtAuthorisedBy.Text; cropts.Pk = CSR.TLCUTSHR_Pk; cropts.CutSheetPk = selected.TLCutSH_Pk; cropts.ReturnedTo = context.TLADM_WhseStore.Find(WhseSelected.WhStore_Id).WhStore_Description; var cs = context.TLCUT_CutSheet.Find(selected.TLCutSH_Pk); if (cs != null) { cs.TLCutSH_Notes = rtbNotes.Text; } foreach (DataGridViewRow row in dataGridView1.Rows) { if ((bool)row.Cells[1].Value == false) { continue; } //------------------------------------------------------ // 1st Step reduce the SOH with what was written off //----------------------------------------------------------- var index = (int)row.Cells[0].Value; var CSRD = context.TLCUT_CutSheetReceiptDetail.Find(index); if (CSRD != null) { CSRD.TLCUTSHRD_RejectQty += (int)row.Cells[6].Value; CSRD.TLCUTSHRD_RejectDate = dtpTransDate.Value; CSRD.TLCUTSHRD_RejectReason = (int)row.Cells[5].Value; } //------------------------------------------------- // Now create a new Record of the written off value //--------------------------------------------------- TLCUT_CutSheetReceiptDetail NewCSR = new TLCUT_CutSheetReceiptDetail(); NewCSR.TLCUTSHRD_CutSheet_FK = CSR.TLCUTSHR_Pk; NewCSR.TLCUTSHRD_Description = row.Cells[2].Value.ToString() + "R"; NewCSR.TLCUTSHRD_Size_FK = (int)row.Cells[3].Value; NewCSR.TLCUTSHRD_BundleQty = (int)row.Cells[4].Value; NewCSR.TLCUTSHRD_BoxUnits = 0; NewCSR.TLCUTSHRD_TransactionType = 55; NewCSR.TLCUTSHRD_CurrentStore_FK = WhseSelected.WhStore_Id; NewCSR.TLCUTSHRD_PanelRejected = true; NewCSR.TLCUTSHRD_RejectDate = dtpTransDate.Value; NewCSR.TLCUTSHRD_RejectQty = (int)row.Cells[6].Value; NewCSR.TLCUTSHRD_RejectReason = (int)row.Cells[5].Value; context.TLCUT_CutSheetReceiptDetail.Add(NewCSR); Update = true; } //------------------------------------------------------- // //----------------------------------------------------------- string Mach_IP = Dns.GetHostEntry(Dns.GetHostName()) .AddressList.First(f => f.AddressFamily == AddressFamily.InterNetwork) .ToString(); var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("CUT")).FirstOrDefault(); TLADM_DailyLog DailyLog = new TLADM_DailyLog(); DailyLog.TLDL_IPAddress = Mach_IP; DailyLog.TLDL_Dept_Fk = Dept.Dep_Id; DailyLog.TLDL_Date = DateTime.Now; DailyLog.TLDL_TransDetail = "Cutting Dept Panel Rejected"; DailyLog.TLDL_AuthorisedBy = txtAuthorisedBy.Text;; DailyLog.TLDL_Comments = rtbNotes.Text; context.TLADM_DailyLog.Add(DailyLog); //---------------------------------------------------------- if (Update) { try { context.SaveChanges(); MessageBox.Show("Data saved successfully to database"); frmCutViewRep vRep = new frmCutViewRep(3, cropts); 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); } } } } }
private void button1_Click(object sender, EventArgs e) { Button oBtn = sender as Button; decimal Weight = 0.00M; int CurrentStore_FK = 0; TLADM_TranactionType TT = null; TLADM_Departments Depts = null; TLDYE_DyeTransactions dt = null; if (oBtn != null && formloaded) { var errorM = core.returnMessage(MandSelected, true, MandatoryFields); if (!string.IsNullOrEmpty(errorM)) { MessageBox.Show(errorM); return; } var selected = (TLDYE_DyeBatch)cmboDyeBatches.SelectedItem; using (var context = new TTI2Entities()) { var LNU = context.TLADM_LastNumberUsed.Find(3); if (LNU != null) { LNU.col6 += 1; } var TotalWeight = 0.00M; //--------- first attend to current records foreach (DataGridViewRow row in dataGridView1.Rows) { if ((bool)row.Cells[1].Value == false) { continue; } Weight = (decimal)row.Cells[3].Value; TotalWeight += Weight; var Pk = (int)row.Cells[0].Value; if (Pk != 0) { var Record = context.TLDYE_DyeBatchDetails.Find(Pk); if (Record != null) { Record.DYEBO_AdjustedWeight = Weight; Record.DYEBO_TransactionNo = txtNumber.Text; Record.DYEBO_WriteOff = true; Depts = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("DYE")).FirstOrDefault(); if (Depts != null) { TT = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Depts.Dep_Id && x.TrxT_Number == 1000).FirstOrDefault(); if (TT != null) { Record.DYEBO_CurrentStore_FK = (int)TT.TrxT_ToWhse_FK; CurrentStore_FK = (int)TT.TrxT_ToWhse_FK; } } } } } dt = new TLDYE_DyeTransactions(); dt.TLDYET_BatchNo = selected.DYEB_BatchNo; dt.TLDYET_Date = DateTime.Now; dt.TLDYET_SequenceNo = selected.DYEB_SequenceNo; dt.TLDYET_CurrentStore_FK = CurrentStore_FK; dt.TLDYET_TransactionWeight = TotalWeight; dt.TLDYET_AuthorisedBy = txtApprovedBy.Text; dt.TLDYET_Adjustment_Reasons = txtReasons.Text; dt.TLDYET_TransactionType = TT.TrxT_Pk; dt.TLDYET_BatchWeight = selected.DYEB_BatchKG; dt.TLDYET_Batch_FK = selected.DYEB_Pk; dt.TLDYET_TransactionNumber = txtNumber.Text; context.TLDYE_DyeTransactions.Add(dt); //--------------------------------------------------------------------- // This is the daily log file that needs to be updated //------------------------------------------------------- string Mach_IP = Dns.GetHostEntry(Dns.GetHostName()) .AddressList.First(f => f.AddressFamily == AddressFamily.InterNetwork) .ToString(); TLADM_DailyLog DailyLog = new TLADM_DailyLog(); DailyLog.TLDL_IPAddress = Mach_IP; DailyLog.TLDL_Dept_Fk = Depts.Dep_Id; DailyLog.TLDL_Date = DateTime.Now; DailyLog.TLDL_TransDetail = "Dye House Adjustment"; DailyLog.TLDL_AuthorisedBy = txtApprovedBy.Text; DailyLog.TLDL_Comments = txtNumber.Text; context.TLADM_DailyLog.Add(DailyLog); try { context.SaveChanges(); MessageBox.Show("Data successfully stored to database"); frmDyeViewReport vRep = new frmDyeViewReport(15, dt.TLDYET_Pk); vRep.ShowDialog(this); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } } }
private void btnSave_Click(object sender, EventArgs e) { // dont forget last number used~!!!!! TLADM_Departments DeptDetail; Button oBtn = sender as Button; if (oBtn != null && formloaded) { var ErrorM = core.returnMessage(MandSelected, true, MandatoryFields); if (!String.IsNullOrEmpty(ErrorM)) { MessageBox.Show(ErrorM); return; } using (var context = new TTI2Entities()) { var LastNumber = context.TLADM_LastNumberUsed.Find(1); if (LastNumber != null) { LastNumber.col11 += 1; } //--------------------------------------------------------- TLSPN_YarnTransactions YarnT = new TLSPN_YarnTransactions(); //------------------------------------------------------------- // Review Document for a list of transaction numbers //------------------------------------------------------------- //------------------------------------------------------------- var YO = (TLSPN_YarnOrder)cmboYarnNo.SelectedItem; if (YO != null) { YarnT.YarnTrx_YarnOrder_FK = YO.YarnO_Pk; } //---------------------------------------------------------------------------------------------------- DeptDetail = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "SPIN").FirstOrDefault(); if (DeptDetail != null) { var tranDetail = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == DeptDetail.Dep_Id && x.TrxT_Number == 1100).FirstOrDefault(); if (tranDetail != null) { YarnT.YarnTrx_TranType_FK = tranDetail.TrxT_Pk; YarnT.YarnTrx_ToDep_FK = tranDetail.TrxT_ToWhse_FK; YarnT.YarnTrx_FromDep_FK = tranDetail.TrxT_FromWhse_FK; } } //------------------------------------------------------------------------------- YarnT.YarnTrx_SequenceNo = Convert.ToInt32(txtDeliveryNoteNumber.Text); YarnT.YarnTrx_Date = dateTimePicker1.Value; var PalletNo = (TLSPN_YarnOrderPallets)cmboPalletNumbers.SelectedItem; if (PalletNo != null) { if (_Mode) { YarnT.YarnTrx_PalletNo_Fk = PalletNo.YarnOP_Pk; } else { var PLT = context.TLKNI_YarnOrderPallets.Where(x => x.TLKNIOP_PalletNo == PalletNo.YarnOP_PalletNo).FirstOrDefault(); if (PLT != null) { YarnT.YarnTrx_PalletNo_Fk = PLT.TLKNIOP_Pk; } } } YarnT.YarnTrx_ApprovedBy = txtApprovedBy.Text; YarnT.YarnTrx_Reasons = rtbReasons.Text; var NoCones = Convert.ToInt32(txtNumberOfCones.Text); YarnT.YarnTrx_Cones = NoCones; var NettWeight = Convert.ToDecimal(txtNettWeight.Text); YarnT.YarnTrx_NettWeight = NettWeight; if (_Mode) { var PalletStore = context.TLSPN_YarnOrderPallets.Find(PalletNo.YarnOP_Pk); if (PalletStore != null) { if (rbWriteOff.Checked) { PalletStore.YarnOP_NoOfConesSpun -= NoCones; PalletStore.YarnOP_NettWeight -= NettWeight; YarnT.YarnTrx_WriteOff = true; } else { PalletStore.YarnOP_NoOfConesSpun += NoCones; PalletStore.YarnOP_NettWeight += NettWeight; YarnT.YarnTrx_WriteOff = false; } } } else { var PalletStore = context.TLKNI_YarnOrderPallets.Find(YarnT.YarnTrx_PalletNo_Fk); if (PalletStore != null) { if (rbWriteOff.Checked) { PalletStore.TLKNIOP_Cones -= NoCones; PalletStore.TLKNIOP_NettWeight -= NettWeight; YarnT.YarnTrx_WriteOff = true; } else { PalletStore.TLKNIOP_Cones += NoCones; PalletStore.TLKNIOP_NettWeight += NettWeight; YarnT.YarnTrx_WriteOff = false; } } } String Mach_IP = Dns.GetHostEntry(Dns.GetHostName()) .AddressList.First(f => f.AddressFamily == AddressFamily.InterNetwork) .ToString(); TLADM_DailyLog DailyLog = new TLADM_DailyLog(); DailyLog.TLDL_IPAddress = Mach_IP; DailyLog.TLDL_Dept_Fk = DeptDetail.Dep_Id; DailyLog.TLDL_Date = DateTime.Now; DailyLog.TLDL_TransDetail = "Yarn Adjustment"; DailyLog.TLDL_AuthorisedBy = txtApprovedBy.Text; DailyLog.TLDL_Comments = string.Empty; context.TLADM_DailyLog.Add(DailyLog); try { context.TLSPN_YarnTransactions.Add(YarnT); context.SaveChanges(); Transactions = true; SetUp(); MessageBox.Show("Records stored successfully to database"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLADM_TranactionType TranType = null; int GProdKey = 0; TLADM_Departments Dept = null; if (oBtn != null && formloaded) { var ErrorM = core.returnMessage(MandatorySelected, true, MandatoryFields); if (!String.IsNullOrEmpty(ErrorM)) { MessageBox.Show(ErrorM); return; } var KO = (TLKNI_Order)cmbKnitOrder.SelectedItem; if (KO != null) { using (var context = new TTI2Entities()) { // We may have added some records //-------------------------------------------- var Machine = context.TLADM_MachineDefinitions.Find(KO.KnitO_Machine_FK); if (Machine != null) { if (MLNU > Machine.MD_LastNumberUsed) { Machine.MD_LastNumberUsed = MLNU + 1; } } var LNU = context.TLADM_LastNumberUsed.Find(2); if (LNU != null) { LNU.col8 += 1; } Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("KNIT")).FirstOrDefault(); if (Dept != null) { if (KO.KnitO_YarnO_FK == null) { if (KO.KnitO_CommisionCust) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 2002).FirstOrDefault(); } else { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 2003).FirstOrDefault(); } } else { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 2001).FirstOrDefault(); } } foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[0].Value == null) continue; var Pk = (int)row.Cells[0].Value; if (Pk != 0) { var GreigeProd = context.TLKNI_GreigeProduction.Find(Pk); if (GreigeProd != null) { var NewValue = (Decimal)row.Cells[3].Value; if (NewValue != GreigeProd.GreigeP_weight) { GreigeProd.GreigeP_weight += NewValue; TLKNI_GreigeTransactions GreigeT = new TLKNI_GreigeTransactions(); GreigeT.GreigeT_AdjustedWeight = NewValue; if (row.Cells[2].Value != null) GreigeT.GreigeT_Grade = row.Cells[2].Value.ToString(); else GreigeT.GreigeT_Grade = string.Empty; GreigeT.GreigeT_KOrder_FK = KO.KnitO_Pk; if ((int)row.Cells[0].Value == 0) GreigeT.GreigeT_Piece_FK = GProdKey; else GreigeT.GreigeT_Piece_FK = (int)row.Cells[0].Value; GreigeT.GreigeT_TransactionDate = dtpAdjustDate.Value; GreigeT.GreigeT_TransactionNumber = LNU.col8 - 1; GreigeT.GreigeT_TransactionType_FK = TranType.TrxT_Pk; GreigeT.GreigeT_ApprovedBy = txtApprovedBy.Text; context.TLKNI_GreigeTransactions.Add(GreigeT); } } } } string Mach_IP = Dns.GetHostEntry(Dns.GetHostName()) .AddressList.First(f => f.AddressFamily == AddressFamily.InterNetwork) .ToString(); TLADM_DailyLog DailyLog = new TLADM_DailyLog(); DailyLog.TLDL_IPAddress = Mach_IP; DailyLog.TLDL_Dept_Fk = Dept.Dep_Id; DailyLog.TLDL_Date = DateTime.Now; DailyLog.TLDL_TransDetail = "Greige Adjustment"; DailyLog.TLDL_AuthorisedBy = txtApprovedBy.Text; DailyLog.TLDL_Comments = txtGreigeAdjNo.Text; try { context.TLADM_DailyLog.Add(DailyLog); context.SaveChanges(); MessageBox.Show("Data saved successfully to database"); SetUp(false); frmKnitViewRep vRep = new frmKnitViewRep(14, LNU.col8 - 1); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); } 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) { MessageBox.Show(ex.Message); } } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLCSV_OrderAllocated OrderAllocated = null; Repository repo = new Repository(); CSVServices services = new CSVServices(); shirtParameters = new CustomerServicesParameters(); if (oBtn != null && formloaded) { var WareHouse = (TLADM_WhseStore)cmboWareHouse.SelectedItem; if (WareHouse == null) { MessageBox.Show("Please select a warehouse from the drop down box"); return; } if (txtCustomerRef.Text.Length == 0) { MessageBox.Show("Please enter a customer reference"); return; } if (txtReasons.Text.Length == 0) { MessageBox.Show("Please enter the reason these goods are being returned"); return; } if (txtApprovedBy.Text.Length == 0) { MessageBox.Show("Please enter the name of the approver"); return; } //---------------------------------------------------------------------------------- using (var context = new TTI2Entities()) { foreach (DataGridViewRow row in dataGridView1.Rows) { if ((bool)row.Cells[1].Value == false) { continue; } OrderAllocated = new TLCSV_OrderAllocated(); var Pk = (int)row.Cells[0].Value; OrderAllocated = context.TLCSV_OrderAllocated.Find(Pk); if (OrderAllocated != null) { OrderAllocated.TLORDA_Returned = true; OrderAllocated.TLORDA_ReturnCustRef = txtCustomerRef.Text; OrderAllocated.TLORDA_ApprovedBy = txtApprovedBy.Text; OrderAllocated.TLORDA_ReturnNumber = TransNumber; OrderAllocated.TLORDA_ReturnedDate = dtpTransactionDate.Value; shirtParameters.OrdersAllocated.Add(repo.LoadOrderAllocated(Pk)); } } foreach (DataGridViewRow row in dataGridView2.Rows) { if ((bool)row.Cells[1].Value == false) { continue; } var ReSold = (bool)row.Cells[2].Value; int Pk = (int)row.Cells[0].Value; var soh = context.TLCSV_StockOnHand.Find(Pk); if (soh != null) { int BoxedQty = (int)row.Cells[7].Value; soh.TLSOH_ReturnedBoxQty = BoxedQty; soh.TLSOH_BoxedQty = BoxedQty; soh.TLSOH_WareHouse_FK = WareHouse.WhStore_Id; soh.TLSOH_ReturnNumber = TransNumber; soh.TLSOH_ReturnedDate = dtpTransactionDate.Value; if (!ReSold) { soh.TLSOH_Returned = true; soh.TLSOH_Grade = "B"; } else { soh.TLSOH_Picked = false; soh.TLSOH_PickListDate = null; soh.TLSOH_PickListNo = 0; soh.TLSOH_Sold = false; soh.TLSOH_DNListDate = null; soh.TLSOH_DNListNo = 0; soh.TLSOH_Grade = "A"; soh.TLSOH_SoldDate = null; soh.TLSOH_WareHousePickList = 0; soh.TLSOH_WareHouseDeliveryNo = 0; } } } try { var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("CSV")).FirstOrDefault(); if (Dept != null) { var LNU = context.TLADM_LastNumberUsed.Where(x => x.LUN_Department_FK == Dept.Dep_Id).FirstOrDefault(); if (LNU != null) { TransNumber = LNU.col5; LNU.col5 += 1; } } //------------------------------------------------------- // //----------------------------------------------------------- string Mach_IP = Dns.GetHostEntry(Dns.GetHostName()) .AddressList.First(f => f.AddressFamily == AddressFamily.InterNetwork) .ToString(); TLADM_DailyLog DailyLog = new TLADM_DailyLog(); DailyLog.TLDL_IPAddress = Mach_IP; DailyLog.TLDL_Dept_Fk = Dept.Dep_Id; DailyLog.TLDL_Date = DateTime.Now; DailyLog.TLDL_TransDetail = "Customer Services - Stock Returned"; DailyLog.TLDL_AuthorisedBy = txtApprovedBy.Text;; DailyLog.TLDL_Comments = txtCustomerRef.Text; context.TLADM_DailyLog.Add(DailyLog); context.SaveChanges(); MessageBox.Show("Data successfully saved to the database"); dataGridView1.Rows.Clear(); dataGridView2.Rows.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } services.ApprovedBy = txtApprovedBy.Text; services.Reasons = txtReasons.Text; services.ReturnDate = dtpTransactionDate.Value; services.CustomerRef = txtCustomerRef.Text; services.WareHouse = WareHouse.WhStore_Id; frmCSViewRep vRep = new frmCSViewRep(11, shirtParameters, services); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); frmCustomerReturns_Load(this, null); } } }