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 (oDgv.SelectedRows.Count > 0) { DialogResult res = MessageBox.Show("Please confirm this transaction", "Confirmation Required", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); using (var context = new TTI2Entities()) { if (res == DialogResult.OK) { var Pk = (int)oDgv.CurrentRow.Cells[0].Value; TLADM_Departments shifts = context.TLADM_Departments.Find(Pk); if (shifts != null) { context.TLADM_Departments.Remove(shifts); try { context.SaveChanges(); oDgv.Rows.Clear(); MessageBox.Show("Data successfully saved to database"); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } } } } else { MessageBox.Show("Please select a row in the datagrid", "Information"); } } }
private void button1_Click(object sender, EventArgs e) { Button oBtn = sender as Button; decimal Weight = 0.00M; int CurrentStore_FK = 0; TLADM_TranactionType TT = null; TLADM_Departments Depts = null; TLDYE_DyeTransactions dt = null; if (oBtn != null && formloaded) { var errorM = core.returnMessage(MandSelected, true, MandatoryFields); if (!string.IsNullOrEmpty(errorM)) { MessageBox.Show(errorM); return; } var selected = (TLDYE_DyeBatch)cmboDyeBatches.SelectedItem; using (var context = new TTI2Entities()) { var LNU = context.TLADM_LastNumberUsed.Find(3); if (LNU != null) { LNU.col6 += 1; } var TotalWeight = 0.00M; //--------- first attend to current records foreach (DataGridViewRow row in dataGridView1.Rows) { if ((bool)row.Cells[1].Value == false) { continue; } Weight = (decimal)row.Cells[3].Value; TotalWeight += Weight; var Pk = (int)row.Cells[0].Value; if (Pk != 0) { var Record = context.TLDYE_DyeBatchDetails.Find(Pk); if (Record != null) { Record.DYEBO_AdjustedWeight = Weight; Record.DYEBO_TransactionNo = txtNumber.Text; Record.DYEBO_WriteOff = true; Depts = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("DYE")).FirstOrDefault(); if (Depts != null) { TT = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Depts.Dep_Id && x.TrxT_Number == 1000).FirstOrDefault(); if (TT != null) { Record.DYEBO_CurrentStore_FK = (int)TT.TrxT_ToWhse_FK; CurrentStore_FK = (int)TT.TrxT_ToWhse_FK; } } } } } dt = new TLDYE_DyeTransactions(); dt.TLDYET_BatchNo = selected.DYEB_BatchNo; dt.TLDYET_Date = DateTime.Now; dt.TLDYET_SequenceNo = selected.DYEB_SequenceNo; dt.TLDYET_CurrentStore_FK = CurrentStore_FK; dt.TLDYET_TransactionWeight = TotalWeight; dt.TLDYET_AuthorisedBy = txtApprovedBy.Text; dt.TLDYET_Adjustment_Reasons = txtReasons.Text; dt.TLDYET_TransactionType = TT.TrxT_Pk; dt.TLDYET_BatchWeight = selected.DYEB_BatchKG; dt.TLDYET_Batch_FK = selected.DYEB_Pk; dt.TLDYET_TransactionNumber = txtNumber.Text; context.TLDYE_DyeTransactions.Add(dt); //--------------------------------------------------------------------- // This is the daily log file that needs to be updated //------------------------------------------------------- string Mach_IP = Dns.GetHostEntry(Dns.GetHostName()) .AddressList.First(f => f.AddressFamily == AddressFamily.InterNetwork) .ToString(); TLADM_DailyLog DailyLog = new TLADM_DailyLog(); DailyLog.TLDL_IPAddress = Mach_IP; DailyLog.TLDL_Dept_Fk = Depts.Dep_Id; DailyLog.TLDL_Date = DateTime.Now; DailyLog.TLDL_TransDetail = "Dye House Adjustment"; DailyLog.TLDL_AuthorisedBy = txtApprovedBy.Text; DailyLog.TLDL_Comments = txtNumber.Text; context.TLADM_DailyLog.Add(DailyLog); try { context.SaveChanges(); MessageBox.Show("Data successfully stored to database"); frmDyeViewReport vRep = new frmDyeViewReport(15, dt.TLDYET_Pk); vRep.ShowDialog(this); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; bool lAdd = false; bool lCMT = false; bool lSuccess = true; if (oBtn != null) { using (var context = new TTI2Entities()) { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[1].Value == null) { continue; } TLADM_Departments dpt = new TLADM_Departments(); if (row.Cells[0].Value == null) { lAdd = true; } else { int pk = Convert.ToInt32(row.Cells[0].Value.ToString()); dpt = context.TLADM_Departments.Find(pk); } dpt.Dep_ShortCode = row.Cells[1].Value.ToString(); dpt.Dep_Description = row.Cells[2].Value.ToString(); dpt.Dep_UOM = Convert.ToInt32(row.Cells[3].Value.ToString()); dpt.Dep_ProductType_FK = Convert.ToInt32(row.Cells[4].Value.ToString()); if (row.Cells[5].Value == null && lAdd) { dpt.Dep_PowerN = (int)Math.Pow(2.00D, (double)row.Index); } else { dpt.Dep_PowerN = Convert.ToInt32(row.Cells[5].Value.ToString()); } if (row.Cells[6].Value != null) { if ((row.Cells[6].Value.ToString() == Boolean.TrueString)) { dpt.Dep_IsCMT = true; } } else { dpt.Dep_IsCMT = false; } if (row.Cells[7].Value != null) { if ((row.Cells[7].Value.ToString() == Boolean.TrueString)) { dpt.Dep_IsCut = true; } } else { dpt.Dep_IsCut = false; } if (lAdd) { context.TLADM_Departments.Add(dpt); } lCMT = dpt.Dep_IsCMT; try { context.SaveChanges(); // We need to add a record to the TLADM_LastNumberUsed table if (lAdd) { TLADM_LastNumberUsed LstNumberUsed = new TLADM_LastNumberUsed(); LstNumberUsed.LUN_Department_FK = dpt.Dep_Id; LstNumberUsed.col1 = 1; LstNumberUsed.col2 = 1; LstNumberUsed.col3 = 1; LstNumberUsed.col4 = 1; LstNumberUsed.col5 = 1; LstNumberUsed.col6 = 1; LstNumberUsed.col7 = 1; LstNumberUsed.col8 = 1; LstNumberUsed.col9 = 1; LstNumberUsed.col10 = 1; LstNumberUsed.col11 = 1; LstNumberUsed.col12 = 1; LstNumberUsed.col13 = 1; var LstNumber = context.TLADM_LastNumberUsed.Where(x => x.LUN_Department_FK == dpt.Dep_Id).FirstOrDefault(); if (LstNumber == null) { context.TLADM_LastNumberUsed.Add(LstNumberUsed); context.SaveChanges(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); lSuccess = false; } } } if (lSuccess) { dataGridView1.Rows.Clear(); string Mess = string.Empty; if (lCMT) { Mess = "A new CMT has just been added" + Environment.NewLine; Mess += "Please proceed to tranaction types to add a tranaction 100 to the relevant CMT's" + Environment.NewLine; Mess += "If unsure please contact system developer for assistance" + Environment.NewLine; } Mess += "Records successfully stored to database"; MessageBox.Show(Mess); } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; TLADM_TranactionType TranType = null; int GProdKey = 0; TLADM_Departments Dept = null; if (oBtn != null && formloaded) { var ErrorM = core.returnMessage(MandatorySelected, true, MandatoryFields); if (!String.IsNullOrEmpty(ErrorM)) { MessageBox.Show(ErrorM); return; } var KO = (TLKNI_Order)cmbKnitOrder.SelectedItem; if (KO != null) { using (var context = new TTI2Entities()) { // We may have added some records //-------------------------------------------- var Machine = context.TLADM_MachineDefinitions.Find(KO.KnitO_Machine_FK); if (Machine != null) { if (MLNU > Machine.MD_LastNumberUsed) { Machine.MD_LastNumberUsed = MLNU + 1; } } var LNU = context.TLADM_LastNumberUsed.Find(2); if (LNU != null) { LNU.col8 += 1; } Dept = context.TLADM_Departments.Where(x => x.Dep_ShortCode.Contains("KNIT")).FirstOrDefault(); if (Dept != null) { if (KO.KnitO_YarnO_FK == null) { if (KO.KnitO_CommisionCust) { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 2002).FirstOrDefault(); } else { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 2003).FirstOrDefault(); } } else { TranType = context.TLADM_TranactionType.Where(x => x.TrxT_Department_FK == Dept.Dep_Id && x.TrxT_Number == 2001).FirstOrDefault(); } } foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[0].Value == null) continue; var Pk = (int)row.Cells[0].Value; if (Pk != 0) { var GreigeProd = context.TLKNI_GreigeProduction.Find(Pk); if (GreigeProd != null) { var NewValue = (Decimal)row.Cells[3].Value; if (NewValue != GreigeProd.GreigeP_weight) { GreigeProd.GreigeP_weight += NewValue; TLKNI_GreigeTransactions GreigeT = new TLKNI_GreigeTransactions(); GreigeT.GreigeT_AdjustedWeight = NewValue; if (row.Cells[2].Value != null) GreigeT.GreigeT_Grade = row.Cells[2].Value.ToString(); else GreigeT.GreigeT_Grade = string.Empty; GreigeT.GreigeT_KOrder_FK = KO.KnitO_Pk; if ((int)row.Cells[0].Value == 0) GreigeT.GreigeT_Piece_FK = GProdKey; else GreigeT.GreigeT_Piece_FK = (int)row.Cells[0].Value; GreigeT.GreigeT_TransactionDate = dtpAdjustDate.Value; GreigeT.GreigeT_TransactionNumber = LNU.col8 - 1; GreigeT.GreigeT_TransactionType_FK = TranType.TrxT_Pk; GreigeT.GreigeT_ApprovedBy = txtApprovedBy.Text; context.TLKNI_GreigeTransactions.Add(GreigeT); } } } } string Mach_IP = Dns.GetHostEntry(Dns.GetHostName()) .AddressList.First(f => f.AddressFamily == AddressFamily.InterNetwork) .ToString(); TLADM_DailyLog DailyLog = new TLADM_DailyLog(); DailyLog.TLDL_IPAddress = Mach_IP; DailyLog.TLDL_Dept_Fk = Dept.Dep_Id; DailyLog.TLDL_Date = DateTime.Now; DailyLog.TLDL_TransDetail = "Greige Adjustment"; DailyLog.TLDL_AuthorisedBy = txtApprovedBy.Text; DailyLog.TLDL_Comments = txtGreigeAdjNo.Text; try { context.TLADM_DailyLog.Add(DailyLog); context.SaveChanges(); MessageBox.Show("Data saved successfully to database"); SetUp(false); frmKnitViewRep vRep = new frmKnitViewRep(14, LNU.col8 - 1); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); } catch (System.Data.Entity.Validation.DbEntityValidationException en) { foreach (var eve in en.EntityValidationErrors) { MessageBox.Show("following validation errors: Type" + eve.Entry.Entity.GetType().Name.ToString() + "State " + eve.Entry.State.ToString()); foreach (var ve in eve.ValidationErrors) { MessageBox.Show("- Property" + ve.PropertyName + " Message " + ve.ErrorMessage); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } }