/// <summary> /// 测试ProductOnUnitPrice /// </summary> /// <returns>新建的ProductOnUnitPrice对象</returns> public ProductOnUnitPrice ProductOnUnitPriceTest() { MemberOrganization oOrg = new MemberOrganization { Code = GetRandCode() }; oLiveEntities.MemberOrganizations.Add(oOrg); oLiveEntities.SaveChanges(); GeneralResource oName = new GeneralResource { }; oLiveEntities.GeneralResources.Add(oName); oLiveEntities.SaveChanges(); ProductInformation oProduct = new ProductInformation { Organization = oOrg, Code = GetRandCode(), Name = oName }; oLiveEntities.ProductInformations.Add(oProduct); oLiveEntities.SaveChanges(); ProductInfoItem oProductInfoItem = new ProductInfoItem { Organization = oOrg, Product = oProduct, Code = GetRandCode() }; oLiveEntities.ProductInfoItems.Add(oProductInfoItem); oLiveEntities.SaveChanges(); ProductOnItem oPOI = new ProductOnItem { OnSale = ProductOnSaleTest(), SkuItem = oProductInfoItem }; oLiveEntities.ProductOnItems.Add(oPOI); oLiveEntities.SaveChanges(); GeneralMeasureUnit oGMU = new GeneralMeasureUnit { Code = GetRandCode() }; oLiveEntities.GeneralMeasureUnits.Add(oGMU); oLiveEntities.SaveChanges(); ProductOnUnitPrice oPUP = new ProductOnUnitPrice { OnSkuItem = oPOI, ShowUnit = oGMU }; oLiveEntities.ProductOnUnitPrices.Add(oPUP); oLiveEntities.SaveChanges(); return oPUP; }
/// <summary> /// 导入商品定义,包括PU和SKU /// </summary> /// <param name="sExcelFile">Excel文件名</param> /// <param name="sSheetName">Sheet名</param> public void ImportProduct(string sExcelFile, string sSheetName) { try { ExcelData oExcel = new ExcelData(sExcelFile, sSheetName); DataColumn colOrgan = oExcel.ExcelTable.Columns["组织"]; DataColumn colProdCode = oExcel.ExcelTable.Columns["PU代码"]; DataColumn colSkuCode = oExcel.ExcelTable.Columns["SKU代码"]; DataColumn colBarcode = oExcel.ExcelTable.Columns["条码"]; DataColumn colExCode1 = oExcel.ExcelTable.Columns["自定义编码"]; DataColumn colProdNameCN = oExcel.ExcelTable.Columns["PU中文名称"]; DataColumn colSkuNameCN = oExcel.ExcelTable.Columns["SKU中文名称"]; DataColumn colStdCat = oExcel.ExcelTable.Columns["标准分类"]; DataColumn colPrvCat = oExcel.ExcelTable.Columns["私有分类"]; DataColumn colBlock = oExcel.ExcelTable.Columns["拆单分组标志"]; DataColumn colMode = oExcel.ExcelTable.Columns["产品模式"]; DataColumn colUnitType = oExcel.ExcelTable.Columns["单位类型"]; DataColumn colUnitCode = oExcel.ExcelTable.Columns["单位代码"]; DataColumn colPercision = oExcel.ExcelTable.Columns["计量精度"]; DataColumn colSpecification = oExcel.ExcelTable.Columns["规格"]; DataColumn colProdPicture = oExcel.ExcelTable.Columns["主图路径"]; DataColumn colBriefCN = oExcel.ExcelTable.Columns["简单描述"]; DataColumn colIntroCN = oExcel.ExcelTable.Columns["详细描述"]; DataColumn colMinQuantity = oExcel.ExcelTable.Columns["起订量"]; DataColumn colCycle = oExcel.ExcelTable.Columns["生产周期"]; DataColumn colGuarantee = oExcel.ExcelTable.Columns["保质期"]; DataColumn colMarketPriceRMB = oExcel.ExcelTable.Columns["市场价¥"]; DataColumn colSuggestPriceRMB = oExcel.ExcelTable.Columns["建议价¥"]; DataColumn colLowestPriceRMB = oExcel.ExcelTable.Columns["最低价¥"]; DataColumn colKeywords = oExcel.ExcelTable.Columns["关键词"]; DataColumn colGrossWeight = oExcel.ExcelTable.Columns["毛重"]; DataColumn colNetWeight = oExcel.ExcelTable.Columns["净重"]; DataColumn colGrossVolume = oExcel.ExcelTable.Columns["毛体积"]; DataColumn colNetVolume = oExcel.ExcelTable.Columns["净体积"]; DataColumn colNetPiece = oExcel.ExcelTable.Columns["计件"]; DataColumn colRemark = oExcel.ExcelTable.Columns["备注"]; ProductInformation oProduct = null; MemberOrganization oOrgan = null; foreach (DataRow row in oExcel.ExcelTable.Rows) { string sOrgan = row[colOrgan].ToString(); if (!String.IsNullOrEmpty(sOrgan)) oOrgan = (from o in dbEntity.MemberOrganizations where o.Code == sOrgan && o.Otype == (byte)ModelEnum.OrganizationType.CORPORATION select o).FirstOrDefault(); string sProdCode = row[colProdCode].ToString(); string sSkuCode = row[colSkuCode].ToString(); if (String.IsNullOrEmpty(sSkuCode)) continue; string sBarcode = row[colBarcode].ToString(); string sExCode1 = row[colExCode1].ToString(); GeneralResource oProdName = new GeneralResource(ModelEnum.ResourceType.STRING, 2052, row[colProdNameCN].ToString()); GeneralResource oSkuName = new GeneralResource(ModelEnum.ResourceType.STRING, 2052, row[colSkuNameCN].ToString()); GeneralResource oFullName = new GeneralResource(ModelEnum.ResourceType.STRING, 2052, row[colProdNameCN].ToString() + row[colSkuNameCN].ToString()); GeneralResource oShortName = new GeneralResource(ModelEnum.ResourceType.STRING, 2052, row[colSkuNameCN].ToString()); string sStdCat = row[colStdCat].ToString(); string sPrvCat = row[colPrvCat].ToString(); byte nBlock; Byte.TryParse(row[colBlock].ToString(), out nBlock); byte nMode; Byte.TryParse(row[colMode].ToString(), out nMode); byte nUnitType; Byte.TryParse(row[colUnitType].ToString(), out nUnitType); string sUnitCode = row[colUnitCode].ToString(); byte nPercision; Byte.TryParse(row[colPercision].ToString(), out nPercision); GeneralResource oSpecification = new GeneralResource(ModelEnum.ResourceType.STRING, 2052, row[colSpecification].ToString()); string sProdPicture = row[colProdPicture].ToString(); GeneralResource oBrief = new GeneralResource(ModelEnum.ResourceType.STRING, 2052, row[colBriefCN].ToString()); GeneralLargeObject oIntro = new GeneralLargeObject(2052, row[colIntroCN].ToString()); decimal nMinQuantity; Decimal.TryParse(row[colMinQuantity].ToString(), out nMinQuantity); int nCycle; Int32.TryParse(row[colCycle].ToString(), out nCycle); int nGuarantee; Int32.TryParse(row[colGuarantee].ToString(), out nGuarantee); decimal nMarketPriceRMB; Decimal.TryParse(row[colMarketPriceRMB].ToString(), out nMarketPriceRMB); decimal nSuggestPriceRMB; Decimal.TryParse(row[colSuggestPriceRMB].ToString(), out nSuggestPriceRMB); decimal nLowestPriceRMB; Decimal.TryParse(row[colLowestPriceRMB].ToString(), out nLowestPriceRMB); string sKeywords = row[colKeywords].ToString(); decimal nGrossWeight; Decimal.TryParse(row[colGrossWeight].ToString(), out nGrossWeight); decimal nNetWeight; Decimal.TryParse(row[colNetWeight].ToString(), out nNetWeight); decimal nGrossVolume; Decimal.TryParse(row[colGrossVolume].ToString(), out nGrossVolume); decimal nNetVolume; Decimal.TryParse(row[colNetVolume].ToString(), out nNetVolume); int nNetPiece; Int32.TryParse(row[colNetPiece].ToString(), out nNetPiece); string sRemark = row[colRemark].ToString(); if (!String.IsNullOrEmpty(sProdCode)) { // 导入产品主表 oProduct = (from p in dbEntity.ProductInformations where p.OrgID == oOrgan.Gid && p.Code == sProdCode select p).FirstOrDefault(); if (oProduct == null) { oProduct = new ProductInformation { Organization = oOrgan, Code = sProdCode }; dbEntity.ProductInformations.Add(oProduct); } if (oProduct.Name == null) oProduct.Name = oProdName; else oProduct.Name.SetResource(ModelEnum.ResourceType.STRING, oProdName); oProduct.StandardCategory = dbEntity.GeneralStandardCategorys.Where(c => c.Code == sStdCat && c.Ctype == (byte)ModelEnum.StandardCategoryType.PRODUCT).FirstOrDefault(); oProduct.Block = nBlock; oProduct.Mode = nMode; oProduct.Picture = sProdPicture; if (oProduct.Brief == null) oProduct.Brief = oBrief; else oProduct.Brief.SetResource(ModelEnum.ResourceType.STRING, oBrief); if (oProduct.Matter == null) oProduct.Matter = oIntro; else oProduct.Matter.SetLargeObject(oIntro); oProduct.MinQuantity = nMinQuantity; oProduct.ProductionCycle = nCycle; oProduct.GuaranteeDays = nGuarantee; oProduct.Keywords = sKeywords; oProduct.Remark = sRemark; dbEntity.SaveChanges(); } // 导入产品SKU表 var oProdItem = (from i in dbEntity.ProductInfoItems where i.OrgID == oOrgan.Gid && i.Code == sSkuCode select i).FirstOrDefault(); if (oProdItem == null) { oProdItem = new ProductInfoItem { Organization = oOrgan, Code = sSkuCode }; dbEntity.ProductInfoItems.Add(oProdItem); } oProdItem.Product = oProduct; oProdItem.Barcode = (String.IsNullOrEmpty(sBarcode)) ? sSkuCode : sBarcode; oProdItem.CodeEx1 = sExCode1; if (oProdItem.FullName == null) oProdItem.FullName = oFullName; else oProdItem.FullName.SetResource(ModelEnum.ResourceType.STRING, oFullName); if (oProdItem.ShortName == null) oProdItem.ShortName = oShortName; else oProdItem.ShortName.SetResource(ModelEnum.ResourceType.STRING, oShortName); oProdItem.StandardUnit = dbEntity.GeneralMeasureUnits.Where(u => u.Code == sUnitCode && u.Utype == nUnitType).FirstOrDefault(); if (oProdItem.Specification == null) oProdItem.Specification = oSpecification; else oProdItem.Specification.SetResource(ModelEnum.ResourceType.STRING, oSpecification); var oCurrency = (from u in dbEntity.GeneralMeasureUnits where u.Utype == (byte)ModelEnum.MeasureUnit.CURRENCY && u.Code == "¥" select u).FirstOrDefault(); if (oProdItem.MarketPrice == null) oProdItem.MarketPrice = new GeneralResource(ModelEnum.ResourceType.MONEY, oCurrency.Gid, nMarketPriceRMB); else oProdItem.MarketPrice.SetResource(ModelEnum.ResourceType.MONEY, oCurrency.Gid, nMarketPriceRMB); if (oProdItem.SuggestPrice == null) oProdItem.SuggestPrice = new GeneralResource(ModelEnum.ResourceType.MONEY, oCurrency.Gid, nSuggestPriceRMB); else oProdItem.SuggestPrice.SetResource(ModelEnum.ResourceType.MONEY, oCurrency.Gid, nSuggestPriceRMB); if (oProdItem.LowestPrice == null) oProdItem.LowestPrice = new GeneralResource(ModelEnum.ResourceType.MONEY, oCurrency.Gid, nLowestPriceRMB); else oProdItem.LowestPrice.SetResource(ModelEnum.ResourceType.MONEY, oCurrency.Gid, nLowestPriceRMB); oProdItem.GrossWeight = nGrossWeight; oProdItem.NetWeight = nNetWeight; oProdItem.GrossVolume = nGrossVolume; oProdItem.NetVolume = nNetVolume; oProdItem.NetPiece = nNetPiece; oProdItem.Remark = sRemark; dbEntity.SaveChanges(); if (Utility.ConfigHelper.GlobalConst.IsDebug) Debug.WriteLine("{0} {1} {2} {3} {4}", this.ToString(), sProdCode, oProdName.Matter, oSkuName.Matter, sRemark); } oEventBLL.WriteEvent(String.Format("导入ProductInformation成功: {0} {1}", sExcelFile, sSheetName), ModelEnum.ActionLevel.GENERIC, ModelEnum.ActionSource.SYSTEM, this.ToString()); } catch (Exception ex) { oEventBLL.WriteEvent(String.Format("导入ProductInformation错误: {0} {1} {2}", sExcelFile, sSheetName, ex.Message), ModelEnum.ActionLevel.ERROR, ModelEnum.ActionSource.SYSTEM, this.ToString()); } }
/// <summary> /// ProductOnItem /// </summary> public ProductOnItem ProductOnItemTest() { GeneralResource oResource = new GeneralResource { }; oLiveEntities.GeneralResources.Add(oResource); MemberOrganization oOrg = new MemberOrganization { Code = GetRandCode() }; oLiveEntities.MemberOrganizations.Add(oOrg); ProductInformation oProd = new ProductInformation { Code = GetRandCode(), Organization = oOrg, Name = oResource }; oLiveEntities.ProductInformations.Add(oProd); MemberChannel mChl = new MemberChannel { Code = GetRandCode() }; oLiveEntities.MemberChannels.Add(mChl); MemberOrgChannel oOChl = new MemberOrgChannel { Organization = oOrg, Channel = mChl }; oLiveEntities.MemberOrgChannels.Add(oOChl); ProductOnSale onSale = new ProductOnSale { Code = GetRandCode(), Product = oProd, Channel = mChl, Name = oResource }; oLiveEntities.ProductOnSales.Add(onSale); ProductInfoItem oSku = new ProductInfoItem { Code = GetRandCode(), Organization = oOrg, Product = oProd }; oLiveEntities.ProductInfoItems.Add(oSku); ProductOnItem oOnSku = new ProductOnItem { OnSale = onSale, SkuItem = oSku }; oLiveEntities.ProductOnItems.Add(oOnSku); oLiveEntities.SaveChanges(); return oOnSku; }
public void ProductOnAdjustTest() { ProductOnSale oSale = ProductOnSaleTest(); ProductOnItem oSku = ProductOnItemTest(); MemberOrganization org = new MemberOrganization { Code = GetRandCode() }; oLiveEntities.MemberOrganizations.Add(org); GeneralResource res = new GeneralResource { }; oLiveEntities.GeneralResources.Add(res); ProductInformation prod = new ProductInformation { Name = res, Organization = org, Code = GetRandCode() }; oLiveEntities.ProductInformations.Add(prod); ProductInfoItem infoItem = new ProductInfoItem { Organization = org, Product = prod, Code = GetRandCode() }; oLiveEntities.ProductInfoItems.Add(infoItem); oLiveEntities.SaveChanges(); ProductOnAdjust oAdjust = new ProductOnAdjust { OnSaleID = oSale.Gid, OnSkuID = oSku.Gid }; oLiveEntities.ProductOnAdjusts.Add(oAdjust); oLiveEntities.SaveChanges(); }
/// <summary> /// 添加SKU /// </summary> /// <returns></returns> public ActionResult AddProductSKU() { if (base.GetProgramNode("EnableEdit") == "1") { MemberOrganization regex = dbEntity.MemberOrganizations.Where(p => p.Gid == organizationGuid).FirstOrDefault(); ViewBag.regexCode = regex.SkuCodePolicy; ViewBag.regexBarcode = regex.BarcodePolicy; List<GeneralMeasureUnit> oMeasureUnit = dbEntity.GeneralMeasureUnits.ToList(); List<SelectListItem> modelList = new List<SelectListItem>(); foreach (GeneralMeasureUnit item in oMeasureUnit) { if (item.Utype != 6) { modelList.Add(new SelectListItem { Text = item.Name.GetResource(CurrentSession.Culture), Value = item.Gid.ToString() }); } } ViewBag.modelList = modelList; ProductInfoItem oAdd = new ProductInfoItem { FullName = NewResource(ModelEnum.ResourceType.STRING, organizationGuid), ShortName = NewResource(ModelEnum.ResourceType.STRING, organizationGuid), Specification = NewResource(ModelEnum.ResourceType.STRING, organizationGuid), MarketPrice = NewResource(ModelEnum.ResourceType.MONEY, organizationGuid), SuggestPrice = NewResource(ModelEnum.ResourceType.MONEY, organizationGuid), LowestPrice = NewResource(ModelEnum.ResourceType.MONEY, organizationGuid), }; //计件默认值为1 oAdd.NetPiece = 1; return View(oAdd); } return RedirectToAction("ErrorPage", "Home", new { message = LiveAzure.Resource.Common.NoPermission }); }
/// <summary> /// 保存编辑过的SKU /// </summary> /// <param name="formCollection"></param> /// <returns></returns> public ActionResult SaveEditProductSKU(ProductInfoItem oEdit,FormCollection Form) { if (base.GetProgramNode("EnableEdit") == "1") { ProductInfoItem oProductInfoItem = dbEntity.ProductInfoItems.Where(p => p.Gid == selectedProductSKUGuid).Single(); oProductInfoItem.Barcode = Form["Barcode"]; oProductInfoItem.CodeEx1 = oEdit.CodeEx1; oProductInfoItem.FullName.SetResource(ModelEnum.ResourceType.STRING, oEdit.FullName); oProductInfoItem.ShortName.SetResource(ModelEnum.ResourceType.STRING, oEdit.ShortName); oProductInfoItem.StdUnit = Guid.Parse(Form["StdUnit"]); oProductInfoItem.Specification.SetResource(ModelEnum.ResourceType.STRING, oEdit.Specification); oProductInfoItem.Percision = oEdit.Percision; oProductInfoItem.MarketPrice.SetResource(ModelEnum.ResourceType.MONEY, oEdit.MarketPrice); oProductInfoItem.SuggestPrice.SetResource(ModelEnum.ResourceType.MONEY, oEdit.SuggestPrice); oProductInfoItem.LowestPrice.SetResource(ModelEnum.ResourceType.MONEY, oEdit.LowestPrice); oProductInfoItem.GrossWeight = oEdit.GrossWeight; oProductInfoItem.NetWeight = oEdit.NetWeight; oProductInfoItem.GrossVolume = oEdit.GrossVolume; oProductInfoItem.NetVolume = oEdit.NetVolume; oProductInfoItem.NetPiece = oEdit.NetPiece; oProductInfoItem.Remark = oEdit.Remark; dbEntity.SaveChanges(); return RedirectToAction("ProductSKUGrid"); } return RedirectToAction("ErrorPage", "Home", new { message = LiveAzure.Resource.Common.NoPermission }); }
/// <summary> /// 保存增加的SKU /// </summary> /// <param name="formCollection"></param> /// <returns></returns> public ActionResult SaveAddProductSKU(ProductInfoItem oAdd,FormCollection Form) { if (base.GetProgramNode("EnableEdit") == "1") { ProductInfoItem oOld = dbEntity.ProductInfoItems.Where(p=>p.OrgID==organizationGuid && p.Code==oAdd.Code).FirstOrDefault(); if (oOld == null) { ProductInfoItem newProductSKU = new ProductInfoItem { OrgID = organizationGuid, ProdID = selectedProductGuid, Code = Form["Code"], Barcode = Form["Barcode"], CodeEx1 = oAdd.CodeEx1, FullName = new GeneralResource(ModelEnum.ResourceType.STRING, oAdd.FullName), ShortName = new GeneralResource(ModelEnum.ResourceType.STRING, oAdd.ShortName), StdUnit = Guid.Parse(Form["StdUnit"]), Specification = new GeneralResource(ModelEnum.ResourceType.STRING, oAdd.Specification), Percision = oAdd.Percision, MarketPrice = new GeneralResource(ModelEnum.ResourceType.MONEY, oAdd.MarketPrice), SuggestPrice = new GeneralResource(ModelEnum.ResourceType.MONEY, oAdd.SuggestPrice), LowestPrice = new GeneralResource(ModelEnum.ResourceType.MONEY, oAdd.LowestPrice), GrossWeight = oAdd.GrossWeight, NetWeight = oAdd.NetWeight, GrossVolume = oAdd.GrossVolume, NetVolume = oAdd.NetVolume, NetPiece = oAdd.NetPiece, Remark = oAdd.Remark }; dbEntity.ProductInfoItems.Add(newProductSKU); dbEntity.SaveChanges(); selectedProductSKUGuid = newProductSKU.Gid; return RedirectToAction("ProductSKUGrid"); } else { oOld.Deleted = false; oOld.Barcode = Form["Barcode"]; oOld.CodeEx1 = oAdd.CodeEx1; oOld.FullName.SetResource(ModelEnum.ResourceType.STRING, oAdd.FullName); oOld.ShortName.SetResource(ModelEnum.ResourceType.STRING, oAdd.ShortName); oOld.StdUnit = Guid.Parse(Form["StdUnit"]); oOld.Specification.SetResource(ModelEnum.ResourceType.STRING, oAdd.Specification); oOld.Percision = oAdd.Percision; oOld.MarketPrice.SetResource(ModelEnum.ResourceType.MONEY, oAdd.MarketPrice); oOld.SuggestPrice.SetResource(ModelEnum.ResourceType.MONEY, oAdd.SuggestPrice); oOld.LowestPrice.SetResource(ModelEnum.ResourceType.MONEY, oAdd.LowestPrice); oOld.GrossWeight = oAdd.GrossWeight; oOld.NetWeight = oAdd.NetWeight; oOld.GrossVolume = oAdd.GrossVolume; oOld.NetVolume = oAdd.NetVolume; oOld.NetPiece = oAdd.NetPiece; oOld.Remark = oAdd.Remark; dbEntity.SaveChanges(); selectedProductSKUGuid = oOld.Gid; return null; } } return RedirectToAction("ErrorPage", "Home", new { message = LiveAzure.Resource.Common.NoPermission }); }