private void button1_Click(object sender, EventArgs e) { BindingList <KeyValuePair <int, decimal> > CurrentRatios; Button oBtn = sender as Button; if (oBtn != null) { using (var context = new TTI2Entities()) { //------------------------------------------------------------------------------------ // First we must ensure that all records are removed from // the expectedUnits table for this particular Cut Sheet //--------------------------------------------------------------------------- context.TLCUT_ExpectedUnits.RemoveRange(context.TLCUT_ExpectedUnits.Where(x => x.TLCUTE_CutSheet_FK == _CsPk)); context.SaveChanges(); foreach (DataGridViewRow Row in dataGridView1.Rows) { var DbPk = (int)Row.Cells[1].Value; if ((bool)Row.Cells[2].Value == false) { //------------------------------------------------------------ // The pieces that are left are used to recalculate // the number of expected units //-------------------------------------------------------------- decimal Nett = (decimal)Row.Cells[5].Value; TLDYE_DyeBatchDetails dbd = context.TLDYE_DyeBatchDetails.Find(DbPk); if (dbd != null) { // Based on code developed for frmCutSheet // Is a body or is it a Trim Record //================================================= if (dbd.DYEBD_BodyTrim) { //-------------------------------------------------------------- // It is a body // Now calculate the yield //------------------------------------------------------------------ var Yield = core.FabricYield(dbd.DYEBO_DiskWeight, dbd.DYEBO_Width); var Rating = context.TLADM_ProductRating.Find((int)dbd.DYEBO_ProductRating_FK).Pr_numeric_Rating; var Factor = Math.Round(Yield / Rating * Nett, 0); var tst = core.CalculateRatios((int)dbd.DYEBO_ProductRating_FK, (int)Factor); foreach (var row in tst) { bool Add = true; var Kg = Math.Round(0.01M * row.Value / Yield, 2); TLCUT_ExpectedUnits eUnits = new TLCUT_ExpectedUnits(); eUnits = context.TLCUT_ExpectedUnits.Where(x => x.TLCUTE_CutSheet_FK == _CsPk && x.TLCUTE_Size_FK == row.Key).FirstOrDefault(); if (eUnits == null) { eUnits = new TLCUT_ExpectedUnits(); eUnits.TLCUTE_CutSheet_FK = _CsPk; eUnits.TLCUTE_Size_FK = row.Key; eUnits.TLCUTE_NoofGarments = row.Value; eUnits.TLCUTE_NoOfTrims = Kg; eUnits.TLCUTE_NoOfBinding = 0; } else { eUnits.TLCUTE_NoofGarments += row.Value; eUnits.TLCUTE_NoOfTrims += Kg; Add = !Add; } if (Add) { context.TLCUT_ExpectedUnits.Add(eUnits); context.SaveChanges(); } } } else { //-------------------------------------------------------------- // It is a Trim // Now calculate the yield //------------------------------------------------------------------ var Yield = core.FabricYield(dbd.DYEBO_DiskWeight, dbd.DYEBO_Width); var Rating = context.TLADM_ProductRating.Find((int)dbd.DYEBO_ProductRating_FK).Pr_numeric_Rating; CurrentRatios = core.ReturnRatios((int)dbd.DYEBO_ProductRating_FK); if (dbd.DYEBO_GVRowNumber == 1) { var NumberOf = Math.Round(Yield / Rating * Nett, 0); var TotalOf = CurrentRatios.Sum(x => (decimal?)x.Value) ?? 0.00M; foreach (var row in CurrentRatios) { int Calc = (int)Math.Round(row.Value / TotalOf * NumberOf, 0); TLCUT_ExpectedUnits eUnits = new TLCUT_ExpectedUnits(); eUnits = context.TLCUT_ExpectedUnits.Where(x => x.TLCUTE_CutSheet_FK == _CsPk && x.TLCUTE_Size_FK == row.Key).FirstOrDefault(); if (eUnits != null) { // The imfamous switch //---------------------------- eUnits.TLCUTE_NoOfTrims += Calc; } } } else if (dbd.DYEBO_GVRowNumber == 2) { var NumberOf = Math.Round(Yield / Rating * Nett, 0); var TotalOf = CurrentRatios.Sum(x => (decimal?)x.Value) ?? 0.00M; foreach (var row in CurrentRatios) { int Calc = (int)Math.Round(row.Value / TotalOf * NumberOf, 0); TLCUT_ExpectedUnits eUnits = new TLCUT_ExpectedUnits(); eUnits = context.TLCUT_ExpectedUnits.Where(x => x.TLCUTE_CutSheet_FK == _CsPk && x.TLCUTE_Size_FK == row.Key).FirstOrDefault(); if (eUnits != null) { // The imfamous switch //---------------------------- eUnits.TLCUTE_NoOfBinding += Calc; } } } } } continue; } var DyeBatchDetails = context.TLDYE_DyeBatchDetails.Find(DbPk); if (DyeBatchDetails != null) { DyeBatchDetails.DYEBO_CutSheet = false; } var CutSheetPk = (int)Row.Cells[0].Value; var CutSheetDetails = context.TLCUT_CutSheetDetail.Find(CutSheetPk); if (CutSheetDetails != null) { context.TLCUT_CutSheetDetail.Remove(CutSheetDetails); } } try { context.SaveChanges(); MessageBox.Show("Data saved to the database successfully"); frmCutViewRep vRep = new frmCutViewRep(1, _CsPk); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); this.Close(); return; } 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 = 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 btnSearch_Click(object sender, EventArgs e) { Button oBtn = (Button)sender; if (oBtn != null && txtPieceNo.Text.Length > 0) { using (var context = new TTI2Entities()) { dataGridView1.Rows.Clear(); frmPieceEnquiry_Load(this, null); FormLoaded = false; var Production = context.TLKNI_GreigeProduction.Where(x => x.GreigeP_PieceNo == txtPieceNo.Text).FirstOrDefault(); if (Production == null) { MessageBox.Show("No record found for value entered"); txtPieceNo.Text = string.Empty; return; } if (Production.GreigeP_KnitO_Fk != null) { if (Production.GreigeP_Greige_Fk != null) { var Quality = context.TLADM_Griege.Find(Production.GreigeP_Greige_Fk).TLGreige_Description; if (Quality != null) { txtQuality.Text = Quality; } } var KO = context.TLKNI_Order.Find(Production.GreigeP_KnitO_Fk); if (KO != null) { txtKnitOrder.Text = KO.KnitO_OrderNumber.ToString(); var YarnOrderPallet = context.TLKNI_YarnOrderPallets.Where(x => x.TLKNIOP_ReservedBy == KO.KnitO_Pk).FirstOrDefault(); if (YarnOrderPallet != null) { if (YarnOrderPallet.TLKNIOP_OwnYarn) { var YarnOrder = context.TLSPN_YarnOrder.Find(KO.KnitO_YarnO_FK); if (YarnOrder != null) { txtYarnOrder.Text = YarnOrder.YarnO_OrderNumber.ToString(); } } else { txtYarnOrder.Text = YarnOrderPallet.TLKNIOP_TLPalletNo; } } else if (KO.KnitO_YarnO_FK != null) { var YarnOrder = context.TLSPN_YarnOrder.Find(KO.KnitO_YarnO_FK); if (YarnOrder != null) { txtYarnOrder.Text = YarnOrder.YarnO_OrderNumber.ToString(); } else { var YarnTrans = context.TLKNI_YarnTransaction.Find(KO.KnitO_YarnO_FK); if (YarnTrans != null) { txtYarnOrder.Text = YarnTrans.KnitY_TransactionDoc; } } } } } if (Production.GreigeP_Dye) { DyeBatchDetail = context.TLDYE_DyeBatchDetails.Where(x => x.DYEBD_GreigeProduction_FK == Production.GreigeP_Pk).FirstOrDefault(); if (DyeBatchDetail != null) { txtMeters.Text = Math.Round(DyeBatchDetail.DYEBO_Meters, 2).ToString(); txtGross.Text = Math.Round(Production.GreigeP_weight, 2).ToString(); txtWidth.Text = Math.Round(DyeBatchDetail.DYEBO_Width, 2).ToString(); txtDisk.Text = Math.Round(DyeBatchDetail.DYEBO_DiskWeight, 2).ToString(); txtNett.Text = Math.Round(DyeBatchDetail.DYEBO_Nett, 2).ToString(); btnRecalc.Enabled = true; var DyeBatch = context.TLDYE_DyeBatch.Find(DyeBatchDetail.DYEBD_DyeBatch_FK); if (DyeBatch != null) { txtDyeBatch.Text = DyeBatch.DYEB_BatchNo; var DO = context.TLDYE_DyeOrder.Find(DyeBatch.DYEB_DyeOrder_FK); if (DO != null) { txtColour.Text = context.TLADM_Colours.Find(DO.TLDYO_Colour_FK).Col_Description; txtDyeOrder.Text = DO.TLDYO_DyeOrderNum; chkDOClosed.Checked = DO.TLDYO_Closed; } chkDBClosed.Checked = DyeBatch.DYEB_Closed; } } if (DyeBatchDetail != null && DyeBatchDetail.DYEBO_CutSheet) { } } dataGridView1.Rows[0].Cells[2].Value = Production.GreigeP_Meas1; dataGridView1.Rows[1].Cells[2].Value = Production.GreigeP_Meas2; dataGridView1.Rows[2].Cells[2].Value = Production.GreigeP_Meas3; dataGridView1.Rows[3].Cells[2].Value = Production.GreigeP_Meas4; dataGridView1.Rows[4].Cells[2].Value = Production.GreigeP_Meas5; dataGridView1.Rows[5].Cells[2].Value = Production.GreigeP_Meas6; dataGridView1.Rows[6].Cells[2].Value = Production.GreigeP_Meas7; dataGridView1.Rows[7].Cells[2].Value = Production.GreigeP_Meas8; FormLoaded = true; } } }
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); } } } }