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 List<Paper> GetPaperList(Paper p, out int totalCount) { StringBuilder sqlfield = new StringBuilder(); StringBuilder sqlfrom = new StringBuilder(); StringBuilder sqlwhere = new StringBuilder(); StringBuilder sql = new StringBuilder(); StringBuilder sqlcount = new StringBuilder(); sqlfield.AppendLine(@"SELECT paperID,paperName,paperMemo,paperBanner,bannerUrl,"); sqlfield.AppendFormat(@" isRepeatGift,event_ID,isNewMember,"); //sqlfield.AppendLine(@"isPromotion,promotionUrl,isGiveBonus,bonusNum,isGiveProduct,productID,"); sqlfield.AppendLine(@"isRepeatWrite,paperStart,paperEnd,status,creator,created,modifier,modified,ipfrom "); sqlcount.Append(" select count(paperID) as totalCount "); sql.Append(sqlfield); sqlfrom.AppendFormat(" FROM paper WHERE 1=1 "); sql.Append(sqlfrom); if (p.paperID != 0) { sqlwhere.AppendFormat(@" AND paperID='{0}' ", p.paperID); } if (!string.IsNullOrEmpty(p.paperName)) { sqlwhere.AppendFormat(@" AND paperName like N'%{0}%' ", p.paperName); } if (p.status != 0) { sqlwhere.AppendFormat(@" AND status='{0}' ", p.status); } sql.Append(sqlwhere); sql.AppendFormat(" order by paperID DESC "); totalCount = 0; if (p.IsPage) { sqlcount.Append(sqlfrom.ToString() + sqlwhere.ToString()); DataTable dt = _access.getDataTable(sqlcount.ToString()); if (dt != null && dt.Rows.Count > 0) { totalCount =Convert.ToInt32(dt.Rows[0]["totalCount"]); } sql.AppendFormat(@"limit {0},{1};", p.Start, p.Limit); } try { return _access.getDataTableForObj<Paper>(sql.ToString()); } catch (Exception ex) { throw new Exception("PaperDao-->GetPaperList" + ex.Message + sql.ToString() + sqlcount.ToString(), ex); } }
public int Add(Paper p) { StringBuilder sql = new StringBuilder(); sql.AppendLine(@"INSERT INTO paper (paperName,paperMemo,paperBanner,bannerUrl,"); //sql.AppendLine(@"isPromotion,promotionUrl,isGiveBonus,bonusNum,isGiveProduct,productID,"); sql.AppendLine(@" event_id,isRepeatGift,isNewMember,"); sql.AppendLine(@" isRepeatWrite,paperStart,paperEnd,"); sql.AppendLine(@"status,creator,created,ipfrom ) VALUES ("); sql.AppendFormat(@"'{0}','{1}','{2}','{3}',", p.paperName, p.paperMemo, p.paperBanner, p.bannerUrl); //sql.AppendFormat(@"'{0}','{1}','{2}','{3}','{4}','{5}',", p.promotionUrl, p.isGiveBonus, p.bonusNum, p.isGiveBonus, p.productID, p.isRepeatWrite); sql.AppendFormat(@"'{0}','{1}','{2}',", p.event_ID, p.isRepeatGift, p.isNewMember); sql.AppendFormat(@" '{0}','{1}','{2}',", p.isRepeatWrite, p.paperStart.ToString("yyyy-MM-dd HH:mm:ss"), p.paperEnd.ToString("yyyy-MM-dd HH:mm:ss")); sql.AppendFormat(@"'{0}','{1}','{2}','{3}')", p.status, p.creator, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), p.ipfrom); try { return _access.execCommand(sql.ToString()); } catch (Exception ex) { throw new Exception("PaperDao-->Add" + ex.Message + sql.ToString(), ex); } }
public int Update(Paper p) { StringBuilder sql = new StringBuilder(); sql.AppendFormat(@"UPDATE paper SET paperName='{0}',paperMemo='{1}',paperBanner='{2}',", p.paperName, p.paperMemo, p.paperBanner); sql.AppendFormat(@"bannerUrl='{0}',event_ID='{1}',isRepeatGift='{2}',isNewMember='{3}',", p.bannerUrl, p.event_ID, p.isRepeatGift, p.isNewMember); //sql.AppendFormat(@"bannerUrl='{0}',isPromotion='{1}',promotionUrl='{2}',isGiveBonus='{3}',", p.bannerUrl, p.isPromotion, p.promotionUrl, p.isGiveBonus); //sql.AppendFormat(@"bonusNum='{0}',isGiveProduct='{1}',productID='{2}',", p.bonusNum, p.isGiveProduct, p.productID, p.isRepeatWrite); sql.AppendFormat(@" isRepeatWrite='{0}',paperStart='{1}',paperEnd='{2}',", p.isRepeatWrite, p.paperStart.ToString("yyyy-MM-dd HH:mm:ss"), p.paperEnd.ToString("yyyy-MM-dd HH:mm:ss")); sql.AppendFormat(@"modifier='{0}',modified='{1}',ipfrom='{2}' ", p.modifier, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), p.ipfrom); sql.AppendFormat(@" where paperID='{0}';", p.paperID); try { return _access.execCommand(sql.ToString()); } catch (Exception ex) { throw new Exception("PaperDao-->Update" + ex.Message + sql.ToString(), ex); } }
public int UpdateState(Paper p) { StringBuilder sql = new StringBuilder(); sql.AppendFormat(@"UPDATE paper SET `status`='{0}',modifier='{1}',", p.status, p.modifier); sql.AppendFormat(@"modified='{0}',ipfrom='{1}' ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), p.ipfrom); sql.AppendFormat(@" where paperID='{0}';", p.paperID); try { return _access.execCommand(sql.ToString()); } catch (Exception ex) { throw new Exception("PaperDao-->UpdateState" + ex.Message + sql.ToString(), ex); } }
public JsonResult UpdateState() { int id = Convert.ToInt32(Request.Params["id"]); int activeValue = Convert.ToInt32(Request.Params["active"]); _paperMgr = new PaperMgr(mySqlConnectionString); Paper p = new Paper(); p.paperID = id; p.status = activeValue; p.modifier = 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 (_paperMgr.UpdateState(p) > 0) { return Json(new { success = "true", msg = "" }); } else { return Json(new { success = "false", msg = "" }); } }
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; }