protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { ScreenPrivilegeData priData = RoleBiz.GetScreenPrivilege(HttpContext.Current.User.Identity.Name, "SLM_SCR_034"); if (priData == null || priData.IsView != 1) { AppUtil.ClientAlertAndRedirect(Page, "คุณไม่มีสิทธิ์เข้าใช้หน้าจอนี้", "SLM_SCR_003.aspx"); return; } ((Label)Page.Master.FindControl("lblTopic")).Text = "นำเข้างานติดปัญหา"; Page.Form.Attributes.Add("enctype", "multipart/form-data"); Page.Form.DefaultButton = btnSearch.UniqueID; cmbInsComImport.DataSource = SlmScr034Biz.GetImportInsComListData(); cmbInsComImport.DataBind(); cmbInsComSearch.DataSource = SlmScr034Biz.GetSearchInsComListData(); cmbInsComSearch.DataBind(); cmbFileNameSearch.DataSource = SlmScr034Biz.GetSearchFileNameListData(); cmbFileNameSearch.DataBind(); } } catch (Exception ex) { string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; _log.Error(message); AppUtil.ClientAlert(Page, message); } }
protected void btnConfirmImport_Click(object sender, EventArgs e) { try { DataTable dt = null; decimal insComId = -1; string fileName = ""; if (Session["ImportTable"] != null) { dt = Session["ImportTable"] as DataTable; } if (Session["insComId"] != null) { decimal.TryParse(Session["insComId"].ToString(), out insComId); } if (Session["fileName"] != null) { fileName = Session["fileName"].ToString(); } if (fileName != "" && insComId > 0) { SlmScr034Biz.DeleteImportedProblem(insComId, fileName, DateTime.Today); if (DoImport(dt, insComId, fileName)) { // AppUtil.ClientAlert(Page, "นำเข้าข้อมูลงานติดปัญหาเรียบร้อย"); btnSearch_Click(null, null); cmbFileNameSearch.DataSource = SlmScr034Biz.GetSearchFileNameListData(); cmbFileNameSearch.DataBind(); AppUtil.ClientAlert(this, "นำเข้าข้อมูลเรียบร้อย"); } else { AppUtil.ClientAlert(this, "ข้อมูลไม่ถูกนำเข้า กรุณาตรวจสอบข้อผิดพลาด"); } } mpePopupConfirm.Hide(); upnPopupImport.Update(); mpePopupImport.Show(); //clearSession(); } catch (Exception ex) { string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; _log.Error(message); AppUtil.ClientAlert(Page, message); } finally { fuData.ClearAllFilesFromPersistedStore(); } }
protected void btnUpload_Click(object sender, EventArgs e) { tableUploadResult.Visible = false; gvUploadError.Visible = false; gvUploadErrorHeader.Visible = false; if (cmbInsComImport.SelectedIndex == 0) { lblCompError.Text = "กรุณาเลือกบริษัท"; fuData.ClearAllFilesFromPersistedStore(); mpePopupImport.Show(); return; } if (fuData.HasFile) { var ext = Path.GetExtension(fuData.FileName).ToLower(); if (ext != ".xls") { lblUploadError.Text = "กรุณาระบุไฟล์ให้ถูก format (xls)"; fuData.ClearAllFilesFromPersistedStore(); mpePopupImport.Show(); return; } try { using (OleDbConnection conn = new OleDbConnection()) { DataTable dt = new DataTable(); string filename = Path.GetTempFileName(); lblFilename.Text = fuData.FileName; fuData.SaveAs(filename); //fuData.ClearAllFilesFromPersistedStore(); conn.ConnectionString = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES;IMEX=0;'", filename); conn.Open(); DataTable dbSchema = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string firstSheetName = dbSchema.Rows[0]["TABLE_NAME"].ToString(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.Text; //cmd.CommandText = "SELECT * FROM [Sheet1$]"; cmd.CommandText = "SELECT * FROM [" + firstSheetName + "]"; OleDbDataAdapter adp = new OleDbDataAdapter(cmd); adp.Fill(dt); adp.Dispose(); cmd.Dispose(); decimal insComId = cmbInsComImport.SelectedValue == "" ? -1 : decimal.Parse(cmbInsComImport.SelectedValue); // check duplicate bool hasDup = SlmScr034Biz.HasDuplicate(insComId, fuData.FileName, DateTime.Today); if (hasDup) { Session["ImportTable"] = dt; Session["insComId"] = insComId; Session["fileName"] = fuData.FileName; mpePopupImport.Show(); mpePopupConfirm.Show(); } else { if (DoImport(dt, insComId, fuData.FileName)) { // AppUtil.ClientAlert(Page, "นำเข้าข้อมูลงานติดปัญหาเรียบร้อย"); -- change to display result on popup instead btnSearch_Click(null, null); cmbFileNameSearch.DataSource = SlmScr034Biz.GetSearchFileNameListData(); cmbFileNameSearch.DataBind(); AppUtil.ClientAlert(this, "นำเข้าข้อมูลเรียบร้อย"); } else { AppUtil.ClientAlert(this, "ข้อมูลไม่ถูกนำเข้า กรุณาตรวจสอบข้อผิดพลาด"); } } } } catch (Exception ex) { // if (ex.Message.Contains("Ticket Id มากกว่า 1 รายการ ")) string message = ex.InnerException == null ? ex.Message : ex.InnerException.Message; _log.Error(message); AppUtil.ClientAlert(Page, message); } finally { fuData.ClearAllFilesFromPersistedStore(); } } else { lblUploadError.Text = "กรุณาระบุไฟล์ที่ต้องการนำเข้า"; } // lblUploadError.Text = "after upload"; mpePopupImport.Show(); }