private void frmCSSelectDyeBatch_Load(object sender, EventArgs e) { using (var context = new TTI2Entities()) { var DBatches = (from T1 in context.TLDYE_DyeBatch join T2 in context.TLDYE_DyeBatchDetails on T1.DYEB_Pk equals T2.DYEBD_DyeBatch_FK where T2.DYEBO_QAApproved && !T2.DYEBO_Sold && !T2.DYEBO_WriteOff && !T2.DYEBO_CutSheet && !T1.DYEB_CommissinCust select T1).GroupBy(x => x.DYEB_Pk); foreach (var DBatch in DBatches) { var index = dataGridView1.Rows.Add(); dataGridView1.Rows[index].Cells[0].Value = DBatch.FirstOrDefault().DYEB_Pk; dataGridView1.Rows[index].Cells[2].Value = DBatch.FirstOrDefault().DYEB_BatchNo; dataGridView1.Rows[index].Cells[3].Value = context.TLADM_Colours.Find(DBatch.FirstOrDefault().DYEB_Colour_FK).Col_Display; var DO = context.TLDYE_DyeOrder.Find(DBatch.FirstOrDefault().DYEB_DyeOrder_FK); if (DO != null) { dataGridView1.Rows[index].Cells[4].Value = DO.TLDYO_OrderNum; dataGridView1.Rows[index].Cells[5].Value = DO.TLDYO_OrderDate; DateTime dt = core.FirstDateOfWeek(DO.TLDYO_OrderDate.Year, DO.TLDYO_CutReqWeek); dt = dt.AddDays(5); dataGridView1.Rows[index].Cells[6].Value = dt; int cnt = 0; var details = context.TLDYE_DyeOrderDetails.Where(x => x.TLDYOD_DyeOrder_Fk == DO.TLDYO_Pk).ToList(); foreach (var row in details) { if (cnt == 0) { dataGridView1.Rows[index].Cells[7].Value = context.TLADM_Griege.Find(row.TLDYOD_Greige_FK).TLGreige_Description; } else if (cnt == 1) { dataGridView1.Rows[index].Cells[8].Value = context.TLADM_Griege.Find(row.TLDYOD_Greige_FK).TLGreige_Description; } else if (cnt == 2) { dataGridView1.Rows[index].Cells[9].Value = context.TLADM_Griege.Find(row.TLDYOD_Greige_FK).TLGreige_Description; } // dataGridView1.Rows[index].Cells[10].Value = context.TLADM_Sizes.Find(row.TLDYOD_Sizes_FK).SI_Description; ++cnt; } } } } }
private void btnSave_Click(object sender, EventArgs e) { IList <TLDYE_DyeBatch> DB = new List <TLDYE_DyeBatch>(); Button oBtn = sender as Button; TLADM_TranactionType TranType = null; TLADM_LastNumberUsed LNU = null; if (oBtn != null && formloaded) { using (var context = new TTI2Entities()) { if (_Commission) { // This is for Commission Deliveries //============================================ if (!rbCommissionDeliveriesReprint.Checked) { var Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode == "DYE").FirstOrDefault(); if (Dept != null) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 1300).FirstOrDefault(); } LNU = context.TLADM_LastNumberUsed.Find(3); if (LNU != null) { LNU.col9 += 1; } foreach (var Batch in QueryParms.DyeBatches) { var DyeBatchDetails = context.TLDYE_DyeBatchDetails.Where(x => x.DYEBD_DyeBatch_FK == Batch.DYEB_Pk).ToList(); foreach (var Detail in DyeBatchDetails) { Detail.DYEBO_CurrentStore_FK = (int)TranType.TrxT_ToWhse_FK; Detail.DYEBO_TransactionNo = TxtTransNumber.Text; Detail.DYEBO_DateSold = dtpTransDate.Value; Detail.DYEBO_Sold = true; } } try { context.SaveChanges(); MessageBox.Show("Data succesfully saved to database"); String TransNumber = TxtTransNumber.Text.Trim(); QueryParms.CommDyeing = false; StringBuilder sb = new StringBuilder(); sb.Append(richTextBox1.Text); QueryParms.Notes = sb; if (rbCommissionDyeing.Checked) { QueryParms.CommDyeing = true; } else { QueryParms.CommDyeing = false; } frmDyeViewReport vRep = new frmDyeViewReport(17, QueryParms, TransNumber); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); vRep = new frmDyeViewReport(16, QueryParms, TransNumber); h = Screen.PrimaryScreen.WorkingArea.Height; w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); frmCommissionDeliveries_Load(this, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { QueryParms.CommDyeingReprint = true; String TransNumber = string.Empty; foreach (var DBDet in QueryParms.DyeBatchDetails) { TransNumber = DBDet.DYEBO_TransactionNo; } var DyeBatches = (from DyeBatch in context.TLDYE_DyeBatch join DyeBatchDetails in context.TLDYE_DyeBatchDetails on DyeBatch.DYEB_Pk equals DyeBatchDetails.DYEBD_DyeBatch_FK where DyeBatchDetails.DYEBO_TransactionNo == TransNumber select DyeBatch).GroupBy(x => x.DYEB_BatchNo); foreach (var DBatch in DyeBatches) { var Pk = DBatch.FirstOrDefault().DYEB_Pk; QueryParms.DyeBatches.Add(repo.LoadDyeBatch(Pk)); } frmDyeViewReport vRep = new frmDyeViewReport(17, QueryParms, TransNumber); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); vRep = new frmDyeViewReport(16, QueryParms, TransNumber); h = Screen.PrimaryScreen.WorkingArea.Height; w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); frmCommissionDeliveries_Load(this, null); } } else { // This is for Fabric Sales //============================================================ QueryParms.FabricSales = true; frmDyeViewReport vRep = new frmDyeViewReport(17, QueryParms); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); vRep = new frmDyeViewReport(16, QueryParms); h = Screen.PrimaryScreen.WorkingArea.Height; w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); frmCommissionDeliveries_Load(this, null); } } } else { } }