public HttpResponseBase SaveItemPrice() { string json = string.Empty; string msg = string.Empty; try { if (!PriceMaster.CheckProdName(Request.Form["product_name"])) { json = "{success:false,msg:'" + Resources.Product.FORBIDDEN_CHARACTER + "'}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } JavaScriptSerializer jsSer = new JavaScriptSerializer(); string items = Request.Form["Items"]; float default_bonus_percent = 0; float.TryParse(Request.Form["default_bonus_percent"] ?? "1", out default_bonus_percent); float bonus_percent = 0; float.TryParse(Request.Form["bonus_percent"] ?? "1", out bonus_percent); int same_price = (Request.Form["same_price"] ?? "") == "on" ? 1 : 0; int accumulated_bonus = (Request.Form["accumulated_bonus"] ?? "") == "on" ? 1 : 0; string start = Request.Form["event_product_start"] ?? Request.Form["event_start"]; string end = Request.Form["event_product_end"] ?? Request.Form["event_end"]; string bonus_start = Request.Form["bonus_percent_start"]; string bonus_end = Request.Form["bonus_percent_end"]; string valid_start = Request.Form["valid_start"]; string valid_end = Request.Form["valid_end"]; if (!string.IsNullOrEmpty(Request.Form["ProductId"]) && !string.IsNullOrEmpty(Request.Form["site_name"])) { #region price_master,item_price 新增站台价格 List<ItemPrice> itemPrices = jsSer.Deserialize<List<ItemPrice>>(items); PriceMaster priceMaster = new PriceMaster { bonus_percent = bonus_percent, default_bonus_percent = default_bonus_percent }; if (!string.IsNullOrEmpty(start)) { priceMaster.event_start = Convert.ToUInt32(CommonFunction.GetPHPTime(start)); } if (!string.IsNullOrEmpty(end)) { priceMaster.event_end = Convert.ToUInt32(CommonFunction.GetPHPTime(end)); } priceMaster.product_name = PriceMaster.Product_Name_FM(Request.Form["product_name"]); priceMaster.site_id = uint.Parse(Request.Form["site_name"]); priceMaster.product_id = uint.Parse(Request.Form["ProductId"]); priceMaster.user_level = uint.Parse(Request.Form["user_level"] ?? "1"); priceMaster.same_price = same_price; priceMaster.accumulated_bonus = Convert.ToUInt32(accumulated_bonus); priceMaster.price_status = 2;//申請審核 priceMaster.price = Convert.ToInt32(itemPrices.Min(m => m.item_money)); priceMaster.event_price = Convert.ToInt32(itemPrices.Min(m => m.event_money)); priceMaster.cost = Convert.ToInt32(itemPrices.Min(m => m.item_cost)); priceMaster.event_cost = Convert.ToInt32(itemPrices.Min(m => m.event_cost)); if (same_price == 0) { priceMaster.max_price = Convert.ToInt32(itemPrices.Max(m => m.item_money)); priceMaster.max_event_price = Convert.ToInt32(itemPrices.Max(m => m.event_money)); } if (!string.IsNullOrEmpty(bonus_start)) { priceMaster.bonus_percent_start = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_start)); } if (!string.IsNullOrEmpty(bonus_start)) { priceMaster.bonus_percent_end = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_end)); } if (!string.IsNullOrEmpty(valid_start)) { priceMaster.valid_start = Convert.ToInt32(CommonFunction.GetPHPTime(valid_start)); } if (!string.IsNullOrEmpty(valid_end)) { priceMaster.valid_end = Convert.ToInt32(CommonFunction.GetPHPTime(valid_end)); } _usersMgr = new UsersMgr(connectionString); System.Data.DataTable dt_User = _usersMgr.Query(Request.Form["user_id"] ?? ""); if (dt_User != null && dt_User.Rows.Count > 0) { priceMaster.user_id = Convert.ToUInt32(dt_User.Rows[0]["user_id"]); } Resource.CoreMessage = new CoreResource("Product"); _priceMasterMgr = new PriceMasterMgr(connectionString); _priceMasterTsMgr = new PriceMasterTsMgr(""); int priceMasterId = _priceMasterMgr.Save(priceMaster, itemPrices, null, ref msg); if (priceMasterId != -1) { //價格修改 申請審核 PriceUpdateApply priceUpdateApply = new PriceUpdateApply { price_master_id = Convert.ToUInt32(priceMasterId) }; priceUpdateApply.apply_user = Convert.ToUInt32((Session["caller"] as Caller).user_id); //價格審核記錄 PriceUpdateApplyHistory applyHistroy = new PriceUpdateApplyHistory(); applyHistroy.user_id = Convert.ToInt32(priceUpdateApply.apply_user); //applyHistroy.price_status = 1; //applyHistroy.type = 3; applyHistroy.price_status = 1; //edit by wwei0216w 2014/12/16 價格修改時 price_status為 2申請審核 applyHistroy.type = 1;//edit by wwei0216w 所作操作為 1:申請審核的操作 _priceUpdateApplyMgr = new PriceUpdateApplyMgr(connectionString); _priceUpdateApplyHistoryMgr = new PriceUpdateApplyHistoryMgr(connectionString); int apply_id = _priceUpdateApplyMgr.Save(priceUpdateApply); if (apply_id != -1) { priceMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault(); priceMaster.apply_id = Convert.ToUInt32(apply_id); applyHistroy.apply_id = apply_id; ArrayList excuteSql = new ArrayList(); excuteSql.Add(_priceMasterMgr.Update(priceMaster)); excuteSql.Add(_priceMasterTsMgr.UpdateTs(priceMaster));//edit by xiangwang0413w 2014/07/22 更新price_master_ts表後用時更新price_master_ts表,以便價格審核 excuteSql.Add(_priceUpdateApplyHistoryMgr.SaveSql(applyHistroy)); _functionMgr = new FunctionMgr(connectionString); string function = Request.Params["function"] ?? ""; Function fun = _functionMgr.QueryFunction(function, "/Product/ProductSave"); int functionid = fun == null ? 0 : fun.RowId; HistoryBatch batch = new HistoryBatch { functionid = functionid }; batch.batchno = Request.Params["batch"] ?? ""; batch.kuser = (Session["caller"] as Caller).user_email; _tableHistoryMgr = new TableHistoryMgr(connectionString); if (_tableHistoryMgr.SaveHistory<PriceMaster>(priceMaster, batch, excuteSql)) { json = "{success:true}"; } else { json = "{success:false,msg:'" + Resources.Product.SAVE_FAIL + "'}"; } } else { json = "{success:false,msg:'" + Resources.Product.SAVE_FAIL + "'}"; } } else { json = "{success:false,msg:'" + msg + "'}"; } #endregion } else { #region product_item_temp 修改临时表数据 ProductTemp proTemp = new ProductTemp { Bonus_Percent = bonus_percent, Default_Bonus_Percent = default_bonus_percent }; List<ProductItemTemp> proItemTemps = jsSer.Deserialize<List<ProductItemTemp>>(items); if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { proTemp.Product_Id = Request.Form["OldProductId"]; proItemTemps.ForEach(m => m.Product_Id = proTemp.Product_Id); } if (!string.IsNullOrEmpty(start)) { proTemp.Bonus_Percent_Start = Convert.ToUInt32(CommonFunction.GetPHPTime(start)); proItemTemps.ForEach(m => m.Event_Product_Start = proTemp.Bonus_Percent_Start); } if (!string.IsNullOrEmpty(end)) { proTemp.Bonus_Percent_End = Convert.ToUInt32(CommonFunction.GetPHPTime(end)); proItemTemps.ForEach(m => m.Event_Product_End = proTemp.Bonus_Percent_End); } if (!string.IsNullOrEmpty(Request.Form["product_price_list"])) { uint product_price_list = 0; uint.TryParse(Request.Form["product_price_list"] ?? "0", out product_price_list); proTemp.Product_Price_List = product_price_list; } if (!string.IsNullOrEmpty(Request.Form["bag_check_money"])) { proTemp.Bag_Check_Money = uint.Parse(Request.Form["bag_check_money"]); } proTemp.show_listprice = Convert.ToUInt32((Request.Form["show_listprice"] ?? "") == "on" ? 1 : 0); proTemp.Writer_Id = (Session["caller"] as Caller).user_id; proTemp.Combo_Type = COMBO_TYPE; proItemTemps.ForEach(m => m.Writer_Id = proTemp.Writer_Id); _productTempMgr = new ProductTempMgr(connectionString); #region PriceMasterTemp PriceMasterTemp priceMasterTemp = new PriceMasterTemp { price_status = 1, default_bonus_percent = default_bonus_percent, bonus_percent = bonus_percent, same_price = same_price }; priceMasterTemp.accumulated_bonus = Convert.ToUInt32(accumulated_bonus); priceMasterTemp.product_id = proTemp.Product_Id; priceMasterTemp.combo_type = COMBO_TYPE; priceMasterTemp.product_name = PriceMaster.Product_Name_FM(Request.Form["product_name"] ?? ""); priceMasterTemp.writer_Id = proTemp.Writer_Id; priceMasterTemp.site_id = 1;//默認站臺1:吉甲地 priceMasterTemp.user_level = 1; priceMasterTemp.price = Convert.ToInt32(proItemTemps.Min(m => m.Item_Money)); priceMasterTemp.event_price = Convert.ToInt32(proItemTemps.Min(m => m.Event_Item_Money)); priceMasterTemp.cost = Convert.ToInt32(proItemTemps.Min(m => m.Item_Cost)); priceMasterTemp.event_cost = Convert.ToInt32(proItemTemps.Min(m => m.Event_Item_Cost)); if (same_price == 0) { priceMasterTemp.max_price = Convert.ToInt32(proItemTemps.Max(m => m.Item_Money)); priceMasterTemp.max_event_price = Convert.ToInt32(proItemTemps.Max(m => m.Event_Item_Money)); } if (!string.IsNullOrEmpty(bonus_start)) { priceMasterTemp.bonus_percent_start = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_start)); } if (!string.IsNullOrEmpty(bonus_start)) { priceMasterTemp.bonus_percent_end = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_end)); } if (!string.IsNullOrEmpty(start)) { priceMasterTemp.event_start = Convert.ToUInt32(CommonFunction.GetPHPTime(start)); } if (!string.IsNullOrEmpty(end)) { priceMasterTemp.event_end = Convert.ToUInt32(CommonFunction.GetPHPTime(end)); } if (!string.IsNullOrEmpty(valid_start)) { priceMasterTemp.valid_start = Convert.ToInt32(CommonFunction.GetPHPTime(valid_start)); } if (!string.IsNullOrEmpty(valid_end)) { priceMasterTemp.valid_end = Convert.ToInt32(CommonFunction.GetPHPTime(valid_end)); } #endregion _productItemTempMgr = new ProductItemTempMgr(connectionString); _priceMasterTempMgr = new PriceMasterTempMgr(connectionString); if (_productItemTempMgr.UpdateCostMoney(proItemTemps) && _productTempMgr.PriceBonusInfoSave(proTemp) > 0) { bool result = false; PriceMasterTemp query = new PriceMasterTemp { writer_Id = priceMasterTemp.writer_Id, product_id = proTemp.Product_Id, combo_type = COMBO_TYPE }; if (_priceMasterTempMgr.Query(query) == null)//插入 { result = _priceMasterTempMgr.Save(new List<PriceMasterTemp> { priceMasterTemp }, null, null); } else//更新 { result = _priceMasterTempMgr.Update(new List<PriceMasterTemp> { priceMasterTemp }, null); } json = "{success:" + result.ToString().ToLower() + "}"; } else { json = "{success:false}"; } #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:'" + Resources.Product.SAVE_FAIL + "'}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase SaveItemPrice() { string json = string.Empty; string msg = string.Empty; try { BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"]; int writerID = (int)vendorModel.vendor_id; //获取前台输入的信息 JavaScriptSerializer jsSer = new JavaScriptSerializer(); string items = Request.Form["Items"]; int same_price = (Request.Form["same_price"] ?? "") == "on" ? 1 : 0; string start = Request.Form["event_product_start"] ?? Request.Form["event_start"]; string end = Request.Form["event_product_end"] ?? Request.Form["event_end"]; string valid_start = Request.Form["valid_start"]; string valid_end = Request.Form["valid_end"]; #region product_item_temp 获取product_item_temp和product_temp的数据 ProductTemp proTemp = new ProductTemp(); List<ProductItemTemp> proItemTemps = jsSer.Deserialize<List<ProductItemTemp>>(items); if (!string.IsNullOrEmpty(Request.Form["ProductId"])) { proTemp.Product_Id = Request.Form["ProductId"].ToString(); proItemTemps.ForEach(m => m.Product_Id = proTemp.Product_Id); } //if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) //{ // proTemp.Product_Id = Request.Form["OldProductId"].ToString(); // proItemTemps.ForEach(m => m.Product_Id = proTemp.Product_Id); //} if (!string.IsNullOrEmpty(start)) { proItemTemps.ForEach(m => m.Event_Product_Start = Convert.ToUInt32(CommonFunction.GetPHPTime(start))); } if (!string.IsNullOrEmpty(end)) { proItemTemps.ForEach(m => m.Event_Product_End = Convert.ToUInt32(CommonFunction.GetPHPTime(end))); } if (!string.IsNullOrEmpty(Request.Form["product_price_list"])) { uint product_price_list = 0; uint.TryParse(Request.Form["product_price_list"] ?? "0", out product_price_list); proTemp.Product_Price_List = product_price_list; } if (!string.IsNullOrEmpty(Request.Form["bag_check_money"])) { proTemp.Bag_Check_Money = uint.Parse(Request.Form["bag_check_money"]); } proTemp.show_listprice = Convert.ToUInt32((Request.Form["show_listprice"] ?? "") == "on" ? 1 : 0); proTemp.Writer_Id = writerID; proTemp.Combo_Type = COMBO_TYPE; proItemTemps.ForEach(m => m.Writer_Id = proTemp.Writer_Id); proTemp.Create_Channel = 2; _productTempMgr = new ProductTempMgr(connectionString); #region PriceMasterTemp 获取PriceMasterTemp的数据 PriceMasterTemp priceMasterTemp = new PriceMasterTemp { price_status = 1, same_price = same_price }; priceMasterTemp.product_id = proTemp.Product_Id; priceMasterTemp.combo_type = COMBO_TYPE; priceMasterTemp.product_name = Request.Form["product_name"] ?? ""; priceMasterTemp.writer_Id = proTemp.Writer_Id; priceMasterTemp.site_id = 1;//默認站臺1:吉甲地 priceMasterTemp.user_level = 1; priceMasterTemp.price = Convert.ToInt32(proItemTemps.Min(m => m.Item_Money)); priceMasterTemp.event_price = Convert.ToInt32(proItemTemps.Min(m => m.Event_Item_Money)); priceMasterTemp.cost = Convert.ToInt32(proItemTemps.Min(m => m.Item_Cost)); priceMasterTemp.event_cost = Convert.ToInt32(proItemTemps.Min(m => m.Event_Item_Cost)); if (same_price == 0) { priceMasterTemp.max_price = Convert.ToInt32(proItemTemps.Max(m => m.Item_Money)); priceMasterTemp.max_event_price = Convert.ToInt32(proItemTemps.Max(m => m.Event_Item_Money)); } if (!string.IsNullOrEmpty(start)) { priceMasterTemp.event_start = Convert.ToUInt32(CommonFunction.GetPHPTime(start)); } if (!string.IsNullOrEmpty(end)) { priceMasterTemp.event_end = Convert.ToUInt32(CommonFunction.GetPHPTime(end)); } if (!string.IsNullOrEmpty(valid_start)) { priceMasterTemp.valid_start = Convert.ToInt32(CommonFunction.GetPHPTime(valid_start)); } if (!string.IsNullOrEmpty(valid_end)) { priceMasterTemp.valid_end = Convert.ToInt32(CommonFunction.GetPHPTime(valid_end)); } #endregion //执行 _productItemTempMgr = new ProductItemTempMgr(connectionString); _priceMasterTempMgr = new PriceMasterTempMgr(connectionString); if (_productItemTempMgr.UpdateCostMoney(proItemTemps) && _productTempMgr.PriceBonusInfoSaveByVendor(proTemp) > 0)//供應商商品無購物金 { bool result = false; PriceMasterTemp query = new PriceMasterTemp { writer_Id = priceMasterTemp.writer_Id, product_id = proTemp.Product_Id, combo_type = COMBO_TYPE }; if (_priceMasterTempMgr.QueryByVendor(query) == null)//插入 { result = _priceMasterTempMgr.Save(new List<PriceMasterTemp> { priceMasterTemp }, null, null); } else//更新 { result = _priceMasterTempMgr.UpdateByVendor(new List<PriceMasterTemp> { priceMasterTemp }, null); } json = "{success:" + result.ToString().ToLower() + "}"; } else { json = "{success:false}"; } #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:'" + Resources.VendorProduct.SAVE_FAIL + "'}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }