public HttpResponseBase GetPaperList() { string json = string.Empty; List<Paper> store = new List<Paper>(); Paper p = new Paper(); try { p.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量 p.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");//用於分頁的變量 _paperMgr = new PaperMgr(mySqlConnectionString); int totalCount = 0; if (!string.IsNullOrEmpty(Request.Params["paper_id"])) { p.paperID = int.Parse(Request.Params["paper_id"]); } if (!string.IsNullOrEmpty(Request.Params["status"])) { p.status = 1; } p.paperName = Request.Params["paper_name"]; if (!string.IsNullOrEmpty(Request.Params["isPage"])) { p.IsPage = false; } store = _paperMgr.GetPaperList(p, out totalCount); foreach (var item in store) { if (!string.IsNullOrEmpty(item.paperBanner)) { item.paperBanner = imgServerPath + PaperPath + item.paperBanner; } } IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, 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}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase PaperEdit() { string json = string.Empty; Paper p = new Paper(); _paperMgr = new PaperMgr(mySqlConnectionString); string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_Min_Element"); SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); //擴展名、最小值、最大值 string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string localBannerPath = imgLocalPath + PaperPath;//圖片存儲地址 FileManagement fileLoad = new FileManagement(); try { List<Paper> store = new List<Paper>(); if (!string.IsNullOrEmpty(Request.Params["paper_id"])) { int totalCount = 0; p.IsPage = false; p.paperID = int.Parse(Request.Params["paper_id"]); store = _paperMgr.GetPaperList(p, out totalCount); } string oldImg = string.Empty; foreach (var item in store) { oldImg = item.paperBanner; } p = new Paper(); p.paperName = Request.Params["paper_name"]; p.paperMemo = Request.Params["paper_memo"]; p.bannerUrl = Request.Params["banner_url"]; if (!string.IsNullOrEmpty(Request.Params["paper_start"])) { p.paperStart = DateTime.Parse(DateTime.Parse(Request.Params["paper_start"]).ToString("yyyy-MM-dd HH:mm:ss")); } if (!string.IsNullOrEmpty(Request.Params["paper_end"])) { p.paperEnd = DateTime.Parse(DateTime.Parse(Request.Params["paper_end"]).ToString("yyyy-MM-dd HH:mm:ss")); } p.event_ID = Request.Params["eventid"]; if (!string.IsNullOrEmpty(Request.Params["isRepeatGift"])) { p.isRepeatGift = int.Parse(Request.Params["isRepeatGift"]); } //if (!string.IsNullOrEmpty(Request.Params["isPromotion"])) //{ // p.isPromotion = int.Parse(Request.Params["isPromotion"]); // if (p.isPromotion == 1) // { // p.promotionUrl = Request.Params["promotion_url"]; // } //} //if (!string.IsNullOrEmpty(Request.Params["isPromotion"])) //{ // p.isPromotion = int.Parse(Request.Params["isPromotion"]); // if (p.isPromotion == 1) // { // p.promotionUrl = Request.Params["promotion_url"]; // } //} //if (!string.IsNullOrEmpty(Request.Params["isGiveBonus"])) //{ // p.isGiveBonus = int.Parse(Request.Params["isGiveBonus"]); // if (p.isGiveBonus == 1) // { // if (!string.IsNullOrEmpty(Request.Params["bonus_num"])) // { // p.bonusNum = int.Parse(Request.Params["bonus_num"]); // } // } //} //if (!string.IsNullOrEmpty(Request.Params["isGiveProduct"])) //{ // p.isGiveProduct = int.Parse(Request.Params["isGiveProduct"]); // if (p.isGiveProduct == 1) // { // if (!string.IsNullOrEmpty(Request.Params["product_id"])) // { // p.productID = int.Parse(Request.Params["product_id"]); // } // } //} if (!string.IsNullOrEmpty(Request.Params["isRepeatWrite"])) { p.isRepeatWrite = int.Parse(Request.Params["isRepeatWrite"]); } if (!string.IsNullOrEmpty(Request.Params["isNewMember"])) { p.isNewMember = int.Parse(Request.Params["isNewMember"]); } p.creator = int.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString()); System.Net.IPAddress[] addlist = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList; if (addlist.Length > 0) { p.ipfrom = addlist[0].ToString(); } if (!string.IsNullOrEmpty(Request.Params["paper_id"]) && Request.Params["paper_banner"] == oldImg) { p.paperBanner = oldImg; } else { string ServerPath = string.Empty; ServerPath = Server.MapPath(imgLocalServerPath + PaperPath); if (Request.Files.Count > 0)//單個圖片上傳 { HttpPostedFileBase file = Request.Files[0]; string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 //獲取圖片名稱 fileName = fileLoad.NewFileName(file.FileName); if (fileName != "") { fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString(); string NewFileName = string.Empty; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); //判斷目錄是否存在,不存在則創建 FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localBannerPath.Substring(0, localBannerPath.Length - PaperPath.Length + 1), PaperPath.Substring(1, PaperPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localBannerPath + NewFileName + fileExtention;//絕對路徑 string ErrorMsg = string.Empty; bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { p.paperBanner = fileName; //上傳新圖片成功后,再刪除舊的圖片 CommonFunction.DeletePicFile(ServerPath + oldImg);//刪除本地圖片 FTP ftp = new FTP(localBannerPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldImg)) { FTP ftps = new FTP(localBannerPath + oldImg, ftpuser, ftppwd); ftps.DeleteFile(localBannerPath + oldImg);//刪除ftp:71.159上的舊圖片 } } else { p.paperBanner = oldImg; } } else { //上傳之前刪除已有的圖片 CommonFunction.DeletePicFile(ServerPath + oldImg);//刪除本地圖片 FTP ftp = new FTP(localBannerPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldImg)) { FTP ftps = new FTP(localBannerPath + oldImg, ftpuser, ftppwd); ftps.DeleteFile(localBannerPath + oldImg);//刪除ftp:71.159上的舊圖片 } p.paperBanner = ""; } } } #region 新增 if (String.IsNullOrEmpty(Request.Params["paper_id"])) { if (_paperMgr.Add(p) > 0) { json = "{success:true,msg:\"" + "新增成功!" + "\"}"; } } #endregion #region 編輯 else { p.paperID = int.Parse(Request.Params["paper_id"]); p.modifier = int.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString()); if (_paperMgr.Update(p) > 0) { json = "{success:true,msg:\"" + "修改成功!" + "\"}"; } } #endregion } catch (Exception ex) { json = "{success:false,msg:\"" + "異常" + "\"}"; 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); } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }