/// <summary> /// 獲取商品數據 /// </summary> /// <returns></returns> public HttpResponseBase GetTrialProdCateList() { List<TrialProdCateQuery> store = new List<TrialProdCateQuery>(); string json = string.Empty; try { TrialProdCateQuery query = new TrialProdCateQuery(); #region 獲取query對象數據 query.Start = Convert.ToInt32(Request.Params["start"] ?? "0"); if (!string.IsNullOrEmpty(Request.Form["limit"])) { query.Limit = Convert.ToInt32(Request.Params["limit"]); } #endregion _trialProdMgr = new TrialProdCateMgr(mySqlConnectionString); _prodMgr = new ProductMgr(mySqlConnectionString); prodCateMgr = new ProductCategoryMgr(mySqlConnectionString);//實例化對象mgr _giftMgr = new PromotionsAmountGiftMgr(mySqlConnectionString); _trialMgr = new PromotionsAmountTrialMgr(mySqlConnectionString); int totalCount = 0; store = _trialProdMgr.Query(query, out totalCount); foreach (var item in store) { item.product_name = _prodMgr.QueryClassify(Convert.ToUInt32(item.product_id)).Product_Name; item.category_name = prodCateMgr.QueryAll(new ProductCategory { category_id = item.category_id }).FirstOrDefault().category_name; if (item.event_id.StartsWith("T1") || item.event_id.StartsWith("T2")) { int id = Convert.ToInt16(item.event_id.Substring(2).ToString()); item.event_name = _trialMgr.GetModel(id).name; } if (item.event_id.StartsWith("G3")) { int id = Convert.ToInt16(item.event_id.Substring(2).ToString()); item.event_name = _giftMgr.GetModel(id).name; } } IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, Formatting.Indented, timeConverter) + "}";//返回json數據 } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); json = "{success:false}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
/// <summary> /// 更改活動使用狀態 /// </summary> /// <returns>數據庫操作結果</returns> public JsonResult UpdateActive() { string jsonStr = string.Empty; try { string currentUser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString(); string muser = string.Empty; int activeValue = Convert.ToInt32(Request.Params["active"]); if (!string.IsNullOrEmpty(Request.Params["muser"])) { muser = (Request.Params["muser"]); } if (currentUser == muser && activeValue == 1) { return Json(new { success = "stop" }); } _promotionsAmountTrialMgr = new PromotionsAmountTrialMgr(mySqlConnectionString); int id = Convert.ToInt32(Request.Params["id"]); PromotionsAmountTrialQuery model = _promotionsAmountTrialMgr.Select(id); model.active = activeValue; model.id = id; model.muser = currentUser; model.modified = DateTime.Now; if (_promotionsAmountTrialMgr.UpdateActive(model) > 0) { return Json(new { success = "true" }); } else { return Json(new { 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); return Json(new { success = "false" }); } }
public HttpResponseBase SaveTrial() { string jsonStr = String.Empty; try { PromotionsAmountTrialQuery patmodel = new PromotionsAmountTrialQuery(); _promotionsAmountTrialMgr = new PromotionsAmountTrialMgr(mySqlConnectionString); #region 試吃試用第一步數據 if (!string.IsNullOrEmpty(Request.Params["name"])) {//活動名稱 patmodel.name = Request.Params["name"].ToString(); } //活動類型 int event_type = 0; if (!string.IsNullOrEmpty(Request.Params["event_type"])) { if (int.TryParse(Request.Params["event_type"], out event_type)) { if (event_type == 1) { patmodel.event_type = "T1"; } else if (event_type == 2) { patmodel.event_type = "T2"; } } } int paper_id = 0; if (int.TryParse(Request.Params["paper_id"].ToString(), out paper_id)) { patmodel.paper_id = paper_id; } else { patmodel.paper_id = 0; } if (!string.IsNullOrEmpty(Request.Params["start_date"])) { patmodel.start_date = Convert.ToDateTime(Request.Params["start_date"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["end_date"])) { patmodel.end_date = Convert.ToDateTime(Request.Params["end_date"].ToString()); } //活動描述 if (!string.IsNullOrEmpty(Request.Params["event_desc"])) { patmodel.event_desc = Request.Params["event_desc"].ToString(); } patmodel.status = 0;//第一步保存為無效數據 patmodel.kuser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString(); patmodel.created = DateTime.Now; patmodel.modified = patmodel.created; patmodel.muser = patmodel.kuser; #endregion int id = _promotionsAmountTrialMgr.Save(patmodel); string event_id = CommonFunction.GetEventId(patmodel.event_type, id.ToString()); if (id > 0) { jsonStr = "{success:true,\"id\":\"" + id + "\",\"event_id\":\"" + event_id + "\"}"; } else { jsonStr = "{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); jsonStr = "{success:false}"; } this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; }
public HttpResponseBase UpdateTrial() { string jsonStr = String.Empty; int isTranInt = 0; try { string trial_id = Request.Params["trial_id"].ToString(); string isEdit = Request.Params["isEdit"].ToString(); _promotionsAmountTrialMgr = new PromotionsAmountTrialMgr(mySqlConnectionString); _ucMgr = new UserConditionMgr(mySqlConnectionString); PromotionsAmountTrialQuery model = new PromotionsAmountTrialQuery(); PromotionsAmountTrialQuery OldModel = new PromotionsAmountTrialQuery(); #region 第一面板數據 if (!string.IsNullOrEmpty(Request.Params["trial_id"])) { model.id = Convert.ToInt32(Request.Params["trial_id"]); OldModel = _promotionsAmountTrialMgr.Select(model.id); } if (!string.IsNullOrEmpty(Request.Params["name"])) {//活動名稱 model.name = Request.Params["name"].ToString(); } int event_type = 0; if (!string.IsNullOrEmpty(Request.Params["event_type"])) { if (int.TryParse(Request.Params["event_type"], out event_type)) { if (event_type == 1) { model.event_type = "T1"; } else if (event_type == 2) { model.event_type = "T2"; } } } model.event_id = CommonFunction.GetEventId(model.event_type, model.id.ToString()); int paper_id = 0; if (int.TryParse(Request.Params["paper_id"].ToString(), out paper_id)) { model.paper_id = paper_id; } if (!string.IsNullOrEmpty(Request.Params["event_url"].ToString())) { model.url = Request.Params["event_url"]; } if (!string.IsNullOrEmpty(Request.Params["start_date"])) { model.start_date = Convert.ToDateTime(Request.Params["start_date"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["end_date"])) { model.end_date = Convert.ToDateTime(Request.Params["end_date"].ToString()); } //活動描述 if (!string.IsNullOrEmpty(Request.Params["event_desc"])) { model.event_desc = Request.Params["event_desc"].ToString(); } #endregion #region 第二面板數據 if (!string.IsNullOrEmpty(Request.Params["group_id"].ToString())) { if (int.TryParse(Request.Params["group_id"].ToString(), out isTranInt)) { model.group_id = Convert.ToInt32(Request.Params["group_id"].ToString()); } else { model.group_id = OldModel.group_id; } //當編輯活動時將會員條件改為會員群組則刪除原有的會員條件 if (OldModel.condition_id != 0) { UserCondition uc = new UserCondition(); uc.condition_id = OldModel.condition_id; if (_ucMgr.Delete(uc) > 0) { jsonStr = "{success:true}"; model.condition_id = 0; } else { jsonStr = "{success:false,msg:'user_condition刪除出錯!'}"; this.Response.Clear(); this.Response.Write(jsonStr.ToString()); this.Response.End(); return this.Response; } } //當活動設置完會員條件又改為會員群組時刪除設置的會員條件 if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0") { UserCondition uc = new UserCondition(); uc.condition_id = Convert.ToInt32(Request.Params["condition_id"]); if (_ucMgr.Delete(uc) > 0) { jsonStr = "{success:true}"; model.condition_id = 0; } else { jsonStr = "{success:false,msg:'user_condition刪除出錯!'}"; this.Response.Clear(); this.Response.Write(jsonStr.ToString()); this.Response.End(); return this.Response; } } } else if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0") { model.condition_id = Convert.ToInt32(Request.Params["condition_id"].ToString()); model.group_id = 0; } if (!string.IsNullOrEmpty(Request.Params["count_by"])) { model.count_by = Convert.ToInt32(Request.Params["count_by"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["numLimit"])) { model.num_limit = Convert.ToInt32(Request.Params["numLimit"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["gift_mundane"])) { model.gift_mundane = Convert.ToInt32(Request.Params["gift_mundane"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["IsRepeat"])) { model.repeat = Convert.ToInt32(Request.Params["IsRepeat"].ToString()) == 1 ? true : false; } if (!string.IsNullOrEmpty(Request.Params["freight_type"].ToString())) { if (int.TryParse(Request.Params["freight_type"].ToString(), out isTranInt)) { model.freight_type = Convert.ToInt32(Request.Params["freight_type"].ToString()); } else { model.freight_type = OldModel.freight_type; } } if (!string.IsNullOrEmpty(Request.Params["device_name"])) { model.device = Convert.ToInt32(Request.Params["device_name"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["site"].ToString()))//修改時傳的值為siteName { Regex reg = new Regex("^([0-9]+,)*([0-9]+)$"); if (reg.IsMatch(Request.Params["site"].ToString())) { model.site = Request.Params["site"].ToString();// 將站台改為多選 edit by shuangshuang0420j 20140925 10:08 } else { model.site = OldModel.site; } } #endregion #region 第三面板數據 if (!string.IsNullOrEmpty(Request.Params["product_id"])) { model.product_id = Convert.ToInt32(Request.Params["product_id"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["product_name"])) { model.product_name = Request.Params["product_name"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["sale_product_id"])) { model.sale_productid = Convert.ToInt32(Request.Params["sale_product_id"].ToString()); } model.category_id = Convert.ToUInt32(Request.Params["category_id"].ToString()); model.brand_id = Convert.ToInt32(Request.Params["brand_id"].ToString()); model.market_price = Convert.ToInt32(Request.Params["market_price"].ToString()); model.show_number = Convert.ToInt32(Request.Params["show_number"].ToString()); model.apply_limit = Convert.ToInt32(Request.Params["apply_limit"].ToString()); model.apply_sum = Convert.ToInt32(Request.Params["apply_sum"].ToString()); #region 上傳圖片 try { string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MinValue"); SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); //擴展名、最小值、最大值 string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string localPromoPath = imgLocalPath + promoPath;//圖片存儲地址 string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 bool result = false; string NewFileName = string.Empty;//編譯后的文件名 string oldFile = ""; string ServerPath = string.Empty; string ErrorMsg = string.Empty; //判斷目錄是否存在,不存在則創建 CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/')); FileManagement fileLoad = new FileManagement(); for (int iFile = 0; iFile < Request.Files.Count; iFile++) { if (iFile == 0 && !string.IsNullOrEmpty(Request.Params["prod_file"])) { model.product_img = Request.Params["prod_file"].ToString().Substring(Request.Params["prod_file"].ToString().LastIndexOf("/") + 1); } else { HttpPostedFileBase file = Request.Files[iFile]; Random rand = new Random(); int newRand = rand.Next(1000, 9999); fileName = Path.GetFileName(file.FileName); if (fileName != "") { switch (iFile) { case 1: oldFile = OldModel.event_img_small; break; case 2: oldFile = OldModel.event_img; break; case 0: oldFile = OldModel.product_img; break; } FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFile)) { FTP ftps = new FTP(localPromoPath + oldFile, ftpuser, ftppwd); ftps.DeleteFile(localPromoPath + oldFile);//刪除ftp:71.159上的舊圖片 DeletePicFile(ServerPath + oldFile);//刪除本地圖片 } fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); NewFileName = model.event_id + newRand + fileExtention; fileName = NewFileName; NewFileName = localPromoPath + NewFileName;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + promoPath); try { //上傳 result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { switch (iFile) { case 1: model.event_img_small = fileName; break; case 2: model.event_img = fileName; break; case 0: model.product_img = fileName; break; } } } 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); } } else { switch (iFile) { case 1: model.event_img_small = OldModel.event_img_small; break; case 2: model.event_img = OldModel.event_img; break; case 0: model.product_img = OldModel.product_img; break; } } } } } 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); } #endregion #endregion #region 更新表結構 if (string.IsNullOrEmpty(isEdit))//新增數據 { model.active = 0;//默認不啟用 model.status = 1;//第二步保存為有效數據 model.kuser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString(); model.created = DateTime.Now; model.muser = model.kuser; model.modified = model.created; if (_promotionsAmountTrialMgr.Update(model) > 0) { jsonStr = "{success:true,msg:0}";//返回json數據 } else { jsonStr = "{success:false,msg:0}";//返回json數據 } } else//編輯數據 { model.active = OldModel.active; model.status = OldModel.status; model.kuser = OldModel.kuser; model.created = OldModel.created; model.muser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString(); model.modified = DateTime.Now; if (_promotionsAmountTrialMgr.Update(model) > 0) { jsonStr = "{success:true,msg:0}";//返回json數據 } else { jsonStr = "{success:false,msg:0}";//返回json數據 } } #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); jsonStr = "{success:false,msg:0}"; } this.Response.Clear(); this.Response.Write(jsonStr.ToString()); this.Response.End(); return this.Response; }
public HttpResponseBase GetPromotionsAmountTrialList() { List<PromotionsAmountTrialQuery> store = new List<PromotionsAmountTrialQuery>(); string json = string.Empty; try { PromotionsAmountTrialQuery query = new PromotionsAmountTrialQuery(); #region 獲取query對象數據 query.Start = Convert.ToInt32(Request.Params["start"] ?? "0"); if (!string.IsNullOrEmpty(Request.Form["limit"])) { query.Limit = Convert.ToInt32(Request.Params["limit"]); } if (!string.IsNullOrEmpty(Request.Params["ddlSel"])) { query.expired = Convert.ToInt32(Request.Params["ddlSel"]); } if (!string.IsNullOrEmpty(Request.Params["serchcontent"])) { query.key = Request.Params["serchcontent"]; } #endregion _promotionsAmountTrialMgr = new PromotionsAmountTrialMgr(mySqlConnectionString); _prodMgr = new ProductMgr(mySqlConnectionString); int totalCount = 0; _ITrialRecordMgr = new TrialRecordMgr(mySqlConnectionString); store = _promotionsAmountTrialMgr.Query(query, out totalCount); List<Parametersrc> ProductFreightStore = new List<Parametersrc>(); List<Parametersrc> DeviceStore = new List<Parametersrc>(); List<Parametersrc> EventTypeStore = new List<Parametersrc>(); _parasrcMgr = new ParameterMgr(mySqlConnectionString); ProductFreightStore = _parasrcMgr.GetElementType("product_freight");//---deliver_type DeviceStore = _parasrcMgr.GetElementType("device");//--device EventTypeStore = _parasrcMgr.GetElementType("event_type");//--event_type foreach (var item in store) { for (int i = 0; i < ProductFreightStore.Count; i++) { if (int.Parse(ProductFreightStore[i].ParameterCode) == item.freight_type) { item.freight = ProductFreightStore[i].parameterName; } } for (int i = 0; i < DeviceStore.Count; i++) { if (DeviceStore[i].ParameterCode == item.device.ToString()) { item.device_name = DeviceStore[i].parameterName; } } for (int i = 0; i < EventTypeStore.Count; i++) { if (EventTypeStore[i].ParameterCode == item.event_type) { item.eventtype = EventTypeStore[i].parameterName; } } if (item.sale_productid != 0) { item.sale_product_name = _prodMgr.QueryClassify(Convert.ToUInt32(item.sale_productid)).Product_Name; } if (item.event_img_small != "") { item.event_img_small = imgServerPath + promoPath + item.event_img_small; } else { item.event_img_small = defaultImg; } if (item.event_img != "") { item.event_img = imgServerPath + promoPath + item.event_img; } else { item.event_img = defaultImg; } if (item.product_img != "") { if (item.product_img.ToString().StartsWith("T1") || item.product_img.ToString().StartsWith("T2")) { item.product_img = imgServerPath + promoPath + item.product_img; } else { item.product_img = imgServerPath + prodPath + GetDetailFolder(item.product_img) + item.product_img; } } else { item.product_img = defaultImg; } DataTable _dtCount = _ITrialRecordMgr.GetSumCount(item); if (_dtCount.Rows.Count != 0) { if (_dtCount.Rows[0][1].ToString() != "") { item.recordCount = Convert.ToInt32(_dtCount.Rows[0][1].ToString()); }; if (_dtCount.Rows[0][2].ToString() != "") { item.shareCount = Convert.ToInt32(_dtCount.Rows[0][2].ToString()); } } } IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, Formatting.Indented, timeConverter) + "}";//返回json數據 } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); json = "{success:false,totalCount:0,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }