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 cmboCutSheet_SelectedIndexChanged(object sender, EventArgs e) { ComboBox oCmbo = sender as ComboBox; if (oCmbo != null && formloaded) { var selected = (TLCUT_CutSheet)oCmbo.SelectedItem; if (selected != null) { using (var context = new TTI2Entities()) { dataGridView1.Rows.Clear(); var DB = context.TLDYE_DyeBatch.Find(selected.TLCutSH_DyeBatch_FK); if (DB != null) { txtDyeBatch.Text = DB.DYEB_BatchNo; var DO = context.TLDYE_DyeOrder.Find(DB.DYEB_DyeOrder_FK); if (DO != null) { txtCustomer.Text = context.TLADM_CustomerFile.Find(DO.TLDYO_Customer_FK).Cust_Description; txtColour.Text = context.TLADM_Colours.Find(DO.TLDYO_Colour_FK).Col_Description; txtDateOrdered.Text = DO.TLDYO_OrderDate.ToString("dd/MM/yyyy"); DateTime dt = core.FirstDateOfWeek(DO.TLDYO_OrderDate.Year, DO.TLDYO_CutReqWeek); txtDateRequired.Text = dt.AddDays(5).ToString("dd/MM/yyyy"); var DBDetails = context.TLDYE_DyeBatchDetails.Where(x => x.DYEBD_DyeBatch_FK == DB.DYEB_Pk).ToList(); foreach (var row in DBDetails) { if (row.DYEBD_BodyTrim) { txtBody.Text = context.TLADM_Griege.Find(row.DYEBD_QualityKey).TLGreige_Description; } else { if (String.IsNullOrEmpty(txtTrim1.Text)) { txtTrim1.Text = context.TLADM_Griege.Find(row.DYEBD_QualityKey).TLGreige_Description; } else if (String.IsNullOrEmpty(txtTrim2.Text)) { txtTrim2.Text = context.TLADM_Griege.Find(row.DYEBD_QualityKey).TLGreige_Description; } } } } } TLCUT_CutSheetReceipt CSR = new TLCUT_CutSheetReceipt(); CSR = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == selected.TLCutSH_Pk).FirstOrDefault(); if (CSR != null) { IList <TLCUT_CutSheetReceiptDetail> CSRD = new List <TLCUT_CutSheetReceiptDetail>(); CSRD = context.TLCUT_CutSheetReceiptDetail.Where(x => x.TLCUTSHRD_CutSheet_FK == CSR.TLCUTSHR_Pk && !x.TLCUTSHRD_PanelRejected && x.TLCUTSHRD_BundleQty != 0).ToList(); if (CSRD != null) { foreach (var row in CSRD) { var index = dataGridView1.Rows.Add(); dataGridView1.Rows[index].Cells[0].Value = row.TLCUTSHRD_Pk; dataGridView1.Rows[index].Cells[1].Value = false; dataGridView1.Rows[index].Cells[2].Value = row.TLCUTSHRD_Description; dataGridView1.Rows[index].Cells[3].Value = row.TLCUTSHRD_Size_FK; dataGridView1.Rows[index].Cells[4].Value = row.TLCUTSHRD_BundleQty - row.TLCUTSHRD_RejectQty; if (row.TLCUTSHRD_RejectReason == 0) { dataGridView1.Rows[index].Cells[5].Value = context.TLCUT_RejectReasons.FirstOrDefault().TLCUTRJR_Pk; } else { dataGridView1.Rows[index].Cells[5].Value = row.TLCUTSHRD_RejectReason; } dataGridView1.Rows[index].Cells[6].Value = 0; } } } } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; bool Add = false; TLCUT_CutSheetReceipt CSR = null; if (oBtn != null) { if (dataGridView1.Rows.Count < Convert.ToInt32(txtBundles.Text)) { MessageBox.Show("Please complete the form correctly"); return; } var selected = (TLCUT_CutSheet)cmboCutSheet.SelectedItem; if (selected != null) { var Machine = (TLADM_MachineDefinitions)cmboMachines.SelectedItem; if (Machine == null) { MessageBox.Show("Please select a machine on which this cutsheet was cut"); return; } using (var context = new TTI2Entities()) { var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("CUT")).FirstOrDefault(); var CS = context.TLCUT_CutSheet.Find(selected.TLCutSH_Pk); if (CS != null) { CS.TLCutSH_WIPComplete = true; CS.TLCUTSH_AddNotes = string.Empty; } CSR = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == selected.TLCutSH_Pk).FirstOrDefault(); if (CSR == null) { Add = true; CSR = new TLCUT_CutSheetReceipt(); } CSR.TLCUTSHR_Style_FK = selected.TLCutSH_Styles_FK; CSR.TLCUTSHR_CutSheet_FK = selected.TLCutSH_Pk; CSR.TLCUTSHR_Date = dtpTransDate.Value; CSR.TLCUTSHR_NoOfBundles = Convert.ToInt32(txtBundles.Text); CSR.TLCUTSHR_Machine_FK = Machine.MD_Pk; CSR.TLCUTSHR_InBundleStore = true; if (CSR.TLCUTSHR_InBundleStore) { var CutStore = context.TLADM_WhseStore.Where(x => x.WhStore_DepartmentFK == CS.TLCutSH_Department_FK && x.WhStore_BundleStore).FirstOrDefault(); if (CutStore != null) { CSR.TLCUTSHR_WhseBunStore_FK = CutStore.WhStore_Id; CSR.TLCUTSHR_DateIntoBunStore = dtpTransDate.Value; } } if (Add) { context.TLCUT_CutSheetReceipt.Add(CSR); } try { context.SaveChanges(); } 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); } foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[2].Value == null) { continue; } TLCUT_CutSheetReceiptDetail CSRD = new TLCUT_CutSheetReceiptDetail(); Add = true; if ((int)row.Cells[0].Value != 0) { var index = (int)row.Cells[0].Value; CSRD = context.TLCUT_CutSheetReceiptDetail.Find(index); if (CSRD != null) { Add = false; } else { CSRD = new TLCUT_CutSheetReceiptDetail(); } } CSRD.TLCUTSHRD_CutSheet_FK = CSR.TLCUTSHR_Pk; CSRD.TLCUTSHRD_Description = (String)row.Cells[1].Value; CSRD.TLCUTSHRD_Size_FK = (int)row.Cells[2].Value; CSRD.TLCUTSHRD_BundleQty = (int)row.Cells[3].Value; CSRD.TLCUTSHRD_InBundleStore = true; if (Dept != null) { var TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 200).FirstOrDefault(); if (TranType != null) { CSRD.TLCUTSHRD_TransactionType = TranType.TrxT_Pk; CSRD.TLCUTSHRD_CurrentStore_FK = (int)TranType.TrxT_ToWhse_FK; } } if (Add) { context.TLCUT_CutSheetReceiptDetail.Add(CSRD); } } TLCUT_CutSheetReceiptBoxes CSRB = new TLCUT_CutSheetReceiptBoxes(); CSRB = context.TLCUT_CutSheetReceiptBoxes.Where(x => x.TLCUTSHB_CutSheet_FK == CSR.TLCUTSHR_Pk).FirstOrDefault(); Add = false; if (CSRB == null) { CSRB = new TLCUT_CutSheetReceiptBoxes(); Add = true; } CSRB.TLCUTSHB_CutSheet_FK = CSR.TLCUTSHR_Pk; if (!String.IsNullOrEmpty(txtAdultBoxes.Text)) { CSRB.TLCUTSHB_AdultBoxes = Convert.ToInt32(txtAdultBoxes.Text); } else { CSRB.TLCUTSHB_AdultBoxes = 0; } if (!String.IsNullOrEmpty(txtKidsBoxes.Text)) { CSRB.TLCUTSHB_KidBoxes = Convert.ToInt32(txtKidsBoxes.Text); } else { CSRB.TLCUTSHB_KidBoxes = 0; } if (!String.IsNullOrEmpty(txtBinding.Text)) { CSRB.TLCUTSHB_Binding = Convert.ToInt32(txtBinding.Text); } else { CSRB.TLCUTSHB_Binding = 0; } if (!String.IsNullOrEmpty(txtRibbing.Text)) { CSRB.TLCUTSHB_Ribbing = Convert.ToInt32(txtRibbing.Text); } else { CSRB.TLCUTSHB_Ribbing = 0; } if (Add) { context.TLCUT_CutSheetReceiptBoxes.Add(CSRB); } try { context.SaveChanges(); MessageBox.Show("Data saved successfully to database"); dataGridView1.Rows.Clear(); dataGridView2.Rows.Clear(); 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 cmboCutSheet_SelectedIndexChanged(object sender, EventArgs e) { ComboBox oCmbo = sender as ComboBox; IList <TLADM_Sizes> sz = new List <TLADM_Sizes>(); int NoOfUnits = 0; if (oCmbo != null && formloaded) { var selected = (TLCUT_CutSheet)oCmbo.SelectedItem; if (selected != null) { dataGridView1.Rows.Clear(); dataGridView2.Rows.Clear(); cutSheet = selected; txtBundles.Enabled = true; txtBundles.Text = "0"; rtbNotes.Text = selected.TLCutSH_Notes; using (var context = new TTI2Entities()) { var Sizes = core.ExtrapNumber(selected.TLCutSH_Size_PN, context.TLADM_Sizes.Count()); Sizes.Sort(); foreach (var Size in Sizes) { var sze = context.TLADM_Sizes.Where(x => x.SI_PowerN == Size).FirstOrDefault(); if (sze != null) { sz.Add(sze); } } var DB = context.TLDYE_DyeBatch.Find(selected.TLCutSH_DyeBatch_FK); if (DB != null) { txtDyeBatch.Text = DB.DYEB_BatchNo; var DO = context.TLDYE_DyeOrder.Find(DB.DYEB_DyeOrder_FK); if (DO != null) { NoOfUnits = context.TLDYE_DyeOrderDetails.Where(x => x.TLDYOD_DyeOrder_Fk == DO.TLDYO_Pk && x.TLDYOD_BodyOrTrim).FirstOrDefault().TLDYOD_Units; txtCustomer.Text = context.TLADM_CustomerFile.Find(DO.TLDYO_Customer_FK).Cust_Description; txtColour.Text = context.TLADM_Colours.Find(cutSheet.TLCutSH_Colour_FK).Col_Description; txtDateOrdered.Text = DO.TLDYO_OrderDate.ToString("dd/MM/yyyy"); DateTime dt = core.FirstDateOfWeek(DO.TLDYO_OrderDate.Year, DO.TLDYO_CutReqWeek); txtDateRequired.Text = dt.AddDays(5).ToString("dd/MM/yyyy"); var DBDetails = context.TLDYE_DyeBatchDetails.Where(x => x.DYEBD_DyeBatch_FK == DB.DYEB_Pk).ToList(); foreach (var row in DBDetails) { if (row.DYEBD_BodyTrim) { txtBody.Text = context.TLADM_Griege.Find(row.DYEBD_QualityKey).TLGreige_Description; } else { if (String.IsNullOrEmpty(txtTrim1.Text)) { txtTrim1.Text = context.TLADM_Griege.Find(row.DYEBD_QualityKey).TLGreige_Description; } else if (String.IsNullOrEmpty(txtTrim2.Text)) { txtTrim2.Text = context.TLADM_Griege.Find(row.DYEBD_QualityKey).TLGreige_Description; } } } var EUnits = (from EUnitsx in context.TLCUT_ExpectedUnits join xSizes in context.TLADM_Sizes on EUnitsx.TLCUTE_Size_FK equals xSizes.SI_id where EUnitsx.TLCUTE_CutSheet_FK == cutSheet.TLCutSH_Pk orderby xSizes.SI_DisplayOrder select EUnitsx).ToList(); // var EUnits = context.TLCUT_ExpectedUnits.Where(x => x.TLCUTE_CutSheet_FK == cutSheet.TLCutSH_Pk).ToList(); foreach (var row in EUnits) { var index = dataGridView2.Rows.Add(); dataGridView2.Rows[index].Cells[0].Value = row.TLCUTE_Size_FK; dataGridView2.Rows[index].Cells[1].Value = context.TLADM_Sizes.Find(row.TLCUTE_Size_FK).SI_Description; dataGridView2.Rows[index].Cells[2].Value = row.TLCUTE_NoofGarments; dataGridView2.Rows[index].Cells[3].Value = 0; dataGridView2.Rows[index].Cells[4].Value = 0.00M; } } } //------------------------------------------------------------ TLCUT_CutSheetReceipt CSR = new TLCUT_CutSheetReceipt(); CSR = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == cutSheet.TLCutSH_Pk).FirstOrDefault(); if (CSR != null) { cmboMachines.SelectedValue = CSR.TLCUTSHR_Machine_FK; dtpTransDate.Value = CSR.TLCUTSHR_Date; txtBundles.Text = CSR.TLCUTSHR_NoOfBundles.ToString(); IList <TLCUT_CutSheetReceiptDetail> CSRD = new List <TLCUT_CutSheetReceiptDetail>(); CSRD = context.TLCUT_CutSheetReceiptDetail.Where(x => x.TLCUTSHRD_CutSheet_FK == CSR.TLCUTSHR_Pk).ToList(); if (CSRD != null) { foreach (var row in CSRD) { var index = dataGridView1.Rows.Add(); dataGridView1.Rows[index].Cells[0].Value = row.TLCUTSHRD_Pk; dataGridView1.Rows[index].Cells[1].Value = row.TLCUTSHRD_Description; dataGridView1.Rows[index].Cells[2].Value = row.TLCUTSHRD_Size_FK; dataGridView1.Rows[index].Cells[3].Value = row.TLCUTSHRD_BundleQty; } DataGridViewCellEventArgs exx = new DataGridViewCellEventArgs(3, 1); try { // dataGridView1_CellLeave(dataGridView1, exx); } catch (Exception ex) { MessageBox.Show(ex.Message); } } TLCUT_CutSheetReceiptBoxes CSRB = new TLCUT_CutSheetReceiptBoxes(); CSRB = context.TLCUT_CutSheetReceiptBoxes.Where(x => x.TLCUTSHB_CutSheet_FK == CSR.TLCUTSHR_Pk).FirstOrDefault(); if (CSRB != null) { txtAdultBoxes.Text = CSRB.TLCUTSHB_AdultBoxes.ToString(); txtBinding.Text = CSRB.TLCUTSHB_Binding.ToString(); txtKidsBoxes.Text = CSRB.TLCUTSHB_KidBoxes.ToString(); txtRibbing.Text = CSRB.TLCUTSHB_Ribbing.ToString(); } } } oCmboA.ValueMember = "SI_Id"; oCmboA.DisplayMember = "SI_Description"; oCmboA.DataSource = sz; } } }
private void cmboCMTLine_SelectedIndexChanged(object sender, EventArgs e) { ComboBox oCmbo = sender as ComboBox; if (oCmbo != null && formloaded) { var selected = (int)oCmbo.SelectedValue; if (selected != 0) { formloaded = false; dataGridView1.Rows.Clear(); dataGridView2.Rows.Clear(); formloaded = true; txtDifference.Text = "0"; txtTotAGrade.Text = "0"; txtTotBGrade.Text = "0"; txtTPIssued.Text = "0"; txtTPPanels.Text = "0"; txtNoBoxes.Text = "0"; using (var context = new TTI2Entities()) { var LI = context.TLCMT_LineIssue.Find(selected); if (LI != null) { CS = context.TLCUT_CutSheet.Find(LI.TLCMTLI_CutSheet_FK); if (CS != null) { CSR = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == CS.TLCutSH_Pk).FirstOrDefault(); if (CSR == null) { MessageBox.Show("Technical error encounted. Qoute number 1400"); frmCompleted_Load(this, null); return; } //------------------------------------------------------- //We have to check that all the BFA Data has been recorded //-------------------------------------------------------------------- int BFACount = context.TLCMT_AuditMeasureRecorded.Where(x => x.TLBFAR_CutSheet_FK == CS.TLCutSH_Pk).Count(); if (BFACount == 0) { MessageBox.Show("Please enter the BFA Audit information" + Environment.NewLine + "using the facility provided"); frmCompleted_Load(this, null); return; } //------------------------------------------------------ // We have to now //========================================= var ExpectUnits = context.TLCUT_ExpectedUnits.Where(x => x.TLCUTE_CutSheet_FK == CS.TLCutSH_Pk).ToList(); foreach (var Unit in ExpectUnits) { TLADM_Sizes Size = new TLADM_Sizes(); Size.SI_Description = context.TLADM_Sizes.Find(Unit.TLCUTE_Size_FK).SI_Description; Size.SI_id = Unit.TLCUTE_Size_FK; oCmboA.Items.Add(Size); } //--------------------------------------------------------------- //If expected units data not available, for what ever reason, go back to the original order //========================================================================== if (oCmboA.Items.Count == 0) { var CutSheetDetail = context.TLCUT_CutSheetReceiptDetail.Where(x => x.TLCUTSHRD_CutSheet_FK == CSR.TLCUTSHR_Pk).GroupBy(x => x.TLCUTSHRD_Size_FK); foreach (var Grouped in CutSheetDetail) { var Size_Pk = Grouped.FirstOrDefault().TLCUTSHRD_Size_FK; TLADM_Sizes Size = new TLADM_Sizes(); Size.SI_Description = context.TLADM_Sizes.Find(Size_Pk).SI_Description; Size.SI_id = Size_Pk; oCmboA.Items.Add(Size); } } oCmboA.DisplayMember = "SI_Description"; oCmboA.ValueMember = "SI_Id"; txtCutSheet.Text = CS.TLCutSH_No; var DB = context.TLDYE_DyeBatch.Find(CS.TLCutSH_DyeBatch_FK); if (DB != null) { var DO = context.TLDYE_DyeOrder.Find(DB.DYEB_DyeOrder_FK); if (DO != null) { var dt = core.FirstDateOfWeek(DO.TLDYO_OrderDate.Year, DO.TLDYO_CMTReqWeek); txtDateRequired.Text = dt.AddDays(5).ToString("dd/MM/yyyy"); } } Styles = context.TLADM_Styles.Find(CS.TLCutSH_Styles_FK); Colours = context.TLADM_Colours.Find(CS.TLCutSH_Colour_FK); StyleGrades = context.TLADM_StylesGrades.Where(x => x.TLSG_Style_Fk == CS.TLCutSH_Styles_FK).FirstOrDefault(); var Existing = context.TLCUT_CutSheetReceiptDetail.Where(x => x.TLCUTSHRD_CutSheet_FK == CSR.TLCUTSHR_Pk).ToList(); /* if (Existing != null) * { * Sizes = context.TLADM_Sizes.Find(Existing.FirstOrDefault().TLCUTSHRD_Size_FK); * }*/ foreach (var row in Existing) { var index = dataGridView1.Rows.Add(); this.dataGridView1.Rows[index].Cells[0].Value = row.TLCUTSHRD_BoxNumber; this.dataGridView1.Rows[index].Cells[1].Value = Styles.Sty_Description; this.dataGridView1.Rows[index].Cells[2].Value = Colours.Col_Display; this.dataGridView1.Rows[index].Cells[3].Value = row.TLCUTSHRD_BoxUnits; } txtTPIssued.Text = Existing.Sum(x => x.TLCUTSHRD_BoxUnits).ToString(); // 0 Box No datagridView2 // 1 Code datagridView2 // 2 Size datagridView2 // 3 Grade datagridView2 // 4 Qty datagridView2 // 5 Weight dataGridView2 // 6 FK CutSheetSheet Receipt Detail datagridView2 formloaded = false; foreach (var row in Existing) { var index = dataGridView2.Rows.Add(); this.dataGridView2.Rows[index].Cells[0].Value = row.TLCUTSHRD_BoxNumber; this.dataGridView2.Rows[index].Cells[1].Value = string.Empty; this.dataGridView2.Rows[index].Cells[2].Value = null; // string.Empty; this.dataGridView2.Rows[index].Cells[3].Value = string.Empty; this.dataGridView2.Rows[index].Cells[4].Value = 0; this.dataGridView2.Rows[index].Cells[5].Value = 0.00M; this.dataGridView2.Rows[index].Cells[6].Value = row.TLCUTSHRD_Pk; } formloaded = true; if (this.dataGridView2.Rows.Count != 0) { this.dataGridView2.CurrentCell = this.dataGridView2.Rows[0].Cells[1]; this.dataGridView2.BeginEdit(true); } } } } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLCUT_CutSheetReceipt CSR = null; if (oBtn != null && formloaded) { using (var context = new TTI2Entities()) { var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("CUT")).FirstOrDefault(); if (CutSheetSelected != 0) { CSR = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == CutSheetSelected).FirstOrDefault(); if (CSR != null) { CSR.TLCUTSHR_InBundleStore = false; CSR.TLCUTSHR_InPanelStore = true; CSR.TLCUTSHR_DateIntoPanelStore = dtpTransActionDate.Value; var CS = context.TLCUT_CutSheet.Find(CSR.TLCUTSHR_CutSheet_FK); if (CS != null) { if (rtbAdditional.Text.Length != 0) { CS.TLCUTSH_AddNotes = rtbAdditional.Text; } CS.TLCUTSH_Completed_Date = DateTime.Now; CSR.TLCUTSHR_Colour_FK = CS.TLCutSH_Colour_FK; var CutStore = context.TLADM_WhseStore.Where(x => x.WhStore_DepartmentFK == CS.TLCutSH_Department_FK && x.WhStore_PanelStore).FirstOrDefault(); if (CutStore != null) { CSR.TLCUTSHR_WhsePanStore_FK = CutStore.WhStore_Id; CSR.TLCUTSHR_DateIntoPanelStore = dtpTransActionDate.Value; } } } } else { MessageBox.Show("Please select a cutsheet from the drop down box"); return; } foreach (DataGridViewRow row in dataGridView1.Rows) { TLCUT_CutSheetReceiptDetail CSRD = new TLCUT_CutSheetReceiptDetail(); var index = (int)row.Cells[0].Value; CSRD = context.TLCUT_CutSheetReceiptDetail.Find(index); if (CSRD != null) { CSRD.TLCUTSHRD_BoxNumber = dataGridView1.Rows[row.Index].Cells[3].Value.ToString(); if ((int)dataGridView1.Rows[row.Index].Cells[4].Value == 0) { continue; } CSRD.TLCUTSHRD_BoxUnits = (int)dataGridView1.Rows[row.Index].Cells[4].Value; CSRD.TLCUTSHRD_BoxType_FK = 1; // removed to speed up data capture (int)dataGridView1.Rows[row.Index].Cells[5].Value; CSRD.TLCUTSHRD_InBundleStore = false; CSRD.TLCUTSHRD_PanelDate = dtpTransActionDate.Value; if (Dept != null) { var TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 600).FirstOrDefault(); if (TranType != null) { CSRD.TLCUTSHRD_TransactionType = TranType.TrxT_Pk; CSRD.TLCUTSHRD_CurrentStore_FK = (int)TranType.TrxT_ToWhse_FK; } } } } var CSB = context.TLCUT_CutSheetReceiptBoxes.Where(x => x.TLCUTSHB_Pk == CSR.TLCUTSHR_Pk).FirstOrDefault(); if (CSB != null) { int value = 0; if (int.TryParse(txtAdultBoxes.Text, out value)) { CSB.TLCUTSHB_AdultBoxes = value; } value = 0; if (int.TryParse(txtBinding.Text, out value)) { CSB.TLCUTSHB_Binding = value; } value = 0; if (int.TryParse(txtKidsBoxes.Text, out value)) { CSB.TLCUTSHB_KidBoxes = value; } value = 0; if (int.TryParse(txtRibbing.Text, out value)) { CSB.TLCUTSHB_Ribbing = value; } } try { context.SaveChanges(); MessageBox.Show("Data saved successfully to database"); dataGridView1.Rows.Clear(); //This form is the summary form for Mary in the accessories store //=================================================== frmCutViewRep vRep = new frmCutViewRep(11, CutSheetSelected); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(); //This form is the CMT Issued to line document //============================================================== vRep = new frmCutViewRep(14, CutSheetSelected); h = Screen.PrimaryScreen.WorkingArea.Height; 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) { MessageBox.Show(ex.Message); } } } }
private void cmboCutSheet_SelectedIndexChanged(object sender, EventArgs e) { ComboBox oCmbo = sender as ComboBox; if (oCmbo != null && formloaded) { Object tst = oCmbo.SelectedItem; foreach (PropertyInfo prop in tst.GetType().GetProperties()) { if (prop.Name == "Pk") { CutSheetSelected = Convert.ToInt32(prop.GetValue(tst)); } } } if (CutSheetSelected != 0) { dataGridView1.Rows.Clear(); using (var context = new TTI2Entities()) { TLCUT_CutSheetReceipt CSR = new TLCUT_CutSheetReceipt(); CSR = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == CutSheetSelected).FirstOrDefault(); if (CSR != null) { IList <TLCUT_CutSheetReceiptDetail> CSRD = new List <TLCUT_CutSheetReceiptDetail>(); CSRD = context.TLCUT_CutSheetReceiptDetail.Where(x => x.TLCUTSHRD_CutSheet_FK == CSR.TLCUTSHR_Pk).ToList(); if (CSRD != null) { foreach (var row in CSRD) { var index = dataGridView1.Rows.Add(); dataGridView1.Rows[index].Cells[0].Value = row.TLCUTSHRD_Pk; dataGridView1.Rows[index].Cells[1].Value = row.TLCUTSHRD_Description; dataGridView1.Rows[index].Cells[2].Value = row.TLCUTSHRD_BundleQty; if (row.TLCUTSHRD_BoxNumber != null) { dataGridView1.Rows[index].Cells[3].Value = row.TLCUTSHRD_BoxNumber; } else { dataGridView1.Rows[index].Cells[3].Value = row.TLCUTSHRD_Description; } dataGridView1.Rows[index].Cells[4].Value = row.TLCUTSHRD_BoxUnits; /* * if(row.TLCUTSHRD_BoxType_FK != 0) * dataGridView1.Rows[index].Cells[5].Value = row.TLCUTSHRD_BoxType_FK; * else * dataGridView1.Rows[index].Cells[5].Value = 1; * */ } if (this.dataGridView1.Rows.Count != 0) { this.dataGridView1.CurrentCell = this.dataGridView1.Rows[0].Cells[4]; this.dataGridView1.BeginEdit(true); } } } var CSB = context.TLCUT_CutSheetReceiptBoxes.Where(x => x.TLCUTSHB_CutSheet_FK == CSR.TLCUTSHR_Pk).FirstOrDefault(); if (CSB != null) { txtAdultBoxes.Text = CSB.TLCUTSHB_AdultBoxes.ToString(); txtBinding.Text = CSB.TLCUTSHB_Binding.ToString(); txtKidsBoxes.Text = CSB.TLCUTSHB_KidBoxes.ToString(); txtRibbing.Text = CSB.TLCUTSHB_Ribbing.ToString(); } } } }