public HttpResponseBase GetVoteArticleList() { List<VoteArticleQuery> store = new List<VoteArticleQuery>(); string json = string.Empty; int totalCount = 0; try { _muMgr = new ManageUserMgr(mySqlConnectionString); ManageUserQuery muq = new ManageUserQuery(); muq.IsPage = false; List<ManageUserQuery> mustore = _muMgr.GetNameMail(muq, out totalCount); VoteArticleQuery query = new VoteArticleQuery(); query.Start = Convert.ToInt32(Request.Params["start"] ?? "0"); if (!string.IsNullOrEmpty(Request.Params["limit"])) { query.Limit = Convert.ToInt32(Request.Params["limit"]); } if (!string.IsNullOrEmpty(Request.Params["ddlSel"])) { query.event_id = Convert.ToInt32(Request.Params["ddlSel"]); } if (!string.IsNullOrEmpty(Request.Params["selcontent"])) { query.article_title = Request.Params["selcontent"]; } if (!string.IsNullOrEmpty(Request.Params["date"])) { query.date = Convert.ToInt32(Request.Params["date"]); } if (!string.IsNullOrEmpty(Request.Params["time_start"])) { query.time_start = Convert.ToDateTime(Request.Params["time_start"]).ToString("yyyy-MM-dd HH:mm:ss"); } if (!string.IsNullOrEmpty(Request.Params["time_end"])) { query.time_end = Convert.ToDateTime(Request.Params["time_end"]).ToString("yyyy-MM-dd HH:mm:ss"); } _votearticle = new VoteArticleMgr(mySqlConnectionString); store = _votearticle.GetAll(query, out totalCount); IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; foreach (var item in store) { item.kendo_editor = Server.HtmlDecode(Server.HtmlDecode(item.article_content)); if (item.article_banner != "") { item.article_banner = imgServerPath + PaperPath + item.article_banner; } int indexc = mustore.FindIndex((ManageUserQuery e) => e.user_id == uint.Parse(item.create_user.ToString())); if (indexc != -1) { item.creat_name = mustore[indexc].user_name; } else { item.creat_name = string.Empty; } int indexu = mustore.FindIndex((ManageUserQuery e) => e.user_id == uint.Parse(item.update_user.ToString())); if (indexu != -1) { item.upd_name = mustore[indexu].user_name; } else { item.upd_name = string.Empty; } } //listUser是准备转换的对象 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,totalCount:0,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase SaveVoteArticle() { string json = string.Empty; #region 圖片用 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(); #endregion try { _votearticle = new VoteArticleMgr(mySqlConnectionString); List<VoteArticleQuery> store = new List<VoteArticleQuery>(); VoteArticleQuery query = new VoteArticleQuery(); if (!string.IsNullOrEmpty(Request.Params["id"])) {//如果是編輯獲取該id數據 int totalCount = 0; query.IsPage = false; query.article_id = int.Parse(Request.Params["id"]); store = _votearticle.GetAll(query, out totalCount); } //product_id if (!string.IsNullOrEmpty(Request.Params["product_id"])) { query.product_id = Convert.ToUInt32(Request.Params["product_id"]); } if (!string.IsNullOrEmpty(Request.Params["event_id"])) { query.event_id = Convert.ToInt32(Request.Params["event_id"]); } if (!string.IsNullOrEmpty(Request.Params["article_title"])) { query.article_title = Request.Params["article_title"]; } if (!string.IsNullOrEmpty(Request.Params["user_id"])) { query.user_id = int.Parse(Request.Params["user_id"]); } if (!string.IsNullOrEmpty(Request.Params["article_content"])) { query.article_content = Request.Params["article_content"]; } if (!string.IsNullOrEmpty(Request.Params["article_sort"])) { query.article_sort =Convert.ToInt32(Request.Params["article_sort"]); } if (!string.IsNullOrEmpty(Request.Params["prod_link"])) { query.prod_link = Request.Params["prod_link"]; } if (!string.IsNullOrEmpty(Request.Params["vote_count"])) { query.vote_count = int.Parse(Request.Params["vote_count"]); } if (!string.IsNullOrEmpty(Request.Params["article_start_time"])) { query.article_start_time =Convert.ToDateTime(Request.Params["article_start_time"]); } if (!string.IsNullOrEmpty(Request.Params["article_end_time"])) { query.article_end_time = Convert.ToDateTime(Request.Params["article_end_time"]); } if (!string.IsNullOrEmpty(Request.Params["article_show_start_time"])) { query.article_show_start_time = Convert.ToDateTime(Request.Params["article_show_start_time"]); } if (!string.IsNullOrEmpty(Request.Params["article_show_end_time"])) { query.article_show_end_time = Convert.ToDateTime(Request.Params["article_show_end_time"]); } #region 上傳圖片 string oldImg = string.Empty; foreach (var item in store) { oldImg = item.article_banner; } if (!string.IsNullOrEmpty(Request.Params["id"]) && Request.Params["article_banner"] == oldImg) { query.article_banner = oldImg; } else { string ServerPath = string.Empty; try { ServerPath = Server.MapPath(imgLocalServerPath + PaperPath); if (Request.Files["article_banner"] != null && Request.Files["article_banner"].ContentLength > 0) { HttpPostedFileBase file = Request.Files["article_banner"]; string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 //獲取圖片名稱 fileName = Path.GetFileName(file.FileName); //獲得後綴名 fileExtention = Path.GetExtension(file.FileName); //獲得不帶後綴名的文件名 fileName = Path.GetFileNameWithoutExtension(file.FileName); 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)//上傳成功 { query.article_banner = 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 { //上傳之前刪除已有的圖片 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上的舊圖片 } query.article_banner = ""; } } 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,msg:'圖片上傳失敗!'}"; } } #endregion query.article_status = 0;//默認啟用 query.create_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id; query.update_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id; query.create_time = DateTime.Now; query.update_time = DateTime.Now; if (query.article_id > 0) {//編輯 if (_votearticle.Update(query) > 0) { json = "{success:true}"; } else { json = "{success:false,msg:'修改失敗!'}"; } } else {//新增 if (_votearticle.Save(query) > 0) { json = "{success:true}"; } else { json = "{success:false,msg:'新增失敗!'}"; } } } 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; }