public HttpResponseBase InsertNewPromoCarnet() { NewPromoCarnetQuery query = new NewPromoCarnetQuery(); NewPromoCarnetQuery oldModel = new NewPromoCarnetQuery(); _INewPromoCarnetMgr = new NewPromoCarnetMgr(mySqlConnectionString); string json = string.Empty; try { if (!string.IsNullOrEmpty(Request.Params["row_id"])) { query.row_id = Convert.ToInt32(Request.Params["row_id"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["present_event_id"])) { query.present_event_id = Request.Params["present_event_id"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["group_id"])) { query.group_id = Convert.ToInt32(Request.Params["group_id"]); } if (!string.IsNullOrEmpty(Request.Params["new_user"])) { query.new_user = Convert.ToInt32(Request.Params["new_user"]); } if (!string.IsNullOrEmpty(Request.Params["new_user_date"])) { query.new_user_date = Convert.ToDateTime(Request.Params["new_user_date"]); } if (!string.IsNullOrEmpty(Request.Params["count_by"])) { query.count_by = Convert.ToInt32(Request.Params["count_by"]); } if (!string.IsNullOrEmpty(Request.Params["count"])) { query.count = Convert.ToInt32(Request.Params["count"]); } if (!string.IsNullOrEmpty(Request.Params["device"])) { query.device = (Request.Params["device"]); } if (!string.IsNullOrEmpty(Request.Params["message_mode"])) { query.message_mode = Convert.ToInt32(Request.Params["message_mode"]); } if (!string.IsNullOrEmpty(Request.Params["message_content"])) { query.message_content = (Request.Params["message_content"]); } if (!string.IsNullOrEmpty(Request.Params["link_url"])) { query.link_url = (Request.Params["link_url"]); } if (!string.IsNullOrEmpty(Request.Params["promo_image"])) { query.promo_image = Request.Params["promo_image"]; } if (!string.IsNullOrEmpty(Request.Params["active_now"])) { query.active_now = Convert.ToInt32(Request.Params["active_now"]); } #region 上傳圖片 string ErrorMsg = string.Empty; 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 localPromoPath = imgLocalPath + NewPromoPath;//圖片存儲地址 FileManagement fileLoad = new FileManagement(); 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"); string ServerPath = string.Empty; FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - NewPromoPath.Length + 1), NewPromoPath.Substring(1, NewPromoPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localPromoPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + NewPromoPath); //上傳之前刪除已有的圖片 if (query.row_id != 0) { oldModel = _INewPromoCarnetMgr.GetModel(query); if (oldModel.promo_image != "") { string oldFileName = oldModel.promo_image; CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localPromoPath + oldFileName); } } } try { Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result) { query.promo_image = fileName; } } 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); } if (!string.IsNullOrEmpty(ErrorMsg)) { string jsonStr = string.Empty; json = "{success:true,msg:\"" + ErrorMsg + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } } else { query.promo_image = oldModel.promo_image; } #endregion if (!string.IsNullOrEmpty(Request.Params["event_name"])) { query.event_name = Request.Params["event_name"]; } if (!string.IsNullOrEmpty(Request.Params["event_desc"])) { query.event_desc = Request.Params["event_desc"]; } if (!string.IsNullOrEmpty(Request.Params["start"])) { query.start = Convert.ToDateTime(Request.Params["start"]); } if (!string.IsNullOrEmpty(Request.Params["end"])) { query.end = Convert.ToDateTime(Request.Params["end"]); } if (query.row_id == 0) { query.kuser = (Session["caller"] as Caller).user_id; query.muser = query.kuser; query.created = DateTime.Now; query.modified = query.created; query.row_id = _INewPromoCarnetMgr.GetNewPromoCarnetMaxId(); query.event_id = BLL.gigade.Common.CommonFunction.GetEventId("F2", query.row_id.ToString()); if (_INewPromoCarnetMgr.InsertNewPromoCarnet(query) > 0) { json = "{success:true}"; } else { json = "{success:false}"; } } else { query.muser = (Session["caller"] as Caller).user_id; query.modified = DateTime.Now; if (_INewPromoCarnetMgr.UpdateNewPromoCarnet(query)) { json = "{success:true}"; } else { json = "{success:false}"; } } } 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 void InsertIntoPromoShareCon(PromoShareCondition query) { List<PromoShareCondition> list = new List<PromoShareCondition>(); PshareConMgr = new PromoShareConditionMgr(mySqlConnectionString); string json = string.Empty; DataTable _dt=new DataTable(); try { for (int i = 0; i < condition.Length; i++) { if (!string.IsNullOrEmpty(Request.Params[condition[i]])) { query = new PromoShareConditionQuery(); query.promo_id = Convert.ToInt32(Request.Params["promo_id"]); query.condition_name = condition[i]; query.condition_value = Request.Params[ condition[i]]; if (query.condition_name == "picture") { #region 上傳圖片 string ErrorMsg = string.Empty; 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 localPromoPath = imgLocalPath + promoPath;//圖片存儲地址 FileManagement fileLoad = new FileManagement(); 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; HashEncrypt hash = new HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); string ServerPath = string.Empty; FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localPromoPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + promoPath); //上傳之前刪除已有的圖片 if (query.promo_id != 0) { _dt = PshareConMgr.Get(condition, query); if (_dt.Rows[0]["picture"].ToString() != "") { string oldFileName = _dt.Rows[0]["picture"].ToString(); CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localPromoPath + oldFileName); } } } try { Resource.CoreMessage = new CoreResource("Product"); bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result) { query.condition_value = fileName; } } 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); } if (!string.IsNullOrEmpty(ErrorMsg)) { string jsonStr = string.Empty; json = "{success:true,msg:\"" + ErrorMsg + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); } } } else { query.condition_value = _dt.Rows[0]["picture"].ToString(); } #endregion } list.Add(query); } } PshareConMgr.AddSql(list); } 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}"; } }
public HttpResponseBase GetUploadArchives() { string json = string.Empty; try { #region 上傳 string ErrorMsg = string.Empty; string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); 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 fileName = string.Empty;//當前文件名 _ITicketDetail = new TicketDetailMgr(mySqlConnectionString); FileManagement fileLoad = new FileManagement(); if (Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; string fileExtention = string.Empty;//當前文件的擴展名 string oldFileName = file.FileName.Substring(0, file.FileName.LastIndexOf('.')); fileName = fileLoad.NewFileName(file.FileName); if (fileName != "") { string filepathday = fileName.Substring(0, fileName.LastIndexOf("."));//每天建立一個文件夾保存村的文件; fileName = oldFileName + "_" + filepathday;//上傳文檔為以前的名字+年月日時分秒.後綴名 filepathday = filepathday.Substring(0, 8); 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"); string ServerPath = string.Empty; FTP f_cf = new FTP(); archives = archives + filepathday + "/";//創建多層路徑 string localPromoPath = imgLocalPath + archives;//圖片存儲地址 f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - archives.Length + 1), archives.Substring(1, archives.Length - 2).Split('/'), ftpuser, ftppwd); // fileName = NewFileName + fileExtention; fileName = localPromoPath + fileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + archives); Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 bool result = _ITicketDetail.UpLoadFile(file, ServerPath, fileName, extention, (int.MaxValue / 1024) - 1, 0, ref ErrorMsg, ftpuser, ftppwd); if (result) { json = "{\"success\":\"true\"}"; } else { json = "{\"success\":\"false\",\"msg\":\"上傳失败\"}"; } } } #endregion } 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 upLoadImg() { string json = string.Empty; string errorInfo = string.Empty; VendorBrandSetQuery query = new VendorBrandSetQuery(); query.Brand_Id = uint.Parse(Request.Params["brand_id"]); query.image_sort = 0; query.image_state = 1; query.image_createdate = (uint)BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.ToString()); _IvendorBrandSet = new VendorBrandSetMgr(connectionString); ImagePathConfig(); string fileName = String.Empty, fileExtention = String.Empty, newFileName = String.Empty, oldFileName = String.Empty; //string localPromoPath = imgLocalPath + vendorPath;//圖片存儲地址 string localPromoPath = imgLocalPath + vendorOriginalPath;//圖片存儲地址 FileManagement fileLoad;//+++++++++++++++++ Boolean sort_repeat = false; for (int i = 0; i < Request.Files.Count; i++) { fileLoad = new FileManagement();//+++++++++++++++ HttpPostedFileBase file = Request.Files[i]; fileName = Path.GetFileName(file.FileName); fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); string[] arrary = fileName.Split('_'); if (arrary.Length < 3) { errorInfo += "[" + file.FileName + "] "; errorInfo += Resources.Product.FILE_NAME_ERROR; errorInfo += " 例:brand_1_tupian" + fileExtention; continue; } string brandStr = fileName.Split('_')[0].ToString(); string sortStr = fileName.Split('_')[1].ToString(); string filenameStr = fileName.Split('_')[2].ToString(); Regex reg = new Regex("^?[1-9][0-9]*$"); if (!brandStr.Equals("brand") || !reg.IsMatch(sortStr)) { errorInfo += "[" + file.FileName + "] "; errorInfo += Resources.Product.FILE_NAME_ERROR; errorInfo += " 例:brand_1_tupian" + fileExtention; continue; } query.image_sort = Convert.ToUInt32(sortStr); if (query.image_sort > 255) query.image_sort = 0; //大於數據庫存儲範圍時,默認為0; string newRand = hash.Md5Encrypt(fileLoad.NewFileName(fileName) + DateTime.Now.ToString(), "32"); fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); newFileName = newRand + fileExtention; string folder1 = newFileName.Substring(0, 2) + "/";//圖片名前兩碼 string folder2 = newFileName.Substring(2, 2) + "/";//圖片名第三四碼 string ServerPath = string.Empty; FTP f_cf = new FTP(); localPromoPath = imgLocalPath + vendorOriginalPath + folder1 + folder2;//圖片存儲地址 string s = localPromoPath.Substring(0, localPromoPath.Length - (vendorOriginalPath + folder1 + folder2).Length + 1); f_cf.MakeMultiDirectory(s, (vendorOriginalPath + folder1 + folder2).Substring(1, (vendorOriginalPath + folder1 + folder2).Length - 2).Split('/'), ftpuser, ftppwd); ServerPath = Server.MapPath(imgLocalServerPath + vendorOriginalPath + folder1 + folder2); fileName = newFileName; newFileName = localPromoPath + newFileName;//絕對路徑 string ErrorMsg = string.Empty; //錯誤消息 //Resource.CoreMessage = new CoreResource("Vendor");//尋找product.resx中的資源文件 try { bool result = fileLoad.UpLoadFile(file, ServerPath, newFileName, extention, 150, int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { //查詢image_sort是否存在重複 if (_IvendorBrandSet.GetSortIsRepeat(query)) { sort_repeat = true; } query.image_filename = fileName; _IvendorBrandSet.SaveBrandStory(query); errorInfo += "[" + file.FileName + "] " + "上傳成功!"; } else { errorInfo += "[" + file.FileName + "] " + ErrorMsg; } } 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); errorInfo += "[" + file.FileName + "] 上傳失敗<br/>"; //json = "{success:false,msg:\"操作失敗,請稍后再試!\"}"; //if (!string.IsNullOrEmpty(errorInfo)) //{ // json = "{success:false,msg:\"<div>操作失敗,請稍后再試!<br/>" + errorInfo + "</div>\"}"; //} } fileName = String.Empty; fileExtention = String.Empty; newFileName = String.Empty; oldFileName = String.Empty;//++++++++++++++++++ localPromoPath = imgLocalPath + vendorOriginalPath;//圖片存儲地址//++++++++++++++++++++ } if (sort_repeat)// json = "{success:true,sort_repeat:true,msg:\"<div>" + errorInfo + "</div>\"}"; else json = "{success:true,sort_repeat:false,msg:\"<div>" + errorInfo + "</div>\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
/// <summary> /// 新增或修改供應商品牌信息 /// </summary> /// <returns></returns> public HttpResponseBase UpdVendorBrand() { List<VendorBrandSetQuery> stores = new List<VendorBrandSetQuery>(); query = new VendorBrandSetQuery(); VendorBrandSetQuery oldquery = new VendorBrandSetQuery(); _IvendorBrandSet = new VendorBrandSetMgr(connectionString); _productMgr = new ProductMgr(connectionString); string json = string.Empty; string errorInfo = string.Empty; try { #region 獲取數據 query.Brand_Id = UInt32.Parse(Request.Params["Brand_Id"]); oldquery = _IvendorBrandSet.GetModelById(Int32.Parse(Request.Params["Brand_Id"])); try { query.Brand_Name = Request.Params["brandName"].ToString(); } catch (Exception) { query.Brand_Name = oldquery.Brand_Name; } try { query.vendor_id = uint.Parse(Request.Params["vendorid"].ToString()); } catch (Exception) { query.vendor_id = oldquery.vendor_id; } try { query.Brand_Sort = uint.Parse(Request.Params["brandsort"].ToString()); } catch (Exception) { query.Brand_Sort = oldquery.Brand_Sort; } try { query.Brand_Status = uint.Parse(Request.Params["brandstatus"].ToString()); } catch (Exception) { query.Brand_Status = oldquery.Brand_Status; } try { query.Image_Status = uint.Parse(Request.Params["imagestatus"].ToString()); } catch (Exception) { query.Image_Status = oldquery.Image_Status; } try { query.Image_Link_Mode = uint.Parse(Request.Params["imagelinkmode"].ToString()); } catch (Exception) { query.Image_Link_Mode = oldquery.Image_Link_Mode; } try { query.Image_Link_Url = Request.Params["imagelinkurl"].ToString(); } catch (Exception) { query.Image_Link_Url = oldquery.Image_Link_Url; } try { query.Resume_Image_Link = Request.Params["resumeimagelink"].ToString(); } catch (Exception) { query.Resume_Image_Link = oldquery.Resume_Image_Link; } try { query.Media_Report_Link_Url = Request.Params["mediareportlinkurl"].ToString(); } catch (Exception) { query.Media_Report_Link_Url = oldquery.Media_Report_Link_Url; } try { query.Brand_Msg = Request.Params["brandmsg"].ToString(); } catch (Exception) { query.Brand_Msg = oldquery.Brand_Msg; } long start = CommonFunction.GetPHPTime(Request.Params["begin_time"].ToString()); long end = CommonFunction.GetPHPTime(Request.Params["end_time"].ToString()); try { query.Brand_Msg_Start_Time = uint.Parse(start.ToString()); } catch (Exception) { query.Brand_Msg_Start_Time = oldquery.Brand_Msg_Start_Time; } try { query.Brand_Msg_End_Time = uint.Parse(end.ToString()); } catch (Exception) { query.Brand_Msg_End_Time = oldquery.Brand_Msg_End_Time; } try { query.Brand_Createdate = uint.Parse(CommonFunction.GetPHPTime(DateTime.Now.ToString()).ToString()); } catch (Exception) { query.Brand_Createdate = oldquery.Brand_Createdate; } try { query.classIds = Request["shopclass"].ToString(); } catch (Exception) { query.classIds = oldquery.classIds; } query.Brand_Ipfrom = Request.UserHostAddress; try { query.Cucumber_Brand = uint.Parse(Request.Params["cucumberbrand"].ToString()); } catch { query.Cucumber_Brand = oldquery.Cucumber_Brand; } try { query.Image_Name = Request.Params["imagename"].ToString(); } catch (Exception) { query.Image_Name = oldquery.Image_Name; } try { query.Promotion_Banner_Image_Link = Request.Params["promotionbannerimagelink"].ToString(); } catch (Exception) { query.Promotion_Banner_Image_Link = oldquery.Promotion_Banner_Image_Link; } try { query.short_description = Request.Params["short_description"].ToString(); } catch (Exception) { query.short_description = oldquery.short_description; } query.Image_Name = oldquery.Image_Name; query.Resume_Image = oldquery.Resume_Image; query.Promotion_Banner_Image = oldquery.Promotion_Banner_Image; query.brand_logo = oldquery.brand_logo; #endregion #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_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 + brandPath;//圖片存儲地址 FileManagement fileLoad = new FileManagement(); for (int i = 0; i < Request.Files.Count; i++) { string fileName = string.Empty; //當前文件名 HttpPostedFileBase file = Request.Files[i]; fileName = Path.GetFileName(file.FileName); if (string.IsNullOrEmpty(fileName)) { continue; } fileLoad = new FileManagement(); string oldFileName = string.Empty; //舊文件名 string fileExtention = string.Empty;//當前文件的擴展名 bool result = false; string NewFileName = string.Empty; string ServerPath = string.Empty; string newRand = string.Empty; string ErrorMsg = string.Empty; newRand = hash.Md5Encrypt(fileLoad.NewFileName(fileName) + DateTime.Now.ToString(), "32"); fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); NewFileName = newRand + fileExtention; string folder1 = NewFileName.Substring(0, 2) + "/"; //圖片名前兩碼 string folder2 = NewFileName.Substring(2, 2) + "/"; //圖片名第三四碼 FTP f_cf = new FTP(); localPromoPath = imgLocalPath + brandPath + folder1 + folder2; //圖片存儲地址 string s = localPromoPath.Substring(0, localPromoPath.Length - (brandPath + folder1 + folder2).Length + 1); f_cf.MakeMultiDirectory(s, (brandPath + folder1 + folder2).Substring(1, (brandPath + folder1 + folder2).Length - 2).Split('/'), ftpuser, ftppwd); ServerPath = Server.MapPath(imgLocalServerPath + brandPath + folder1 + folder2); fileName = NewFileName; NewFileName = localPromoPath + NewFileName;//絕對路徑 Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 //上傳 result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { //圖片上傳成功后記錄新圖片名稱 switch (i) { case 0: query.Image_Name = fileName; break; case 1: query.Resume_Image = fileName; break; case 2: query.Promotion_Banner_Image = fileName; break; case 3: query.brand_logo = fileName; break; default: break; } //圖片上傳成功后如果存在舊圖片則根據舊圖片名刪除舊圖片 if (!string.IsNullOrEmpty(oldFileName)) { switch (i) { case 0: oldFileName = oldquery.Image_Name; break; case 1: oldFileName = oldquery.Resume_Image; break; case 2: oldFileName = oldquery.Promotion_Banner_Image; break; case 3: oldFileName = oldquery.brand_logo; break; default: break; } DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 } } else { //圖片上傳失敗則圖片名稱為原有圖片名稱 switch (i) { case 0: query.Image_Name = oldquery.Image_Name;//形象圖片 break; case 1: query.Resume_Image = oldquery.Resume_Image;//安心聲明圖片 break; case 2: query.Promotion_Banner_Image = oldquery.Promotion_Banner_Image;//促銷圖片 break; case 3: query.brand_logo = oldquery.brand_logo;//品牌logo break; default: break; } errorInfo += "第" + (i + 1) + "張" + ErrorMsg + "<br/>"; //json = "{success:false,msg:\"第" + i + "張" + ErrorMsg + ",之後圖片未作處理" + "\"}"; } } #endregion //更新數據庫記錄 if (_IvendorBrandSet.Update(query) > 0) { if (_productMgr.UpdateSaleStatusByCondition(new Product { Vendor_Id = query.vendor_id, Brand_Id = query.Brand_Id })) { json = "{success:true,msg:\"數據保存成功!\"}"; } } if (!string.IsNullOrEmpty(errorInfo)) { json = "{success:true,msg:\"<div>數據保存成功!<br/>但<br/>" + errorInfo + "</div>\"}"; } } 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:\"保存失敗,請稍后再試!\"}"; if (!string.IsNullOrEmpty(errorInfo)) { json = "{success:false,msg:\"<div>保存失敗,請稍后再試!<br/>" + errorInfo + "</div>\"}"; } } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase AddorEdit() { string json = string.Empty; string errorInfo = string.Empty; uint brand_id = 0; bool result = false; try { _promotionBannerMgr = new PromotionBannerMgr(mySqlConnectionString); int i = 0; PromotionBannerQuery query = new PromotionBannerQuery(); PromotionBannerQuery oldquery = new PromotionBannerQuery(); if (!string.IsNullOrEmpty(Request.Params["pb_id"])) { oldquery.pb_id = Convert.ToInt32(Request.Params["pb_id"]); List<PromotionBannerQuery> oldModel = _promotionBannerMgr.GetModelById(oldquery.pb_id); if (oldModel != null) { query.pb_image = oldModel[0].pb_image; } } #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_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 + brandPath;//圖片存儲地址 FileManagement fileLoad = new FileManagement(); for (int j = 0; j < Request.Files.Count; j++) { string fileName = string.Empty;//當前文件名 HttpPostedFileBase file = Request.Files[j]; fileName = Path.GetFileName(file.FileName); if (string.IsNullOrEmpty(fileName)) { continue; } fileLoad = new FileManagement(); string oldFileName = string.Empty; //舊文件名 string fileExtention = string.Empty;//當前文件的擴展名 string NewFileName = string.Empty; string ServerPath = string.Empty; string newRand = string.Empty; string ErrorMsg = string.Empty; newRand = hash.Md5Encrypt(fileLoad.NewFileName(fileName) + DateTime.Now.ToString(), "32"); fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); NewFileName = newRand + fileExtention; string folder1 = NewFileName.Substring(0, 2) + "/"; //圖片名前兩碼 string folder2 = NewFileName.Substring(2, 2) + "/"; //圖片名第三四碼 FTP f_cf = new FTP(); localPromoPath = imgLocalPath + brandPath + folder1 + folder2; //圖片存儲地址 string s = localPromoPath.Substring(0, localPromoPath.Length - (brandPath + folder1 + folder2).Length + 1); f_cf.MakeMultiDirectory(s, (brandPath + folder1 + folder2).Substring(1, (brandPath + folder1 + folder2).Length - 2).Split('/'), ftpuser, ftppwd); ServerPath = Server.MapPath(imgLocalServerPath + brandPath + folder1 + folder2); fileName = NewFileName; NewFileName = localPromoPath + NewFileName;//絕對路徑 Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 //上傳 result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { query.pb_image = fileName; } else { errorInfo += ErrorMsg; } } #endregion if (!string.IsNullOrEmpty(Request.Params["image_link"])) { query.pb_image_link = Request.Params["image_link"]; } if (!string.IsNullOrEmpty(Request.Params["begin_time"])) { query.pb_startdate = Convert.ToDateTime(Request.Params["begin_time"]); } if (!string.IsNullOrEmpty(Request.Params["end_time"])) { query.pb_enddate = Convert.ToDateTime(Request.Params["end_time"]); } if (!string.IsNullOrEmpty(Request.Params["vb_ids"])) { query.brandIDS = Request.Params["vb_ids"].Substring(0, Request.Params["vb_ids"].LastIndexOf(',')); } if (!string.IsNullOrEmpty(Request.Params["multi"])) { query.multi = Convert.ToInt32(Request.Params["multi"]); } if (!string.IsNullOrEmpty(Request.Params["pb_id"])) { //編輯 query.pb_id = Convert.ToInt32(Request.Params["pb_id"]); query.pb_muser = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id); result = _promotionBannerMgr.UpdateImageInfo(query, out brand_id); if (result && string.IsNullOrEmpty(errorInfo)) { json = "{success:true}"; } else if (result == false && brand_id != 0) { json = "{success:false,msg:\"" + brand_id + "\"}";//brand_id重複 } else if (result && !string.IsNullOrEmpty(errorInfo)) { json = "{success:true,msg:\"數據保存成功<br/>但圖片保存失敗 <br/>" + errorInfo + "\"}"; } else { json = "{success:false}"; } } else { //新增 query.pb_kuser = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id); query.pb_muser = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id); result = _promotionBannerMgr.AddImageInfo(query, out brand_id); if (result && string.IsNullOrEmpty(errorInfo)) { json = "{success:true}"; } else if (result == false && brand_id != 0) { json = "{success:false,msg:\"" + brand_id + "\"}";//brand_id重複 } else if (result && !string.IsNullOrEmpty(errorInfo)) { json = "{success:true,msg:\"數據保存成功<br/>但圖片保存失敗 <br/>" + errorInfo + "\"}"; } else { json = "{success:false}"; } } } 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.ToString()); this.Response.End(); return this.Response; }
/// <summary> /// 圖檔維護中上傳圖片 /// </summary> /// <returns></returns> public HttpResponseBase UploadPicture() { string json = string.Empty; string errorInfo = string.Empty; VendorBrandSetQuery query = new VendorBrandSetQuery(); query.Brand_Id = uint.Parse(Request.Params["brand_id"]); query.image_sort = 0; query.image_state = 1; query.image_createdate = (uint)BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.ToString()); _IvendorBrandSet = new VendorBrandSetMgr(connectionString); ImagePathConfig(); string fileName = String.Empty, fileExtention = String.Empty, newFileName = String.Empty, oldFileName = String.Empty; //string localPromoPath = imgLocalPath + vendorPath;//圖片存儲地址 string localPromoPath = imgLocalPath + vendorOriginalPath;//圖片存儲地址 FileManagement fileLoad;//+++++++++++++++++ for (int i = 0; i < Request.Files.Count; i++) { fileLoad = new FileManagement();//+++++++++++++++ HttpPostedFileBase file = Request.Files[i]; fileName = Path.GetFileName(file.FileName); string newRand = hash.Md5Encrypt(fileLoad.NewFileName(fileName) + DateTime.Now.ToString(), "32"); fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); newFileName = newRand + fileExtention; string folder1 = newFileName.Substring(0, 2) + "/";//圖片名前兩碼 string folder2 = newFileName.Substring(2, 2) + "/";//圖片名第三四碼 string ServerPath = string.Empty; FTP f_cf = new FTP(); localPromoPath = imgLocalPath + vendorOriginalPath + folder1 + folder2;//圖片存儲地址 string s = localPromoPath.Substring(0, localPromoPath.Length - (vendorOriginalPath + folder1 + folder2).Length + 1); f_cf.MakeMultiDirectory(s, (vendorOriginalPath + folder1 + folder2).Substring(1, (vendorOriginalPath + folder1 + folder2).Length - 2).Split('/'), ftpuser, ftppwd); ServerPath = Server.MapPath(imgLocalServerPath + vendorOriginalPath + folder1 + folder2); fileName = newFileName; newFileName = localPromoPath + newFileName;//絕對路徑 string ErrorMsg = string.Empty; //錯誤消息 Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 try { //bool result = fileLoad.UpLoadFile(file, ServerPath, newFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); bool result = fileLoad.UpLoadFile(file, ServerPath, newFileName, extention, 150, int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { query.image_filename = fileName; _IvendorBrandSet.SaveBrandStory(query); //json = "{success:true,msg:\"圖片上傳成功!\"}"; } else { errorInfo += "第" + (i + 1) + "張" + ErrorMsg + "<br/>"; //json = "{success:false,msg:\"<div>圖片上傳成功!<br/>但第" + countError + "張" + ErrorMsg + "</div>\"}"; } json = "{success:true,msg:\"圖片上傳成功!\"}"; if (!string.IsNullOrEmpty(errorInfo)) { json = "{success:true,msg:\"<div>操作完成!<br/>但<br/>" + errorInfo + "</div>\"}"; } } 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:\"操作失敗,請稍后再試!\"}"; if (!string.IsNullOrEmpty(errorInfo)) { json = "{success:false,msg:\"<div>操作失敗,請稍后再試!<br/>" + errorInfo + "</div>\"}"; } } fileName = String.Empty; fileExtention = String.Empty; newFileName = String.Empty; oldFileName = String.Empty;//++++++++++++++++++ localPromoPath = imgLocalPath + vendorOriginalPath;//圖片存儲地址//++++++++++++++++++++ } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase SaveChinatrust() { string json = string.Empty; try { _eventChinatrust = new EventChinatrustMgr(mySqlConnectionString); FileManagement fileLoad = new FileManagement(); EventChinatrustQuery query = new EventChinatrustQuery(); EventChinatrustQuery oldModel = new EventChinatrustQuery(); List<EventChinatrustQuery> store = new List<EventChinatrustQuery>(); if (!string.IsNullOrEmpty(Request.Params["row_id"])) {//如果是編輯獲取該id數據 int totalCount = 0; query.IsPage = false; query.event_active = -1; query.row_id = int.Parse(Request.Params["row_id"]); store = _eventChinatrust.GetEventChinatrustList(query, out totalCount); } #region 需要更改的屬性 if (!string.IsNullOrEmpty(Request.Params["row_id"])) { query.row_id = Convert.ToInt32(Request.Params["row_id"]); } if (!string.IsNullOrEmpty(Request.Params["event_name"])) { query.event_name = Request.Params["event_name"]; } if (!string.IsNullOrEmpty(Request.Params["event_desc"])) { query.event_desc = Request.Params["event_desc"]; } if (!string.IsNullOrEmpty(Request.Params["event_start_time"])) { query.event_start_time = DateTime.Parse(Request.Params["event_start_time"]); } if (!string.IsNullOrEmpty(Request.Params["event_end_time"])) { query.event_end_time = DateTime.Parse(Request.Params["event_end_time"]); } if (!string.IsNullOrEmpty(Request.Params["user_register_time"])) { query.user_register_time=DateTime.Parse(Request.Params["user_register_time"]); } if (!string.IsNullOrEmpty(Request.Params["event_banner"])) { query.event_banner = Request.Params["event_banner"]; } #endregion query.event_type = "EC"; #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 localPromoPath = imgLocalPath + 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"); string ServerPath = string.Empty; FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1), PaperPath.Substring(1, PaperPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localPromoPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + PaperPath); string ErrorMsg = string.Empty; //上傳之前刪除已有的圖片 if (query.row_id != 0) { oldModel = store.FirstOrDefault(); if (oldModel.event_banner != "") { string oldFileName = oldModel.event_banner; CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localPromoPath + oldFileName); } } } try { Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result) { query.event_banner = fileName; } } 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); } if (!string.IsNullOrEmpty(ErrorMsg)) { string jsonStr = string.Empty; json = "{success:true,msg:\"" + ErrorMsg + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } } #endregion if (query.row_id == 0) { query.event_create_time = DateTime.Now; query.event_update_time = query.event_create_time; query.event_create_user = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id); query.event_update_user = query.event_create_user; if (_eventChinatrust.AddEventChinatrust(query) > 0) { json = "{success:true }"; } else { json = "{success:false,msg:'新增失敗!'}"; } } else { query.event_update_time = DateTime.Now; query.event_update_user = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id); if (_eventChinatrust.UpdateEventChinatrust(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}"; } this.Response.Clear(); this.Response.Write(json.ToString()); this.Response.End(); return this.Response; }
public HttpResponseBase EventChinaTrustBagSave() { string json = string.Empty; EventChinaTrustBagQuery query = new EventChinaTrustBagQuery(); EventChinaTrustBagQuery oldModel = new EventChinaTrustBagQuery(); try { if (!string.IsNullOrEmpty(Request.Params["event_id"])) { query.event_id = Request.Params["event_id"]; } if (!string.IsNullOrEmpty(Request.Params["bag_name"])) { query.bag_name = Request.Params["bag_name"]; } if (!string.IsNullOrEmpty(Request.Params["bag_desc"])) { query.bag_desc = Request.Params["bag_desc"]; } if (!string.IsNullOrEmpty(Request.Params["bag_banner"])) { query.bag_banner = Request.Params["bag_banner"]; } if (!string.IsNullOrEmpty(Request.Params["bag_start_time"])) { query.bag_start_time =Convert.ToDateTime( Request.Params["bag_start_time"]); } if (!string.IsNullOrEmpty(Request.Params["bag_end_time"])) { query.bag_end_time = Convert.ToDateTime(Request.Params["bag_end_time"]); } if (!string.IsNullOrEmpty(Request.Params["bag_show_start_time"])) { query.bag_show_start_time = Convert.ToDateTime(Request.Params["bag_show_start_time"]); } if (!string.IsNullOrEmpty(Request.Params["bag_show_end_time"])) { query.bag_show_end_time =Convert.ToDateTime(Request.Params["bag_show_end_time"]); } if (!string.IsNullOrEmpty(Request.Params["product_number"])) { query.product_number =Convert.ToInt32(Request.Params["product_number"]); } if (string.IsNullOrEmpty(Request.Params["bag_id"]))//新增 { query.bag_create_user=(Session["caller"] as Caller).user_id; query.bag_update_user = (Session["caller"] as Caller).user_id; query.bag_create_time = DateTime.Now; query.bag_update_time = query.bag_create_time; } else//編輯 { query.bag_id = Convert.ToInt32(Request.Params["bag_id"]); query.bag_update_time = DateTime.Now; query.bag_update_user = (Session["caller"] as Caller).user_id; } _eventChinaTrustBag = new EventChinaTrustBagMgr(mySqlConnectionString); #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 localPromoPath = imgLocalPath + PaperPath;//圖片存儲地址 if (Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 FileManagement fileLoad = new FileManagement(); 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"); string ServerPath = string.Empty; FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1), PaperPath.Substring(1, PaperPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localPromoPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + PaperPath); string ErrorMsg = string.Empty; if (query.bag_id != 0) { oldModel = _eventChinaTrustBag.GetSinggleData(query); if (oldModel.bag_banner != "") { string oldFileName = oldModel.bag_banner; CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除 FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localPromoPath + oldFileName); } } } try { Resource.CoreMessage = new CoreResource("Product"); bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result) { query.bag_banner = fileName; } } 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); } if (!string.IsNullOrEmpty(ErrorMsg)) { string jsonStr = string.Empty; json = "{success:true,msg:\"" + ErrorMsg + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); } } } else { query.bag_banner = oldModel.bag_banner; } #endregion if (_eventChinaTrustBag.EventChinaTrustBagSave(query) > 0) { json = "{success:true}"; } else { json = "{success:false}"; } } 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 SaveElementDetaiil() { string resultJson = "{success:false}"; ElementDetail model = new ElementDetail(); ElementDetail oldModel = new ElementDetail(); _detailMgr = new ElementDetailMgr(mySqlConnectionString); #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 + ElementPath;//圖片存儲地址 #endregion if (!String.IsNullOrEmpty(Request.Params["element_id"]))//如果不存在該id說明是添加頁面 { model.element_id = Convert.ToInt32(Request.Params["element_id"].ToString()); oldModel = _detailMgr.GetModel(model); } #region 獲取數據 int isTranInt = 0; //if (Int32.TryParse(Request.Params["element_area_id"].ToString(), out isTranInt)) //{ // model.element_area_id = Convert.ToInt32(Request.Params["element_area_id"].ToString()); //} //else //{ // model.element_area_id = oldModel.element_area_id; //} if (!string.IsNullOrEmpty(Request.Params["element_name"].ToString())) { model.element_name = Request.Params["element_name"].ToString(); } else { model.element_name = oldModel.element_name; } if (!string.IsNullOrEmpty(Request.Params["packet_id"])) { model.packet_id = Convert.ToInt32(Request.Params["packet_id"]); } if (Int32.TryParse(Request.Params["element_type"].ToString(), out isTranInt)) { model.element_type = Convert.ToInt32(Request.Params["element_type"]); } if (model.element_type == 1) { #region 上傳圖片 try { FileManagement fileLoad = new FileManagement(); //if (Request.Files.Count > 0)//單個圖片上傳 for (int iFile = 0; iFile < Request.Files.Count; iFile++)//多個上傳圖片 { HttpPostedFileBase file = Request.Files[iFile];//單個Request.Files[0] string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 //獲取圖片名稱 fileName = fileLoad.NewFileName(file.FileName); if (iFile == 0 && fileName == oldModel.element_content) { fileName = ""; } if(iFile == 1 && string.IsNullOrEmpty(Request.Params["element_img_big"].ToString()) ) { fileName = Request.Params["element_img_big"].ToString(); } if (!String.IsNullOrEmpty(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"); string ServerPath = string.Empty; //判斷目錄是否存在,不存在則創建 FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localBannerPath.Substring(0, localBannerPath.Length - ElementPath.Length + 1), ElementPath.Substring(1, ElementPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localBannerPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + ElementPath); string ErrorMsg = string.Empty; //上傳之前刪除已有的圖片 if (model.element_id != 0) { string oldFileName = oldModel.element_content; if (iFile == 1) { oldFileName = oldModel.element_img_big; } CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 FTP ftp = new FTP(localBannerPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localBannerPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localBannerPath + oldFileName);//刪除ftp:71.159上的舊圖片 } } try { //上傳 Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { if (iFile == 0) { model.element_content = fileName; } else { model.element_img_big = fileName; } } } 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); model.element_content = oldModel.element_content; } if (!string.IsNullOrEmpty(ErrorMsg)) { if (iFile == 0) { ErrorMsg = "元素圖 " + ErrorMsg; } else { ErrorMsg = "元素圖(大) " + ErrorMsg; } string json = string.Empty; json = "{success:true,msg:\""+ ErrorMsg + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } else { if (iFile == 0) { model.element_content = oldModel.element_content; } else { if (Request.Params["element_img_big"].ToString() == "") {//編輯時如果傳過來空值則直接刪除 model.element_img_big = ""; } else { model.element_img_big = oldModel.element_img_big; } //model.element_img_big = oldModel.element_img_big; } } } } 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); model.element_content = oldModel.element_content; } #endregion } else if (model.element_type == 2) { if (!string.IsNullOrEmpty(Request.Params["element_content"].ToString())) { model.element_content = Request.Params["element_content"].ToString(); } else { model.element_content = oldModel.element_content; } } else if (model.element_type == 3) { if (int.TryParse(Request.Params["element_product_id"].ToString(), out isTranInt)) { model.element_content = Request.Params["element_product_id"].ToString(); } else { model.element_content = oldModel.element_content; } #region 上傳圖片 try { FileManagement fileLoad = new FileManagement(); //if (Request.Files.Count > 0)//單個圖片上傳 for (int iFile = 1; iFile < Request.Files.Count; iFile++)//多個上傳圖片 { HttpPostedFileBase file = Request.Files[iFile];//單個Request.Files[0] string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 //獲取圖片名稱 fileName = fileLoad.NewFileName(file.FileName); if (!String.IsNullOrEmpty(fileName) && !String.IsNullOrEmpty(Request.Params["element_img_big"].ToString())) {//可獲取文件,名稱不為空則變更圖片 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"); string ServerPath = string.Empty; //判斷目錄是否存在,不存在則創建 FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localBannerPath.Substring(0, localBannerPath.Length - ElementPath.Length + 1), ElementPath.Substring(1, ElementPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localBannerPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + ElementPath); string ErrorMsg = string.Empty; //上傳之前刪除已有的圖片 if (model.element_id != 0) { string oldFileName = oldModel.element_img_big; CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 FTP ftp = new FTP(localBannerPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localBannerPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localBannerPath + oldFileName);//刪除ftp:71.159上的舊圖片 } } try { //上傳 Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { model.element_img_big = fileName; } } 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); model.element_img_big = oldModel.element_img_big; } if (!string.IsNullOrEmpty(ErrorMsg)) { ErrorMsg = "元素圖(大)" + ErrorMsg; string json = string.Empty; json = "{success:true,msg:\"" + ErrorMsg + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } else { if (Request.Params["element_img_big"].ToString() == "") {//編輯時如果傳過來空值則直接刪除 model.element_img_big = ""; } else { model.element_img_big = oldModel.element_img_big; } } } } 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); model.element_img_big = oldModel.element_img_big; } #endregion } if (int.TryParse(Request.Params["category_id_s"].ToString(), out isTranInt)) { model.category_id = uint.Parse(Request.Params["category_id_s"].ToString()); } else { model.category_id = 0; } model.category_name = Server.HtmlDecode(Request.Params["category_name_s"].ToString()); if (!string.IsNullOrEmpty(Request.Params["element_link_url"].ToString())) { model.element_link_url = Request.Params["element_link_url"].ToString(); } //else //{ // model.element_link_url = oldModel.element_link_url; //} if (int.TryParse(Request.Params["element_link_mode"].ToString(), out isTranInt)) { model.element_link_mode = Convert.ToInt32(Request.Params["element_link_mode"]); } else { model.element_link_mode = oldModel.element_link_mode; } if (!string.IsNullOrEmpty(Request.Params["element_sort"].ToString())) { model.element_sort = Convert.ToInt32(Request.Params["element_sort"].ToString()); } //else //{ // model.element_sort = oldModel.element_sort; //} if (!string.IsNullOrEmpty(Request.Params["element_start"].ToString())) { model.element_start = Convert.ToDateTime(Request.Params["element_start"].ToString()); } else { model.element_start = oldModel.element_start; } if (!string.IsNullOrEmpty(Request.Params["element_end"].ToString())) { model.element_end = Convert.ToDateTime(Request.Params["element_end"].ToString()); } else { model.element_end = oldModel.element_end; } model.element_remark = (Request.Params["element_remark"].ToString()); model.element_status = 0;//默認為不啟用 #endregion try { //判斷是否能夠獲取到rowid if (String.IsNullOrEmpty(Request.Params["element_id"]))//如果不存在該id說明是添加頁面 { model.element_createdate = DateTime.Now; model.element_updatedate = model.element_createdate; model.create_userid = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id; model.update_userid = model.create_userid; //這裡加上各種參數 if (_detailMgr.Save(model) > 0) { resultJson = "{success:true}";//返回json數據 } } else { //model.element_createdate = oldModel.element_createdate; model.element_updatedate = DateTime.Now; model.update_userid = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id; // model.create_userid = oldModel.create_userid; //這裡加上各種參數 if (_detailMgr.Update(model) > 0)//如果可以獲取到rowid則進行修改 { resultJson = "{success:true}";//返回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); resultJson = "{success:false}"; } this.Response.Clear(); this.Response.Write(resultJson); this.Response.End(); return this.Response; }
public HttpResponseBase BannerImageEdit() { string json = string.Empty; BannerContent bc = new BannerContent(); Serial serial = new Serial(); _bcMgr = new BannerContentMgr(mySqlConnectionString); _ISerImplMgr = new SerialMgr(mySqlConnectionString); serial = _ISerImplMgr.GetSerialById(72); 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 = imgLocalServerPath + promoPath;//圖片存儲地址 /aimg.gigade100.com/ +/promotion/dev/ string NewName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 string NewFileName = string.Empty; FileManagement fileLoad = new FileManagement(); try { string oldImg = string.Empty; serial = _ISerImplMgr.GetSerialById(6); List<BannerContent> store = new List<BannerContent>(); if (!string.IsNullOrEmpty(Request.Params["banner_content_id"])) { int totalCount = 0; bc.IsPage = false; bc.banner_content_id = uint.Parse(Request.Params["banner_content_id"]); if (Request.Params["history"] == "1") { bc.banner_status = 3; } store = _bcMgr.GetList(bc, out totalCount); foreach (var item in store) { oldImg = item.banner_image; } } bc = new BannerContent(); bc.banner_title = Request.Params["banner_title"]; bc.banner_link_url = Request.Params["banner_link_url"]; if (!string.IsNullOrEmpty(Request.Params["banner_site_id"])) { bc.banner_site_id = uint.Parse(Request.Params["banner_site_id"]); } if (!string.IsNullOrEmpty(Request.Params["banner_link_mode"])) { bc.banner_link_mode = int.Parse(Request.Params["banner_link_mode"]); } if (!string.IsNullOrEmpty(Request.Params["banner_sort"])) { bc.banner_sort = uint.Parse(Request.Params["banner_sort"]); } if (!string.IsNullOrEmpty(Request.Params["banner_statuses"])) { bc.banner_status = uint.Parse(Request.Params["banner_statuses"]); } if (!string.IsNullOrEmpty(Request.Params["banner_start"])) { bc.banner_start = DateTime.Parse(DateTime.Parse(Request.Params["banner_start"]).ToString("yyyy-MM-dd") + " 00:00:00"); } if (!string.IsNullOrEmpty(Request.Params["banner_end"])) { bc.banner_end = DateTime.Parse(DateTime.Parse(Request.Params["banner_end"]).ToString("yyyy-MM-dd") + " 23:59:59"); } bc.banner_ipfrom = CommonFunction.GetClientIPNew(); if (bc.banner_ipfrom == "::1") { bc.banner_ipfrom = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName())[2].ToString(); } if (!string.IsNullOrEmpty(Request.Params["banner_content_id"]) && Request.Params["banner_image"] == oldImg) { bc.banner_image = oldImg; } if (Request.Files["banner_image"] != null && Request.Files["banner_image"].ContentLength > 0) { HttpPostedFileBase file = Request.Files["banner_image"]; if (file.ContentLength > int.Parse(minValue) * 1024 && file.ContentLength < int.Parse(maxValue) * 1024) { NewName = Path.GetFileName(file.FileName); bool result = false; string filename = NewName.Substring(0, NewName.LastIndexOf(".")); //獲得文件的後綴名 fileExtention = NewName.Substring(NewName.LastIndexOf(".")).ToLower(); //新的文件名是哈希字符串 BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(filename, "32"); string firstFolder = NewFileName.Substring(0, 2) + "/"; string secondFolder = NewFileName.Substring(2, 2) + "/"; NewFileName = NewFileName + fileExtention; NewName = NewFileName; string ServerPath = string.Empty; string localPromoDirectory = Server.MapPath(localPromoPath); if (!System.IO.Directory.Exists(localPromoDirectory)) { System.IO.Directory.CreateDirectory(localPromoDirectory); } FTP ftp = new FTP(); string directorys = promoPath + firstFolder + secondFolder; ftp.MakeMultiDirectory(imgLocalPath+"/", directorys.Substring(1, directorys.Length - 2).Split('/'), ftpuser, ftppwd); //NewFileName = localPromoPath + NewFileName;//絕對路徑 ServerPath = Server.MapPath(localPromoPath + firstFolder + secondFolder); string ErrorMsg = string.Empty; //上傳 result = fileLoad.UpLoadFile(file, ServerPath, imgLocalPath + directorys + NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (!result) { json = "{success:false,msg:'圖片上傳失敗!'}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } bc.banner_image = NewName; string oldImgPath = string.Empty; string ftppath = string.Empty; if (oldImg.Length >= 4) { oldImgPath = localPromoPath + oldImg.Substring(0, 2) + "/" + oldImg.Substring(2, 2) + "/" + oldImg; } if (System.IO.File.Exists(Server.MapPath(oldImgPath))) { ftppath=imgLocalPath + promoPath + oldImg.Substring(0, 2) + "/" + oldImg.Substring(2, 2) + "/"; System.IO.File.Delete(Server.MapPath(oldImgPath)); FTP ftp1 = new FTP(ftppath, ftpuser, ftppwd); List<string> tem = ftp1.GetFileList(); if (tem.Contains(oldImg)) { FTP ftps = new FTP(ftppath + oldImg, ftpuser, ftppwd); ftps.DeleteFile(ftppath + oldImg); } } } else { json = "{success:false,msg:'上傳圖片不能超過" + maxValue + "K'}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } #region 新增 if (String.IsNullOrEmpty(Request.Params["banner_content_id"])) { bc.banner_content_id = uint.Parse((serial.Serial_Value + 1).ToString()); if (_bcMgr.Add(bc) > 0) { serial.Serial_Value = serial.Serial_Value + 1;/*所在操作表的列增加*/ _ISerImplMgr.Update(serial);/*修改所在的表的列對應的值*/ json = "{success:true,msg:\"" + "新增成功!" + "\"}"; } } #endregion #region 編輯 else { bc.banner_content_id = uint.Parse(Request.Params["banner_content_id"]); if (_bcMgr.Update(bc) > 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; }
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; }
/// <summary> /// 新增或者修改 /// </summary> /// <returns></returns> public HttpResponseBase SaveEvent() { string json = string.Empty; VoteEvent vevent = new VoteEvent(); veMgr = new VoteEventMgr(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<VoteEventQuery> store = new List<VoteEventQuery>(); VoteEventQuery veq = new VoteEventQuery(); if (!string.IsNullOrEmpty(Request.Params["event_id"])) { int totalCount = 0; veq.IsPage = false; veq.event_id = int.Parse(Request.Params["event_id"]); store = veMgr.GetVoteEventList(veq, out totalCount); } vevent.event_name = Request.Params["event_name"]; vevent.event_desc = Request.Params["event_desc"]; if (!string.IsNullOrEmpty(Request.Params["event_start"])) { vevent.event_start = DateTime.Parse(Request.Params["event_start"]); } if (!string.IsNullOrEmpty(Request.Params["event_end"])) { vevent.event_end = DateTime.Parse(Request.Params["event_end"]); } if (!string.IsNullOrEmpty(Request.Params["word_length"])) { vevent.word_length = int.Parse(Request.Params["word_length"]); } if (!string.IsNullOrEmpty(Request.Params["vote_everyone_limit"])) { vevent.vote_everyone_limit = int.Parse(Request.Params["vote_everyone_limit"]); } if (!string.IsNullOrEmpty(Request.Params["vote_everyday_limit"])) { vevent.vote_everyday_limit = int.Parse(Request.Params["vote_everyday_limit"]); } if (!string.IsNullOrEmpty(Request.Params["number_limit"])) { vevent.number_limit = int.Parse(Request.Params["number_limit"]); } if (!string.IsNullOrEmpty(Request.Params["is_repeat"])) { vevent.is_repeat = int.Parse(Request.Params["is_repeat"]); } vevent.present_event_id = Request.Params["present_event_id"]; vevent.event_status = 0; vevent.update_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id; vevent.create_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id; #region 上傳圖片 string oldImg = string.Empty; foreach (var item in store) { oldImg = item.event_banner; } if (!string.IsNullOrEmpty(Request.Params["event_id"]) && Request.Params["event_banner"] == oldImg) { vevent.event_banner = oldImg; } else { string ServerPath = string.Empty; try { ServerPath = Server.MapPath(imgLocalServerPath + PaperPath); if (Request.Files["event_banner"] != null && Request.Files["event_banner"].ContentLength > 0) { HttpPostedFileBase file = Request.Files["event_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)//上傳成功 { vevent.event_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上的舊圖片 } vevent.event_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}"; } } #endregion if (!string.IsNullOrEmpty(Request.Params["event_id"])) { vevent.event_id = int.Parse(Request.Params["event_id"]); //rgModel.group_ipfrom = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList.FirstOrDefault().ToString(); if (veMgr.Update(vevent) > 0) { json = "{success:true,msg:'修改成功!'}"; } else { json = "{success:true,msg:'修改失敗!'}"; } } else { vevent.create_time = DateTime.Now; vevent.update_time = vevent.create_time; if (veMgr.Save(vevent) > 0) { json = "{success:true,msg:'保存成功!'}"; } else { json = "{success:true,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 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; }
public HttpResponseBase SaveWebContentType2() { WebContentType2 model = new WebContentType2(); WebContentType2 oldModel = new WebContentType2(); int isTranInt = 0; if (!String.IsNullOrEmpty(Request.Params["rowid"]))//如果不存在該id說明是添加頁面 { model.content_id = Convert.ToInt32(Request.Params["rowid"].ToString()); oldModel = _wctMgr2.GetModel(model); } #region 獲取數據 model.site_id = 7; try { model.page_id = Convert.ToInt32(Request.Params["page_id"].ToString()); } catch { model.page_id = oldModel.page_id; } try { model.area_id = Convert.ToInt32(Request.Params["area_id"].ToString()); } catch { model.area_id = oldModel.area_id; } model.content_title = Request.Params["content_title"].ToString(); model.home_title = Request.Params["home_title"].ToString(); model.home_text = Request.Params["home_text"].ToString(); #region 圖片上傳 try { ImagePathConfig(); for (int iFile = 0; iFile < Request.Files.Count; iFile++) { HttpPostedFileBase file = Request.Files[iFile]; 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"); string ServerPath = string.Empty; //判斷目錄是否存在,不存在則創建 FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localHealthPath.Substring(0, localHealthPath.Length - healthPath.Length + 1), healthPath.Substring(1, healthPath.Length - 2).Split('/'), ftpuser, ftppwd); // CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - healthPath.Length + 1), healthPath.Substring(1, healthPath.Length - 2).Split('/')); // returnName += promoPath + NewFileName; fileName = NewFileName + fileExtention; NewFileName = localHealthPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + healthPath); string ErrorMsg = string.Empty; //上傳之前刪除已有的圖片 if (model.content_id != 0) { string oldFileName = oldModel.content_image; CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 FTP ftp = new FTP(localHealthPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localHealthPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localHealthPath + oldFileName);//刪除ftp:71.159上的舊圖片 } } try { //上傳 Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { model.content_image = fileName; } } 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); model.content_image = oldModel.content_image; } if (!string.IsNullOrEmpty(ErrorMsg)) { string json = string.Empty; json = "{success:true,msg:\"" + ErrorMsg + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } else { model.content_image = oldModel.content_image; } } } catch (Exception) { model.content_image = oldModel.content_image; } #endregion if (!string.IsNullOrEmpty(Request.Params["product_id"].ToString())) { if (int.TryParse(Request.Params["product_id"].ToString(), out isTranInt)) { model.product_id = Convert.ToInt32(Request.Params["product_id"]); } else { model.product_id = oldModel.product_id; } } else { model.product_id = 0; } model.content_default = Convert.ToInt32(Request.Params["content_default"]); model.content_status = Convert.ToInt32(Request.Params["content_status"]); model.link_url = Request.Params["link_url"].ToString(); if (!string.IsNullOrEmpty(Request.Params["start_time"].ToString())) { model.start_time = DateTime.Parse(Request.Params["start_time"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["end_time"].ToString())) { model.end_time = DateTime.Parse(Request.Params["end_time"].ToString()); } //model.link_page = Request.Params["link_page"].ToString(); model.link_mode = Convert.ToInt32(Request.Params["link_mode"]); #endregion //判斷是否能夠獲取到rowid if (String.IsNullOrEmpty(Request.Params["content_id"]))//如果不存在該id說明是添加頁面 { model.created_on = DateTime.Now; model.update_on = model.created_on;//這裡加上各種參數 return InsertWebContentType2(model);//如果獲取不到則進行新增 } else { model.update_on = DateTime.Now;//這裡加上各種參數 return updateWebContentType2(model);//如果可以獲取到rowid則進行修改 } }
public HttpResponseBase UploadHtmlEditorPicture() { String fileUrl = ""; try { ImagePathConfig(); HttpPostedFileBase file = Request.Files["imgFile"]; if (file == null) { showError("请选择文件。"); } string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 //獲取圖片名稱 fileName = fileLoad.NewFileName(file.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"); string ServerPath = string.Empty; //判斷目錄是否存在,不存在則創建 FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localHealthPath.Substring(0, localHealthPath.Length - healthPath.Length + 1), healthPath.Substring(1, healthPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localHealthPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + healthPath); string ErrorMsg = string.Empty; try { //上傳 bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { fileUrl = imgServerPath + healthPath + fileName; } } catch (Exception) { showError("圖片上傳失敗。"); } } catch (Exception) { showError("圖片上傳失敗。"); } Hashtable hashResult = new Hashtable(); hashResult["error"] = 0; hashResult["url"] = fileUrl; this.Response.AddHeader("Content-Type", "text/html; charset=UTF-8"); this.Response.Write(JsonMapper.ToJson(hashResult)); this.Response.End(); return this.Response; }