public HttpResponseBase IsGetEventID() { string json = string.Empty; try { if (!string.IsNullOrEmpty(Request.Params["event_id"])) { string event_id = Request.Params["event_id"]; _memberEvent = new MemberEventMgr(mySqlConnectionString); json= _memberEvent.IsGetEventID(event_id); } } 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; }
/// <summary> /// 會員活動新增編輯 /// </summary> /// <returns></returns> public HttpResponseBase SaveMemberEvent() { string json = string.Empty; try { MemberEventQuery query = new MemberEventQuery(); _memberEvent = new MemberEventMgr(mySqlConnectionString); if (!string.IsNullOrEmpty(Request.Params["rowID"])) { query.rowID = int.Parse(Request.Params["rowID"]); } query.me_name = Request.Params["me_name"]; query.me_desc = Request.Params["me_desc"]; query.event_id = Request.Params["event_id"]; if (!string.IsNullOrEmpty(Request.Params["me_startdate"])) { query.me_startdate = DateTime.Parse(Request.Params["me_startdate"]); } if (!string.IsNullOrEmpty(Request.Params["me_enddate"])) { query.me_enddate = DateTime.Parse(Request.Params["me_enddate"]); } if (!string.IsNullOrEmpty(Request.Params["me_birthday"])) { //query.me_birthday = int.Parse(Request.Params["me_birthday"]); if (Request.Params["me_birthday"] == "1") { query.me_birthday = 1; } else { query.me_birthday = 0; } } if (!string.IsNullOrEmpty(Request.Params["me_bonus_onetime"])) { if (Request.Params["me_bonus_onetime"] == "1") { query.me_bonus_onetime = 1; } else { query.me_bonus_onetime = 0; } } if (!string.IsNullOrEmpty(Request.Params["me_banner_link"])) { query.me_banner_link = Request.Params["me_banner_link"]; } if (!string.IsNullOrEmpty(Request.Params["code"])) { query.ml_code = Request.Params["code"].TrimEnd(','); } else { query.ml_code = "0"; } if (!string.IsNullOrEmpty(Request.Params["et_id"])) { query.et_id = int.Parse(Request.Params["et_id"]); } //query.et_name = Request.Params["et_name"]; switch (Request.Params["et_name"]) { case "1": query.et_name = "DD"; query.et_date_parameter = ""; break; case "2": query.et_name = "WW"; if (!string.IsNullOrEmpty(Request.Params["week"])) { query.et_date_parameter = Request.Params["week"].TrimEnd(','); } break; case "3": query.et_name = "MM"; if (!string.IsNullOrEmpty(Request.Params["month"])) { query.et_date_parameter = Request.Params["month"].TrimEnd(','); } break; } #region 處理每天的開始結束時間 query.et_starttime = Request.Params["et_starttime"]; query.et_endtime = Request.Params["et_endtime"]; #endregion query.k_user = (Session["caller"] as Caller).user_id; query.m_user = (Session["caller"] as Caller).user_id; query.k_date = DateTime.Now; query.m_date = query.k_date; string event_json=_memberEvent.IsGetEventID(query.event_id); if (event_json.IndexOf("true") > 0) { #region 判斷數據不能重複 if (_memberEvent.IsRepeat(query))//不重複 { #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 localMemberEventPath = imgLocalPath + MemberEventPath;//圖片存儲地址 FileManagement fileLoad = new FileManagement(); int totalCount = 0; MemberEventQuery oldQuery = _memberEvent.Query(new MemberEventQuery { rowID = query.rowID }, out totalCount).FirstOrDefault(); 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[] dirPath = new string[2]; //dirPath[0] = NewFileName.Substring(0, 2)+"/"; //dirPath[1] = NewFileName.Substring(2, 2)+"/"; string ServerPath = string.Empty; FTP f_cf = new FTP(); CreateFolder(localMemberEventPath, dirPath); fileName = NewFileName + fileExtention; NewFileName = localMemberEventPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + MemberEventPath); string ErrorMsg = string.Empty; //上傳之前刪除已有的圖片 if (query.rowID != 0) { if (oldQuery.me_big_banner != "") { string oldFileName = oldQuery.me_big_banner; CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 FTP ftp = new FTP(localMemberEventPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localMemberEventPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localMemberEventPath + 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.me_big_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; } } else { query.me_big_banner = oldQuery.me_big_banner; } } #endregion if (_memberEvent.MemberEventSave(query) > 0) { //json = "{success:true}"; if (!string.IsNullOrEmpty(Request.Params["rowID"])) { json = "{success:true,msg:'修改成功!'}"; } else { json = "{success:true,msg:'新增成功!'}"; } } else { if (!string.IsNullOrEmpty(Request.Params["rowID"])) { json = "{success:false,msg:'修改失敗!'}"; } else { json = "{success:false,msg:'新增失敗!'}"; } } } else { json = "{success:false,msg:'數據重複!'}"; } #endregion } 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; }