public HttpResponseBase ImportExcel() { string json = string.Empty; try { BLL.gigade.Model.SiteAnalytics query = new BLL.gigade.Model.SiteAnalytics(); if (Request.Files.Count > 0) { string path = Request.Params["ImportExcel"]; HttpPostedFileBase excelFile = Request.Files["ImportExcel"]; FileManagement fileManagement = new FileManagement(); string newExcelName = Server.MapPath(excelPath) + "analytics" + fileManagement.NewFileName(excelFile.FileName); excelFile.SaveAs(newExcelName); NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newExcelName); DataTable _dt = helper.ExcelToTableForXLSX(); _siteAnalytics = new SiteAnalyticsMgr(mySqlConnectionString); if (!string.IsNullOrEmpty(Request.Params["search_con"])) { query.search_con = Convert.ToInt32(Request.Params["search_con"]); } if (!string.IsNullOrEmpty(Request.Params["serch_sa_date"])) { query.s_sa_date = (Convert.ToDateTime(Request.Params["serch_sa_date"]).ToString("yyyy-MM-dd")); } json = _siteAnalytics.ImportExcelToDt(_dt);//匯入成功 } } 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; }
public HttpResponseBase GetSiteStatisticsList() { string json = string.Empty; try { if (Request.Files.Count > 0) { string path = Request.Params["ImportExcel"]; HttpPostedFileBase excelFile = Request.Files["ImportExcel"]; FileManagement fileManagement = new FileManagement(); string savePath=Server.MapPath(excelPath) + "statistics"; string newExcelName = savePath+ fileManagement.NewFileName(excelFile.FileName); excelFile.SaveAs(newExcelName); NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newExcelName); DataTable _dt = helper.ExcelToTableForXLSX(); ssMgr = new SiteStatisticsMgr(mySqlConnectionString); json = ssMgr.ImportExcelToDt(_dt);//匯入成功 } else { SiteStatistics query = new SiteStatistics(); ssMgr = new SiteStatisticsMgr(mySqlConnectionString); query.Start = Convert.ToInt32(Request.Params["start"] ?? "0"); query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25"); query.ss_code = Request.Params["ss_code"]; if (!string.IsNullOrEmpty(Request.Params["startdate"])) { query.sss_date = Convert.ToDateTime(DateTime.Parse(Request.Params["startdate"]).ToString("yyyy-MM-dd 00:00:00")); } if (!string.IsNullOrEmpty(Request.Params["enddate"])) { query.ess_date = Convert.ToDateTime(DateTime.Parse(Request.Params["enddate"]).ToString("yyyy-MM-dd 23:59:59")); } #region 用來判斷相同的廠家代碼和時間是否已經存在 if (!string.IsNullOrEmpty(Request.Params["ss_id"])) { query.ss_id = int.Parse(Request.Params["ss_id"]); } if (!string.IsNullOrEmpty(Request.Params["ss_date"])) { query.ss_date = DateTime.Parse(Request.Params["ss_date"]); } if (!string.IsNullOrEmpty(Request.Params["ispage"])) { query.IsPage = bool.Parse(Request.Params["ispage"]); } #endregion int totalCount = 0; DataTable dt = ssMgr.GetSiteStatisticsList(query, out totalCount); IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; //listUser是准备转换的对象 json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(dt, Formatting.Indented, timeConverter) + "}";//返回json數據 } } 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,totalCount:0,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }