/// <summary>
        /// 更新组合产品的价格,用于Create HM Group页面的价格更新。和非组合产品调用的是同一个方法。
        /// CreateDate:2013年11月19日17:27:11
        /// </summary>
        /// <param name="model"></param>
        /// <param name="costing"></param>
        /// <returns></returns>
        public ActionResult EditHMGroupCosting(CMS_HMNUM_Model model, CMS_HM_Costing_Model costing)
        {
            try
            {
                User_Profile_Model curUserInfo = new CommonController().GetCurrentUserbyCookie(Request[ConfigurationManager.AppSettings["userInfoCookiesKey"]]);

                HmConfigServices hcSvr = new HmConfigServices();
                if (!hcSvr.EditHmnumCosting(model, ref costing, curUserInfo.User_Account))
                {
                    return(Json(new NBCMSResultJson
                    {
                        Status = StatusType.Error,
                        Data = "Fail to udate current HM#'s costing"
                    }));
                }
                return(Json(new NBCMSResultJson
                {
                    Status = StatusType.OK,
                    Data = costing
                }));
            }
            catch (Exception ex)
            {
                NBCMSLoggerManager.Error("");
                NBCMSLoggerManager.Error(ex.Message);
                NBCMSLoggerManager.Error(ex.StackTrace);
                NBCMSLoggerManager.Error("");
                return(Json(new NBCMSResultJson
                {
                    Status = StatusType.Exception,
                    Data = ex.Message
                }));
            }
        }
        /// <summary>
        /// 更新HMNUMCosting的信息,用于HMNUM Management页面的的inline-edit的编辑更新
        /// 需要注意的是每一次的跟新都将在库表新增一条价格信息,影响将来报表的生成。
        /// CreateDate:2013年11月13日6:00:34
        /// </summary>
        /// <param name="model"></param>
        /// <param name="costing"></param>
        /// <returns></returns>
        public bool EditHMNUMCosting(CMS_HMNUM_Model model, CMS_HM_Costing_Model costing, string User_Account)
        {
            //逻辑:先讲当前最新的价格插入到Costing表(注意是新增不是编辑),然后更新当前HMNUM的Costing信息,取最新的那条。
            //EF本身自带有Transaction功能。
            using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
            {
                int retVal     = 0;
                var newCosting = new CMS_HM_Costing
                {
                    CreateBy      = User_Account,
                    CreateOn      = DateTime.Now,
                    EffectiveDate = DateTime.Now,

                    HMNUM           = costing.HMNUM,
                    FirstCost       = Convert.ToDecimal(costing.FirstCost),
                    LandedCost      = Convert.ToDecimal(costing.LandedCost),
                    EstimateFreight = Convert.ToDecimal(costing.EstimateFreight),

                    OceanFreight      = Convert.ToDecimal(costing.OceanFreight),
                    USAHandlingCharge = Convert.ToDecimal(costing.USAHandlingCharge),
                    Drayage           = Convert.ToDecimal(costing.Drayage),
                };
                db.CMS_HM_Costing.Add(newCosting);
                long newCostID = newCosting.HMCostID;
                var  HMNUM     = db.CMS_HMNUM.FirstOrDefault(h => h.ProductID == model.ProductID);
                HMNUM.HMCostID = newCostID;
                retVal         = db.SaveChanges();

                newCosting.HisProductID = HMNUM.ProductID;
                retVal = db.SaveChanges();
                return(retVal > 0);
            }
        }
        /// <summary>
        /// 更新HMNUMCosting的信息,用于HMNUM Management页面的的inline-edit的编辑更新
        /// 需要注意的是每一次的跟新都将在库表新增一条价格信息,影响将来报表的生成。
        /// CreateDate:2013年11月13日6:00:34
        /// </summary>
        /// <param name="model"></param>
        /// <param name="costing"></param>
        /// <returns></returns>
        public ActionResult EditHMNUMCosting(CMS_HMNUM_Model model, CMS_HM_Costing_Model costing)
        {
            try
            {
                string             cookis      = Request[ConfigurationManager.AppSettings["userInfoCookiesKey"]];
                var                serializer  = new JavaScriptSerializer();
                string             decCookies  = CryptTools.Decrypt(cookis);
                User_Profile_Model curUserInfo = serializer.Deserialize(decCookies, typeof(User_Profile_Model)) as User_Profile_Model;

                HMNUMServices hSvr      = new HMNUMServices();
                Boolean       isCreated = hSvr.EditHMNUMCosting(model, costing, curUserInfo.User_Account);
                return(Json(new NBCMSResultJson
                {
                    Status = isCreated == true ? StatusType.OK : StatusType.Error,
                    Data = isCreated == true ? "Done" : "Fail to udate current HM#'s costing"
                }));
            }
            catch (Exception ex)
            {
                NBCMSLoggerManager.Error("");
                NBCMSLoggerManager.Error(ex.Message);
                NBCMSLoggerManager.Error(ex.StackTrace);
                NBCMSLoggerManager.Error("");
                return(Json(new NBCMSResultJson
                {
                    Status = StatusType.Exception,
                    Data = ex.Message
                }));
            }
        }
示例#4
0
 /// <summary>
 /// 放在using里面可以减少一次数据库打开、关闭的操作,但是增加耦合度 并且如果查询价格失败也会导致加入回滚,这让我很纠结...
 /// 如果可以,应该传递 PermaisuriCMSEntities 给该方法...
 /// CreateDate:2013年11月24日19:25:07
 /// </summary>
 /// <param name="model"></param>
 /// <returns>SKU对于的Costing永远只有一个,之所以以List形式出现,是为了以后。。。扩展 以及各个页面的方法兼容</returns>
 public List <CMS_HM_Costing_Model> GetHMCosting(SKU_HM_Relation_Model model)
 {
     using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
     {
         var query = db.CMS_HMNUM.FirstOrDefault(c => c.ProductID == model.ProductID);
         if (query == null)
         {
             return(null);
         }
         var costing = new CMS_HM_Costing_Model
         {
             FirstCost         = query.CMS_HM_Costing.FirstCost.ConvertToNotNull().ToString("C", new CultureInfo("en-US")),
             LandedCost        = query.CMS_HM_Costing.LandedCost.ConvertToNotNull().ToString("C", new CultureInfo("en-US")),
             EstimateFreight   = query.CMS_HM_Costing.EstimateFreight.ConvertToNotNull().ToString("C", new CultureInfo("en-US")),
             OceanFreight      = query.CMS_HM_Costing.OceanFreight.ConvertToNotNull().ToString("C", new CultureInfo("en-US")),
             USAHandlingCharge = query.CMS_HM_Costing.USAHandlingCharge.ConvertToNotNull().ToString("C", new CultureInfo("en-US")),
             Drayage           = query.CMS_HM_Costing.Drayage.ConvertToNotNull().ToString("C", new CultureInfo("en-US")),
             SellSets          = model.R_QTY //这里的SellSets不应该是组合产品的SellSets了..而应该是当前HM和SKU关联的R_QTY....
         };
         List <CMS_HM_Costing_Model> list = new List <CMS_HM_Costing_Model>();
         list.Add(costing);
         return(list);
     }
 }
