private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; Decimal weight = 0.00M; bool AddRec = false; TLADM_TranactionType TranType = null; if (oBtn != null && formloaded) { var Select = (TLDYE_DyeBatch)cmboBatchNumber.SelectedItem; if (Select == null) { MessageBox.Show("Please select a batch number from the drop down box "); return; } using (var context = new TTI2Entities()) { 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 == 1400).FirstOrDefault(); } foreach (DataGridViewRow row in dataGridView1.Rows) { TLDYE_DyeBatchDetails bd = new TLDYE_DyeBatchDetails(); int index = (int)row.Cells[0].Value; bd = context.TLDYE_DyeBatchDetails.Find(index); if (bd != null) { if ((bool)row.Cells[6].Value == true) { bd.DYEBO_Rejected = false; bd.DYEBO_RejectedDate = null; bd.DYEBO_QAApproved = true; bd.DYEBO_ApprovalDate = dtpTransDate.Value; if (bd.DYEBO_CutSheet) bd.DYEBO_CutSheet = false; weight += (decimal)row.Cells[5].Value; bd.DYEBO_CurrentStore_FK = (int)TranType.TrxT_ToWhse_FK; AddRec = true; } } } if (AddRec) { var LNU = context.TLADM_LastNumberUsed.Find(3); TLDYE_DyeTransactions tt = new TLDYE_DyeTransactions(); tt.TLDYET_BatchNo = Select.DYEB_BatchNo; tt.TLDYET_BatchWeight = Select.DYEB_BatchKG; tt.TLDYET_SequenceNo = Select.DYEB_SequenceNo; tt.TLDYET_Batch_FK = Select.DYEB_Pk; tt.TLDYET_TransactionNumber = "RFREV" + LNU.col7.ToString().PadLeft(6, '0'); tt.TLDYET_Date = dtpTransDate.Value; tt.TLDYET_TransactionWeight = weight; tt.TLDYET_TransactionType = (int)TranType.TrxT_Pk; tt.TLDYET_CurrentStore_FK = (int)TranType.TrxT_ToWhse_FK; context.TLDYE_DyeTransactions.Add(tt); try { LNU.col7 += 1; context.SaveChanges(); MessageBox.Show("Data successfully saved to the database"); frmDyeViewReport vRep = new frmDyeViewReport(11, tt.TLDYET_Pk, true); vRep.ShowDialog(this); frmRejectFabricReversal_Load(this, null); } 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; decimal weight = 0.00M; bool AddRec = true; TLADM_TranactionType TranType = null; if (oBtn != null && formloaded) { var Select = (TLDYE_DyeBatch)cmboBatchNumber.SelectedItem; if (Select == null) { MessageBox.Show("Please select a batch number from the drop down box"); return; } using (var context = new TTI2Entities()) { var DB = context.TLDYE_DyeBatch.Find(Select.DYEB_Pk); if (DB != null) { DB.DYEB_QAInspected = true; } var LNU = context.TLADM_LastNumberUsed.Find(3); if (LNU != null) { LNU.col8 += 1; } if (Select.DYEB_CommissinCust) { 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 == 900).FirstOrDefault(); } } else { 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 == 700).FirstOrDefault(); } } foreach (DataGridViewRow row in dataGridView1.Rows) { TLDYE_DyeBatchDetails bd = new TLDYE_DyeBatchDetails(); if (row.Cells[0].Value == null) { continue; } int index = (int)row.Cells[0].Value; bd = context.TLDYE_DyeBatchDetails.Find(index); if (bd != null) { if ((bool)row.Cells[6].Value == true) { bd.DYEBO_QAApproved = true; //use this date tocalculate the days production days bd.DYEBO_ApprovalDate = dtpTransDate.Value; bd.DYEBO_CurrentStore_FK = (int)TranType.TrxT_ToWhse_FK; weight += (decimal)row.Cells[5].Value; AddRec = true; } } } if (AddRec) { TLDYE_DyeTransactions tt = new TLDYE_DyeTransactions(); tt.TLDYET_BatchNo = Select.DYEB_BatchNo; tt.TLDYET_BatchWeight = Select.DYEB_BatchKG; tt.TLDYET_SequenceNo = Select.DYEB_SequenceNo; tt.TLDYET_Batch_FK = Select.DYEB_Pk; tt.TLDYET_Date = dtpTransDate.Value; tt.TLDYET_TransactionWeight = weight; tt.TLDYET_TransactionNumber = txtTransNumber.Text; tt.TLDYET_Batch_FK = Select.DYEB_Pk; tt.TLDYET_TransactionType = (int)TranType.TrxT_Pk; tt.TLDYET_CurrentStore_FK = (int)TranType.TrxT_ToWhse_FK; context.TLDYE_DyeTransactions.Add(tt); try { context.SaveChanges(); MessageBox.Show("Data successfully saved to the database"); Setup(); } 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; bool AddRec; bool success = true; if (oBtn != null && formLoaded) { var SelectedDept = (TLADM_Departments)cmbDepartments.SelectedItem; using (var context = new TTI2Entities()) { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[1].Value == null) continue; TLADM_TranactionType tranType = new TLADM_TranactionType(); AddRec = true; if (row.Cells[0].Value != null) { tranType = context.TLADM_TranactionType.Find((int)row.Cells[0].Value); if (tranType != null) { AddRec = false; } } tranType.TrxT_Number = (int)row.Cells[1].Value; tranType.TrxT_Description = (string)row.Cells[2].Value; tranType.TrxT_FromWhse_FK = null; tranType.TrxT_ToWhse_FK = null; if (SelectedDept != null) tranType.TrxT_Department_FK = SelectedDept.Dep_Id; if (row.Cells[3].Value != null) { tranType.TrxT_FromWhse_FK = (int)row.Cells[3].Value; } if (row.Cells[4].Value != null) { tranType.TrxT_ToWhse_FK = (int)row.Cells[4].Value; } if (row.Cells[5].Value != null) { tranType.TrxT_FinishedGoods_FK = (int)row.Cells[5].Value; } else tranType.TrxT_FinishedGoods_FK = 0; if (AddRec) context.TLADM_TranactionType.Add(tranType); try { context.SaveChanges(); } catch(Exception ex) { MessageBox.Show(ex.Message); success = false; } } } if (success) { dataGridView1.Rows.Clear(); MessageBox.Show("Records Stored to database"); } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLADM_CustomerFile CommissionCust; TLKNI_YarnTransaction yarnT; TLKNI_YarnTransactionDetails yarnTD; //TLKNI_YarnStatus yarnStat; TLADM_TranactionType TranType = null; TLKNI_YarnOrderPallets PalletStore; int LastNumberUsed = 0; if (oBtn != null && formloaded) { var ErrorM = core.returnMessage(MandSelected, false, MandatoryFields); if (!String.IsNullOrEmpty(ErrorM)) { MessageBox.Show(ErrorM); return; } if (dataGridView1.RowCount == 0) { MessageBox.Show("Please enter a least one row in the datagrid"); return; } CommissionCust = (TLADM_CustomerFile)cmbCommissionCustomers.SelectedItem; using (var context = new TTI2Entities()) { //------------------------- // Yarn Header Record //---------------------------------------- yarnT = new TLKNI_YarnTransaction(); yarnT.KnitY_TransactionDate = dtpDateReceived.Value; yarnT.KnitY_Customer_FK = CommissionCust.Cust_Pk; yarnT.KnitY_Notes = rtbComments.Text; yarnT.KnitY_TransactionDoc = txtCustomerDoc.Text; yarnT.KnitY_ThirdParty = false; yarnT.KnitY_RTS = false; var LastNumber = context.TLADM_LastNumberUsed.Find(2); if (LastNumber != null) { LastNumberUsed = LastNumber.col1; yarnT.KnitY_GRNNumber = LastNumberUsed; LastNumber.col1 += 1; } var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("KNIT")).FirstOrDefault(); if (Dept != null) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 100).FirstOrDefault(); } try { context.TLKNI_YarnTransaction.Add(yarnT); context.SaveChanges(); foreach (DataGridViewRow dr in dataGridView1.Rows) { if (dr.Cells[1].Value == null) { continue; } var PalletNo = (int)dr.Cells[0].Value; PalletStore = new TLKNI_YarnOrderPallets(); PalletStore.TLKNIOP_CommisionCust = true; PalletStore.TLKNIOP_Cones = (int)dr.Cells[7].Value; PalletStore.TLKNIOP_DatePacked = dtpDateReceived.Value; PalletStore.TLKNIOP_Grade = string.Empty; PalletStore.TLKNIOP_GrossWeight = (decimal)dr.Cells[5].Value; PalletStore.TLKNIOP_TareWeight = 0.00M; PalletStore.TLKNIOP_NettWeight = (decimal)dr.Cells[6].Value; PalletStore.TLKNIOP_YarnType_FK = (int)dr.Cells[1].Value; PalletStore.TLKNIOP_PalletNo = PalletNo; PalletStore.TLKNIOP_Store_FK = (int)TranType.TrxT_ToWhse_FK; PalletStore.TLKNIOP_NettWeightReserved = 0.00M; PalletStore.TLKNIOP_HeaderRecord_FK = yarnT.KnitY_Pk; PalletStore.TLKNIOP_ConesReserved = 0; context.TLKNI_YarnOrderPallets.Add(PalletStore); context.SaveChanges(); yarnTD = new TLKNI_YarnTransactionDetails(); yarnTD.KnitYD_KnitY_FK = yarnT.KnitY_Pk; yarnTD.KnitYD_YarnType_FK = (int)dr.Cells[1].Value; yarnTD.KnitYD_PalletNo_FK = PalletStore.TLKNIOP_Pk; yarnTD.KnitYD_GrossWeight = (decimal)dr.Cells[5].Value; yarnTD.KnitYD_NettWeight = (decimal)dr.Cells[6].Value; yarnTD.KnitYD_NoOfCones = (int)dr.Cells[7].Value; yarnTD.KnitYD_TransactionDate = dtpDateReceived.Value; yarnTD.KnitYD_RTS = false; yarnTD.KnitYD_TransactionNumber = LastNumberUsed; if (TranType != null) { yarnTD.KnitYD_TransactionType = TranType.TrxT_Pk; } yarnTD.KnitYD_RTS = false; context.TLKNI_YarnTransactionDetails.Add(yarnTD); } context.SaveChanges(); dataGridView1.Rows.Clear(); MessageBox.Show("Records stored successfully to database"); frmKnitViewRep vRep = new frmKnitViewRep(1, yarnT.KnitY_Pk); vRep.ShowDialog(this); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLKNI_YarnTransactionDetails yarnTD; TLSPN_YarnOrderPallets palletStore; TLADM_TranactionType TranType = null; int LastNumberUsed = 0; bool success = true; if (oBtn != null && formloaded) { var errorM = core.returnMessage(MandatorySelected, true, MandatoryFields); if (!string.IsNullOrEmpty(errorM)) { MessageBox.Show(errorM); return; } //------------------------------------------------------------- // must write out a header record //------------------------------------------------------------------ if (rbCommission.Checked || rb3rdParty.Checked) { var YarnTrx = (TLKNI_YarnTransaction)oCmboTransactions.SelectedItem; if (YarnTrx != null) { using (var context = new TTI2Entities()) { var LastNumber = context.TLADM_LastNumberUsed.Find(2); if (LastNumber != null) { LastNumberUsed = LastNumber.col5; LastNumber.col5 += 1; } var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("KNIT")).FirstOrDefault(); if (Dept != null) { if (rbCommission.Checked) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 600).FirstOrDefault(); } else { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 500).FirstOrDefault(); } } try { context.SaveChanges(); var yt = (TLKNI_YarnTransaction)oCmboTransactions.SelectedItem; foreach (DataGridViewRow dr in dataGridView1.Rows) { if (!(bool)dr.Cells[1].Value) { continue; } yarnTD = new TLKNI_YarnTransactionDetails(); yarnTD.KnitYD_KnitY_FK = YarnTrx.KnitY_Pk; var TypeOfYarn = dr.Cells[3].Value; var YarnDetails = context.TLADM_Yarn.Where(x => x.YA_Description.Contains(TypeOfYarn.ToString())).FirstOrDefault(); if (YarnDetails != null) { yarnTD.KnitYD_YarnType_FK = YarnDetails.YA_Id; } yarnTD.KnitYD_PalletNo_FK = (int)dr.Cells[0].Value; yarnTD.KnitYD_NoOfCones = Convert.ToInt32(dr.Cells[7].Value.ToString()); yarnTD.KnitYD_NettWeight = Convert.ToDecimal(dr.Cells[8].Value.ToString()); yarnTD.KnitYD_TransactionNumber = LastNumberUsed; yarnTD.KnitYD_TransactionDate = dateTimePicker1.Value; yarnTD.KnitYD_ApprovedBy = txtApprovedBy.Text; yarnTD.KnitYD_Notes = rtbNotes.Text; yarnTD.KnitYD_RTS = false; if (yt != null) { yarnTD.KnitYD_OriginalOrderNo = yt.KnitY_GRNNumber; } if (TranType != null) { yarnTD.KnitYD_TransactionType = TranType.TrxT_Pk; } context.TLKNI_YarnTransactionDetails.Add(yarnTD); //-------------------------------------------------------------------- // Now we have to keep the Status file uptodate //-------------------------------------------------------------------------- var _key = (int)dr.Cells[0].Value; var palletStorex = context.TLKNI_YarnOrderPallets.Find(_key); if (palletStorex != null) { if ((bool)dr.Cells[9].Value == true) { palletStorex.TLKNIOP_Cones -= yarnTD.KnitYD_NoOfCones; palletStorex.TLKNIOP_NettWeight -= yarnTD.KnitYD_NettWeight; palletStorex.TLKNIOP_GrossWeight -= yarnTD.KnitYD_GrossWeight; } else { palletStorex.TLKNIOP_Cones += yarnTD.KnitYD_NoOfCones; palletStorex.TLKNIOP_NettWeight += yarnTD.KnitYD_NettWeight; palletStorex.TLKNIOP_GrossWeight += yarnTD.KnitYD_GrossWeight; } if (core.CalculatePalletNett(palletStorex) <= 0.00M) { palletStorex.TLKNIOP_PalletAllocated = true; } else { palletStorex.TLKNIOP_PalletAllocated = false; } } } context.SaveChanges(); MessageBox.Show("Data successfully stored to database"); frmKnitViewRep vRep = new frmKnitViewRep(6, LastNumberUsed); 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); success = false; } } if (success) { dataGridView1.Rows.Clear(); SetUp(); } } } else { } } }
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; IList <TLDYE_DyeBatch> DB = new List <TLDYE_DyeBatch>(); Decimal Nett = 0.00M; TLADM_TranactionType TranType = null; Decimal BatchWeight = 0.00M; 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 Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "DYE").FirstOrDefault(); if (Dept != null) { if (rbFabricStore.Checked) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1100).FirstOrDefault(); } else { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1200).FirstOrDefault(); } } var LNU = context.TLADM_LastNumberUsed.Find(3); if (LNU != null) { LNU.col10 += 1;; } foreach (DataGridViewRow row in dataGridView1.Rows) { if ((bool)row.Cells[10].Value == true) { var index = Int32.Parse(row.Cells[0].Value.ToString()); var DBD = context.TLDYE_DyeBatchDetails.Find(index); if (DBD != null) { DBD.DYEBO_CurrentStore_FK = TranType.TrxT_Pk; DBD.DYEBO_TransactionNo = txtTransNumber.Text; DBD.DYEBO_DateSold = dtTransDate.Value; DBD.DYEBO_Sold = true; BatchWeight += DBD.DYEBD_GreigeProduction_Weight; Nett += DBD.DYEBO_Nett; } } } TLDYE_DyeTransactions tt = new TLDYE_DyeTransactions(); tt.TLDYET_BatchNo = "0"; tt.TLDYET_BatchWeight = BatchWeight; tt.TLDYET_SequenceNo = 0; tt.TLDYET_Batch_FK = 0; tt.TLDYET_Date = dtTransDate.Value; tt.TLDYET_TransactionWeight = Nett; tt.TLDYET_TransactionNumber = txtTransNumber.Text; tt.TLDYET_TransactionType = TranType.TrxT_Pk; tt.TLDYET_CurrentStore_FK = (int)TranType.TrxT_ToWhse_FK; tt.TLDYET_Customer_FK = ((TLADM_CustomerFile)cmboCustomers.SelectedItem).Cust_Pk; tt.TLDYET_FabricSales = true; tt.TLDYET_CustomerOrderNo = txtOrderNumber.Text; context.TLDYE_DyeTransactions.Add(tt); try { context.SaveChanges(); MessageBox.Show("Data succesfully saved to database"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; int RecCount = 0; int LastNumberUsed = 0; TLADM_Suppliers CommissionCust; TLKNI_YarnTransaction yarnT; TLKNI_YarnTransactionDetails yarnTD; TLADM_TranactionType TranType = null; TLKNI_YarnOrderPallets PalletStore; if (oBtn != null && formloaded) { var ErrorM = core.returnMessage(MandFieldsSelected, false, MandatoryFields); if (!String.IsNullOrEmpty(ErrorM)) { MessageBox.Show(ErrorM); return; } if (dataGridView1.RowCount == 0) { MessageBox.Show("Please enter a least one row in the datagrid"); return; } foreach (DataGridViewRow dr in dataGridView1.Rows) { var tst = fieldEntered.Find(x => x.rownumber == dr.Index); if (tst.fieldComplete == null) { continue; } var cnt = tst.fieldComplete.Where(x => x == false).Count(); if (cnt == MandatoryRows.Length) { continue; } cnt = tst.fieldComplete.Where(x => x == true).Count(); if (cnt != MandatoryRows.Length) { MessageBox.Show("Line " + (1 + dr.Index).ToString() + " Has not been completed correctly"); return; } } CommissionCust = (TLADM_Suppliers)cmbCommissionCustomers.SelectedItem; using (var context = new TTI2Entities()) { yarnT = new TLKNI_YarnTransaction(); yarnT.KnitY_TransactionDate = dtpDateReceived.Value; yarnT.KnitY_Customer_FK = CommissionCust.Sup_Pk; yarnT.KnitY_Notes = rtbComments.Text; yarnT.KnitY_TransactionDoc = txtCustomerDoc.Text; yarnT.KnitY_ThirdParty = true; var LastNumber = context.TLADM_LastNumberUsed.Find(2); if (LastNumber != null) { LastNumberUsed = LastNumber.col2; yarnT.KnitY_GRNNumber = LastNumberUsed; LastNumber.col2 += 1; } var YarnLastNumber = context.TLADM_LastNumberUsed.Find(1); var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("KNIT")).FirstOrDefault(); if (Dept != null) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 200).FirstOrDefault(); } try { context.TLKNI_YarnTransaction.Add(yarnT); context.SaveChanges(); StringBuilder sb = null; int Counter = 0; foreach (DataGridViewRow dr in dataGridView1.Rows) { var tst = fieldEntered.Find(x => x.rownumber == dr.Index); if (tst.fieldComplete == null) { continue; } var cnt = tst.fieldComplete.Where(x => x == false).Count(); if (cnt == MandatoryRows.Count()) { continue; } var PalletNo = (int)dr.Cells[0].Value; PalletStore = new TLKNI_YarnOrderPallets(); PalletStore.TLKNIOP_CommisionCust = false; sb = new StringBuilder(); sb.Append(YarnLastNumber.col6.ToString()); sb.Append(" - "); sb.Append((++Counter).ToString()); PalletStore.TLKNIOP_TLPalletNo = sb.ToString(); PalletStore.TLKNIOP_Cones = (int)dr.Cells[7].Value; PalletStore.TLKNIOP_DatePacked = dtpDateReceived.Value; PalletStore.TLKNIOP_Grade = string.Empty; PalletStore.TLKNIOP_GrossWeight = (decimal)dr.Cells[5].Value; PalletStore.TLKNIOP_TareWeight = 0.00M; PalletStore.TLKNIOP_NettWeight = (decimal)dr.Cells[6].Value; PalletStore.TLKNIOP_YarnType_FK = (int)dr.Cells[1].Value; PalletStore.TLKNIOP_PalletNo = PalletNo; PalletStore.TLKNIOP_Store_FK = (int)TranType.TrxT_ToWhse_FK; PalletStore.TLKNIOP_NettWeightReserved = 0.00M; PalletStore.TLKNIOP_HeaderRecord_FK = yarnT.KnitY_Pk; PalletStore.TLKNIOP_ConesReserved = 0; context.TLKNI_YarnOrderPallets.Add(PalletStore); context.SaveChanges(); yarnTD = new TLKNI_YarnTransactionDetails(); yarnTD.KnitYD_KnitY_FK = yarnT.KnitY_Pk; yarnTD.KnitYD_YarnType_FK = (int)dr.Cells[1].Value; yarnTD.KnitYD_PalletNo_FK = PalletStore.TLKNIOP_Pk; yarnTD.KnitYD_GrossWeight = (decimal)dr.Cells[5].Value; yarnTD.KnitYD_NettWeight = (decimal)dr.Cells[6].Value; yarnTD.KnitYD_NoOfCones = (int)dr.Cells[7].Value; yarnTD.KnitYD_TransactionDate = dtpDateReceived.Value; yarnTD.KnitYD_RTS = false; yarnTD.KnitYD_TransactionNumber = LastNumberUsed; if (TranType != null) { yarnTD.KnitYD_TransactionType = TranType.TrxT_Pk; } yarnTD.KnitYD_RTS = false; context.TLKNI_YarnTransactionDetails.Add(yarnTD); RecCount += 1; } YarnLastNumber = context.TLADM_LastNumberUsed.Find(1); if (YarnLastNumber != null) { YarnLastNumber.col6 += 1; } context.SaveChanges(); formloaded = false; dataGridView1.Rows.Clear(); formloaded = true; MessageBox.Show("Records stored successfully to database"); frmKnitViewRep vRep = new frmKnitViewRep(3, yarnT.KnitY_Pk); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); SetUp(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLKNI_YarnTransactionDetails yarnTD; TLADM_TranactionType TranType = null; int LastNumberUsed = 0; bool success = true; if (oBtn != null && formloaded) { var ErrorM = core.returnMessage(MandatoryFieldsSelected, true, MandatoryFields); if (!string.IsNullOrEmpty(ErrorM)) { MessageBox.Show(ErrorM); return; } var YO = (TLKNI_YarnTransaction)cmboYarnOrder.SelectedItem; if (YO != null) { using (var context = new TTI2Entities()) { var LNU = context.TLADM_LastNumberUsed.Find(2); if (LNU != null) { LastNumberUsed = LNU.col3; LNU.col3 += 1; } var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("KNIT")).FirstOrDefault(); if (Dept != null) { if (_reportNo == 1) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 400).FirstOrDefault(); } else { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 300).FirstOrDefault(); } } foreach (DataGridViewRow dr in dataGridView1.Rows) { if (!(bool)dr.Cells[1].Value) { continue; } yarnTD = new TLKNI_YarnTransactionDetails(); yarnTD.KnitYD_KnitY_FK = YO.KnitY_Pk; var TypeOfYarn = dr.Cells[3].Value; var YarnDetails = context.TLADM_Yarn.Where(x => x.YA_Description.Contains(TypeOfYarn.ToString())).FirstOrDefault(); if (YarnDetails != null) { yarnTD.KnitYD_YarnType_FK = YarnDetails.YA_Id; } yarnTD.KnitYD_PalletNo_FK = (int)dr.Cells[0].Value; yarnTD.KnitYD_GrossWeight = (decimal)dr.Cells[7].Value; yarnTD.KnitYD_NettWeight = (decimal)dr.Cells[8].Value; yarnTD.KnitYD_NoOfCones = (int)dr.Cells[9].Value; yarnTD.KnitYD_WriteOff = true; yarnTD.KnitYD_RTS = true; yarnTD.KnitYD_TransactionDate = dtpDateReceived.Value; yarnTD.KnitYD_TransactionNumber = LastNumberUsed; if (TranType != null) { yarnTD.KnitYD_TransactionType = TranType.TrxT_Pk; } context.TLKNI_YarnTransactionDetails.Add(yarnTD); //-------------------------------------------------------------------- // Now we have to keep the Status file uptodate //-------------------------------------------------------------------------- TLKNI_YarnOrderPallets palletStore = context.TLKNI_YarnOrderPallets.Find(yarnTD.KnitYD_PalletNo_FK); if (palletStore != null) { palletStore.TLKNIOP_Cones -= yarnTD.KnitYD_NoOfCones; palletStore.TLKNIOP_NettWeight -= yarnTD.KnitYD_NettWeight; palletStore.TLKNIOP_GrossWeight -= yarnTD.KnitYD_GrossWeight; palletStore.TLKNIOP_PalletAllocated = true; } } try { context.SaveChanges(); frmKnitViewRep vRep = new frmKnitViewRep(4, LastNumberUsed); 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); } } if (success) { dataGridView1.Rows.Clear(); MessageBox.Show("Data saved to database successfully"); SetUp(); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; bool success = true; TLADM_TranactionType TranType = null; TLADM_MachineOperators Operators = null; if (oBtn != null && formloaded) { var ErrorM = core.returnMessage(MandatorySelected, false, MandatoryFields); if (!String.IsNullOrEmpty(ErrorM)) { MessageBox.Show(ErrorM); return; } var Inspector = (TLADM_MachineOperators)cmbInspector.SelectedItem; var KO = (TLKNI_Order)cmbKnitOrder.SelectedItem; using (var context = new TTI2Entities()) { Operators = (TLADM_MachineOperators)cmbInspector.SelectedItem; var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("KNIT")).FirstOrDefault(); foreach (DataGridViewRow row in dataGridView1.Rows) { TLKNI_GreigeProduction record = new TLKNI_GreigeProduction(); record = context.TLKNI_GreigeProduction.Find(row.Cells[0].Value); if (row.Cells[2].Value != null) { record.GreigeP_Grade = row.Cells[2].Value.ToString(); } else { record.GreigeP_Grade = "A"; } if (row.Cells[3].Value != null) { record.GreigeP_Remarks = row.Cells[3].Value.ToString(); } else { record.GreigeP_Remarks = string.Empty; } record.GreigeP_Meas1 = (int)row.Cells[4].Value; record.GreigeP_Meas2 = (int)row.Cells[5].Value; record.GreigeP_Meas3 = (int)row.Cells[6].Value; record.GreigeP_Meas4 = (int)row.Cells[7].Value; record.GreigeP_Meas5 = (int)row.Cells[8].Value; record.GreigeP_Meas6 = (int)row.Cells[9].Value; record.GreigeP_Meas7 = (int)row.Cells[10].Value; record.GreigeP_Meas8 = (int)row.Cells[11].Value; record.GreigeP_Inspected = (bool)row.Cells[12].Value; record.GreigeP_InspDate = dateTimePicker1.Value; record.GreigeP_Inspector_FK = Inspector.MachOp_Pk; record.GreigeP_WarningMessage = (bool)row.Cells[14].Value; if (row.Cells[2].Value != null) { if (row.Cells[2].Value.ToString().Contains("C")) { // We need to record a transaction //----------------------------------------------- TLKNI_GreigeTransactions GreigeT = new TLKNI_GreigeTransactions(); GreigeT.GreigeT_AdjustedWeight = record.GreigeP_weight; GreigeT.GreigeT_TransactionDate = dateTimePicker1.Value; GreigeT.GreigeT_TransactionNumber = 9999; GreigeT.GreigeT_Grade = row.Cells[2].Value.ToString(); GreigeT.GreigeT_KOrder_FK = KO.KnitO_Pk; GreigeT.GreigeT_Piece_FK = record.GreigeP_Pk; if (KO.KnitO_YarnO_FK != null) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1500).FirstOrDefault(); if (TranType != null) { record.GreigeP_Store_FK = TranType.TrxT_ToWhse_FK; } } else { if (KO.KnitO_CommisionCust) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1700).FirstOrDefault(); if (TranType != null) { record.GreigeP_Store_FK = TranType.TrxT_ToWhse_FK; } } else { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1600).FirstOrDefault(); if (TranType != null) { record.GreigeP_Store_FK = TranType.TrxT_ToWhse_FK; } } } GreigeT.GreigeT_TransactionType_FK = TranType.TrxT_Pk; context.TLKNI_GreigeTransactions.Add(GreigeT); } else { if (KO.KnitO_YarnO_FK != null) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1400).FirstOrDefault(); if (TranType != null) { record.GreigeP_Store_FK = TranType.TrxT_ToWhse_FK; } } else { if (KO.KnitO_CommisionCust) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1300).FirstOrDefault(); if (TranType != null) { record.GreigeP_Store_FK = TranType.TrxT_ToWhse_FK; } } else { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1200).FirstOrDefault(); if (TranType != null) { record.GreigeP_Store_FK = TranType.TrxT_ToWhse_FK; } } } } } } try { context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.InnerException.ToString()); success = false; } } if (success) { MessageBox.Show("Records stored successfully to the database"); dataGridView1.Rows.Clear(); } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLADM_TranactionType TranType = null; if (oBtn != null && formloaded) { var KO = (TLKNI_Order)cmbKnitOrder.SelectedItem; if (KO != null) { using (var context = new TTI2Entities()) { KO = context.TLKNI_Order.Find(KO.KnitO_Pk); KO.KnitO_Closed = true; KO.KnitO_ClosedDate = dtpKnitOrderClosed.Value; var LNU = context.TLADM_LastNumberUsed.Find(2); var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("KNIT")).FirstOrDefault(); foreach (DataGridViewRow dr in dataGridView1.Rows) { if (dr.Cells[0].Value == null) { continue; } if (dr.Cells[3].Value != null && (bool)dr.Cells[3].Value == true) { if (dr.Cells[4].Value == null) { MessageBox.Show("When using the select button please select an alternative Knit Order to allocate against", "Line " + (dr.Index + 1).ToString()); return; } } TLKNI_YarnTransactionDetails trnsDet = new TLKNI_YarnTransactionDetails(); trnsDet.KnitYD_Notes = txtNotes.Text; trnsDet.KnitYD_OriginalOrderNo = KO.KnitO_OrderNumber; trnsDet.KnitYD_PalletNo_FK = (int)dr.Cells[0].Value; trnsDet.KnitYD_RTS = false; trnsDet.KnitYD_TransactionDate = dtpKnitOrderClosed.Value; trnsDet.KnitYD_WriteOff = false; if (LNU != null) { trnsDet.KnitYD_TransactionNumber = LNU.col7; } trnsDet.KnitYD_ApprovedBy = string.Empty; trnsDet.KnitYD_NoOfCones = (int)dr.Cells[1].Value; trnsDet.KnitYD_NettWeight = (decimal)dr.Cells[2].Value; trnsDet.KnitYD_GrossWeight = 0.00M; trnsDet.KnitYD_KnitY_FK = KO.KnitO_Pk; trnsDet.KnitYD_YarnReturned = true; Decimal WeightRecorded = (decimal)dr.Cells[2].Value; var Pallet = context.TLKNI_YarnOrderPallets.Find(trnsDet.KnitYD_PalletNo_FK); if (Pallet != null) { trnsDet.KnitYD_YarnType_FK = Pallet.TLKNIOP_YarnType_FK; if (dr.Cells[3].Value != null && (bool)dr.Cells[3].Value == true) { //====================================================================== // has to be a negative number to facilitate the calculations //================================================================= TLKNI_YarnAllocTransctions TransAlloc = new TLKNI_YarnAllocTransctions(); TransAlloc.TLKYT_KnitOrder_FK = KO.KnitO_Pk; TransAlloc.TLKYT_NettWeight = -1 * WeightRecorded; TransAlloc.TLKYT_NoOfCones = -1 * (int)dr.Cells[1].Value;; TransAlloc.TLKYT_TransDate = dtpKnitOrderClosed.Value; TransAlloc.TLKYT_TranType = 3; TransAlloc.TLKYT_YOP_FK = Pallet.TLKNIOP_Pk; context.TLKNI_YarnAllocTransctions.Add(TransAlloc); //================================================================= // Now find the pallet to which the balance is going to be added //======================================================== var ReservedBy = (int)dr.Cells[4].Value; var Trans = context.TLKNI_YarnAllocTransctions.Where(x => x.TLKYT_KnitOrder_FK == ReservedBy && x.TLKYT_TranType == 1).FirstOrDefault(); if (Trans != null) { var PalletTo = context.TLKNI_YarnOrderPallets.Find(Trans.TLKYT_YOP_FK); if (PalletTo != null) { PalletTo.TLKNIOP_AdditionalYarn += WeightRecorded; //============================================= // we need a record of this transaction //======================================== TransAlloc = new TLKNI_YarnAllocTransctions(); TransAlloc.TLKYT_KnitOrder_FK = ReservedBy; TransAlloc.TLKYT_NoOfCones += (int)dr.Cells[1].Value; TransAlloc.TLKYT_NettWeight = WeightRecorded; TransAlloc.TLKYT_TransDate = dtpKnitOrderClosed.Value; TransAlloc.TLKYT_TranType = 3; TransAlloc.TLKYT_YOP_FK = PalletTo.TLKNIOP_Pk; context.TLKNI_YarnAllocTransctions.Add(TransAlloc); if (core.CalculatePalletNett(PalletTo) <= 0.00m) { PalletTo.TLKNIOP_PalletAllocated = true; } else { PalletTo.TLKNIOP_PalletAllocated = false; } } } trnsDet.KnitYD_TransactionType = 2005; } else { var Cones = (int)dr.Cells[1].Value; WeightRecorded = (decimal)dr.Cells[2].Value; trnsDet.KnitYD_YarnReturned = true; Pallet.TLKNIOP_NettWeightReturned += WeightRecorded; //============================================= //we need a record of this transaction //======================================== var TransAlloc = new TLKNI_YarnAllocTransctions(); TransAlloc.TLKYT_KnitOrder_FK = KO.KnitO_Pk; TransAlloc.TLKYT_NettWeight = WeightRecorded; TransAlloc.TLKYT_NoOfCones = -Cones; TransAlloc.TLKYT_TransDate = dtpKnitOrderClosed.Value; TransAlloc.TLKYT_TranType = 2; TransAlloc.TLKYT_YOP_FK = Pallet.TLKNIOP_Pk; context.TLKNI_YarnAllocTransctions.Add(TransAlloc); //========================================= // This should make the pallet available //====================================================== if (core.CalculatePalletNett(Pallet) <= 0.00M) { Pallet.TLKNIOP_PalletAllocated = true; } else { Pallet.TLKNIOP_PalletAllocated = false; } //============================== // Now do the the swop between stores // dont have to do this for the above has it stays in WIP spinning //=================================================== if (Pallet.TLKNIOP_OwnYarn) { frmSelectStore selectStore = new frmSelectStore(); selectStore.ShowDialog(); Pallet.TLKNIOP_Store_FK = selectStore.WhseId; /* * TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Number == 1400).FirstOrDefault(); * if (TranType != null) * Pallet.TLKNIOP_Store_FK = (int)TranType.TrxT_ToWhse_FK; */ trnsDet.KnitYD_TransactionType = 1400; } else { if (Pallet.TLKNIOP_CommisionCust) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Number == 1300).FirstOrDefault(); if (TranType != null) { Pallet.TLKNIOP_Store_FK = (int)TranType.TrxT_ToWhse_FK; } trnsDet.KnitYD_TransactionType = 1300; } else { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Number == 1200).FirstOrDefault(); if (TranType != null) { Pallet.TLKNIOP_Store_FK = (int)TranType.TrxT_ToWhse_FK; } trnsDet.KnitYD_TransactionType = 1200; } } } } context.TLKNI_YarnTransactionDetails.Add(trnsDet); } if (LNU != null) { LNU.col7 += 1; } try { context.SaveChanges(); MessageBox.Show("Data successfully saved to database"); dataGridView1.Rows.Clear(); frmKnitViewRep vRep = new frmKnitViewRep(11, LNU.col7 - 1); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); frmCloseKnitOrder_Load(this, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } }
private void dataGridView1_KeyDown(object sender, KeyEventArgs e) { DataGridView oDgv = sender as DataGridView; TLADM_TranactionType TranType = null; TLKNI_GreigeProduction GreigeP = null; if (oDgv != null && e.KeyCode == Keys.Enter) { dataGridView1.CurrentCell = core.GetNextCell(oDgv, oDgv.CurrentCell); e.Handled = true; } else if (oDgv != null && e.KeyCode == Keys.Insert) { DialogResult res = MessageBox.Show("You are about to insert a new record into this Knit order ", "Please confirm ", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res == DialogResult.Yes) { var KO = (TLKNI_Order)cmbKnitOrder.SelectedItem; if (KO == null) { MessageBox.Show("Please select a Knit order"); return; } using (var context = new TTI2Entities()) { var Machine = context.TLADM_MachineDefinitions.Find(KO.KnitO_Machine_FK); if (Machine != null) { MCode = Machine.MD_MachineCode.Remove(0, 1).Trim(); MLNU = Machine.MD_LastNumberUsed; var MachDet = Machine.MD_MachineCode.Remove(0); var 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(); } GreigeP = new TLKNI_GreigeProduction(); GreigeP.GreigeP_Store_FK = TranType.TrxT_ToWhse_FK; GreigeP.GreigeP_KnitO_Fk = KO.KnitO_Pk; GreigeP.GreigeP_Greige_Fk = KO.KnitO_Product_FK; GreigeP.GreigeP_PieceNo = MCode + MLNU.ToString().PadLeft(4,'0'); GreigeP.GreigeP_weight = 0.00M; GreigeP.GreigeP_weightAvail = 0.00M; GreigeP.GreigeP_Meas1 = 0; GreigeP.GreigeP_Meas2 = 0; GreigeP.GreigeP_Meas3 = 0; GreigeP.GreigeP_Meas4 = 0; GreigeP.GreigeP_Meas5 = 0; GreigeP.GreigeP_Meas6 = 0; GreigeP.GreigeP_Meas7 = 0; GreigeP.GreigeP_Meas8 = 0; GreigeP.GreigeP_Grade = "A"; GreigeP.GreigeP_Captured = true; GreigeP.GreigeP_Shift_FK = 1; GreigeP.GreigeP_Captured = true; Machine.MD_LastNumberUsed += 1; context.TLKNI_GreigeProduction.Add(GreigeP); } try { context.SaveChanges(); var Index = dataGridView1.Rows.Add(); dataGridView1.Rows[Index].Cells[0].Value = GreigeP.GreigeP_Pk; dataGridView1.Rows[Index].Cells[1].Value = GreigeP.GreigeP_PieceNo; dataGridView1.Rows[Index].Cells[2].Value = "A"; dataGridView1.Rows[Index].Cells[3].Value = 0.00M; this.dataGridView1.CurrentCell = this.dataGridView1.Rows[Index].Cells[3]; this.dataGridView1.BeginEdit(true); } 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) { //dont forget last number used Button oBtn = sender as Button; TLADM_TranactionType tranType = null; 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 LastNumberUsed = context.TLADM_LastNumberUsed.Find(1); if (LastNumberUsed != null) { LastNumberUsed.col8 += 1; } //--------------------------------------------------------- TLSPN_YarnTransactions YarnT = new TLSPN_YarnTransactions(); var YO = (TLSPN_YarnOrder)comboYarnNo.SelectedItem; if (YO != null) { YarnT.YarnTrx_YarnOrder_FK = YO.YarnO_Pk; } YarnT.YarnTrx_SequenceNo = Convert.ToInt32(txtDeliveryNoteNumber.Text); YarnT.YarnTrx_Date = dateTimePicker1.Value; var deptDetail = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "SPIN").FirstOrDefault(); if (deptDetail != null) { //tranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == deptDetail.Dep_Id && x.TrxT_Number == 800).FirstOrDefault(); tranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == deptDetail.Dep_Id && x.TrxT_Number == 700).FirstOrDefault(); if (tranType != null) { YarnT.YarnTrx_TranType_FK = tranType.TrxT_Pk; YarnT.YarnTrx_FromDep_FK = tranType.TrxT_FromWhse_FK; YarnT.YarnTrx_ToDep_FK = tranType.TrxT_ToWhse_FK; } } var PalletNo = (TLSPN_YarnOrderPallets)cmboPalletNumbers.SelectedItem; if (PalletNo != null) { YarnT.YarnTrx_PalletNo_Fk = PalletNo.YarnOP_Pk; } var NoCones = Convert.ToInt32(txtNumberOfCones.Text); YarnT.YarnTrx_Cones = NoCones; var NettWeight = Convert.ToDecimal(txtNettWeight.Text); YarnT.YarnTrx_NettWeight = Convert.ToDecimal(txtNettWeight.Text); //---------------------------------------------------------------- // This Transaction updates the spinning rocords var PalletStore = context.TLSPN_YarnOrderPallets.Find(PalletNo.YarnOP_Pk); if (PalletStore != null) { PalletStore.YarnOP_NoOfConesSpun -= NoCones; PalletStore.YarnOP_YarnAvailable = true; PalletStore.YarnOP_Issued = false; PalletStore.YarnOP_Store_FK = (int)tranType.TrxT_ToWhse_FK; PalletStore.YarnOP_YarnType_FK = YO.Yarno_YarnType_FK; PalletStore.YarnOP_NettWeight = NettWeight; } //--------------------------------------------------------- try { context.TLSPN_YarnTransactions.Add(YarnT); context.SaveChanges(); SetUp(false); Transactions = true; MessageBox.Show("Data saved to database successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLADM_TranactionType tranType = null; if (oBtn != null && formloaded) { var YO = (TLSPN_YarnOrder)cmboKnitOrder.SelectedItem; if (YO != null) { using (var context = new TTI2Entities()) { var deptDetail = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "SPIN").FirstOrDefault(); if (deptDetail != null) { tranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == deptDetail.Dep_Id && x.TrxT_Number == 800).FirstOrDefault(); } foreach (DataGridViewRow Row in dataGridView1.Rows) { if ((bool)Row.Cells[1].Value == false) { continue; } TLSPN_YarnTransactions YarnT = new TLSPN_YarnTransactions(); YarnT.YarnTrx_YarnOrder_FK = YO.YarnO_Pk; YarnT.YarnTrx_SequenceNo = Convert.ToInt32(txtDelNo.Text); YarnT.YarnTrx_Date = dateTimePicker1.Value; if (tranType != null) { YarnT.YarnTrx_TranType_FK = tranType.TrxT_Pk; YarnT.YarnTrx_FromDep_FK = tranType.TrxT_FromWhse_FK; YarnT.YarnTrx_ToDep_FK = tranType.TrxT_ToWhse_FK; } var NettWeight = (Decimal)Row.Cells[4].Value; context.TLSPN_YarnTransactions.Add(YarnT); var index = (int)Row.Cells[0].Value; var PalletStore = context.TLSPN_YarnOrderPallets.Find(index); if (PalletStore != null) { PalletStore.YarnOP_NoOfConesSpun -= PalletStore.YarnOP_NoOfCones; PalletStore.YarnOP_Issued = true; PalletStore.YarnOP_DateDispatched = dateTimePicker1.Value; PalletStore.YarnOP_Store_FK = (int)tranType.TrxT_ToWhse_FK; PalletStore.YarnOP_YarnType_FK = YO.Yarno_YarnType_FK; PalletStore.YarnOP_NettWeight = NettWeight; PalletStore.YarnOP_ReservedBy = int.Parse(txtDelNo.Text); TLKNI_YarnOrderPallets KnitYOP = new TLKNI_YarnOrderPallets(); KnitYOP.TLKNIOP_Cones = PalletStore.YarnOP_NoOfCones; KnitYOP.TLKNIOP_PalletNo = PalletStore.YarnOP_PalletNo; KnitYOP.TLKNIOP_NettWeight = NettWeight; KnitYOP.TLKNIOP_YarnOrder_FK = YO.YarnO_Pk; KnitYOP.TLKNIOP_YarnType_FK = YO.Yarno_YarnType_FK; KnitYOP.TLKNIOP_ConesReserved = 0; KnitYOP.TLKNIOP_NettWeightReserved = 0.00M; KnitYOP.TLKNIOP_Grade = PalletStore.YarnOP_Grade; KnitYOP.TLKNIOP_Store_FK = (int)tranType.TrxT_ToWhse_FK; KnitYOP.TLKNIOP_OwnYarn = true; context.TLKNI_YarnOrderPallets.Add(KnitYOP); } } try { context.SaveChanges(); MessageBox.Show("Data saved to database successfully"); frmYarnwithdrawl_Load(this, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } } /* * int TransNum = int.Parse(txtDelNo.Text); * frmKnitViewRep vRep = new frmKnitViewRep(8, TransNum); * int h = Screen.PrimaryScreen.WorkingArea.Height; * int w = Screen.PrimaryScreen.WorkingArea.Width; * vRep.ClientSize = new Size(w, h); * vRep.ShowDialog(this); */ } } }
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) { bool success = true; Button oBtn = sender as Button; TLSPN_CottonReceivedBales bales; TLADM_TranactionType trantypes = new TLADM_TranactionType(); if (oBtn != null) { 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 CottonContract = (TLADM_CottonContracts)cmbContractNo.SelectedItem; var CottonTrans = (TLSPN_CottonTransactions)cmbLotNo.SelectedItem; var Supplier = (TLADM_Cotton)cmbSupplierDetails.SelectedItem; //Dont forget last number used //---------------------------------------------- using (var context = new TTI2Entities()) { //Hard Coded at the moment // See Table TLADM_TranactionType for a complete List of the Transaction Type Per Department //-------------------------------------------------------------------------------------------------- var DeptDetails = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "SPIN").FirstOrDefault(); if (DeptDetails != null) { trantypes = context.TLADM_TranactionType.Where(x => x.TrxT_Number == 200 && x.TrxT_Department_FK == DeptDetails.Dep_Id).FirstOrDefault(); } var Haulier = (TLADM_CottonHauliers)cmbTransporter.SelectedItem; var TransDet = (TLSPN_CottonTransactions)cmbLotNo.SelectedItem; int noBales = 0; //------------------------------------------------------------------------------------------- // Up date the records from DataGridView....If Not in Edit Mode //-------------------------------------------------- if (!_EditMode) { var LastNumber = context.TLADM_LastNumberUsed.Find(1); if (LastNumber != null) { LastNumber.col2 += 1; } foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[1].Value == null || (bool)row.Cells[1].Value == false) { continue; } 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(txtReturnNoteNumber.Text); noBales += 1; try { context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); success = false; } } } } } else { foreach (DataGridViewRow row in dataGridView1.Rows) { if ((bool)row.Cells[1].Value == false) { bales = context.TLSPN_CottonReceivedBales.Find((int)row.Cells[0].Value); if (bales != null) { bales.CoBales_CottonReturned = false; bales.CoBales_CottonSequence = 0; try { context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); success = false; } } } else { noBales += 1; } } } //---------------------------------------------------------------- // Now onto the main transaction // Edit Mode plays a role!!!!! //------------------------------------------------------------------- TLSPN_CottonTransactions CTS = new TLSPN_CottonTransactions(); if (_EditMode) { var prev = (TLSPN_CottonTransactions)cmbPrevious.SelectedItem; if (prev != null) { CTS = context.TLSPN_CottonTransactions.Find(prev.cotrx_pk); } } //------------------------------------------------------------------ CTS.cotrx_ContractNo_Fk = CottonContract.CottonCon_Pk; CTS.cotrx_Customer_FK = null; CTS.cotrx_GrossAveBaleWeight = (Convert.ToDecimal(txtGrossWeightReturned.Text) / noBales); CTS.cotrx_GrossWeight = Convert.ToDecimal(txtGrossWeightReturned.Text); CTS.cotrx_LotNo = TransDet.cotrx_LotNo; CTS.cotrx_NetWeight = Convert.ToDecimal(txtNettWeightReturned.Text); CTS.cotrx_NoBales = noBales; CTS.cotrx_Notes = string.Empty; CTS.cotrx_Haulier_FK = Haulier.Haul_Pk; CTS.cotrx_Return_No = Convert.ToInt32(txtReturnNoteNumber.Text); CTS.cotrx_Supplier_FK = Supplier.Cotton_Pk; CTS.cotrx_TransDate = dtpDateReturned.Value; CTS.cotrx_TranType = trantypes.TrxT_Pk; CTS.cotrx_VehReg = txtVehReg.Text; CTS.cotrx_WeighBridgeEmpty = Convert.ToDecimal(txtWeighBridgeEmpty.Text); CTS.cotrx_WeighBridgeFull = Convert.ToDecimal(txtWeighBridgeFull.Text); CTS.cotrx_WriteOff = true; CTS.cottrx_NettAveBaleWeight = Convert.ToDecimal(txtNettWeightReturned.Text) / noBales; CTS.cotrx_NettPerWB = CTS.cotrx_WeighBridgeFull - CTS.cotrx_WeighBridgeEmpty; //---------------------------------------------------------------------------------- if (!_EditMode) { context.TLSPN_CottonTransactions.Add(CTS); } try { context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); success = false; } //---------------------------------------------------------------------- } if (success) { MessageBox.Show("Records stored to database successfully"); var ReturnNo = Convert.ToInt32(txtReturnNoteNumber.Text); frmViewReport vRep = new frmViewReport(3, ReturnNo); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); SetUp(); } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; Decimal Weight = 0.00M; TLADM_TranactionType trantype = null; if (oBtn != null && formloaded) { var Select = (TLDYE_DyeBatch)cmboBatchNumber.SelectedItem; if (Select == null) { MessageBox.Show("Please select a Batch number from the drop down box"); return; } int SingleRow = (from Rows in dataGridView1.Rows.Cast <DataGridViewRow>() where ((Decimal)Rows.Cells[5].Value == 0.00M || (Decimal)Rows.Cells[6].Value == 0.00M || (Decimal)Rows.Cells[7].Value == 0.00M) select Rows).Count(); if (SingleRow > 0) { MessageBox.Show("There are incorrect values in the form. Please correct before saving"); return; } using (var context = new TTI2Entities()) { var DB = context.TLDYE_DyeBatch.Find(Select.DYEB_Pk); if (DB != null) { DB.DYEB_OutProcess = true; DB.DYEB_OutProcessDate = DateTime.Now; } 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 == 600).FirstOrDefault(); } int Cnt = 0; foreach (DataGridViewRow row in dataGridView1.Rows) { TLDYE_DyeBatchDetails bd = new TLDYE_DyeBatchDetails(); if (row.Cells[0].Value == null) { continue; } int index = (int)row.Cells[0].Value; bd = context.TLDYE_DyeBatchDetails.Find(index); if (bd != null) { Weight += (decimal)row.Cells[5].Value; bd.DYEBO_Nett = (decimal)row.Cells[5].Value; bd.DYEBO_DiskWeight = (decimal)row.Cells[6].Value; bd.DYEBO_Width = (decimal)row.Cells[7].Value; bd.DYEBO_Meters = (decimal)row.Cells[8].Value; bd.DYEBO_TransDate = dtpTransDate.Value; bd.DYEBO_DyeDate = dtpDyeDate.Value; if (trantype != null) { bd.DYEBO_CurrentStore_FK = (int)trantype.TrxT_ToWhse_FK; } if (Convert.ToDecimal(row.Cells[5].Value.ToString()) != 0) { Cnt += 1; } } } int NoOfRecs = context.TLDYE_DyeBatchDetails.Where(x => x.DYEBD_DyeBatch_FK == DB.DYEB_Pk).ToList().Count; if (Cnt == NoOfRecs) { DB.DYEB_Closed = true; } TLDYE_DyeTransactions tt = new TLDYE_DyeTransactions(); tt.TLDYET_BatchNo = Select.DYEB_BatchNo; tt.TLDYET_BatchWeight = Select.DYEB_BatchKG; tt.TLDYET_TransactionType = (int)trantype.TrxT_Pk; tt.TLDYET_SequenceNo = Select.DYEB_SequenceNo; tt.TLDYET_Batch_FK = Select.DYEB_Pk; tt.TLDYET_Date = dtpTransDate.Value; tt.TLDYET_TransactionWeight = Weight; tt.TLDYET_CurrentStore_FK = (int)trantype.TrxT_ToWhse_FK; context.TLDYE_DyeTransactions.Add(tt); try { context.SaveChanges(); MessageBox.Show("Data successfully saved to the database"); Setup(); } 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); } } } }