private void Delete() { try { FormHelpers.CursorWait(true); var msg = "Deleting"; if (MessageHelpers.ShowQuestion("Are you sure you want to delete record?") == System.Windows.Forms.DialogResult.Yes) { var yearused = UserSettings.LogInYear; var moldno = mgridListPI.Rows[mgridListPI.SelectedCells[0].RowIndex].Cells["colMoldNo"].Value.ToString(); pi = pibal.GetByID(Convert.ToInt32(yearused), moldno.ToString());; if (pibal.Delete(pi)) { MessageHelpers.ShowInfo(msg + " Successful!"); RefreshGrid(); PageManager(1); } else { MessageHelpers.ShowWarning(msg + " Failed!"); } } } catch (Exception ex) { throw ex; } finally { FormHelpers.CursorWait(false); } }
private void Import() { List <tbl_000_H_PART> write_list_com; List <tbl_000_H_PI> write_list_pi; List <tbl_000_H_VP> write_list_vp; List <tbl_000_H_ASSY> write_list_assy; List <tbl_000_PROCESS> write_list_proc; try { GetExclData(mtxtFilePath.Text); if (!mcbOverWrite.Checked) { msg = "This process will import previous components from the selected year to the current logged in year. Do you want to continue?"; if (MessageHelpers.ShowQuestion(msg) == DialogResult.Yes) { switch (YearSource) { #region Components to Import case YearsOf.Components: write_list_com = new List <tbl_000_H_PART>(); var currentyear_list_com = combal.GetByYear(UserSettings.LogInYear).ToList(); //Matching by 'PartNo' or 'PartName' foreach (tbl_000_H_PART c in currentyear_list_com) { write_list_com.Add(combal.GetAll().Where(w => w.YEARUSED == UserSettings.LogInYear && (w.PartNo == c.PartNo || w.PartName == c.PartName)).FirstOrDefault()); } //Remove columns from excell if it exists in current year foreach (tbl_000_H_PART c in write_list_com) { if (c != null) { comlist.RemoveAll(r => r.PartNo == c.PartNo || r.PartName == c.PartName); } } //Fill some Columns and Save them Save_com(); break; #endregion #region Tabulation to Import case YearsOf.MaintainanceTable: switch (YearofMaintenanceTable_Sub) { case MaintainanceTableSub.PlasticInjection: write_list_pi = new List <tbl_000_H_PI>(); var currentyear_list_pi = pibal.GetByYear(UserSettings.LogInYear).ToList(); foreach (tbl_000_H_PI p in currentyear_list_pi) { write_list_pi.Add(pibal.GetAll().Where(w => w.YEARUSED == UserSettings.LogInYear && (w.MoldNo == p.MoldNo || w.MoldName == p.MoldName)).FirstOrDefault()); } foreach (tbl_000_H_PI p in write_list_pi) { if (p != null) { pilist.RemoveAll(r => r.MoldNo == p.MoldNo || r.MoldName == p.MoldName); } } Save_pi(); break; case MaintainanceTableSub.VacuumPlating: write_list_vp = new List <tbl_000_H_VP>(); var currentyear_list_vp = vpbal.GetByYear(UserSettings.LogInYear).ToList(); foreach (tbl_000_H_VP v in currentyear_list_vp) { write_list_vp.Add(vpbal.GetAll().Where(w => w.YEARUSED == UserSettings.LogInYear && (w.PartNo == v.PartNo || w.PartName == v.PartName)).FirstOrDefault()); } foreach (tbl_000_H_VP v in write_list_vp) { if (v != null) { vplist.RemoveAll(r => r.PartNo == v.PartNo || r.PartName == v.PartName); } } Save_vp(); break; case MaintainanceTableSub.Assembly: write_list_assy = new List <tbl_000_H_ASSY>(); var currentyear_list_assy = assybal.GetByYear(UserSettings.LogInYear).ToList(); foreach (tbl_000_H_ASSY a in currentyear_list_assy) { write_list_assy.Add(assybal.GetAll().Where(w => w.YEARUSED == UserSettings.LogInYear && (w.PartNo == a.PartNo || w.PartName == a.PartName)).FirstOrDefault()); } foreach (tbl_000_H_ASSY a in write_list_assy) { if (a != null) { assylist.RemoveAll(r => r.PartNo == a.PartNo || r.PartName == a.PartName); } } Save_assy(); break; } break; #endregion #region Process to Import case YearsOf.ProcessSetup: write_list_proc = new List <tbl_000_PROCESS>(); var currentyear_list_proc = procbal.GetByYear(UserSettings.LogInYear).ToList(); foreach (tbl_000_PROCESS p in currentyear_list_proc) { write_list_proc.Add(procbal.GetAll().Where(w => w.YEARUSED == UserSettings.LogInYear && (w.SubProcessCode == p.SubProcessCode || w.ItemDescription == p.ItemDescription)).FirstOrDefault()); } foreach (tbl_000_PROCESS p in write_list_proc) { if (p != null) { proclist.RemoveAll(r => r.SubProcessCode == p.SubProcessCode || r.ItemDescription == p.ItemDescription); } } Save_proc(); break; #endregion } } } else { msg = "This process will remove the existing components and replace it with the selected year. Do you want to continue?"; if (MessageHelpers.ShowQuestion(msg) == DialogResult.Yes) { switch (YearSource) { #region Components to Import with Overwrite case YearsOf.Components: write_list_com = new List <tbl_000_H_PART>(); //Matching by 'PartNo' or 'PartName' foreach (tbl_000_H_PART c in comlist) { write_list_com.Add(combal.GetAll().Where(w => w.YEARUSED == UserSettings.LogInYear && (w.PartNo == c.PartNo || w.PartName == c.PartName)).FirstOrDefault()); } //Delete the records to be Overwritten if (BPSUtilitiesV1.NZ(write_list_com, "").ToString() != "") { foreach (tbl_000_H_PART c in write_list_com) { if (c != null) { combal.Delete(c); } } } //Fill some Columns and Save them Save_com(); break; #endregion #region Tabulation to import with Overwrite case YearsOf.MaintainanceTable: switch (YearofMaintenanceTable_Sub) { case MaintainanceTableSub.PlasticInjection: write_list_pi = new List <tbl_000_H_PI>(); foreach (tbl_000_H_PI p in pilist) { write_list_pi.Add(pibal.GetAll().Where(w => w.YEARUSED == UserSettings.LogInYear && (w.MoldNo == p.MoldNo || w.MoldName == p.MoldName)).FirstOrDefault()); } if (BPSUtilitiesV1.NZ(write_list_pi, "").ToString() != "") { foreach (tbl_000_H_PI p in write_list_pi) { if (p != null) { pibal.Delete(p); } } } Save_pi(); break; case MaintainanceTableSub.VacuumPlating: write_list_vp = new List <tbl_000_H_VP>(); foreach (tbl_000_H_VP v in vplist) { write_list_vp.Add(vpbal.GetAll().Where(w => w.YEARUSED == UserSettings.LogInYear && (w.PartNo == v.PartNo || w.PartName == v.PartName)).FirstOrDefault()); } if (BPSUtilitiesV1.NZ(write_list_vp, "").ToString() != "") { foreach (tbl_000_H_VP v in write_list_vp) { if (v != null) { vpbal.Delete(v); } } } Save_vp(); break; case MaintainanceTableSub.Assembly: write_list_assy = new List <tbl_000_H_ASSY>(); foreach (tbl_000_H_ASSY a in assylist) { write_list_assy.Add(assybal.GetAll().Where(w => w.YEARUSED == UserSettings.LogInYear && (w.PartNo == a.PartNo || w.PartName == a.PartName)).FirstOrDefault()); } if (BPSUtilitiesV1.NZ(write_list_assy, "").ToString() != "") { foreach (tbl_000_H_ASSY a in write_list_assy) { if (a != null) { assybal.Delete(a); } } } Save_assy(); break; } break; #endregion #region Process to Import with Overwrite case YearsOf.ProcessSetup: write_list_proc = new List <tbl_000_PROCESS>(); List <tbl_000_PROCESS> todelete_proc = new List <tbl_000_PROCESS>(); foreach (tbl_000_PROCESS p in proclist) { write_list_proc.Add(procbal.GetAll().Where(w => w.YEARUSED == UserSettings.LogInYear && (w.SubProcessCode == p.SubProcessCode || w.ItemDescription == p.ItemDescription)).FirstOrDefault()); } if (BPSUtilitiesV1.NZ(write_list_proc, "").ToString() != "") { foreach (tbl_000_PROCESS p in write_list_proc) { if (p != null) { todelete_proc.Add(p); } } procbal.Delete(todelete_proc); } Save_proc(); break; #endregion } } } this.Close(); } catch (Exception ex) { throw ex; } }