示例#5
0
        /// <summary>
        /// 更新HMNUMCosting的信息,用于HMNUM Configuration页面的的Costing的编辑更新
        /// 需要注意的是每一次的跟新都将在库表新增一条价格信息,影响将来报表的生成。
        /// 虽然和HMNUMController页面的方法一样,但是还是分开维护,因为2个展示有可能不同,遇到需求变动会变得痛苦!
        /// </summary>
        /// <param name="model"></param>
        /// <param name="costing">输入输出参数,输入时候代表客户端需要更新的价格传递给服务器,输出代表价格跟新后在数据库的实际存储方式。比如,客户端输入10个小数点的数字后....</param>
        /// <param name="userAccount"></param>
        /// <returns></returns>
        public bool EditHmnumCosting(CMS_HMNUM_Model model, ref CMS_HM_Costing_Model costing, string userAccount)
        {
            //逻辑:先讲当前最新的价格插入到Costing表(注意是新增不是编辑),然后更新当前HMNUM的Costing信息,取最新的那条。
            //EF本身自带有Transaction功能。
            using (var db = new PermaisuriCMSEntities())
            {
                var newCosting = new CMS_HM_Costing
                {
                    CreateBy        = userAccount,
                    CreateOn        = DateTime.Now,
                    EffectiveDate   = DateTime.Now,
                    HMNUM           = costing.HMNUM, // out: use unsigned parameter costing....2013年11月14日11:25:25
                    FirstCost       = Convert.ToDecimal(costing.FirstCost),
                    LandedCost      = Convert.ToDecimal(costing.LandedCost),
                    EstimateFreight = Convert.ToDecimal(costing.EstimateFreight),

                    OceanFreight      = Convert.ToDecimal(costing.OceanFreight),
                    USAHandlingCharge = Convert.ToDecimal(costing.USAHandlingCharge),
                    Drayage           = Convert.ToDecimal(costing.Drayage),
                };

                //db.CMS_HM_Costing.Add(newCosting);
                //long newCostID = newCosting.HMCostID;

                var hmnum = db.CMS_HMNUM.FirstOrDefault(h => h.ProductID == model.ProductID);

                //HMNUM.HMCostID = newCostID;
                if (hmnum != null)
                {
                    hmnum.CMS_HM_Costing = newCosting;

                    hmnum.SKU_HM_Relation.Select(r => r.CMS_SKU.CMS_Ecom_Sync ?? (r.CMS_SKU.CMS_Ecom_Sync = new CMS_Ecom_Sync {
                        StatusID = 1//这里可以不用做任何设置,因为后面那个操作会全面覆盖这个...
                    })).ForEach(k =>
                    {
                        k.StatusID   = 0;
                        k.StatusDesc = "NeedSend";
                        k.UpdateBy   = userAccount;
                        k.UpdateOn   = DateTime.Now;
                    });


                    var sb = new StringBuilder();
                    sb.Append(" <b> [FirstCost] </b> : old value =  <span style='color:red'>  " + hmnum.CMS_HM_Costing.FirstCost + " </span> , new Value = <span style='color:red'>  " + newCosting.FirstCost + "  </span>");
                    sb.Append("<br>");

                    sb.Append(" <b> [LandedCost] </b> : old value =  <span style='color:red'>  " + hmnum.CMS_HM_Costing.LandedCost + " </span> , new Value = <span style='color:red'>  " + newCosting.LandedCost + "  </span>");
                    sb.Append("<br>");

                    sb.Append(" <b> [EstimateFreight] </b> : old value =  <span style='color:red'>  " + hmnum.CMS_HM_Costing.EstimateFreight + " </span> , new Value = <span style='color:red'>  " + newCosting.EstimateFreight + "  </span>");

                    sb.Append(" <b> [OceanFreight] </b> : old value =  <span style='color:red'>  " + hmnum.CMS_HM_Costing.OceanFreight + " </span> , new Value = <span style='color:red'>  " + newCosting.OceanFreight + "  </span>");

                    sb.Append(" <b> [USAHandlingCharge] </b> : old value =  <span style='color:red'>  " + hmnum.CMS_HM_Costing.USAHandlingCharge + " </span> , new Value = <span style='color:red'>  " + newCosting.USAHandlingCharge + "  </span>");

                    sb.Append(" <b> [Drayage] </b> : old value =  <span style='color:red'>  " + hmnum.CMS_HM_Costing.Drayage + " </span> , new Value = <span style='color:red'>  " + newCosting.Drayage + "  </span>");
                    sb.Append("<br>");

                    BllExtention.DbRecorder(new LogOfUserOperatingDetails
                    {
                        ModelName    = ModelName,
                        ActionName   = MethodBase.GetCurrentMethod().Name,
                        ActionType   = LogActionTypeEnum.Inert.GetHashCode(),
                        ProductID    = hmnum.ProductID,
                        HMNUM        = hmnum.HMNUM,
                        Descriptions = sb.ToString(),
                        CreateBy     = userAccount,
                        CreateOn     = DateTime.Now
                    });

                    db.SaveChanges();

                    newCosting.HisProductID = hmnum.ProductID;
                }
                var retVal = db.SaveChanges();
                costing.FirstCost       = newCosting.FirstCost.ConvertToNotNull().ToString("C", new CultureInfo("en-US"));
                costing.LandedCost      = newCosting.LandedCost.ConvertToNotNull().ToString("C", new CultureInfo("en-US"));
                costing.EstimateFreight = newCosting.EstimateFreight.ConvertToNotNull().ToString("C", new CultureInfo("en-US"));

                costing.OceanFreight      = newCosting.OceanFreight.ConvertToNotNull().ToString("C", new CultureInfo("en-US"));
                costing.USAHandlingCharge = newCosting.USAHandlingCharge.ConvertToNotNull().ToString("C", new CultureInfo("en-US"));
                costing.Drayage           = newCosting.Drayage.ConvertToNotNull().ToString("C", new CultureInfo("en-US"));

                return(retVal > 0);
            }
        }