private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; bool Add = true; bool[] complete = null; if (oBtn != null && formloaded) { var selected = (TLCUT_CutSheet)cmboCutSheet.SelectedItem; if (selected == null) { MessageBox.Show("Please select a Production Line and / or CutSheet from the drop down box"); return; } var Operator = cmboSupervisor.SelectedItem; if (Operator == null) { MessageBox.Show("Please select an Supervisor from the drop down box"); return; } using (var context = new TTI2Entities()) { TLCMT_LineIssue LineIssue = context.TLCMT_LineIssue.Where(x => x.TLCMTLI_CutSheet_FK == selected.TLCutSH_Pk).FirstOrDefault(); foreach (DataGridViewRow row in dataGridView1.Rows) { Add = true; TLCMT_LineFeederBundleCheck lfBundle = new TLCMT_LineFeederBundleCheck(); if (row.Cells[0].Value != null) { int index = (int)row.Cells[0].Value; lfBundle = context.TLCMT_LineFeederBundleCheck.Find(index); if (lfBundle == null) { lfBundle = new TLCMT_LineFeederBundleCheck(); } else { Add = false; } } //--------------------------------------------- // 0 : Pk // 1 : Bundle No // 2 : Bundle Qty // 3 : Difference Qty // 4 : Sleeve Qty // 5 : Labels Qty // 6 : Sizes // 7 : Sizes (Not Visible...FK); //--------------------------------------------------------------- complete = core.RowComplete(row, MandatoryFields); var errorM = core.returnMessage(complete, true, MandatoryFields); if (!string.IsNullOrEmpty(errorM)) { errorM = errorM + Environment.NewLine + "Process will now be aborted"; MessageBox.Show(errorM, "Error Message on Line " + (1 + row.Index).ToString()); return; } lfBundle.TLCMTLF_Operator_FK = (int)cmboSupervisor.SelectedValue; lfBundle.TLCMTLF_Bundle_No = row.Cells[1].Value.ToString(); lfBundle.TLCMTLF_Body_Qty = (int)row.Cells[2].Value; lfBundle.TLCMTLF_Difference = (int)row.Cells[3].Value; lfBundle.TLCMTFL_TransDate = dtpTransDate.Value; if (LineIssue != null) { lfBundle.TLCMTLF_LineNo_FK = LineIssue.TLCMTLI_LineNo_FK; lfBundle.TLCMTLF_Facility_FK = LineIssue.TLCMTLI_CmtFacility_FK; lfBundle.TLCMTLF_CutSheet_FK = LineIssue.TLCMTLI_CutSheet_FK; } lfBundle.TLCMTLF_Sleeve_Qty = (int)row.Cells[4].Value; lfBundle.TLCMTLF_Labels_Qty = (int)row.Cells[5].Value; lfBundle.TLCMTLF_Size_FK = (int)row.Cells[7].Value; var CS = context.TLCUT_CutSheet.Find(LineIssue.TLCMTLI_CutSheet_FK); if (CS != null) { var DB = context.TLDYE_DyeBatch.Find(CS.TLCutSH_DyeBatch_FK); if (DB != null) { lfBundle.TLCMTLF_Colour_FK = context.TLADM_Colours.Find(DB.DYEB_Colour_FK).Col_Id; } } if (Add) { context.TLCMT_LineFeederBundleCheck.Add(lfBundle); } } try { context.SaveChanges(); MessageBox.Show("Data successfully saved to the database"); dataGridView1.Rows.Clear(); formloaded = false; cmboLineIssue.SelectedValue = -1; cmboSupervisor.SelectedValue = -1; txtColour.Text = string.Empty; cmboCutSheet.SelectedValue = -1; // txtCutSheet.Text = string.Empty; txtDescription.Text = string.Empty; formloaded = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; bool UpDateHeader = true; if (oBtn != null && formloaded) { var LNSelected = (TLADM_WhseStore)cmboStoreFacilities.SelectedItem; if (LNSelected == null) { MessageBox.Show("Please select a store"); return; } TLCMT_PanelIssue PIselected = (TLCMT_PanelIssue)cmboDelivery.SelectedItem; using (var context = new TTI2Entities()) { foreach (DataGridViewRow row in dataGridView1.Rows) { var CutSheetPk = (int)row.Cells[0].Value; if ((bool)row.Cells[2].Value == false) { DialogResult Res = MessageBox.Show("Warning . This cutsheet not selected. Will be sent back to originating Panel Store", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (Res == DialogResult.Yes) { var CutSheetReceipt = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == CutSheetPk).FirstOrDefault(); if (CutSheetReceipt != null) { CutSheetReceipt.TLCUTSHR_InPanelStore = true; CutSheetReceipt.TLCUTSHR_Issued = false; CutSheetReceipt.TLCUTSHR_InReceiptCage = false; } UpDateHeader = false; continue; } } TLCMT_LineIssue li = new TLCMT_LineIssue(); li.TLCMTLI_Date = dtpTransDate.Value; li.TLCMTLI_CutSheet_FK = CutSheetPk; li.TLCMTLI_CmtFacility_FK = PIselected.CMTPI_Department_FK; li.TLCMTLI_PanelIssue_FK = PIselected.CMTPI_Pk; li.TLCMTLI_WhStore_FK = LNSelected.WhStore_Id; li.TLCMTLI_Required_Date = dtpTransDate.Value.AddDays(7); li.TLCMTLI_PanelIssue_FK = PIselected.CMTPI_Pk; try { li.TLCMTLI_IssueQty = int.Parse(row.Cells[5].Value.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); } //--------------------------------------- // this is to ensure that the record is only added once to the table //------------------------------------------------------------------------------- var AlreadyIssued = context.TLCMT_LineIssue.Where(x => x.TLCMTLI_CutSheet_FK == CutSheetPk).FirstOrDefault(); if (AlreadyIssued == null) { context.TLCMT_LineIssue.Add(li); } var CSR = context.TLCUT_CutSheetReceipt.Where(x => x.TLCUTSHR_CutSheet_FK == CutSheetPk).FirstOrDefault(); if (CSR != null) { CSR.TLCUTSHR_InReceiptCage = true; var PanIssueDetail = context.TLCMT_PanelIssueDetail.Where(X => X.CMTPID_CutSheet_FK == CSR.TLCUTSHR_Pk).FirstOrDefault(); if (PanIssueDetail != null) { PanIssueDetail.CMTPID_Receipted = true; } } } if (UpDateHeader) { PIselected = context.TLCMT_PanelIssue.Find(PIselected.CMTPI_Pk); if (PIselected != null) { PIselected.CMTPI_Receipted = true; } } try { context.SaveChanges(); dataGridView1.Rows.Clear(); cmboStoreFacilities.SelectedIndex = -1; cmboCMT.SelectedIndex = -1; TxtStoreFacilities.Text = string.Empty; MessageBox.Show("Data saved successfully to database"); DialogResult res = MessageBox.Show("Do you wish to print a full report", "All transactions", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (res == DialogResult.OK) { frmCMTViewRep vRep = new frmCMTViewRep(3, PIselected.CMTPI_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.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { Button oBtn = sender as Button; int Col3 = 0; TLCMT_LineIssue LineIssue = null; int Pk = 0; string Description = string.Empty; var RepOpts = new CMTReportOptions(); if (oBtn != null && formloaded) { if (!InternalTransfer) { var DeptSelected = (TLADM_Departments)cmboDepartment.SelectedItem; if (DeptSelected == null) { MessageBox.Show("Please select an location from the drop down box"); return; } using (var context = new TTI2Entities()) { Object tst = cmboCutSheet.SelectedItem; if (tst != null) { foreach (PropertyInfo prop in tst.GetType().GetProperties()) { if (prop.Name == "Key") { Pk = Convert.ToInt32(prop.GetValue(tst)); } else if (prop.Name == "Value") { Description = Convert.ToString(prop.GetValue(tst)); } } } if (Pk == 0) { MessageBox.Show("Please select a cut sheet from the drop down box"); return; } var LineDetails = (TLCMT_FactConfig)cmboLineDetails.SelectedItem; if (LineDetails == null) { MessageBox.Show("Please select a line to assign this cut sheet too"); return; } LineIssue = new TLCMT_LineIssue(); LineIssue = context.TLCMT_LineIssue.Find(Pk); if (LineIssue != null) { LineIssue.TLCMTLI_TransactionNo = Col3; LineIssue.TLCMTLI_TransferDate = DateTime.Now; LineIssue.TLCMTLI_CutSheetDetails = "SI" + Description.Remove(0, 2); LineIssue.TLCMTLI_OnHold = false; var LNU = context.TLADM_LastNumberUsed.Where(x => x.LUN_Department_FK == LineIssue.TLCMTLI_CmtFacility_FK).FirstOrDefault(); if (LNU != null) { LineIssue.TLCMTLI_TransactionNo = LNU.col3; } LineIssue.TLCMTLI_Required_Date = dtpRequiredDate.Value; LineIssue.TLCMTLI_LineNo_FK = LineDetails.TLCMTCFG_Pk; LineIssue.TLCMTLI_IssuedToLine = true; } Col3 += 1; try { context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { MessageBox.Show("Data successfully saved to database"); //--------------Cut Sheet document frmCMTViewRep vRep = new frmCMTViewRep(8, LineIssue.TLCMTLI_Pk); int h = Screen.PrimaryScreen.WorkingArea.Height; int w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); RepOpts.ReportTitle = context.TLCUT_CutSheet.Find(LineIssue.TLCMTLI_CutSheet_FK).TLCutSH_No; RepOpts.SLFCutSheetFK = LineIssue.TLCMTLI_CutSheet_FK; /*//------------------Line Feeder Document * No longer required as they copy this onto the back of cutsheet to conserve * vRep = new frmCMTViewRep(23, RepOpts); * h = Screen.PrimaryScreen.WorkingArea.Height; * w = Screen.PrimaryScreen.WorkingArea.Width; * vRep.ClientSize = new Size(w, h); * vRep.ShowDialog(this);*//// vRep = new frmCMTViewRep(5, LineIssue.TLCMTLI_CutSheet_FK); h = Screen.PrimaryScreen.WorkingArea.Height; w = Screen.PrimaryScreen.WorkingArea.Width; vRep.ClientSize = new Size(w, h); vRep.ShowDialog(this); formloaded = false; cmboCutSheet.SelectedValue = -1; cmboDepartment.SelectedValue = -1; cmboLineDetails.SelectedValue = -1; formloaded = true; txtColours.Text = string.Empty; txtPanels.Text = string.Empty; txtSizes.Text = string.Empty; txtStyle.Text = string.Empty; } } } else { using (var context = new TTI2Entities()) { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[0].Value == null) { continue; } var OnHold = (bool)row.Cells[5].Value; if (OnHold) { var Reason = row.Cells[2].Value.ToString(); if (Reason.Length == 0) { MessageBox.Show("Please provide a reason as to why this Cutsheet is placed on hold"); return; } } Pk = (int)row.Cells[0].Value; LineIssue = context.TLCMT_LineIssue.Find(Pk); if (LineIssue != null) { LineIssue.TLCMTLI_Reason = row.Cells[2].Value.ToString(); LineIssue.TLCMTLI_TransferApproved = row.Cells[3].Value.ToString(); LineIssue.TLCMTLI_TransferDate = DateTime.Now; LineIssue.TLCMTLI_OnHold = OnHold; if (NewLineAssigned != 0) { LineIssue.TLCMTLI_LineNo_FK = NewLineAssigned; } } } try { context.SaveChanges(); MessageBox.Show("Data successfully saved to database"); dataGridView1.Rows.Clear(); dataGridView1.Rows.Add(); cmboCutSheet.SelectedValue = -1; cmboDepartment.SelectedValue = -1; cmboLineDetails.SelectedValue = -1; txtColours.Text = string.Empty; txtPanels.Text = string.Empty; txtSizes.Text = string.Empty; txtStyle.Text = string.Empty; } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } }