Esempio n. 1
0
 public HttpResponseBase ImportExcel()
 {
     string json = string.Empty;
     string excelPath = "../ImportUserIOExcel/";
     try
     {
         if (Request.Files.Count > 0)
         {
             int group_id = Convert.ToInt32(Request.Params["group_id"]);
             HttpPostedFileBase excelFile = Request.Files["ImportExcel"];
             FileManagement fileManagement = new FileManagement();
             string newExcelName = Server.MapPath(excelPath) + "email_group" + fileManagement.NewFileName(excelFile.FileName);
             excelFile.SaveAs(newExcelName);
             NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newExcelName);
             DataTable _dt = helper.SheetData();
             _emailGroupMgr = new EmailGroupMgr(mySqlConnectionString);
             _newDt.Clear();
             int totalCount = 0;
             _newDt = _emailGroupMgr.ImportEmailList(_dt, group_id, out totalCount);//匯入失敗的數據
             if (_newDt.Rows.Count > 0 && _newDt != null)
             {
                 int totalCountData = totalCount;
                 int wrongCount = _newDt.Rows.Count;
                 json = "{success:true,totalCount:'" + totalCountData + "',wrongCount:'" + wrongCount + "'}";
             }
             else
             {
                 json = "{success:true,wrongCount:'" + 0 + "'}";
             }
           
         }
     }
     catch (Exception ex)
     {
         Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
         logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
         logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
         log.Error(logMessage);
         json = "{success:false}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }