public HttpResponseBase SaveChinaTrustBagMap() { string json = string.Empty; bool pic = true; DataTable dt = new DataTable(); try { _ChinatrustBMMgr = new EventChinaTrustBagMapMgr(mySqlConnectionString); EventChinaTrustBagMapQuery store = new EventChinaTrustBagMapQuery(); EventChinaTrustBagMapQuery query = new EventChinaTrustBagMapQuery(); if (!string.IsNullOrEmpty(Request.Params["id"])) {//如果是編輯獲取該id數據 int totalCount = 0; query.IsPage = false; query.map_id = int.Parse(Request.Params["id"]); store = _ChinatrustBMMgr.GetChinaTrustBagMapList(query, out totalCount).FirstOrDefault(); query = store; } //product_id if (!string.IsNullOrEmpty(Request.Params["product_id"])) { query.product_id = Convert.ToUInt32(Request.Params["product_id"]); } else { query.product_id = 0; } if (!string.IsNullOrEmpty(Request.Params["bag_id"])) { query.bag_id = Convert.ToInt32(Request.Params["bag_id"]); } if (!string.IsNullOrEmpty(Request.Params["linkurl"])) { query.linkurl = Request.Params["linkurl"]; } if (!string.IsNullOrEmpty(Request.Params["product_forbid_banner"])) { query.product_forbid_banner = Request.Params["product_forbid_banner"]; } if (!string.IsNullOrEmpty(Request.Params["product_active_banner"])) { query.product_active_banner = Request.Params["product_active_banner"]; } if (!string.IsNullOrEmpty(Request.Params["ad_product_id"])) { string p_id = Request.Params["ad_product_id"]; RegexOptions options = RegexOptions.None; Regex regex = new Regex(@"[ ]{2,}", options); p_id = regex.Replace(p_id, @" "); p_id = p_id.Replace(" ", ","); for (int i = p_id.Length - 1; i > 0; i--) { if (p_id.Substring(p_id.Length - 1, 1) == ",") { p_id = p_id.Substring(0, p_id.Length - 1); } } string[] pr_id = p_id.Split(',').Distinct().ToArray(); ; string pro_id = ""; for (int i = 0; i < pr_id.Length; i++) { if (_ChinatrustBMMgr.IsProductId(pr_id[i].ToString())) { pro_id += pr_id[i].ToString() + ","; } } if (pro_id.Length > 0) { query.ad_product_id = pro_id.Substring(0, pro_id.Length - 1); } else { query.ad_product_id = null; } } else { query.ad_product_id = null; } if (!string.IsNullOrEmpty(Request.Params["product_desc"])) { query.product_desc = Request.Params["product_desc"]; } else { query.product_desc = null; } #region 上傳圖片 try { 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_MinValue"); 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 localPromoPath = imgLocalPath + PaperPath;//圖片存儲地址 Random rand = new Random(); FileManagement fileLoad = new FileManagement(); for (int iFile = 0; iFile < Request.Files.Count; iFile++) { //int newRand = rand.Next(1000, 9999); HttpPostedFileBase file = Request.Files[iFile]; string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 bool result = false; string NewFileName = string.Empty; string ServerPath = string.Empty; fileName = Path.GetFileName(file.FileName); string newRand = hash.Md5Encrypt(fileLoad.NewFileName(fileName), "32"); string ErrorMsg = string.Empty; if (iFile == 0) { if (string.IsNullOrEmpty(file.FileName)) { query.product_forbid_banner = store.product_forbid_banner; } else { fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); NewFileName = newRand + fileExtention; //判斷目錄是否存在,不存在則創建 string[] mapPath = new string[1]; mapPath[0] = PaperPath.Substring(1, PaperPath.Length - 1); string s = localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1); CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1), mapPath); // returnName += PaperPath + NewFileName; fileName = NewFileName; NewFileName = localPromoPath + NewFileName;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + PaperPath); string oldFileName = ""; oldFileName = store.product_forbid_banner; if (!string.IsNullOrEmpty(oldFileName)) { DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 } try { //上傳 result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { query.product_forbid_banner = fileName; } else { pic = false; } } catch (Exception) { query.product_forbid_banner = store.product_forbid_banner; query.product_active_banner = store.product_active_banner; } } } if (iFile == 1) { if (string.IsNullOrEmpty(file.FileName)) { query.product_active_banner = store.product_active_banner; } else { fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); NewFileName = newRand + fileExtention; //判斷目錄是否存在,不存在則創建 string[] mapPath = new string[1]; mapPath[0] = PaperPath.Substring(1, PaperPath.Length - 1); string s = localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1); CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1), mapPath); // returnName += PaperPath + NewFileName; fileName = NewFileName; NewFileName = localPromoPath + NewFileName;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + PaperPath); string oldFileName = ""; oldFileName = store.product_active_banner; if (!string.IsNullOrEmpty(oldFileName)) { DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 } try { //上傳 result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { query.product_active_banner = fileName; } else { pic = false; } } catch (Exception) { query.product_forbid_banner = store.product_forbid_banner; query.product_active_banner = store.product_active_banner; } } } } } catch (Exception) { query.product_forbid_banner = store.product_forbid_banner; query.product_active_banner = store.product_active_banner; } #endregion if (pic) { if (query.map_id > 0) {//編輯 if (!string.IsNullOrEmpty(Request.Params["map_sort"])) { query.map_sort = Convert.ToInt32(Request.Params["map_sort"]); } if (_ChinatrustBMMgr.Update(query) > 0) { json = "{success:true,msg:'修改成功!'}"; } else { json = "{success:false,msg:'修改失敗!'}"; } } else {//新增 dt = _ChinatrustBMMgr.GetMapSort(query); if (dt.Rows.Count > 0) { query.map_sort = int.Parse(dt.Rows[0]["map_sort"].ToString()) + 1; } else { query.map_sort = 0; } query.map_active = 0;//默認不啟用 if (_ChinatrustBMMgr.Save(query) > 0) { json = "{success:true,msg:'新增成功!'}"; } else { json = "{success:false,msg:'新增失敗!'}"; } } } 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,msg:'操作失敗!'}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase GetChinaTrustBagMapList() { List<EventChinaTrustBagMapQuery> store = new List<EventChinaTrustBagMapQuery>(); string json = string.Empty; int totalCount = 0; try { _ChinatrustBMMgr = new EventChinaTrustBagMapMgr(mySqlConnectionString); EventChinaTrustBagMapQuery query = new EventChinaTrustBagMapQuery(); 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["bag_id"])) //{ // query.bag_id = Convert.ToInt32(Request.Params["bag_id"]); //} if (!string.IsNullOrEmpty(Request.Params["bagid"])) { query.bag_id = Convert.ToInt32(Request.Params["bagid"]); } if (!string.IsNullOrEmpty(Request.Params["search_con"])) { query.search_con = Convert.ToInt32(Request.Params["search_con"]); } if (!string.IsNullOrEmpty(Request.Params["con"])) { query.con = Request.Params["con"]; } store = _ChinatrustBMMgr.GetChinaTrustBagMapList(query, out totalCount); IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; foreach (var item in store) { item.link = link; if (item.product_forbid_banner != "") { item.forbid_banner = imgServerPath + PaperPath + item.product_forbid_banner; } else { item.forbid_banner = defaultImg; } if (item.product_active_banner != "") { item.active_banner = imgServerPath + PaperPath + item.product_active_banner; } else { item.active_banner = defaultImg; } } //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; }