protected void btnCancelImport_Click(object sender, EventArgs e) { List <string> import_successList = new List <string>(); if (ddlJobName.SelectedIndex != 0) { if (FileUpload1.HasFile) { if (Path.GetExtension(FileUpload1.FileName) == ".xlsx") { #region "Multi Sheet or Sheet by Sheet Import" (third thinking => ) using (ExcelPackage ex_package = new ExcelPackage(FileUpload1.FileContent)) { int ws_count = ex_package.Workbook.Worksheets.Count(); if (ws_count == 1) { var jobName = ddlJobName.SelectedValue.ToString(); var center = ddlCenterName.SelectedValue.ToString(); #region "For Probes" if (jobName.ToString().Trim() == "Probes") //job_name == "Probes" { var cancel = new Cancel().FindByCancelMonthAndJob(GeneralUtility.ConvertMonthYearStringFormat(txtImportDate.Text.Trim()), jobName, center); if (cancel.Count() == 0) { var cancel_list = new List <CancelEntity>(); ExcelWorksheet cancel_workSheet = ex_package.Workbook.Worksheets[1]; // probes_workSheet.DeleteRow(1); if (cancel_workSheet.Dimension != null) { Cancel_Probes_BindBusiness(cancel_list, cancel_workSheet); #region Save Cancel Probes Cancel itemBusiness = new Cancel(); int i = BulkInsertIntoCancel(cancel_list); MessageBox.MessageShow(this.GetType(), "Cancel Probes Import Successfully!.", ClientScript); //using (TransactionScope Scope = new TransactionScope()) //{ // try // { // //probes_list.RemoveAt(0); // foreach (var v in cancel_list) // { // itemBusiness.Entity = v; // itemBusiness.Save(); // } // Scope.Complete(); // import_successList.Add("Cancel Probes Import Successfully!\n"); // MessageBox.MessageShow(this.GetType(), "Cancel Probes Import Successfully!.", ClientScript); // } // catch (Exception ex) // { // Response.Redirect("error.aspx"); // throw ex; // } //} #endregion } } else { MessageBox.MessageShow(this.GetType(), "This Excel File has already been Imported!", ClientScript); } } #endregion #region "For Scenes" if (jobName.ToString().Trim() == "Scenes") //job_name == "Probes" { var cancel = new Cancel().FindByCancelMonthAndJob(GeneralUtility.ConvertMonthYearStringFormat(txtImportDate.Text.Trim()), jobName, center); if (cancel.Count() == 0) { var cancel_list = new List <CancelEntity>(); ExcelWorksheet cancel_workSheet = ex_package.Workbook.Worksheets[1]; // probes_workSheet.DeleteRow(1); if (cancel_workSheet.Dimension != null) { Cancel_Scenes_BindBusiness(cancel_list, cancel_workSheet); #region Save Cancel Probes Cancel itemBusiness = new Cancel(); int i = BulkInsertIntoCancel(cancel_list); MessageBox.MessageShow(this.GetType(), "Cancel Scenes Import Successfully!.", ClientScript); //using (TransactionScope Scope = new TransactionScope()) //{ // try // { // //probes_list.RemoveAt(0); // foreach (var v in cancel_list) // { // itemBusiness.Entity = v; // itemBusiness.Save(); // } // Scope.Complete(); // import_successList.Add("Cancel Scenes Import Successfully!\n"); // MessageBox.MessageShow(this.GetType(), "Cancel Scenes Import Successfully!.", ClientScript); // } // catch (Exception ex) // { // Response.Redirect("error.aspx"); // throw ex; // } //} #endregion } } else { MessageBox.MessageShow(this.GetType(), "This Excel File has already been Imported!", ClientScript); } } #endregion #region "For Stitching" if (jobName.ToString().Trim() == "Stitching") //job_name == "Stitching" { var cancel = new Cancel().FindByCancelMonthAndJob(GeneralUtility.ConvertMonthYearStringFormat(txtImportDate.Text.Trim()), jobName, center); if (cancel.Count() == 0) { var cancel_list = new List <CancelEntity>(); ExcelWorksheet cancel_workSheet = ex_package.Workbook.Worksheets[1]; // probes_workSheet.DeleteRow(1); if (cancel_workSheet.Dimension != null) { Cancel_Stitching_BindBusiness(cancel_list, cancel_workSheet); #region Save Cancel Probes Cancel itemBusiness = new Cancel(); int i = BulkInsertIntoCancel(cancel_list); MessageBox.MessageShow(this.GetType(), "Cancel Probes Import Successfully!.", ClientScript); //using (TransactionScope Scope = new TransactionScope()) //{ // try // { // //probes_list.RemoveAt(0); // foreach (var v in cancel_list) // { // itemBusiness.Entity = v; // itemBusiness.Save(); // } // Scope.Complete(); // import_successList.Add("Cancel Probes Import Successfully!\n"); // MessageBox.MessageShow(this.GetType(), "Cancel Probes Import Successfully!.", ClientScript); // } // catch (Exception ex) // { // Response.Redirect("error.aspx"); // throw ex; // } //} #endregion } } else { MessageBox.MessageShow(this.GetType(), "This Excel File has already been Imported!", ClientScript); } } #endregion } else { MessageBox.MessageShow(this.GetType(), "Not Provided Multiple Sheet Import!", ClientScript); } } #endregion } } } else { MessageBox.MessageShow(this.GetType(), "Please Choose Job Name!.", ClientScript); } }