/// <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> /// 获取HMNUM的信息 /// </summary> /// <returns></returns> public ActionResult GetHMNUMList(CMS_HMNUM_Model model, int page, int rows) { try { HMNUMServices hSvr = new HMNUMServices(); int count = 0; List <CMS_HMNUM_Model> list = hSvr.GetHMNUMList(model, page, rows, out count); return(Json(new NBCMSResultJson { Status = StatusType.OK, Data = new { total = count, rows = list } })); } 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> /// 通过ID获取当个HMNUM的信息,方法只要包含了当前HMNUM在WEBPO对应的图像的信息。主要给AddMedia页面调用。 /// Created:2014年1月24日15:30:55. /// </summary> /// <param name="ProductID"></param> /// <returns></returns> public CMS_HMNUM_Model GetSingleHMNUMByID(long ProductID) { using (PermaisuriCMSEntities db = new PermaisuriCMSEntities()) { var p = db.CMS_HMNUM.FirstOrDefault(c => c.ProductID == ProductID); if (p == null) { return(null); } var img = db.WebPO_ImageUrls_V.FirstOrDefault(v => v.HMNUM == p.HMNUM && !String.IsNullOrEmpty(v.SmallPic) && !String.IsNullOrEmpty(v.Pic)); String webPoUrl = ConfigurationManager.AppSettings["WebPOProductImageUrl"]; String webpoRelStr = "../../../";//替换掉webPO数据库提取出来的路径前缀 var newHMNUM = new CMS_HMNUM_Model { ProductID = p.ProductID, HMNUM = p.HMNUM, ProductName = p.ProductName, StockKey = p.StockKey, StockKeyQTY = p.CMS_HM_Inventory.StockkeyQTY.ConvertToNotNull(), // 库存 2013年11月24日18:17:06 MaxImaSeq = p.CMS_StockKey.MediaLibrary.FirstOrDefault() == null ? 0 : p.CMS_StockKey.MediaLibrary.OrderByDescending(r => r.SerialNum).FirstOrDefault().SerialNum, webSystemImage = img == null ? null : new OtherSystemImages { SmallPic = webPoUrl + img.SmallPic.Replace(webpoRelStr, ""), Pic = webPoUrl + img.Pic.Replace(webpoRelStr, ""), SystemName = "WebPO System" } }; return(newHMNUM); } }
// ReSharper disable InconsistentNaming public ActionResult AddNewSKU(CMS_SKU_Model model, MCCC mcModel, CMS_HMNUM_Model hmModel, User_Profile_Model userModel) // ReSharper restore InconsistentNaming { try { var skuSvr = new SKUCreateServices(); string msg; var newSkuid = skuSvr.AddProduct(model, mcModel, hmModel, userModel.User_Account, out msg); return(Json(new NBCMSResultJson { Status = newSkuid > 0 ? StatusType.OK : StatusType.Error, Data = newSkuid })); } catch (Exception ex) { NBCMSLoggerManager.Fatal(ex.Message); NBCMSLoggerManager.Fatal(ex.StackTrace); NBCMSLoggerManager.Error(""); return(Json(new NBCMSResultJson { Status = StatusType.Exception, Data = ex.Message })); } }
/// <summary> /// 用户添加组合产品的时候,选择HM# 自动实现AutoCompleted的功能 /// 2013年11月19日10:37:42 /// </summary> /// <param name="hmModel"></param> /// <param name="SKUID"></param> /// <returns></returns> public ActionResult GetProductInfo(CMS_HMNUM_Model hmModel) { try { HMGroupCreateServices gsvr = new HMGroupCreateServices(); /*尝试在前端构建ExcludedProductIDs数组,但是非常复杂,既需要考虑新增,又需要考虑删除,同时还需要考虑更新, * 将原先的id为1的改成ID为2的,非常复杂而且不利于后续维护,最好的办法只能在这里多做一次数据库查询,一劳永逸.. * 2014年3月18日*/ hmModel.ExcludedProductIDs = gsvr.GetChildrenProductID(hmModel.ProductID); return(Json(new NBCMSResultJson { Status = StatusType.OK, Data = new ProductCommonServices().GetProductsByKeyWords(hmModel, 0) })); } catch (Exception ex) { NBCMSLoggerManager.Error(""); NBCMSLoggerManager.Error(ex.Message); NBCMSLoggerManager.Error(ex.Source); NBCMSLoggerManager.Error(ex.StackTrace); NBCMSLoggerManager.Error(""); return(Json(new NBCMSResultJson { Status = StatusType.Error, Data = ex.Message })); } }
/// <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 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 })); } }
/// <summary> /// 编辑HM#基本信息,用于HMNUM Configuration页面 /// </summary> /// <param name="model"></param> /// <returns></returns> public ActionResult EditHmBasicInfo(CMS_HMNUM_Model model) { try { var curUserInfo = new CommonController().GetCurrentUserbyCookie(Request[ConfigurationManager.AppSettings["userInfoCookiesKey"]]); var hcSvr = new HmConfigServices(); if (!hcSvr.EditHmBasicInfo(model, curUserInfo.User_Account)) { return(Json(new NBCMSResultJson { Status = StatusType.Error, Data = "Fail to udate current HM#'s basic info" })); } return(Json(new NBCMSResultJson { Status = StatusType.OK, Data = "OK" })); } 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 })); } }
public ActionResult GetProductInfo(CMS_HMNUM_Model hmModel) { return(Json(new NBCMSResultJson { Status = StatusType.OK, Data = new ProductCommonServices().GetProductsByKeyWords(hmModel, 0) })); }
/// <summary> /// 组合产品的基础信息添加,用于Create New Product Group 页面的第一阶段 /// </summary> /// <param name="gpModel"></param> /// <returns>如果成功,返回新增成功的数据库ID</returns> public ActionResult HMGroupBaseInfoAdd(CMS_HMNUM_Model gpModel) { try { User_Profile_Model curUserInfo = new CommonController().GetCurrentUserbyCookie(Request[ConfigurationManager.AppSettings["userInfoCookiesKey"]]); HMGroupCreateServices gSvr = new HMGroupCreateServices(); string errMsg = string.Empty; long newID = gSvr.HMGroupBaseInfoAdd(gpModel, curUserInfo.User_Account, ref errMsg); if (newID > 0) { return(Json(new NBCMSResultJson { Status = StatusType.OK, Data = newID })); } return(Json(new NBCMSResultJson { Status = StatusType.Error, Data = errMsg == string.Empty ? "Faile to add HM# Group" : errMsg })); } catch (DbEntityValidationException e) { NBCMSLoggerManager.Error(""); NBCMSLoggerManager.Error(""); foreach (var eve in e.EntityValidationErrors) { foreach (var ve in eve.ValidationErrors) { NBCMSLoggerManager.Error(String.Format(" Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage)); } } NBCMSLoggerManager.Error(""); NBCMSLoggerManager.Error(""); return(Json(new NBCMSResultJson { Status = StatusType.Exception, Data = e.Message })); } catch (Exception ex) { NBCMSLoggerManager.Error(""); NBCMSLoggerManager.Error(ex.Message); NBCMSLoggerManager.Error(ex.Source); NBCMSLoggerManager.Error(ex.StackTrace); NBCMSLoggerManager.Error(""); return(Json(new NBCMSResultJson { Status = StatusType.Exception, Data = ex.Message })); } }
/// <summary> /// 编辑HM#基本信息,用于HMNUM Configuration页面 /// </summary> /// <param name="model"></param> /// <param name="userAccount"></param> /// <returns></returns> public bool EditHmBasicInfo(CMS_HMNUM_Model model, string userAccount) { using (var db = new PermaisuriCMSEntities()) { var hmnum = db.CMS_HMNUM.FirstOrDefault(h => h.ProductID == model.ProductID); if (hmnum == null) { return(db.SaveChanges() > 0); } hmnum.StockKey = model.StockKey; hmnum.Comments = model.Comments; hmnum.StatusID = model.StatusID; hmnum.ShipViaTypeID = model.ShipViaTypeID; hmnum.NetWeight = model.NetWeight; 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 entry = db.Entry(hmnum); BllExtention.DbRecorder(entry, new LogOfUserOperatingDetails { ModelName = ModelName, ActionName = MethodBase.GetCurrentMethod().Name, ActionType = LogActionTypeEnum.Update.GetHashCode(), ProductID = hmnum.ProductID, HMNUM = hmnum.HMNUM, CreateBy = userAccount, CreateOn = DateTime.Now }); hmnum.ModifyBy = userAccount; hmnum.ModifyOn = DateTime.Now; return(db.SaveChanges() > 0); } }
// // GET: /HMConfig/ public ActionResult Index() { CMS_HMNUM_Model model = null; var hSvr = new HmConfigServices(); var pID = Request["ProductID"]; if (String.IsNullOrEmpty(pID)) { return(View(model)); } model = hSvr.GetSingleHm(new CMS_HMNUM_Model { ProductID = Convert.ToInt64(pID) }); ViewBag.Media_Data_list = new JavaScriptSerializer().Serialize(model.MediaList);//提供JS脚本做图像的bubble展示使用 2014年5月16日14:25:18... //ViewBag.CMSImgUrl = ConfigurationManager.AppSettings["CMSImgUrl"]; ViewBag.CMSImgUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath + "/MediaLib/Files/"; return(View(model)); }
/// <summary> /// 编辑HM#基本信息,用于HMNUM Configuration页面 /// </summary> /// <param name="model"></param> /// <param name="User_Account"></param> /// <returns></returns> public bool EditHMBasicInfo(CMS_HMNUM_Model model, string User_Account) { using (PermaisuriCMSEntities db = new PermaisuriCMSEntities()) { var HMNUM = db.CMS_HMNUM.FirstOrDefault(h => h.ProductID == model.ProductID); HMNUM.StockKey = model.StockKey; HMNUM.Comments = model.Comments; HMNUM.SKU_HM_Relation.Select(r => r.CMS_SKU.CMS_Ecom_Sync == null ? r.CMS_SKU.CMS_Ecom_Sync = new CMS_Ecom_Sync { StatusID = 1//这里可以不用做任何设置,因为后面那个操作会全面覆盖这个... } : r.CMS_SKU.CMS_Ecom_Sync).ForEach(k => { k.StatusID = 0; k.StatusDesc = "NeedSend"; k.UpdateBy = User_Account; k.UpdateOn = DateTime.Now; }); var entry = db.Entry(HMNUM); BllExtention.DbRecorder(entry, new LogOfUserOperatingDetails { ModelName = Model_Name, ActionName = MethodBase.GetCurrentMethod().Name, ActionType = LogActionTypeEnum.Update.GetHashCode(), ProductID = HMNUM.ProductID, HMNUM = HMNUM.HMNUM, CreateBy = User_Account, CreateOn = DateTime.Now }); HMNUM.ModifyBy = User_Account; HMNUM.ModifyOn = DateTime.Now; return(db.SaveChanges() > 0); } }
/// <summary> /// 组合产品的和基础产品的关联表,存在基础产品就更新,不存在就插入 /// </summary> /// <param name="HMModel"></param> /// <param name="db"></param> public void HMNUMGroup_Action(CMS_SKU_Model skuModel, EcomEntities db, ref int pieces) { CMS_HMNUM_Model HMModel = skuModel.SKU_HM_Relation.CMS_HMNUM; pieces = 0; if (!HMModel.IsGroup) { return; } foreach (var subHM in HMModel.Children_CMS_HMNUM_List) { var subImgPath = string.Empty; var hmPImgObj = subHM.MediaList.FirstOrDefault(m => m.IsPrimaryImages == true); if (hmPImgObj != null) { subImgPath = Path.Combine(skuModel.CMSPhysicalPath, hmPImgObj.HMNUM + "\\" + hmPImgObj.ImgName + hmPImgObj.fileFormat); } this.HMNUM_Action(subHM, db, 1, subImgPath, decimal.Parse(skuModel.SKU_Costing.EstimateFreight, NumberStyles.Currency, new CultureInfo("en-US")));//调用内部方法,插入or更新HMNUM 2014年4月22日16:17:23 pieces += subHM.SellSets; var query = db.ProductGroup.FirstOrDefault(g => g.HMNUM == subHM.HMNUM && g.HMNUMParent == HMModel.HMNUM); if (query == null)//【不】存在基础产品-组合产品的一条记录 { db.ProductGroup.Add(new ProductGroup { HMNUMParent = HMModel.HMNUM, HMNUM = subHM.HMNUM, Description = subHM.ProductName, SellSets = subHM.SellSets }); } else//存在基础产品-组合产品的一条记录 { query.SellSets = subHM.SellSets; query.Description = subHM.ProductName; } } }
/// <summary> /// 为批量删除提供HM关联的 autoCompelted使用 /// CreateDate:2013年11月27日15:31:37 /// </summary> /// <param name="hmModel"></param> /// <returns></returns> public ActionResult GetProductInfo(CMS_HMNUM_Model hmModel) { try { return(Json(new NBCMSResultJson { Status = StatusType.OK, Data = new ProductCommonServices().GetProductsByKeyWords(hmModel, 0) })); } catch (Exception ex) { NBCMSLoggerManager.Error(""); NBCMSLoggerManager.Error(ex.Message); NBCMSLoggerManager.Error(ex.Source); NBCMSLoggerManager.Error(ex.StackTrace); NBCMSLoggerManager.Error(""); return(Json(new NBCMSResultJson { Status = StatusType.Error, Data = ex.Message })); } }
public CMS_HMNUM_Model GetSingleHm(CMS_HMNUM_Model qModel) { using (var db = new PermaisuriCMSEntities()) { var query = db.CMS_HMNUM.Include(h => h.CMS_ProductCTN).Include(h => h.CMS_ProductDimension) .FirstOrDefault(h => h.ProductID == qModel.ProductID); if (query == null) { return(null); } var rModel = new CMS_HMNUM_Model { ProductID = query.ProductID, StockKeyID = query.StockKeyID, Comments = query.Comments, ProductName = query.ProductName, StockKey = query.StockKey, MasterPack = query.MasterPack, StockKeyQTY = query.CMS_HM_Inventory == null ? 0 : query.CMS_HM_Inventory.StockkeyQTY.ConvertToNotNull(), StatusID = query.StatusID, NetWeight = query.NetWeight.ConvertToNotNull(), CMS_HMNUM_Status = new CMS_HMNUM_Status_Model { StatusID = query.CMS_HMNUM_Status.StatusID, StatusName = query.CMS_HMNUM_Status.StatusName }, CMS_ShipVia_Type = new CMS_ShipViaType_Model { //这里设置为-1的原因是因为....避免和List里面的All(id=0)起冲突...2014年5月7日18:04:15 ShipViaTypeID = query.CMS_ShipViaType == null ? -1 : query.CMS_ShipViaType.ShipViaTypeID, ShipViaTypeName = query.CMS_ShipViaType == null ? "" : query.CMS_ShipViaType.ShipViaTypeName//返回空给前端 }, //2013年12月12日18:21:54 这里有个前提,CMS_HMNUM的CategoryID存储的一定是子类的CatgeoryID,绝无可能是大类的ID! // 再也不要相信这个verCD的假设了,在测试了的时候被提了100遍的BUG,一百遍啊一百遍!!! 2014年2月19日15:31:03 Category = new WebPO_Category_V_Model { CategoryID = query.WebPO_Category_V == null ? 0 : query.WebPO_Category_V.CategoryID, CategoryName = query.WebPO_Category_V == null ? "NONE" : query.WebPO_Category_V.CategoryName, OrderIndex = query.WebPO_Category_V == null ? 0 : query.WebPO_Category_V.OrderIndex.ConvertToNotNull(), ParentCategoryID = query.WebPO_Category_V == null ? 0 : query.WebPO_Category_V.ParentCategoryID.ConvertToNotNull(), ParentCategoryName = query.WebPO_Category_V == null ? "NONE" : query.WebPO_Category_V.ParentCategoryName }, //CategoryID = query.WebPO_Category_V.CategoryID, //CategoryName = query.WebPO_Category_V.CategoryName, //SubCategoryID = query.CategoryID, //SubCategoryName =query.WebPO_Category_V.SubCategoryName, HMColour = new CMS_HMNUM_Colour_Model { ColourID = query.WebPO_Colour_V == null ? -1 : query.WebPO_Colour_V.ColourID, ColourName = query.WebPO_Colour_V == null ? "NONE" : query.WebPO_Colour_V.ColourDesc }, HMMaterial = new CMS_HMNUM_Material_Model { MaterialID = query.WebPO_Material_V == null ? -1 : query.WebPO_Material_V.MaterialID, MaterialName = query.WebPO_Material_V == null ? "NONE" : query.WebPO_Material_V.MaterialName }, HMNUM = query.HMNUM, HM_Costing = new CMS_HM_Costing_Model//价格 { FirstCost = query.CMS_HM_Costing == null ? "$0.00" : query.CMS_HM_Costing.FirstCost.ConvertToNotNull().ToString("C", new CultureInfo("en-US")), LandedCost = query.CMS_HM_Costing == null ? "$0.00" : query.CMS_HM_Costing.LandedCost.ConvertToNotNull().ToString("C", new CultureInfo("en-US")), EstimateFreight = query.CMS_HM_Costing == null ? "$0.00" : query.CMS_HM_Costing.EstimateFreight.ConvertToNotNull().ToString("C", new CultureInfo("en-US")), OceanFreight = query.CMS_HM_Costing == null ? "$0.00" : query.CMS_HM_Costing.OceanFreight.ConvertToNotNull().ToString("C", new CultureInfo("en-US")), USAHandlingCharge = query.CMS_HM_Costing == null ? "$0.00" : query.CMS_HM_Costing.USAHandlingCharge.ConvertToNotNull().ToString("C", new CultureInfo("en-US")), Drayage = query.CMS_HM_Costing == null ? "$0.00" : query.CMS_HM_Costing.Drayage.ConvertToNotNull().ToString("C", new CultureInfo("en-US")) }, CTNList = query.CMS_ProductCTN.Select(h => new CMS_ProductCTN_Model//箱柜 { CTNID = h.CTNID, CTNTitle = h.CTNTitle, CTNHeight = h.CTNHeight.ConvertToNotNull(),//JUST Testing 2013年11月11日11:36:48 CTNLength = h.CTNLength.HasValue ? h.CTNLength.Value : 0, CTNWidth = h.CTNWidth.HasValue ? h.CTNWidth.Value : 0, CTNCube = h.CTNCube.HasValue ? h.CTNCube.Value : 0, CTNComment = h.CTNComment, CTNWeight = h.CTNWeight.HasValue ? h.CTNWeight.Value : 0 }).ToList(), DimList = query.CMS_ProductDimension.Select(d => new CMS_ProductDimension_Model//尺寸 { DimID = d.DimID, DimTitle = d.DimTitle, DimHeight = d.DimHeight.HasValue ? d.DimHeight.Value : 0, DimLength = d.DimLength.HasValue ? d.DimLength.Value : 0, DimWidth = d.DimWidth.HasValue ? d.DimWidth.Value : 0, DimCube = d.DimCube.HasValue ? d.DimCube.Value : 0, DimComment = d.DimComment }).ToList(), SKUList = query.SKU_HM_Relation.Select(r => new CMS_SKU_Model//和当前HM关联的SKUOrder { SKUID = r.SKUID, SKU = r.CMS_SKU.SKU, ProductName = r.CMS_SKU.ProductName, ChannelID = r.CMS_SKU.ChannelID, ChannelName = r.CMS_SKU.Channel.ChannelName, BrandID = r.CMS_SKU.BrandID, BrandName = r.CMS_SKU.Brand.BrandName }).ToList(), Parents_CMS_HMNUM_List = query.CMS_HMGroup_Relation_SUB.Select(r => new CMS_HMNUM_Model { ProductID = r.CMS_HMNUM.ProductID, MasterPack = r.CMS_HMNUM.MasterPack, HMNUM = r.CMS_HMNUM.HMNUM, ProductName = r.CMS_HMNUM.ProductName, StockKey = r.CMS_HMNUM.StockKey, StockKeyQTY = r.CMS_HMNUM.CMS_HM_Inventory == null ? 0 : r.CMS_HMNUM.CMS_HM_Inventory.StockkeyQTY.ConvertToNotNull() }).ToList(), MediaList = query.CMS_StockKey.MediaLibrary.Select(r => new MediaLibrary_Model { //2013年12月25日10:23:15 MediaID = r.MediaID, ProductID = r.ProductID, HMNUM = r.HMNUM, ImgName = r.ImgName, fileFormat = r.fileFormat, MediaType = r.MediaType, SerialNum = r.SerialNum, IsPrimaryImages = r.PrimaryImage.HasValue && r.PrimaryImage.Value, fileHeight = r.fileHeight.ConvertToNotNull(), fileSize = r.fileSize, fileWidth = r.fileWidth.ConvertToNotNull(), CloudStatusID = r.CloudStatusID, strCreateOn = r.CreateOn.ToString("yyyy-MM-dd HH:mm:ss"), CMS_SKU = r.SKU_Media_Relation.Where(k => k.MediaID == r.MediaID).Select(s => new CMS_SKU_Model { ChannelName = s.CMS_SKU.Channel.ChannelName, ProductName = s.CMS_SKU.ProductName, SKU = s.CMS_SKU.SKU }).ToList() }).ToList() }; return(rModel); } }
/// <summary> /// For ProductConfiguration page AJAX Searching, /// ChangeDate:新增一个int类型用来指示:0-default:获取全部 1:获取非组合产品 ,2:仅获取组合产品 /// </summary> /// <param name="hmModel"></param> /// <param name="skuid"></param> /// <returns></returns> public List <CMS_HMNUM_Model> GetProductsByKeyWords(CMS_HMNUM_Model hmModel, long skuid) { var list = new List <CMS_HMNUM_Model>(); using (var db = new PermaisuriCMSEntities()) { var query = db.CMS_HMNUM.AsQueryable(); if (skuid > 0) { query = query.Except(query.Where(p => p.SKU_HM_Relation.Any(r => r.SKUID == skuid))); } if (!String.IsNullOrEmpty(hmModel.ProductName)) { query = query.Where(p => p.ProductName.StartsWith(hmModel.ProductName)); } //2014年3月18日:改变模糊搜索的方法从原来全量模糊改成现在的开头模糊 if (!String.IsNullOrEmpty(hmModel.HMNUM)) { query = query.Where(p => p.HMNUM.StartsWith(hmModel.HMNUM)); } if (hmModel.StatusID > 0) // 新增审核状态判断 2014年5月20日14:59:51 { query = query.Where(p => p.StatusID == hmModel.StatusID); } if (hmModel.HMType > 0) //2013年11月27日9:15:42 { switch (hmModel.HMType) { case 1: //非组合产品,注意需要查询为Null的历史数据 query = query.Where(p => p.IsGroup == false || p.IsGroup == null); break; case 2: //仅组合产品 query = query.Where(p => p.IsGroup == true); break; default: break; } } if (hmModel.ExcludedProductIDs != null && hmModel.ExcludedProductIDs.Count > 0) { query = query.Except(query.Where(c => hmModel.ExcludedProductIDs.Contains(c.ProductID))); } query = query.Take(10); query = query.Include(h => h.CMS_HM_Inventory) .Include(h => h.CMS_StockKey.MediaLibrary) .Include(h => h.WebPO_Category_V) .Include(h => h.WebPO_Material_V) .Include(h => h.WebPO_Colour_V) .Include(h => h.CMS_ShipViaType) ; list.AddRange(from p in query let img = db.WebPO_ImageUrls_V.FirstOrDefault(v => v.HMNUM == p.HMNUM) select new CMS_HMNUM_Model { ProductID = p.ProductID, MasterPack = p.MasterPack, strMasterPack = p.IsGroup == true ? "N/A" : p.MasterPack.ToString(), HMNUM = p.HMNUM, ProductName = p.ProductName, StockKey = p.StockKey, StockKeyID = p.StockKeyID, StockKeyQTY = p.CMS_HM_Inventory.StockkeyQTY.ConvertToNotNull(), // 库存 2013年11月24日18:17:06 //MaxImaSeq = p.MediaLibrary.Max(r => r.SerialNum)//Sequence contains no elements MaxImaSeq = p.CMS_StockKey.MediaLibrary.FirstOrDefault() == null ? 0 : p.CMS_StockKey.MediaLibrary.OrderByDescending(r => r.SerialNum).FirstOrDefault() .SerialNum, webSystemImage = img == null ? null : new OtherSystemImages { SmallPic = _webPoUrl + img.SmallPic.Replace(WebpoRelStr, ""), Pic = _webPoUrl + img.Pic.Replace(WebpoRelStr, ""), SystemName = "WebPO System" }, Category = p.WebPO_Category_V == null ? null : new WebPO_Category_V_Model { CategoryName = p.WebPO_Category_V.CategoryName, ParentCategoryID = p.WebPO_Category_V.ParentCategoryID.ConvertToNotNull(), ParentCategoryName = p.WebPO_Category_V.ParentCategoryName }, HMMaterial = p.WebPO_Material_V == null ? null : new CMS_HMNUM_Material_Model { MaterialName = p.WebPO_Material_V.MaterialName }, HMColour = p.WebPO_Colour_V == null ? null : new CMS_HMNUM_Colour_Model { ColourName = p.WebPO_Colour_V.ColourDesc }, CMS_ShipVia_Type = p.CMS_ShipViaType == null ? null : new CMS_ShipViaType_Model { ShipViaTypeID = p.CMS_ShipViaType.ShipViaTypeID, ShipViaTypeName = p.CMS_ShipViaType.ShipViaTypeName } }); return(list); } }
/// <summary> /// 组合产品的基础信息添加,用于Create New Product Group 页面的第一阶段 /// Change:增加一个重复HMNUM插入的判断,如果已经存在则不插入,返回错误提示。2013年11月19日11:08:15 /// Change2:新增StockKey关联表,所以在插入之前需要新增插入StockKey表 2014年3月25日 /// </summary> /// <param name="gpModel"></param> /// <param name="User_Account"></param> /// <returns></returns> public long HMGroupBaseInfoAdd(CMS_HMNUM_Model gpModel, String User_Account, ref string errMsg) { using (PermaisuriCMSEntities db = new PermaisuriCMSEntities()) { errMsg = string.Empty; var query = db.CMS_HMNUM.Where(c => c.HMNUM == gpModel.HMNUM).FirstOrDefault(); if (query != null) { errMsg = String.Format("this item (HMNUM={0}) has been existed!", gpModel.HMNUM); return(0); } var newCosting = new CMS_HM_Costing { CreateBy = User_Account, CreateOn = DateTime.Now, EffectiveDate = DateTime.Now, HMNUM = gpModel.HMNUM, FirstCost = 0, LandedCost = 0, EstimateFreight = 0, HisProductID = 0 }; var newStockkey = new CMS_StockKey { StockKey = gpModel.HMNUM,//stockKey拿HMNUM 2014年2月18日15:05:25 CreateOn = User_Account, CreateTime = DateTime.Now, UpdateOn = User_Account, UdateTime = DateTime.Now }; var newModel = new CMS_HMNUM { HMNUM = gpModel.HMNUM, ProductName = gpModel.ProductName, Comments = gpModel.Comments, HMCostID = gpModel.HMCostID, CategoryID = gpModel.CategoryID, ColourID = 0, MaterialID = 0, IsGroup = true, StatusID = gpModel.StatusID, ShipViaTypeID = gpModel.ShipViaTypeID, NetWeight = gpModel.NetWeight, CreateOn = DateTime.Now, CreateBy = User_Account, ModifyOn = DateTime.Now, ModifyBy = User_Account, MasterPack = 1,//组合产品默认设置为1 Lee 2014年2月12日16:13:12 2014年3月25日 //StockKey = gpModel.HMNUM,//stockKey拿HMNUM 2014年2月18日15:05:25 CMS_StockKey = newStockkey, StockKey = newStockkey.StockKey, CMS_HM_Costing = newCosting//2014年3月18日 }; db.CMS_HMNUM.Add(newModel); db.SaveChanges(); newCosting.HisProductID = newModel.ProductID; db.SaveChanges(); return(newModel.ProductID); } }
/// <summary> /// /// </summary> /// <param name="HMModel"></param> /// <param name="db"></param> /// <param name="UnitQTY">用于给eCom前端展示及套件,比如4张椅子1个座子,就是S/5,5件套</param> /// <param name="imagePath">源文件路径 Formate: D:\\CMS\\Files\\123.jpg</param> /// <param name="SKUFreight">SKU的运费,用于给eCom同步的2014年5月28日</param> public void HMNUM_Action(CMS_HMNUM_Model HMModel, EcomEntities db, int UnitQTY, string imagePath, decimal SKUFreight) { if (HMModel.CMS_ShipVia_Type == null)//HMModel.CMS_ShipVia_Type.CMS_ShipVia_Default.SHIPVIA { throw new Exception("This HMNUM does not set ShipVia Type"); } if (HMModel.CMS_ShipVia_Type.CMS_ShipVia_Default == null) { throw new Exception("This HMNUM does not set ShipVia"); } var query = db.Product.FirstOrDefault(p => p.HMNUM == HMModel.HMNUM); if (!string.IsNullOrEmpty(imagePath) && File.Exists(imagePath)) { //如果不存在,需要增加图片拷贝和略缩图生成的步骤的步骤 var eComImageStoragePath = ConfigurationManager.AppSettings["eComImageStoragePath"]; var strNewPath = Path.Combine(eComImageStoragePath, HMModel.HMNUM); //先判断Width长还是height长 CMSImageTools.SmallImageGenerator(imagePath, strNewPath + "_320.jpg", 320); CMSImageTools.SmallImageGenerator(imagePath, strNewPath + "_80.jpg", 80); } if (query == null)//不存在插入Product { db.Product.Add(new Product { HMNUM = HMModel.HMNUM, StockID = 0, SKUBest = HMModel.StockKey, TAGNUM = string.Empty, Location = string.Empty, BarUPC = string.Empty, //暂时为空 ProductPicture = imagePath == "" ? null : HMModel.HMNUM + "_80.jpg", Unit = HMModel.IsGroup == true ? "S/" + UnitQTY : "S/1", //【注意:】这里不应该拿SellSets,应该拿Pieces! Colour = HMModel.HMColour == null ? null : HMModel.HMColour.ColourName, Weight = Convert.ToDouble(HMModel.NetWeight), MasterPack = Convert.ToInt16(HMModel.MasterPack), //SellSets = HMModel.SellSets, SellSets = HMModel.IsGroup == true ? 1 : HMModel.SellSets,//eComd的组合产品也有SellSets这个概念,默认设置为12014年5月6日17:59:05 Boxes = 1, //Freight = HMModel.HM_Costing == null ? 0 : decimal.Parse(HMModel.HM_Costing.EstimateFreight, NumberStyles.Currency, new CultureInfo("en-US")),//wl -1 Freight = SKUFreight == 0 ? 1 : SKUFreight, //wl -1 CostHM = HMModel.HM_Costing == null ? 0 : decimal.Parse(HMModel.HM_Costing.FirstCost, NumberStyles.Currency, new CultureInfo("en-US")), Status = "Pending", //让当前新增的HMNUM进入eCom的审核列表! Comment = HMModel.Comments, DescriptionHM = HMModel.ProductName, SHIPVIA = HMModel.CMS_ShipVia_Type.CMS_ShipVia_Default.SHIPVIA,//2014年5月14日10:42:29 ColourHM = HMModel.HMColour == null ? null : HMModel.HMColour.ColourName, Category = HMModel.Category == null ? null : HMModel.Category.ParentCategoryName, SubCategory = HMModel.Category == null ? null : HMModel.Category.CategoryName, IsGroup = HMModel.IsGroup, LowStock = 10 }); } else//存在跟新Product { query.ProductPicture = imagePath == "" ? query.ProductPicture : HMModel.HMNUM + "_80.jpg"; query.SKUBest = HMModel.StockKey; query.Comment = HMModel.Comments; query.Weight = Convert.ToDouble(HMModel.NetWeight); query.MasterPack = Convert.ToInt16(HMModel.MasterPack); query.DescriptionHM = HMModel.ProductName; //query.SellSets = HMModel.SellSets; query.SellSets = HMModel.IsGroup == true ? 1 : HMModel.SellSets;//eComd的组合产品也有SellSets这个概念 query.Category = HMModel.Category == null ? null : HMModel.Category.ParentCategoryName; query.SubCategory = HMModel.Category == null ? null : HMModel.Category.CategoryName; query.CostHM = HMModel.HM_Costing == null ? 0 : decimal.Parse(HMModel.HM_Costing.FirstCost, NumberStyles.Currency, new CultureInfo("en-US")); //query.Freight = decimal.Parse(HMModel.HM_Costing.EstimateFreight, NumberStyles.Currency, new CultureInfo("en-US")); //wl-1 //query.SHIPVIA = HMModel.CMS_ShipVia_Type.CMS_ShipVia_Default.SHIPVIA;先不同步! 2014年6月9日17:29:22 } }
/// <summary> /// 对于箱柜尺寸的处理,就是先根据HMNUM删除所有信息,再重新插入 /// </summary> /// <param name="HMModel"></param> /// <param name="db"></param> public void Carton_Action(CMS_HMNUM_Model HMModel, EcomEntities db) { var IsExistCTN = db.ProductCartons.FirstOrDefault(c => c.HMNUM == HMModel.HMNUM);//存在,则删之 if (IsExistCTN != null) { //由于CMS整理出来的HM-ALL item的箱柜尺寸的信息不是非常的规范,所以暂时对已经存在于eCOM的这些信息不做任何处理 //db.ProductCartons.Delete(p => p.HMNUM == HMModel.HMNUM); return; } if (HMModel.IsGroup)//如果箱柜为空,则拿CMS的数据插入 { foreach (var subHM in HMModel.Children_CMS_HMNUM_List) { int ctnNum = 1; foreach (var ctn in subHM.CTNList)//一个HMNUM可以对应多个HMNUM { db.ProductCartons.Add(new ProductCartons { HMNUM = HMModel.HMNUM,//这里取的不是基础产品,而是组合产品! CartonNumber = ctnNum++, Description = subHM.ProductName, CL = Convert.ToDouble(ctn.CTNLength), CW = Convert.ToDouble(ctn.CTNWidth), CH = Convert.ToDouble(ctn.CTNHeight), PL = Convert.ToDouble(subHM.DimList[0].DimLength),//默认取第一个,原因在Dimesion这个类的注释里面做说明了 PW = Convert.ToDouble(subHM.DimList[0].DimWidth), PH = Convert.ToDouble(subHM.DimList[0].DimHeight), //WEIGHTOFPRODUCT = 0, WEIGHTOFPRODUCT = Convert.ToInt32(HMModel.NetWeight), //产品净重量 WEIGHTOFSHIPMENT = Convert.ToInt32(ctn.CTNWeight), //产品+箱子重量 COMMENTS = ctn.CTNComment, SubHMNUM = subHM.HMNUM }); } } } else { int ctnNum = 1; foreach (var ctn in HMModel.CTNList) { db.ProductCartons.Add(new ProductCartons { HMNUM = HMModel.HMNUM, CartonNumber = ctnNum++, Description = HMModel.ProductName, CL = Convert.ToDouble(ctn.CTNLength), CW = Convert.ToDouble(ctn.CTNWidth), CH = Convert.ToDouble(ctn.CTNHeight), PL = Convert.ToDouble(HMModel.DimList[0].DimLength),//默认取第一个,原因在Dimesion这个类的注释里面做说明了 PW = Convert.ToDouble(HMModel.DimList[0].DimWidth), PH = Convert.ToDouble(HMModel.DimList[0].DimHeight), WEIGHTOFPRODUCT = Convert.ToInt32(HMModel.NetWeight),//产品净重量 WEIGHTOFSHIPMENT = Convert.ToInt32(ctn.CTNWeight), COMMENTS = ctn.CTNComment, SubHMNUM = string.Empty }); } } }
/// <summary> /// 新增SKU产品 /// CrateDate:2013年11月24日17:40:08 /// </summary> /// <param name="model"></param> /// <param name="Modifier"></param> /// <param name="msg"></param> /// <returns></returns> public long AddProduct(CMS_SKU_Model model, MCCC mcModel, CMS_HMNUM_Model HMModel, String Modifier, out string msg) { using (PermaisuriCMSEntities db = new PermaisuriCMSEntities()) { msg = ""; var query = db.CMS_SKU.Where(w => w.SKU == model.SKU && w.ChannelID == model.ChannelID).FirstOrDefault(); if (query != null) { msg = string.Format("this item is already exist"); return(-1); } var mat = db.CMS_SKU_Material.FirstOrDefault(s => s.MaterialName == mcModel.Material); if (mat == null) { mat = new CMS_SKU_Material { CreateBy = Modifier, CreateOn = DateTime.Now, ModifyBy = Modifier, ModifyOn = DateTime.Now, MaterialDesc = mcModel.Material, MaterialName = mcModel.Material }; db.CMS_SKU_Material.Add(mat); } var col = db.CMS_SKU_Colour.FirstOrDefault(s => s.ColourName == mcModel.Colour); if (col == null) { col = new CMS_SKU_Colour { CreateBy = Modifier, CreateOn = DateTime.Now, ModifyBy = Modifier, ModifyOn = DateTime.Now, ColourDesc = mcModel.Colour, ColourName = mcModel.Colour }; db.CMS_SKU_Colour.Add(col); } var cat = db.CMS_SKU_Category.FirstOrDefault(s => s.CategoryName == mcModel.Category && s.ParentID == 0); if (cat == null) { cat = new CMS_SKU_Category { CreateBy = Modifier, CreateOn = DateTime.Now, UpdateBy = Modifier, UpdateOn = DateTime.Now, CategoryName = mcModel.Category, CategoryDesc = mcModel.Category, OrderIndex = 0, ParentID = 0 }; db.CMS_SKU_Category.Add(cat); db.SaveChanges(); } var subCat = db.CMS_SKU_Category.FirstOrDefault(s => s.CategoryName == mcModel.SubCategory && s.ParentID != 0); if (subCat == null) { subCat = new CMS_SKU_Category { //CategoryID = ++i, CreateBy = Modifier, CreateOn = DateTime.Now, UpdateBy = Modifier, UpdateOn = DateTime.Now, CategoryName = mcModel.SubCategory, CategoryDesc = mcModel.SubCategory, OrderIndex = 0, //CMS_SKU_Category_Parent = cat ParentID = cat.CategoryID }; db.CMS_SKU_Category.Add(subCat); } var newCosting = new CMS_SKU_Costing { SalePrice = 0, EstimateFreight = 0, EffectiveDate = DateTime.Now, CreateBy = Modifier, CreateOn = DateTime.Now }; //db.CMS_SKU_Costing.Add(newCosting); //db.SaveChanges(); CMS_SKU newProduct = new CMS_SKU { //SKUCostID = 0, //default...为0 会导致后期查询的如果不做NULL排除,会得到意想不到的错误! CMS_SKU_Costing = newCosting, SKU = model.SKU, ProductName = model.ProductName, SKU_QTY = model.SKU_QTY, ChannelID = model.ChannelID, UPC = model.UPC, StatusID = 1,//2014年3月5日 New Visibility = model.Visibility, ProductDesc = model.ProductDesc, Specifications = model.Specifications, Keywords = model.Keywords, BrandID = model.BrandID, RetailPrice = model.RetailPrice, URL = model.URL, //MaterialID = mat.MaterialID, //ColourID = col.ColourID, //CategoryID = cat.CategoryID, //SubCategoryID = subCat.CategoryID, CMS_SKU_Material = mat, CMS_SKU_Colour = col, CMS_SKU_Category = cat, CMS_SKU_Category_Sub = subCat, CMS_Ecom_Sync = new CMS_Ecom_Sync { //SKUID = query.SKUID,坑爹啊 害死人,对象空引用!2014年4月9日 StatusID = 0, StatusDesc = "NeedSend", UpdateBy = Modifier, UpdateOn = DateTime.Now }, CreateBy = Modifier, CreateOn = DateTime.Now, UpdateBy = Modifier, UpdateOn = DateTime.Now, ShipViaTypeID = model.ShipViaTypeID }; //db.CMS_SKU.Add(newProduct); var newHM = db.CMS_HMNUM.Find(HMModel.ProductID); SKU_HM_Relation rModel = new SKU_HM_Relation { CMS_HMNUM = newHM, CMS_SKU = newProduct, StockKeyID = newHM.StockKeyID, R_QTY = HMModel.R_QTY, CreateBy = Modifier, CreateOn = DateTime.Now, UpdateBy = Modifier, UpdateOn = DateTime.Now }; db.SKU_HM_Relation.Add(rModel); db.SaveChanges(); newCosting.HisSKUID = newProduct.SKUID;//经测试:如果让这个生效,一定要在此之前先发生一次db.SaveChanges(),即使是使用强类型嵌套插入也需要这样save 2 次....2014年3月10日 db.SaveChanges(); return(newProduct.SKUID); } }
/// <summary> /// 根据各种条件查询出HMNUM的信息 /// 2013年11月12日15:50:27 Lee /// </summary> /// <param name="model"></param> /// <param name="page"></param> /// <param name="rows"></param> /// <returns></returns> public List <CMS_HMNUM_Model> GetHMNUMList(CMS_HMNUM_Model model, int page, int rows, out int count) { using (PermaisuriCMSEntities db = new PermaisuriCMSEntities()) { count = 0; List <CMS_HMNUM_Model> list = new List <CMS_HMNUM_Model>(); var query = db.CMS_HMNUM.Include(H => H.CMS_HM_Costing).AsQueryable();//include减少了10次查询,底层EF这增加了很多SQL语句 2013年11月20日16:46:00 if (!String.IsNullOrEmpty(model.HMNUM)) { query = query.Where(H => H.HMNUM.StartsWith(model.HMNUM)); } if (!String.IsNullOrEmpty(model.ProductName)) { query = query.Where(H => H.ProductName.Contains(model.ProductName)); } if (!String.IsNullOrEmpty(model.StockKey)) { query = query.Where(H => H.StockKey.Contains(model.StockKey)); } if (model.queryIsGroup > 0) { if (model.queryIsGroup == 1)// <option value="1">HM#</option> { query = query.Where(H => H.IsGroup == false || H.IsGroup == null); } else { query = query.Where(H => H.IsGroup == true); } } if (model.ISOrphan)//是否只查询还未和SKU关联的HM# 2013年12月2日16:14:22 { //query = query.Where(H => H.SKU_HM_Relation.Count < 1); query = query.Except(query.Where(H => H.SKU_HM_Relation.Count > 0)); } if (model.IsExcludedSubHMNUM) { //query = query.Except(query.Where(H => H.CMS_HMGroup_Relation.Count > 0)); query = query.Except(query.Where(H => H.CMS_HMGroup_Relation_SUB.Count > 0)); } if (model.StatusID > 0)//-1代表All 2014年1月10日15:20:26,注意,这里假设数据库没有存在Null的数据 { query = query.Where(H => H.StatusID == model.StatusID); } if (model.RequestType > 0) { switch (model.RequestType) { case 1: query = query.Where(H => H.StatusID == 1); break; case 2: query = query.Where(H => H.StatusID == 2 || H.StatusID == 3); break; default: break; } } if (model.ShipViaTypeID > 0) { switch (model.ShipViaTypeID) { case 1: query = query.Where(H => H.ShipViaTypeID == model.ShipViaTypeID || H.ShipViaTypeID == null); break; default: query = query.Where(H => H.ShipViaTypeID == model.ShipViaTypeID); break; } } count = query.Count(); query = query.OrderByDescending(H => H.ProductID).Skip((page - 1) * rows).Take(rows); foreach (var H in query) { list.Add(new CMS_HMNUM_Model { ProductID = H.ProductID, HMNUM = H.HMNUM, ProductName = H.ProductName, StockKey = H.StockKey, MasterPack = H.MasterPack, IsGroup = H.IsGroup.HasValue ? H.IsGroup.Value : false, CMS_HMNUM_Status = new CMS_HMNUM_Status_Model { StatusID = H.CMS_HMNUM_Status.StatusID, StatusName = H.CMS_HMNUM_Status.StatusName }, HM_Costing = new CMS_HM_Costing_Model { FirstCost = H.CMS_HM_Costing.FirstCost.ConvertToNotNull().ToString("C", new CultureInfo("en-US")), LandedCost = H.CMS_HM_Costing.LandedCost.ConvertToNotNull().ToString("C", new CultureInfo("en-US")), EstimateFreight = H.CMS_HM_Costing.EstimateFreight.ConvertToNotNull().ToString("C", new CultureInfo("en-US")), OceanFreight = H.CMS_HM_Costing.OceanFreight.ConvertToNotNull().ToString("C", new CultureInfo("en-US")), USAHandlingCharge = H.CMS_HM_Costing.USAHandlingCharge.ConvertToNotNull().ToString("C", new CultureInfo("en-US")), Drayage = H.CMS_HM_Costing.Drayage.ConvertToNotNull().ToString("C", new CultureInfo("en-US")) } }); } return(list); } }
/// <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); } }