private void SaveYarnProduction(int machineNo, decimal yarnProduction) { DateTime selectedDate = dtpYarnProductionDate.Value; if (selectedDate != null) { using (var context = new TTI2Entities()) { DateTime selectedDateEndOfDay = selectedDate.Date.AddHours(24); TLSPN_YarnProductionPerMachine yarnProductionInfo = context.TLSPN_YarnProductionPerMachine.Where(x => x.YarnProductionDate >= selectedDate.Date && x.YarnProductionDate < selectedDateEndOfDay && x.MachineNo_FK == machineNo).FirstOrDefault(); if (yarnProductionInfo != null) { //yarnProductionInfo. yarnProductionInfo.YarnProduction = yarnProduction; yarnProductionInfo.YarnProductionDate = selectedDate; } else { yarnProductionInfo = new TLSPN_YarnProductionPerMachine(); yarnProductionInfo.MachineNo_FK = machineNo; yarnProductionInfo.YarnProductionDate = selectedDate; yarnProductionInfo.YarnProduction = yarnProduction; context.TLSPN_YarnProductionPerMachine.Add(yarnProductionInfo); } try { context.SaveChanges(); formloaded = false; SetUp(false); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = (Button)sender; DataGridView oDgv = dataGridView1; if (oBtn != null && FormLoaded) { using (var context = new TTI2Entities()) { foreach (DataGridViewRow Row in dataGridView1.Rows) { if (!(bool)Row.Cells[1].Value) { continue; } var DyeOrder_Pk = (int)Row.Cells[0].Value; var DOrder = context.TLDYE_DyeOrder.Find(DyeOrder_Pk); if (DOrder != null) { DOrder.TLDYO_Closed = true; } } try { context.SaveChanges(); MessageBox.Show("Data successfuly saved to the database"); this.dataGridView1.Rows.Clear(); this.frmCloseDyeOrders_Load(this, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { var loc = e.Location; DataGridView oDgv = sender as DataGridView; if (oDgv != null && e.Button.ToString() == "Right") { if (this.dataGridView1.SelectedRows.Count > 0) { DialogResult res = MessageBox.Show("Please confirm this transaction" + Environment.NewLine + " This action could possible cause a system abend", "Confirmation Required", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (res == DialogResult.OK) { DataGridViewRow cr = oDgv.CurrentRow; using (var context = new TTI2Entities()) { int RecNo = Convert.ToInt32(cr.Cells[0].Value.ToString()); var locRec = context.TLPPS_Replenishment.Find(RecNo); if (locRec != null) { try { context.TLPPS_Replenishment.Remove(locRec); context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } oDgv.Rows.RemoveAt(this.dataGridView1.SelectedRows[0].Index); } } else { MessageBox.Show("Please select a row in the datagrid", "Information"); } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; if (oBtn != null && formloaded) { using (var context = new TTI2Entities()) { foreach (DataGridViewRow row in dataGridView1.Rows) { if ((bool)row.Cells[7].Value == false) { var index = (int)row.Cells[0].Value; var Record = context.TLDYE_DyeBatchDetails.Find(index); if (Record != null) { Record.DYEBO_DateSold = null; Record.DYEBO_Sold = false; Record.DYEBO_TransactionNo = string.Empty; } } } try { context.SaveChanges(); MessageBox.Show("Data saved successfully to database"); string transnumber = cmboPendingSales.SelectedValue.ToString(); frmDyeViewReport vRep = new frmDyeViewReport(18, transnumber); vRep.ShowDialog(this); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void chkDOClosed_CheckedChanged(object sender, EventArgs e) { CheckBox cb = (CheckBox)sender; if (cb != null && DyeBatchDetail != null && FormLoaded) { using (var context = new TTI2Entities()) { var DyeBatch = context.TLDYE_DyeBatch.Find(DyeBatchDetail.DYEBD_DyeBatch_FK); if (DyeBatch != null) { var DyeOrder = context.TLDYE_DyeOrder.Find(DyeBatch.DYEB_DyeOrder_FK); if (DyeOrder != null) { DialogResult DResult = MessageBox.Show("Please confirm this transaction", "Confirmation Required", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DResult == DialogResult.Yes) { DyeOrder.TLDYO_Closed = cb.Checked; try { context.SaveChanges(); MessageBox.Show("Data updated successfully to database"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show("Unable to perform transaction"); } } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = (Button)sender; if (oBtn != null && FormLoaded) { using (var context = new TTI2Entities()) { foreach (DataGridViewRow Row in dataGridView1.Rows) { if (!(bool)Row.Cells[1].Value) { continue; } int Pk = (int)Row.Cells[0].Value; var LineIssue = context.TLCMT_LineIssue.Find(Pk); if (LineIssue != null) { LineIssue.TLCMTLI_Priority = true; LineIssue.TLCMTLI_Priority_Date = dtDate.Value; } } try { context.SaveChanges(); MessageBox.Show("Data saved successfully to database"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; if (oBtn != null && formloaded) { var ErrM = core.returnMessage(MandSelected, false, MandatoryFields); if (!String.IsNullOrEmpty(ErrM)) { MessageBox.Show(ErrM); return; } using (var context = new TTI2Entities()) { if (Add) { var LNU = context.TLADM_LastNumberUsed.Find(3); if (LNU != null) { LNU.col4 += 1; } } TLDYE_ComDyeBatch cb = new TLDYE_ComDyeBatch(); if (!Add) { var Prev = (TLDYE_ComDyeBatch)cmboPrevBatches.SelectedItem; if (Prev != null) { cb = context.TLDYE_ComDyeBatch.Find(Prev.DYEBC_Pk); } } cb.DYEBC_BatchDate = dtpBatchDate.Value; cb.DYEBC_BatchNo = txtBatchNo.Text; cb.DYEBC_DateOrder = dtpDateOrdered.Value; cb.DYEBC_DateRequired = dtpDateOrdered.Value; cb.DYEBC_Greige_FK = (int)cmboGreige.SelectedValue; cb.DYEBC_Trim_Fk = (int)cmboTrims.SelectedValue; cb.DYEBC_Customer_FK = (int)cmboCustomer.SelectedValue; cb.DYEBC_Colour_FK = (int)cmboColours.SelectedValue; var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("DYE")).FirstOrDefault(); if (Dept != null) { var TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 300).FirstOrDefault(); if (TranType != null) { cb.DYEBC_TransactionType = TranType.TrxT_Pk; } } if (Add) { context.TLDYE_ComDyeBatch.Add(cb); 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) { var exceptionMessages = new StringBuilder(); do { exceptionMessages.Append(ex.Message); ex = ex.InnerException; }while (ex != null); MessageBox.Show(exceptionMessages.ToString()); } } foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[1].Value.ToString() == bool.FalseString) { continue; } var index = (int)row.Cells[0].Value; TLKNI_GreigeCommissionTransctions rec = context.TLKNI_GreigeCommissionTransctions.Find(index); if (rec != null) { rec.GreigeCom_Batched = true; rec.GreigeCom_DyeBatch_FK = cb.DYEBC_Pk; } TLDYE_ComDyeBatchDetails cdb = new TLDYE_ComDyeBatchDetails(); cdb.TLCDD_PieceNo_FK = rec.GreigeCom_PK; cdb.TLCDD_ComDyeBatch_FK = cb.DYEBC_Pk; context.TLDYE_ComDyeBatchDetails.Add(cdb); } try { context.SaveChanges(); MessageBox.Show("Data saved to database successfully"); frmDyeViewReport vrep = new frmDyeViewReport(9, cb.DYEBC_Pk); vrep.ShowDialog(this); 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) { var exceptionMessages = new StringBuilder(); do { exceptionMessages.Append(ex.Message); ex = ex.InnerException; }while (ex != null); MessageBox.Show(exceptionMessages.ToString()); } } } }
private void dataGridView1_MouseClick(object sender, MouseEventArgs e) { var loc = e.Location; DataGridView oDgv = sender as DataGridView; int Ratings_FK = 0; if (oDgv != null && formloaded && e.Button.ToString() == "Right") { if (this.dataGridView1.SelectedRows.Count > 0) { DialogResult res = MessageBox.Show("Please confirm this transaction", "Confirmation Required", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (res == DialogResult.OK) { DataGridViewRow cr = oDgv.CurrentRow; if (cr.Cells[0].Value != null) { // We need to check that there are no existing records //======================================================== Ratings_FK = Convert.ToInt32(cr.Cells[0].Value.ToString()); if (core.CheckActiveRatings(Ratings_FK)) { using (var context = new TTI2Entities()) { //------------------------------------------------------------------------------------ // First we must ensure that all subordinate records are deleted first //--------------------------------------------------------------------------- context.TLADM_ProductRating_Detail.RemoveRange(context.TLADM_ProductRating_Detail.Where(x => x.prd_Parent_FK == Ratings_FK)); var locRec = context.TLADM_ProductRating.Find(Ratings_FK); if (locRec != null) { try { context.TLADM_ProductRating.Remove(locRec); context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (dataGridView1.IsCurrentRowDirty) { this.Validate(); } oDgv.Rows.RemoveAt(this.dataGridView1.SelectedRows[0].Index); } } else { MessageBox.Show("There are currently active records for this Rating", "Record cannot be deleted", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } else { MessageBox.Show("Please select a row in the datagrid", "Information"); } } }
private void datagridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { Util core = new Util(); var oDgv = sender as DataGridView; int pn = 0; List <int> xx = null; if (oDgv.Focused && oDgv.CurrentCell is DataGridViewButtonCell) { if (e.ColumnIndex == 1) { if (rbBody.Checked) { var Id = 1005; var RowPos = oDgv.CurrentRow.Index; pn = int.Parse(oDgv.CurrentRow.Cells[9].Value.ToString()); frmTLADMGardProp aprop = new frmTLADMGardProp(Id, pn, Listsizes); aprop.ShowDialog(); var sizes = aprop.TotalPN; if (sizes != 0) { StringBuilder desciption = new StringBuilder(); int a = Convert.ToInt32(sizes); using (var context = new TTI2Entities()) { xx = core.ExtrapNumber(a, context.TLADM_Sizes.Count()); } xx.Sort(); oDgv.CurrentRow.Cells[8].Value = false; if (xx.Count > 1) { oDgv.CurrentRow.Cells[8].Value = true; } foreach (var rw in xx) { bool First = true; foreach (var dd in Listsizes) { if (dd.SI_PowerN == rw) { if (First) { First = !First; oDgv.CurrentRow.Cells[11].Value = dd.SI_id; } if (desciption.Length == 0) { desciption.Append(dd.SI_Description); } else { desciption.Append(", " + dd.SI_Description); } } } } oDgv.CurrentRow.Cells[10].Value = false; if ((int)oDgv.CurrentRow.Cells[0].Value == 0) { oDgv.CurrentRow.Cells[10].Value = true; } oDgv.CurrentRow.Cells[1].Value = desciption; oDgv.CurrentRow.Cells[7].Value = "Ratio"; oDgv.CurrentRow.Cells[9].Value = sizes; } } else if (rbTrims.Checked) { var StyleSelected = (TLADM_Styles)cmbStyles.SelectedItem; if (StyleSelected != null) { var Id = 1007; int[] TrimKeys = new int[2]; // First Element is the style //====================================== TrimKeys[0] = StyleSelected.Sty_Id; // Second element is the Primary Key of the Trim //=============================================== TrimKeys[1] = (int)oDgv.Rows[e.RowIndex].Cells[11].Value; var RowPos = oDgv.CurrentRow.Index; pn = int.Parse(oDgv.CurrentRow.Cells[9].Value.ToString()); frmTLADMGardProp aprop = new frmTLADMGardProp(Id, TrimKeys, true); aprop.ShowDialog(); var sizes = aprop._TrimKeys; oDgv.CurrentRow.Cells[8].Value = false; oDgv.CurrentRow.Cells[10].Value = false; if ((int)oDgv.CurrentRow.Cells[0].Value == 0) { oDgv.CurrentRow.Cells[10].Value = true; } oDgv.CurrentRow.Cells[11].Value = sizes[1]; using (var context = new TTI2Entities()) { oDgv.CurrentRow.Cells[1].Value = context.TLADM_Trims.Find(sizes[1]).TR_Description; } oDgv.CurrentRow.Cells[7].Value = "Ratio"; oDgv.CurrentRow.Cells[9].Value = 0; } } } else { // Only available to body details //----------------------------------------------- if (!rbBody.Checked) { using (DialogCenteringService centeringService = new DialogCenteringService(this)) // center message box { MessageBox.Show("Please select the body check box prior to selecting this option"); } return; } //Only available to multi sized markers //----------------------------------------------- var CurrentRow = oDgv.CurrentRow; if (!(bool)CurrentRow.Cells[8].Value) { using (DialogCenteringService centeringService = new DialogCenteringService(this)) // center message box { MessageBox.Show("This option is only available to multi sized Markers"); return; } } else { var PNumber = (int)CurrentRow.Cells[9].Value; int PrimaryKey = (int)CurrentRow.Cells[0].Value; if (PrimaryKey == 0) { using (var context = new TTI2Entities()) { TLADM_ProductRating ProductRating = new TLADM_ProductRating(); context.TLADM_ProductRating.Add(ProductRating); try { context.SaveChanges(); PrimaryKey = ProductRating.Pr_Id; CurrentRow.Cells[0].Value = PrimaryKey; CurrentRow.Cells[10].Value = false; } catch (Exception ex) { MessageBox.Show(ex.InnerException.Message.ToString()); return; } } } frmTLADMProductRatingDetail prodDetail = new frmTLADMProductRatingDetail(PNumber, PrimaryKey); prodDetail.ShowDialog(this); if (prodDetail.ProductRatio != 0) { oDgv.Rows[e.RowIndex].Cells[4].Value = (decimal)prodDetail.ProductRatio; if (oDgv.Rows[e.RowIndex].Cells[5].Value != null) { var ML = (decimal)oDgv.Rows[e.RowIndex].Cells[5].Value; try { oDgv.Rows[e.RowIndex].Cells[6].Value = Math.Round(ML / prodDetail.ProductRatio, 4); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } } } } } }
private void btnSubmit_Click(object sender, EventArgs e) { Button oBtn = (Button)sender; if (oBtn != null && FormLoaded) { if (_Mode) { if (chkProductionResults.Checked) { QueryParms.ProductionResults = true; } repOptions = new CMTReportOptions(); DateTime FromDate = Convert.ToDateTime(dtpFromDate.Value.ToShortDateString()); DateTime ToDate = Convert.ToDateTime(dtpToDate.Value.ToShortDateString()); ToDate = ToDate.AddHours(23); repOptions.fromDate = FromDate; repOptions.toDate = ToDate; frmCMTViewRep vRep = new frmCMTViewRep(30, QueryParms, repOptions); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); frmDateRequired_Load(this, null); } else { using (var context = new TTI2Entities()) { foreach (DataGridViewRow Row in dataGridView1.Rows) { if (!(bool)Row.Cells[1].Value) { continue; } var Pk = (int)Row.Cells[0].Value; var LineIssue = context.TLCMT_LineIssue.Find(Pk); if (LineIssue != null) { LineIssue.TLCMTLI_Required_Date = dtpFromDate.Value; } } try { context.SaveChanges(); MessageBox.Show("Data successfully saved to the database"); this.frmDateRequired_Load(this, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; if (oBtn != null && FormLoaded) { var Selected = (TLADM_WhseStore)cmboWarehouses.SelectedItem; if (Selected == null) { MessageBox.Show("Please select a warehouse from the combobox provided"); return; } using (var context = new TTI2Entities()) { foreach (DataGridViewRow Row in dataGridView1.Rows) { if (Row.Cells[0].Value == null) { continue; } var RWComplete = core.RowComplete(Row, MandatoryFields); var cnt = RWComplete.Where(x => x == false).Count(); if (cnt == MandatoryFields.Length) { continue; } if (cnt != 0) { var errorM = core.returnMessage(RWComplete, true, MandatoryFields); if (!string.IsNullOrEmpty(errorM)) { MessageBox.Show(errorM, "Error Message for Line No" + (Row.Index + 1).ToString()); return; } } TLCSV_StockOnHand SOH = new TLCSV_StockOnHand(); var Style_FK = (int)Row.Cells[1].Value; var Colour_FK = (int)Row.Cells[2].Value; var Size_FK = (int)Row.Cells[3].Value; TLADM_Styles Styles = context.TLADM_Styles.Find(Style_FK); TLADM_Colours Colours = context.TLADM_Colours.Find(Colour_FK); TLADM_Sizes Sizes = context.TLADM_Sizes.Find(Size_FK); SOH.TLSOH_PastelNumber = Styles.Sty_PastelNo + Colours.Col_FinishedCode + "NG" + Sizes.SI_PastelNo; SOH.TLSOH_BoxNumber = Row.Cells[0].Value.ToString(); SOH.TLSOH_Style_FK = (int)Row.Cells[1].Value; SOH.TLSOH_Colour_FK = (int)Row.Cells[2].Value; SOH.TLSOH_Size_FK = (int)Row.Cells[3].Value; SOH.TLSOH_CMT_FK = (int)Row.Cells[4].Value; SOH.TLSOH_Weight = (decimal)Row.Cells[5].Value; SOH.TLSOH_BoxedQty = Convert.ToInt32(Row.Cells[6].Value.ToString()); SOH.TLSOH_Grade = Row.Cells[7].Value.ToString().ToUpper().Trim(); SOH.TLSOH_BoxType = 1; SOH.TLSOH_DateIntoStock = dtpTransdate.Value; SOH.TLSOH_WareHouse_FK = Selected.WhStore_Id; if (SOH.TLSOH_Grade.Contains("A")) { SOH.TLSOH_Is_A = true; } var Cwork = context.TLCMT_CompletedWork.Where(x => x.TLCMTWC_BoxNumber == SOH.TLSOH_BoxNumber).FirstOrDefault(); if (Cwork != null) { SOH.TLSOH_CutSheet_FK = Cwork.TLCMTWC_CutSheet_FK; } var Already = context.TLCSV_StockOnHand.Where(x => x.TLSOH_BoxNumber == SOH.TLSOH_BoxNumber).FirstOrDefault(); if (Already != null) { if (!Already.TLSOH_Write_Off) { continue; } } context.TLCSV_StockOnHand.Add(SOH); } try { context.SaveChanges(); MessageBox.Show("Data successfully save to the database"); cmboWarehouses.SelectedItem = -1; dataGridView1.Rows.Clear(); frmStockTakeOn_Load(this, null); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = (Button)sender; if (oBtn != null && FormLoaded) { using (var context = new TTI2Entities()) { if (rbOnHold.Checked) { if (txtReasons.Text.Length == 0) { MessageBox.Show("Please give a reason for placing a box on hold"); return; } foreach (DataGridViewRow row in dataGridView1.Rows) { if (!(bool)row.Cells[1].Value) { continue; } var PrimeKey = (int)row.Cells[0].Value; var CS = context.TLCUT_CutSheet.Find(PrimeKey); if (CS != null) { CS.TLCUTSH_OnHold = true; CS.TLCUTSH_OnHold_Reasons = txtReasons.Text; CS.TLCUTSH_OnHoldDate = dtpOnHold.Value; } } } else { foreach (DataGridViewRow row in dataGridView1.Rows) { if ((bool)row.Cells[1].Value) { continue; } var PrimeKey = (int)row.Cells[0].Value; var CS = context.TLCUT_CutSheet.Find(PrimeKey); if (CS != null) { CS.TLCUTSH_OnHold = false; CS.TLCUTSH_OnHold_Reasons = string.Empty; CS.TLCUTSH_OnHoldDate = null; } } } try { context.SaveChanges(); MessageBox.Show("Data successfully saved to database"); frmCutOnOffHold_Load(this, null); } catch (Exception ex) { MessageBox.Show(ex.InnerException.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; bool success = true; if (oBtn != null) { var CottonRec = (TLSPN_CottonTransactions)cmbLotNo.SelectedItem; 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 DeptDetail = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "SPIN").FirstOrDefault(); var TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Number == 500 && x.TrxT_Department_FK == DeptDetail.Dep_Id).FirstOrDefault(); var LastNumber = context.TLADM_LastNumberUsed.Find(1); if (LastNumber != null) { LastNumber.col5 += 1; } var NoBales = 0; var GrossWeight = 0M; var NettWeight = 0M; foreach (DataGridViewRow rw in dataGridView1.Rows) { if (rw.Cells[1].Value == null || (bool)rw.Cells[1].Value == false) { continue; } TLSPN_CottonReceivedBales bales = context.TLSPN_CottonReceivedBales.Find((int)rw.Cells[0].Value); if (bales != null) { bales.CoBales_IssuedToProd = true; bales.CoBales_BlowRoomPosition = 0; bales.CoBales_CottonSequence = Convert.ToInt32(txtIssueToProdNo.Text); NoBales += 1; NettWeight += (decimal)rw.Cells[5].Value; GrossWeight += (decimal)rw.Cells[7].Value; try { context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); success = false; } } } //------------------------------------------------------------------ TLSPN_CottonTransactions cotTrans = new TLSPN_CottonTransactions(); cotTrans.cotrx_TransDate = dtpTransDate.Value; cotTrans.cotrx_Supplier_FK = CottonRec.cotrx_Supplier_FK; cotTrans.cotrx_Return_No = Convert.ToInt32(txtIssueToProdNo.Text); cotTrans.cotrx_ContractNo_Fk = CottonRec.cotrx_ContractNo_Fk; cotTrans.cotrx_LotNo = CottonRec.cotrx_LotNo; cotTrans.cotrx_NoBales = NoBales; cotTrans.cotrx_GrossWeight = GrossWeight; cotTrans.cotrx_NetWeight = NettWeight; cotTrans.cotrx_WeighBridgeFull = 0M; cotTrans.cotrx_WeighBridgeEmpty = 0M; cotTrans.cotrx_NettPerWB = 0M; cotTrans.cotrx_GrossAveBaleWeight = (GrossWeight / NoBales); cotTrans.cottrx_NettAveBaleWeight = (NettWeight / NoBales); cotTrans.cotrx_TranType = TranType.TrxT_Pk; cotTrans.cotrx_WriteOff = true; //--------------------------------------------- // Need to store this to the laydown file //----------------------------------------------------------- TLSPN_YarnOrderLayDown ld = new TLSPN_YarnOrderLayDown(); ld.YarnLD_BaleAvgWeight = cotTrans.cottrx_NettAveBaleWeight; ld.YarnLD_Date = dtpTransDate.Value; ld.YarnLD_LayDownNo = Convert.ToInt32(txtIssueToProdNo.Text); ld.YarnLD_LotNo = CottonRec.cotrx_LotNo; ld.YarnLD_NoOfBales = NoBales; ld.YarnLD_WeightKg = NettWeight; try { context.TLSPN_CottonTransactions.Add(cotTrans); context.TLSPN_YarnOrderLayDown.Add(ld); context.SaveChanges(); SetUp(); } catch (Exception ex) { MessageBox.Show(ex.Message); success = false; } } if (success) { MessageBox.Show("Records stored successfully to database"); } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; DataGridView oDgv = dataGridView1; String PalletNo = string.Empty; String YarnSupplier = String.Empty; Decimal YarnTex = 0.00M; TLADM_Yarn YarnType = null; string MergeDetails = string.Empty; IList <TLKNI_YarnAllocTransctions> PalletTrans = null; if (oBtn != null && formloaded) { using (var context = new TTI2Entities()) { var KO = (TLKNI_Order)cmboKnitOrders.SelectedItem; if (KO != null) { var _Begin = dtpProduction.Value.ToShortDateString(); DateTime psd = Convert.ToDateTime(_Begin); DateTime time = dtpTime.Value; var YarnAllocTrans = context.TLKNI_YarnAllocTransctions.Where(x => x.TLKYT_KnitOrder_FK == KO.KnitO_Pk && x.TLKYT_TranType == 1).FirstOrDefault(); if (YarnAllocTrans != null) { var YarnOrderPallet = context.TLKNI_YarnOrderPallets.Find(YarnAllocTrans.TLKYT_YOP_FK); if (YarnOrderPallet != null) { var YarnOrder = context.TLSPN_YarnOrder.Find(YarnOrderPallet.TLKNIOP_YarnOrder_FK); if (YarnOrder != null) { PalletNo = YarnOrder.YarnO_OrderNumber.ToString() + " - " + YarnOrderPallet.TLKNIOP_PalletNo; YarnType = context.TLADM_Yarn.Find(YarnOrder.Yarno_YarnType_FK); if (YarnType != null) { YarnTex = YarnType.YA_TexCount; YarnSupplier = context.TLADM_Suppliers.Find(YarnType.YA_Supplier_FK).Sup_Description; } } } } KO = context.TLKNI_Order.Find(KO.KnitO_Pk); if (KO != null) { var YarnO = context.TLSPN_YarnOrder.Find(KO.KnitO_YarnO_FK); if (YarnO != null) { if (YarnO.YarnO_MergeContract_FK != null) { var CottonM = context.TLSPN_CottonMerge.Find(YarnO.YarnO_MergeContract_FK); if (CottonM != null) { MergeDetails = CottonM.TLCTM_Description; } } } if (KO.KnitO_ProductionStartDate == null) { KO.KnitO_ProductionStartDate = psd.AddHours(time.Hour); KO.KnitO_ProductionStartDate = psd.AddMinutes(time.Minute); } } PalletTrans = context.TLKNI_YarnAllocTransctions.Where(x => x.TLKYT_KnitOrder_FK == KO.KnitO_Pk && x.TLKYT_TranType == 1).ToList(); foreach (DataGridViewRow row in oDgv.Rows) { if ((decimal)row.Cells[3].Value > 0) { if (row.Cells[4].Value == null || row.Cells[5].Value == null) { MessageBox.Show("Row Number " + (row.Index + 1).ToString() + " incomplete"); return; } TLKNI_GreigeProduction griegP = new TLKNI_GreigeProduction(); var _Key = (int)row.Cells[0].Value; if (_Key != 0) { griegP = context.TLKNI_GreigeProduction.Find(_Key); } else { griegP.GreigeP_KnitO_Fk = KO.KnitO_Pk; griegP.GreigeP_Greige_Fk = KO.KnitO_Product_FK; griegP.GreigeP_Machine_FK = (int)row.Cells[1].Value; griegP.GreigeP_PieceNo = row.Cells[2].Value.ToString(); if (KO.KnitO_Size_Fk != null) { griegP.GreigeP_Size_Fk = (int)KO.KnitO_Size_Fk; } if (KO.KnitO_Colour_Fk != null) { griegP.GreigeP_BIFColour_FK = (int)KO.KnitO_Colour_Fk; } } griegP.GreigeP_MergeDetail = MergeDetails; griegP.GreigeP_weight = (decimal)row.Cells[3].Value; griegP.GreigeP_weightAvail = (decimal)row.Cells[3].Value; if (row.Cells[4].Value != null) { griegP.GreigeP_Shift_FK = (int)row.Cells[4].Value; } if (row.Cells[5].Value != null) { griegP.GreigeP_Operator_FK = (int)row.Cells[5].Value; } if (griegP.GreigeP_PDate == null) { griegP.GreigeP_PDate = dtpProduction.Value; } BatchBalanceCaptured += (decimal)row.Cells[3].Value; griegP.GreigeP_Captured = true; griegP.GreigeP_PalletNo = PalletNo; griegP.GreigeP_YarnSupplier = YarnSupplier; griegP.GreigeP_YarnTex = YarnTex; var TLADMGreige = context.TLADM_Griege.Find(griegP.GreigeP_Greige_Fk); if (TLADMGreige != null) { // We need to start storing the meters knitted for statistical purposes //=========================================================================== var FabWeight = context.TLADM_FabricWeight.Find(TLADMGreige.TLGreige_FabricWeight_FK); var FabWidth = context.TLADM_FabWidth.Find(TLADMGreige.TLGreige_FabricWidth_FK); var FabricYield = core.FabricYield(FabWeight.FWW_Calculation_Value, FabWidth.FW_Calculation_Value); griegP.GreigeP_Meters = FabricYield * griegP.GreigeP_weightAvail; } var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("KNIT")).FirstOrDefault(); if (Dept != null) { if (KO.KnitO_YarnO_FK != null) { var TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1400).FirstOrDefault(); if (TranType != null) { griegP.GreigeP_Store_FK = TranType.TrxT_Pk; } } else { if (KO.KnitO_CommisionCust) { var TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1300).FirstOrDefault(); if (TranType != null) { griegP.GreigeP_Store_FK = TranType.TrxT_Pk; } } else { var TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1200).FirstOrDefault(); if (TranType != null) { griegP.GreigeP_Store_FK = TranType.TrxT_Pk; } } } } //============================================================================== if (_Key == 0) { context.TLKNI_GreigeProduction.Add(griegP); } } } if (BatchBalanceCaptured >= KO.KnitO_Weight) { KO.KnitO_ProductionCaptured = true; } var MachDet = context.TLADM_MachineDefinitions.Find(KO.KnitO_Pk); if (MachDet != null) { var MC = context.TLKNI_MachineLastNumber.Where(x => x.TLMDD_MachineCode == MachDet.MD_MachineCode).FirstOrDefault(); if (MC != null) { MC.TLMDD_LastNumber = _LastNumber; txtPieceNo.Text = _LastNumber.ToString(); } } try { context.SaveChanges(); oDgv.Rows.Clear(); txtNoOfPieces.Text = "0"; _LastNumber = 0; MessageBox.Show("Data saved to database"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } }
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) { TLSPN_CottonReceivedBales bales; Button oBtn = sender as Button; if (oBtn != null & formloaded) { if (RowsSelected != null && rbWriteOff.Checked) { var cnt = RowsSelected.Where(x => x == false).Count(); if (cnt == RowsSelected.Count()) { MessageBox.Show("Please select at least one row from the grid as shown"); return; } } var errorM = core.returnMessage(MandSelected, true, MandatoryFields); if (!string.IsNullOrEmpty(errorM)) { MessageBox.Show(errorM); return; } var LotDetails = (TLSPN_CottonTransactions)cmbLotNo.SelectedItem; //dont forget last number used //------------------------------------------- using (var context = new TTI2Entities()) { var LastNumber = context.TLADM_LastNumberUsed.Find(1); if (LastNumber != null) { LastNumber.col3 += 1; } // 0 // 1 Selected // 2 Bales Numeric // 3 MIC Decimal // 4 kgs (NETT) Decimal // 5 Staple Decimal // 6 kgs (GROSS) decimal int NoBales = 0; decimal NettMass = 0M; decimal GrossMass = 0M; var ContractDetails = (TLADM_CottonContracts)cmbContractNo.SelectedItem; foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[1].Value == null || (bool)row.Cells[1].Value == false) { continue; } NoBales += 1; NettMass += (decimal)row.Cells[4].Value; GrossMass += (decimal)row.Cells[6].Value; if (rbWriteOn.Checked) { TLSPN_CottonReceivedBales Bales = new TLSPN_CottonReceivedBales(); Bales.CotBales_BaleNo = (int)row.Cells[2].Value; Bales.CotBales_Mic = (decimal)row.Cells[3].Value; Bales.CotBales_Staple = (decimal)row.Cells[5].Value; Bales.CotBales_Weight_Nett = (decimal)row.Cells[4].Value; Bales.CotBales_LotNo = LotDetails.cotrx_LotNo; Bales.CotBales_Weight_Gross = (decimal)row.Cells[6].Value; Bales.CoBales_CottonSequence = Convert.ToInt32(txtAdjustmentNumber.Text); context.TLSPN_CottonReceivedBales.Add(Bales); } else { bales = context.TLSPN_CottonReceivedBales.Find((int)row.Cells[0].Value); if (bales != null) { if ((bool)row.Cells[1].Value == true) { bales.CoBales_CottonReturned = true; bales.CoBales_CottonSequence = Convert.ToInt32(txtAdjustmentNumber.Text); try { context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } } //---------------------------------------------------------------------------- // //------------------------------------------------------------------------------ TLSPN_CottonTransactions cotTrans = new TLSPN_CottonTransactions(); cotTrans.cotrx_TransDate = dateTimePicker1.Value; cotTrans.cotrx_ContractNo_Fk = ContractDetails.CottonCon_Pk; cotTrans.cotrx_LotNo = Convert.ToInt32(cmbLotNo.SelectedValue); cotTrans.cotrx_NetWeight = NettMass; cotTrans.cotrx_GrossWeight = GrossMass; cotTrans.cotrx_NoBales = NoBales; //cotTrans.cotrx_VehReg_FK = null; cotTrans.cotrx_WeighBridgeFull = 0; cotTrans.cotrx_WeighBridgeEmpty = 0; cotTrans.cotrx_NettPerWB = 0; cotTrans.cotrx_Return_No = Convert.ToInt32(txtAdjustmentNumber.Text); cotTrans.cotrx_Supplier_FK = ContractDetails.CottonCon_ConSupplier_FK; cotTrans.cotrx_Notes = rtbNotes.Text; //------------------------------------------------------------------------- // Consult Table TLADM_TranTypes //---------------------------------------------------------------------------- var DepDetail = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "SPIN").FirstOrDefault(); if (DepDetail != null) { var Trantype = context.TLADM_TranactionType.Where(x => x.TrxT_Number == 400 && x.TrxT_Department_FK == DepDetail.Dep_Id).FirstOrDefault(); if (Trantype != null) { cotTrans.cotrx_TranType = Trantype.TrxT_Pk; } } if (rbWriteOff.Checked) { cotTrans.cotrx_WriteOff = true; } else { cotTrans.cotrx_WriteOff = false; } //------------------------------------------------------------------------ context.TLSPN_CottonTransactions.Add(cotTrans); //----------------------------------------------------------- // //------------------------------------------------------------ string Mach_IP = Dns.GetHostEntry(Dns.GetHostName()) .AddressList.First(f => f.AddressFamily == AddressFamily.InterNetwork) .ToString(); TLADM_DailyLog DailyLog = new TLADM_DailyLog(); DailyLog.TLDL_IPAddress = Mach_IP; DailyLog.TLDL_Dept_Fk = DepDetail.Dep_Id; DailyLog.TLDL_Date = DateTime.Now; DailyLog.TLDL_TransDetail = "Cotton Adjustment"; DailyLog.TLDL_AuthorisedBy = txtAdjustmentNumber.Text; DailyLog.TLDL_Comments = txtAdjustmentNumber.Text; context.TLADM_DailyLog.Add(DailyLog); try { context.SaveChanges(); var Retno = Convert.ToInt32(txtAdjustmentNumber.Text); frmViewReport vRep = new frmViewReport(4, Retno); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); SetUp(); MessageBox.Show("Data saved to database successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; int MeasureA = 0; if (oBtn != null && formloaded) { if (RadPanelSize.Checked) { if (cmboMeasureArea.SelectedValue != null) { MeasureA = Convert.ToInt32(cmboMeasureArea.SelectedValue.ToString()); } else { MessageBox.Show("Please select an measurement area"); return; } } using (var context = new TTI2Entities()) { foreach (DataGridViewRow row in dataGridView1.Rows) { TLCUT_QAResults qaRes = new TLCUT_QAResults(); bool Add = true; if (row.Cells[0].Value != null) { var index = (int)row.Cells[0].Value; qaRes = context.TLCUT_QAResults.Find(index); if (qaRes == null) { qaRes = new TLCUT_QAResults(); } else { Add = false; } } qaRes.TLCUTQA_Bundle_FK = (int)row.Cells[1].Value; qaRes.TLCUTQA_Inspectore_FK = (int)row.Cells[2].Value; qaRes.TLCUTQA_Date = dtpTransDate.Value; qaRes.TLCUTQA_Col1 = (decimal)row.Cells[4].Value; qaRes.TLCUTQA_Col2 = (decimal)row.Cells[5].Value; qaRes.TLCUTQA_Col3 = (decimal)row.Cells[6].Value; qaRes.TLCUTQA_Col4 = (decimal)row.Cells[7].Value; if (RadPanelSize.Checked && MeasureA > 0) { qaRes.TLCUTQA_MeasureArea_FK = MeasureA; } if (radPPS.Checked) { qaRes.TLCUTQA_PPS = true; } if (Add) { context.TLCUT_QAResults.Add(qaRes); } } try { context.SaveChanges(); MessageBox.Show("Data saved successfully to database"); dataGridView1.Rows.Clear(); } 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) { bool Update = false; Button oBtn = sender as Button; if (oBtn != null && formloaded) { var selected = (TLCUT_CutSheet)cmboCutSheet.SelectedItem; if (selected == null) { MessageBox.Show("Please select a cut sheet from the drop down list "); return; } var WhseSelected = (TLADM_WhseStore)cmboRejectStore.SelectedItem; if (WhseSelected == null) { MessageBox.Show("Please select a reject store from the drop down list"); return; } if (String.IsNullOrEmpty(txtAuthorisedBy.Text)) { MessageBox.Show("Please complete the approved by details"); return; } using (var context = new TTI2Entities()) { var CSR = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == selected.TLCutSH_Pk).FirstOrDefault(); CutReportOptions cropts = new CutReportOptions(); cropts.remarks = rtbNotes.Text; cropts.TransDate = dtpTransDate.Value; cropts.ApprovedBy = txtAuthorisedBy.Text; cropts.Pk = CSR.TLCUTSHR_Pk; cropts.CutSheetPk = selected.TLCutSH_Pk; cropts.ReturnedTo = context.TLADM_WhseStore.Find(WhseSelected.WhStore_Id).WhStore_Description; var cs = context.TLCUT_CutSheet.Find(selected.TLCutSH_Pk); if (cs != null) { cs.TLCutSH_Notes = rtbNotes.Text; } foreach (DataGridViewRow row in dataGridView1.Rows) { if ((bool)row.Cells[1].Value == false) { continue; } //------------------------------------------------------ // 1st Step reduce the SOH with what was written off //----------------------------------------------------------- var index = (int)row.Cells[0].Value; var CSRD = context.TLCUT_CutSheetReceiptDetail.Find(index); if (CSRD != null) { CSRD.TLCUTSHRD_RejectQty += (int)row.Cells[6].Value; CSRD.TLCUTSHRD_RejectDate = dtpTransDate.Value; CSRD.TLCUTSHRD_RejectReason = (int)row.Cells[5].Value; } //------------------------------------------------- // Now create a new Record of the written off value //--------------------------------------------------- TLCUT_CutSheetReceiptDetail NewCSR = new TLCUT_CutSheetReceiptDetail(); NewCSR.TLCUTSHRD_CutSheet_FK = CSR.TLCUTSHR_Pk; NewCSR.TLCUTSHRD_Description = row.Cells[2].Value.ToString() + "R"; NewCSR.TLCUTSHRD_Size_FK = (int)row.Cells[3].Value; NewCSR.TLCUTSHRD_BundleQty = (int)row.Cells[4].Value; NewCSR.TLCUTSHRD_BoxUnits = 0; NewCSR.TLCUTSHRD_TransactionType = 55; NewCSR.TLCUTSHRD_CurrentStore_FK = WhseSelected.WhStore_Id; NewCSR.TLCUTSHRD_PanelRejected = true; NewCSR.TLCUTSHRD_RejectDate = dtpTransDate.Value; NewCSR.TLCUTSHRD_RejectQty = (int)row.Cells[6].Value; NewCSR.TLCUTSHRD_RejectReason = (int)row.Cells[5].Value; context.TLCUT_CutSheetReceiptDetail.Add(NewCSR); Update = true; } //------------------------------------------------------- // //----------------------------------------------------------- string Mach_IP = Dns.GetHostEntry(Dns.GetHostName()) .AddressList.First(f => f.AddressFamily == AddressFamily.InterNetwork) .ToString(); var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("CUT")).FirstOrDefault(); TLADM_DailyLog DailyLog = new TLADM_DailyLog(); DailyLog.TLDL_IPAddress = Mach_IP; DailyLog.TLDL_Dept_Fk = Dept.Dep_Id; DailyLog.TLDL_Date = DateTime.Now; DailyLog.TLDL_TransDetail = "Cutting Dept Panel Rejected"; DailyLog.TLDL_AuthorisedBy = txtAuthorisedBy.Text;; DailyLog.TLDL_Comments = rtbNotes.Text; context.TLADM_DailyLog.Add(DailyLog); //---------------------------------------------------------- if (Update) { try { context.SaveChanges(); MessageBox.Show("Data saved successfully to database"); frmCutViewRep vRep = new frmCutViewRep(3, cropts); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = (Button)sender; if (oBtn != null && FormLoaded) { var selected = (TLCUT_CutSheet)cmboCutSheets.SelectedItem; if (selected == null) { MessageBox.Show("Please select a cut sheet from the drop down list"); return; } using (var context = new TTI2Entities()) { foreach (DataRow Row in dt.Rows) { if (!Row.Field <bool>(1)) { continue; } var ComWork_FK = Row.Field <int>(0); var CompletedWork = context.TLCMT_CompletedWork.Find(ComWork_FK); if (CompletedWork != null) { TLCMT_HistoryBoxedQty History = new TLCMT_HistoryBoxedQty(); History.BoxHist_CompletedWork_FK = CompletedWork.TLCMTWC_Pk; History.BoxHist_DateTime = DateTime.Now; History.BoxHist_New_Qty = Row.Field <int>(4); History.BoxHist_Orignal_Qty = CompletedWork.TLCMTWC_Qty; History.BoxHist_Size_FK = CompletedWork.TLCMTWC_Size_FK; History.BoxHist_CutSheet_FK = selected.TLCutSH_Pk; History.BoxHist_No = CompletedWork.TLCMTWC_BoxNumber; context.TLCMT_HistoryBoxedQty.Add(History); CompletedWork.TLCMTWC_Qty = Row.Field <int>(4); } } try { context.SaveChanges(); MessageBox.Show("Data saved successfully to database"); frmCMTViewRep vRep = new frmCMTViewRep(34, selected.TLCutSH_Pk); 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.InnerException.ToString()); } finally { this.frmCMTBoxedQtyAdjustment_Load(this, null); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; if (oBtn != null) { if (!chkCloseOrder.Checked && _Close) { MessageBox.Show("Please check the close order checkbox, if applicable prior to selecting the save button"); return; } var selected = (TLSPN_YarnOrder)cmbYarnOrders.SelectedItem; if (selected != null) { DialogResult res = MessageBox.Show("Please confirm this action", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (res == DialogResult.OK) { using (var context = new TTI2Entities()) { selected = context.TLSPN_YarnOrder.Find(selected.YarnO_Pk); if (selected != null) { if (_Close) { selected.Yarno_Closed = true; selected.Yarno_ClosedDate = DateTime.Now; if (chkReinstateOrder.Checked) { selected.YarnO_Reinstate = true; } } else { selected.Yarno_Closed = false; selected.Yarno_ClosedDate = DateTime.Now; selected.YarnO_Reinstate = false; } try { context.SaveChanges(); SetUp(); formloaded = false; if (_Close) { cmbYarnOrders.DataSource = context.TLSPN_YarnOrder.Where(x => !x.Yarno_Closed).OrderBy(x => x.YarnO_OrderNumber).ToList(); } else { cmbYarnOrders.DataSource = context.TLSPN_YarnOrder.Where(x => x.YarnO_Reinstate).OrderBy(x => x.YarnO_OrderNumber).ToList(); } formloaded = true; MessageBox.Show("Results stored successfully"); cmbYarnOrders.SelectedIndex = -1; txtBalToBeProduced.Text = string.Empty; txtProducedToDate.Text = string.Empty; txtYarnOrderQty.Text = string.Empty; } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } } } }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { DataGridView oDgv = sender as DataGridView; if (oDgv.Focused && oDgv.CurrentCell is DataGridViewCheckBoxCell) { TLDYE_DyeBatch db = new TLDYE_DyeBatch(); using (var context = new TTI2Entities()) { int DyeBatchKey = (int)oDgv.CurrentRow.Cells[0].Value; db = context.TLDYE_DyeBatch.Find(DyeBatchKey); if (db != null) { db.DYEB_Transfered = true; db.DYEB_TransferDate = dtpTransferDate.Value; var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("DYE")).FirstOrDefault(); if (Dept != null) { var TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 300).FirstOrDefault(); if (TranType != null) { db.DYEB_TransactionType_FK = TranType.TrxT_Pk; } } TLDYE_DyeTransactions dt = new TLDYE_DyeTransactions(); dt.TLDYET_BatchNo = db.DYEB_BatchNo; dt.TLDYET_BatchWeight = db.DYEB_BatchKG; dt.TLDYET_Date = dtpTransferDate.Value; dt.TLDYET_SequenceNo = db.DYEB_SequenceNo; dt.TLDYET_TransactionType = db.DYEB_TransactionType_FK; dt.TLDYET_Batch_FK = db.DYEB_Pk; dt.TLDYET_Stage = 2; dt.TLDYET_CurrentStore_FK = (int)context.TLADM_TranactionType.Find(db.DYEB_TransactionType_FK).TrxT_ToWhse_FK; context.TLDYE_DyeTransactions.Add(dt); var DBD = context.TLDYE_DyeBatchDetails.Where(x => x.DYEBD_DyeBatch_FK == db.DYEB_Pk).ToList(); foreach (var rowx in DBD) { rowx.DYEBO_CurrentStore_FK = dt.TLDYET_CurrentStore_FK; } try { context.SaveChanges(); frmDyeViewReport vRep = new frmDyeViewReport(8, DyeBatchKey); 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); } } } oDgv.Rows.RemoveAt(oDgv.CurrentRow.Index); } }
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; if (SelectedDept == null) { MessageBox.Show("Please select a department from the drop down list"); return; } using (var context = new TTI2Entities()) { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[1].Value == null) { continue; } TLADM_DepartmentsArea tranType = new TLADM_DepartmentsArea(); AddRec = true; if (row.Cells[0].Value != null) { tranType = context.TLADM_DepartmentsArea.Find((int)row.Cells[0].Value); if (tranType != null) { AddRec = false; } } tranType.DeptA_Description = (string)row.Cells[1].Value; tranType.DeptA_Dept_FK = SelectedDept.Dep_Id; if (AddRec) { context.TLADM_DepartmentsArea.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) { 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; 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 btnSaveTrims_Click(object sender, EventArgs e) { Button oBtn = sender as Button; bool updateSuccessful = true; if (formloaded && oBtn != null) { using (var context = new TTI2Entities()) { foreach (DataRow DRow in ProductRating.Rows) { TLADM_ProductRating pr = new TLADM_ProductRating(); if (!DRow.Field <bool>(10)) { pr = context.TLADM_ProductRating.Find(DRow.Field <int>(0)); } if (rbBody.Checked) { pr.Pr_BodyorRibbing = 1; pr.Pr_Size_FK = DRow.Field <int>(11); } else { pr.Pr_BodyorRibbing = 0; pr.Pr_Trim_FK = DRow.Field <int>(11); } var Cust = (TLADM_CustomerFile)cmbLabels.SelectedItem; if (Cust != null) { pr.Pr_Customer_FK = Cust.Cust_Pk; } var Style = (TLADM_Styles)cmbStyles.SelectedItem; if (Style != null) { pr.Pr_Style_FK = Style.Sty_Id; } pr.Pr_PowerN = DRow.Field <int>(9); pr.Pr_Discontinued = DRow.Field <bool>(2); pr.Pr_MultiMarker = DRow.Field <bool>(8); pr.Pr_Ratio = DRow.Field <decimal>(4); if (!DRow.Field <bool>(8)) { pr.Pr_Ratio = 1; } pr.Pr_Marker_Length = DRow.Field <decimal>(5); pr.Pr_numeric_Rating = DRow.Field <decimal>(6); pr.Pr_Display = DRow.Field <String>(1); if (!String.IsNullOrWhiteSpace(DRow.Field <string>(3))) { pr.Pr_Display += " / " + DRow.Field <string>(3); } if (DRow.Field <bool>(10)) { context.TLADM_ProductRating.Add(pr); } } try { context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); updateSuccessful = false; } finally { if (updateSuccessful) { ProductRating.Rows.Clear(); MessageBox.Show("Records successfully updated"); } } } } }
private void btnRecalculate_Click(object sender, EventArgs e) { Button oBtn = (Button)sender; var oDgv = (DataGridView)dataGridView1; if (oBtn != null && FormLoaded) { var RowCount = (from Rows in dataGridView1.Rows.Cast <DataGridViewRow>() where (bool)Rows.Cells[1].Value == true select Rows).Count(); if (RowCount == 0) { using (DialogCenteringService centeringService = new DialogCenteringService(this)) // center message box { MessageBox.Show("Please select at least one row to process"); } return; } using (var context = new TTI2Entities()) { foreach (DataRow dr in dt.Rows) { if (!dr.Field <bool>(1)) { continue; } var CurrentRow = oDgv.CurrentRow; var CurrentCell = oDgv.CurrentCell; if (CurrentRow != null) { var CutSheetIndex = (int)CurrentRow.Cells[0].Value; var CutSheet = context.TLCUT_CutSheet.Find(CutSheetIndex); if (CutSheet != null) { context.TLCUT_ExpectedUnits.Where(x => x.TLCUTE_CutSheet_FK == CutSheet.TLCutSH_Pk) .Update(x => new TLCUT_ExpectedUnits() { TLCUTE_EstNettWeight = 0, TLCUTE_NoOfBinding = 0, TLCUTE_NoofGarments = 0, TLCUTE_NoOfTrims = 0, TLCUTE_MarkerRatio = 0 }); var DBDetails = (from DBatch in context.TLDYE_DyeBatch join DBatchDetails in context.TLDYE_DyeBatchDetails on DBatch.DYEB_Pk equals DBatchDetails.DYEBD_DyeBatch_FK where DBatch.DYEB_Pk == CutSheet.TLCutSH_DyeBatch_FK select DBatchDetails).ToList(); foreach (var dbd in DBDetails) { if (dbd != null) { //Is a body or is it a Trim Record //=================================================== if (dbd.DYEBD_BodyTrim) { //-------------------------------------------------------------- // The aim of this event is to calculate the number of expected units // based on the nett weight of the piece of fabric selected // less the weight of the calculated binding needed (if applicable) //------------------------------------------------------------------ var Yield = core.FabricYield(dbd.DYEBO_DiskWeight, dbd.DYEBO_Width); var NettWeight = dbd.DYEBO_Nett; var BindWeight = 0.00M; var TrimWeight = 0.00M; //--------------------------------------------------------- // We now have to establish whether the style relating to the dye batch // has a Binding and if so what is the rating //---------------------------------------------------------------- var StyleFK = (from DO in context.TLDYE_DyeOrder join DB in context.TLDYE_DyeBatch on DO.TLDYO_Pk equals DB.DYEB_DyeOrder_FK join DBD in context.TLDYE_DyeBatchDetails on DB.DYEB_Pk equals DBD.DYEBD_DyeBatch_FK where DBD.DYEBD_Pk == dbd.DYEBD_Pk select DO).FirstOrDefault().TLDYO_Style_FK; var ISBinding = (from stytrim in context.TLADM_StyleTrim join trim in context.TLADM_Trims on stytrim.StyTrim_Trim_Fk equals trim.TR_Id join prodrating in context.TLADM_ProductRating on stytrim.StyTrim_ProdRating_FK equals prodrating.Pr_Id where stytrim.StyTrim_Styles_Fk == StyleFK && trim.TR_IsBinding select prodrating).FirstOrDefault(); if (ISBinding != null) { BindWeight = NettWeight * ISBinding.Pr_numeric_Rating; NettWeight -= BindWeight; } var ISTrim = (from stytrim in context.TLADM_StyleTrim join trim in context.TLADM_Trims on stytrim.StyTrim_Trim_Fk equals trim.TR_Id join prodrating in context.TLADM_ProductRating on stytrim.StyTrim_ProdRating_FK equals prodrating.Pr_Id where stytrim.StyTrim_Styles_Fk == StyleFK && !trim.TR_IsBinding select prodrating).FirstOrDefault(); if (ISTrim != null) { TrimWeight = dbd.DYEBO_Nett * ISTrim.Pr_numeric_Rating; } // select trims.TR_Description , pr.Pr_numeric_Rating // from TLADM_StyleTrim strim // inner join. TLADM_Trims trims // on trims.TR_Id = strim.StyTrim_Trim_Fk // inner join TLADM_ProductRating pr // on pr.Pr_Id = strim.StyTrim_ProdRating_FK // where trims.TR_IsBinding = 1 and strim.StyTrim_Styles_Fk = 34 //------------------------------------------------- var ProdFK = dbd.DYEBO_ProductRating_FK; var Rating = context.TLADM_ProductRating.Find(ProdFK).Pr_numeric_Rating; var NoOfGarments = Math.Round(Yield / Rating * NettWeight); var Factor = Math.Round(Yield / Rating * NettWeight, 0); var tst = core.CalculateRatios(ProdFK, (int)Factor); foreach (var row in tst) { decimal EstKg = Math.Round(NettWeight * (row.Value / Factor), 2); decimal BindKg = Math.Round(BindWeight * (row.Value / Factor), 2); decimal TrimKg = Math.Round(TrimWeight * (row.Value / Factor), 2); var ExpectUnits = context.TLCUT_ExpectedUnits.FirstOrDefault(x => x.TLCUTE_CutSheet_FK == CutSheet.TLCutSH_Pk && x.TLCUTE_Size_FK == row.Key); if (ExpectUnits != null) { ExpectUnits.TLCUTE_EstNettWeight += EstKg; ExpectUnits.TLCUTE_NoOfBinding += (int)(Yield / Rating) * BindKg; ExpectUnits.TLCUTE_NoOfTrims += (int)(Yield / Rating) * TrimKg; ExpectUnits.TLCUTE_NoofGarments += (int)((Yield / Rating) * EstKg); if (ExpectUnits.TLCUTE_MarkerRatio == 0.00M) { ExpectUnits.TLCUTE_MarkerRatio = row.Value; } } } } } } } dr[1] = false; } } try { context.SaveChanges(); MessageBox.Show("Data successfully saved to database"); } catch (Exception ex) { MessageBox.Show(ex.InnerException.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; if (oBtn != null && formloaded) { var errorM = core.returnMessage(MandSelected, true, MandatoryFields); if (!string.IsNullOrEmpty(errorM)) { MessageBox.Show(errorM); return; } TLADM_CottonContracts cotton = new TLADM_CottonContracts(); using (var context = new TTI2Entities()) { if (!addRec) { var ExistRecords = (TLADM_CottonContracts)cmbCottonContracts.SelectedItem; if (ExistRecords != null) { cotton = context.TLADM_CottonContracts.Find(ExistRecords.CottonCon_Pk); } } cotton.CottonCon_ConSupplier_FK = SupFK; cotton.CottonCon_ContractDate = dtpContractDate.Value; cotton.CottonCon_Description = string.Empty; cotton.CottonCon_StartDate = dtpContractStart.Value; cotton.CottonCon_EndDate = dtpContractComplete.Value; cotton.CottonCon_Mass = 0; cotton.CottonCon_No = txtContractNo.Text; cotton.CottonCon_PerMonth = Convert.ToDecimal(txtKiloPM.Text); cotton.CottonCon_Reference = txtSupplierRef.Text; cotton.CottonCon_Remarks = rtbRemarks.Text; cotton.CottonCon_UOM_Fk = Convert.ToInt32(cmb_unitsOfMeasure.SelectedValue.ToString()); cotton.CottonCon_USPricePerKg = Convert.ToDecimal(txtUSDPerKg.Text); cotton.CottonCon_USPriceperLb = Convert.ToDecimal(txtUSDPerLb.Text); cotton.CottonCon_ZAPricePerKg = Convert.ToDecimal(txtRandPerKg.Text); cotton.CottonCon_Description = txtCottonDescription.Text; cotton.CottonCon_Mass = Convert.ToInt32(txtMass.Text); cotton.CottonCon_NoOfBales = Convert.ToInt32(txtNoOfBales.Text); cotton.CottonCon_StapleFrom = Convert.ToDecimal(txtStapleFrom.Text); cotton.CottonCon_StapleTo = Convert.ToDecimal(txtStapleTo.Text); cotton.CottonCon_MicraFrom = Convert.ToDecimal(txtMicraFrom.Text); cotton.CottonCon_MicraTo = Convert.ToDecimal(txtMicraTo.Text); if (ChkContractClosed.Checked) { cotton.CottonCon_Closed = true; cotton.CottonCon_DateClosed = dtpClosedDate.Value; } if (rbShowKgReceivedYes.Checked) { cotton.CottonCon_ShowTotalKgReceived = true; } else { cotton.CottonCon_ShowTotalKgReceived = false; } if (rbShowKgYes.Checked) { cotton.CottonCon_ShowOutStandingKg = true; } else { cotton.CottonCon_ShowOutStandingKg = false; } if (addRec) { context.TLADM_CottonContracts.Add(cotton); } try { context.SaveChanges(); formloaded = false; cmbCottonContracts.DataSource = context.TLADM_CottonContracts.Where(x => x.CottonCon_ConSupplier_FK == SupFK).OrderBy(x => x.CottonCon_No).ToList(); formloaded = true; setup(); MessageBox.Show("Records save to database successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void cmboStyle_SelectedIndexChanged(object sender, EventArgs e) { ComboBox oCmbo = sender as ComboBox; if (oCmbo != null && FormLoaded) { if (radStyle.Checked) { if (oStockOH == null) { MessageBox.Show("Please enter a box number"); return; } var Selected = (TLADM_Styles)cmboStyle.SelectedItem; if (Selected == null) { MessageBox.Show("Please select an alternative style"); return; } using (var context = new TTI2Entities()) { if (oStockOH != null) { var SOH = context.TLCSV_StockOnHand.Find(oStockOH.TLSOH_Pk); if (SOH != null) { SOH.TLSOH_Style_FK = Selected.Sty_Id; try { context.SaveChanges(); MessageBox.Show("Data wrritten successfully to database"); txtColour.Text = string.Empty; txtSize.Text = string.Empty; txtStyle.Text = string.Empty; FormLoaded = false; cmboStyle.SelectedIndex = -1; oBoxNumber.Text = String.Empty; oBoxNumber.Focus(); FormLoaded = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } } else { using (var context = new TTI2Entities()) { var Selected = (TLADM_Sizes)cmboStyle.SelectedItem; if (Selected == null) { MessageBox.Show("Please select an alternative size"); return; } if (oStockOH != null) { var SOH = context.TLCSV_StockOnHand.Find(oStockOH.TLSOH_Pk); if (SOH != null) { SOH.TLSOH_Size_FK = Selected.SI_id; try { context.SaveChanges(); MessageBox.Show("Data wrritten successfully to database"); txtColour.Text = string.Empty; txtSize.Text = string.Empty; txtStyle.Text = string.Empty; FormLoaded = false; cmboStyle.SelectedIndex = -1; oBoxNumber.Text = String.Empty; oBoxNumber.Focus(); FormLoaded = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } } } }
private void button1_Click(object sender, EventArgs e) { Button oBtn = sender as Button; if (oBtn != null && formloaded) { var WhseIssue = (TLADM_WhseStore)cmboIssueDepartment.SelectedItem; if (WhseIssue == null) { MessageBox.Show("Please select a Chemical Store from the list provided"); return; } var WhseReceiving = (TLADM_WhseStore)cmboReceivingDepartment.SelectedItem; if (WhseReceiving == null) { MessageBox.Show("Please select a Dye Kitchen from the list provided"); return; } using (var context = new TTI2Entities()) { var LNU = context.TLADM_LastNumberUsed.Find(3); LNU.col12 += 1; foreach (DataGridViewRow row in dataGridView1.Rows) { if (!(bool)row.Cells[1].Value) { continue; } var index = (int)row.Cells[0].Value; //--------------------------------------- // 1st decision //------------------------------------------------------- TLDYE_ConsumableSOH newSOH = new TLDYE_ConsumableSOH(); newSOH = context.TLDYE_ConsumableSOH.Where(x => x.DYCSH_WhseStore_FK == WhseReceiving.WhStore_Id && x.DYCSH_Consumable_FK == index).FirstOrDefault(); if (newSOH == null) { newSOH = new TLDYE_ConsumableSOH(); newSOH.DYCSH_StockOnHand = (decimal)row.Cells[4].Value; newSOH.DYCSH_TransNumber = -1 + LNU.col12; newSOH.DYCSH_Consumable_FK = (int)row.Cells[5].Value; newSOH.DYCSH_WhseStore_FK = WhseReceiving.WhStore_Id; newSOH.DYCSH_DyeKitchen = WhseReceiving.WhStore_DyeKitchen; context.TLDYE_ConsumableSOH.Add(newSOH); } else { newSOH.DYCSH_StockOnHand += (decimal)row.Cells[4].Value; } TLDYE_ConsumableSOH oldSOH = new TLDYE_ConsumableSOH(); oldSOH = context.TLDYE_ConsumableSOH.Find(index); if (oldSOH != null) { oldSOH.DYCSH_StockOnHand -= (Decimal)row.Cells[4].Value; } } try { context.SaveChanges(); MessageBox.Show("Data successfully saved to database"); DyeReportOptions opts = new DyeReportOptions(); opts.fromDate = DateTime.Now; opts.LNU = -1 + LNU.col12; opts.toStore = WhseReceiving.WhStore_Id; TLADM_WhseStore FromWhse = context.TLADM_WhseStore.Where(x => x.WhStore_Code.Contains("CS")).FirstOrDefault(); opts.fromStore = FromWhse.WhStore_Id; frmDyeViewReport vRep = new frmDyeViewReport(30, opts); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLKNI_Order KO = null; if (oBtn != null && formloaded) { if (Decimal.Parse(txtAdjustedWeight.Text) > 0) { Decimal Weight = Decimal.Parse(txtAdjustedWeight.Text); if (GreigeProd.GreigeP_weight - Weight >= 0) { using (var context = new TTI2Entities()) { var GP = context.TLKNI_GreigeProduction.Find(GreigeProd.GreigeP_Pk); if (GP != null) { if (GP.GreigeP_KnitO_Fk != null) { KO = context.TLKNI_Order.Find(GP.GreigeP_KnitO_Fk); if (KO != null) { //============================================ // Create an actual Production split record //============================================= TLKNI_ProductionSplit ProdSplit = new TLKNI_ProductionSplit(); ProdSplit.TLKNISP_FromStore_FK = (int)GreigeProd.GreigeP_Store_FK; if (radKNumber.Checked) { ProdSplit.TLKNISP_NewPieceNo = "K" + GreigeProd.GreigeP_PieceNo.ToString(); } else { ProdSplit.TLKNISP_NewPieceNo = "R" + GreigeProd.GreigeP_PieceNo.ToString(); } ProdSplit.TLKNISP_Date = DateTime.Now; ProdSplit.TLKNISP_OrigPieceNo = GreigeProd.GreigeP_PieceNo; ProdSplit.TLKNISP_Notes = txtReasons.Text; ProdSplit.TLKNISP_Mass = GP.GreigeP_weight - Weight; ProdSplit.TLKNISP_KnitOrder_FK = KO.KnitO_Pk; var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("KNIT")).FirstOrDefault(); if (Dept != null) { var TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 2005).FirstOrDefault(); if (TranType != null) { ProdSplit.TLKNISP_ToStore_FK = (int)TranType.TrxT_ToWhse_FK; } } context.TLKNI_ProductionSplit.Add(ProdSplit); //================================================ // Now Adjust the actual GP record with new weight //========================================= GP.GreigeP_weight = Weight; GP.GreigeP_weightAvail = Weight; } } } try { context.SaveChanges(); MessageBox.Show("Data successfully saved to database"); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show("Cannot split more than what was originally Knitted"); } } } }