/// <summary> /// 创建/更新 采购篮商品 /// </summary> /// <param name="basketInfo"></param> /// <returns></returns> public virtual BasketItemsInfo SaveBasket(BasketItemsInfo basketInfo) { #region [Check 实体逻辑] //检查商品数量: if (!basketInfo.Quantity.HasValue || basketInfo.Quantity.Value == 0) { //{0}:该商品数量不能为空 throw new BizException(string.Format(GetMessageString("Basket_ProductQtyEmpty"), basketInfo.ProductID)); } if (!basketInfo.OrderPrice.HasValue) { //{0}:该商品结算价不能为空! throw new BizException(string.Format(GetMessageString("Basket_SettlePriceEmpty"), basketInfo.ProductID)); } //商品编号: if (!basketInfo.ProductSysNo.HasValue || basketInfo.ProductSysNo == 0) { //{0}:该商品编号不能为空! throw new BizException(string.Format(GetMessageString("Basket_ItemSysNoEmpty"), basketInfo.ProductID)); } //商品是否存在于采购篮中: else if (BasketDA.CheckProductHasExistInBasket(basketInfo)) { //{0}:该商品已存在于采购篮中! throw new BizException(string.Format(GetMessageString("Basket_ItemExists"), basketInfo.ProductID)); } #endregion //保存和更新操作: if (basketInfo.ItemSysNo == null || !basketInfo.ItemSysNo.HasValue || basketInfo.ItemSysNo.Value == 0) { //如果不存在SysNo,则为新建操作: basketInfo = BasketDA.CreateBasketItem(basketInfo); //写LOG: //CommonService.WriteLog<BasketItemEntity>(entity, " Created BaksetItem ", entity.SysNo.Value.ToString(), (int)LogType.PO_Basket_Insert); ExternalDomainBroker.CreateLog(" Created BaksetItem " , BizEntity.Common.BizLogType.Purchase_Basket_Insert , basketInfo.ItemSysNo.Value , basketInfo.CompanyCode); } else { basketInfo = BasketDA.UpdateBasketItem(basketInfo); //写LOG: //CommonService.WriteLog<BasketItemEntity>(entity, " Updated BaksetItem ", entity.SysNo.Value.ToString(), (int)LogType.PO_Basket_Update); ExternalDomainBroker.CreateLog(" Updated BaksetItem " , BizEntity.Common.BizLogType.Purchase_Basket_Update , basketInfo.ItemSysNo.Value , basketInfo.CompanyCode); } return(basketInfo); }
/// <summary> /// 创建采购篮商品(备货中心用) /// </summary> /// <param name="prepareInfo"></param> /// <returns></returns> public virtual BasketItemsInfo CreateBasketItemForPrepare(BasketItemsInfo prepareInfo) { if (BasketDA.CheckProductHasExistInBasket(prepareInfo) && !prepareInfo.ItemSysNo.HasValue) { //添加采购篮中item记录是否重复判断条件:采购员,供应商,item,目标仓库 //{0}:该商品已存在于采购篮中! throw new BizException(string.Format(GetMessageString("Basket_ItemExists"), prepareInfo.ProductID)); } prepareInfo.LastVendorSysNo = BasketDA.GetVendorSysNoByProductNoAndStockSysNo(prepareInfo.ProductSysNo.Value, prepareInfo.StockSysNo.Value); #region [Check 实体逻辑] if (!prepareInfo.Quantity.HasValue || prepareInfo.Quantity == 0) { //{0}:该商品数量不能为空! throw new BizException(string.Format(GetMessageString("Basket_ProductQtyEmpty"), prepareInfo.ProductID)); } if (!prepareInfo.OrderPrice.HasValue) { //{0}:该商品结算价不能为空! throw new BizException(string.Format(GetMessageString("Basket_SettlePriceEmpty"), prepareInfo.ProductID)); } if (!prepareInfo.ProductSysNo.HasValue || prepareInfo.ProductSysNo == 0) { //{0}:该商品编号不能为空! throw new BizException(string.Format(GetMessageString("Basket_ItemSysNoEmpty"), prepareInfo.ProductID)); } else if (BasketDA.CheckProductHasExistInBasket(prepareInfo) && !prepareInfo.ItemSysNo.HasValue) { //添加采购篮中item记录是否重复判断条件:采购员,供应商,item,目标仓库 //{0}:该商品已存在于采购篮中! throw new BizException(string.Format(GetMessageString("Basket_ItemExists"), prepareInfo.ProductID)); } #endregion //新建操作: prepareInfo = BasketDA.CreateBasketItemForPrepare(prepareInfo); //写LOG: // CommonService.WriteLog<BasketItemEntity>(entity, " Created BaksetItem For Prepare ", entity.SysNo.Value.ToString(), (int)LogType.PO_Basket_Insert); ExternalDomainBroker.CreateLog(" Created BaksetItem For Prepare " , BizEntity.Common.BizLogType.Purchase_Basket_Insert , prepareInfo.ItemSysNo.Value , prepareInfo.CompanyCode); return(prepareInfo); }
/// <summary> /// 验证导入的采购篮数据是否合法并创建采购篮 /// </summary> /// <param name="itemList"></param> /// <returns></returns> public virtual List <BasketItemsInfo> BatchImportAndCreateBasketItem(List <BasketItemsInfo> itemList, bool isThrowException) { if (null == itemList || 0 == itemList.Count) { //没有需要导入的数据 throw new BizException(GetMessageString("Basket_NoDataImport")); } foreach (var entity in itemList) { #region [Check实体逻辑] if (!entity.LastVendorSysNo.HasValue) { //供应商编号无效 entity.ErrorMessage += GetMessageString("Basket_VendorSysNoInvalid"); if (isThrowException) { throw new BizException(GetMessageString("Basket_VendorSysNoInvalid")); } } var vendor = VendorDA.LoadVendorInfo(entity.LastVendorSysNo.Value); if (vendor == null) { //供应商无效 entity.ErrorMessage += GetMessageString("Basket_VendorInvalid"); if (isThrowException) { throw new BizException(GetMessageString("Basket_VendorInvalid")); } } else { entity.CompanyCode = vendor.CompanyCode; entity.VendorSysNo = vendor.SysNo.Value; } if (!entity.Quantity.HasValue || entity.Quantity == 0) { //{0}:该商品数量不能为空! entity.ErrorMessage += string.Format(GetMessageString("Basket_ProductQtyEmpty"), entity.ProductID); if (isThrowException) { throw new BizException(string.Format(GetMessageString("Basket_ProductQtyEmpty"), entity.ProductID)); } } if (!entity.OrderPrice.HasValue) { //采购价格为空 entity.ErrorMessage += GetMessageString("Basket_PurchasePriceEmpty"); if (isThrowException) { throw new BizException(GetMessageString("Basket_PurchasePriceEmpty")); } } entity.ProductSysNo = BasketDA.GetItemSysNoByItemID(entity.ProductID, entity.CompanyCode); if (!entity.ProductSysNo.HasValue || entity.ProductSysNo == 0) { entity.ErrorMessage += GetMessageString("Basket_ProductSysNoInvalid"); if (isThrowException) { throw new BizException(GetMessageString("Basket_ProductSysNoInvalid")); } } entity.StockSysNo = BasketDA.GetStockSysNoByName(entity.StockName, entity.CompanyCode); if (!entity.StockSysNo.HasValue || entity.StockSysNo == 0) { entity.ErrorMessage += GetMessageString("Basket_StocknameInvalid"); if (isThrowException) { throw new BizException(GetMessageString("Basket_StocknameInvalid")); } } if (BasketDA.CheckProductHasExistInBasket(entity) && !entity.ItemSysNo.HasValue) { //添加采购篮中item记录是否重复判断条件:采购员,供应商,item,目标仓库 //{0}:该商品已存在于采购篮中! entity.ErrorMessage += string.Format(GetMessageString("Basket_ItemExists"), entity.ProductID); if (isThrowException) { throw new BizException(string.Format(GetMessageString("Basket_ItemExists"), entity.ProductID)); } } #endregion if (string.IsNullOrEmpty(entity.ErrorMessage)) { entity.ReadyQuantity = 0; var resultEntity = BasketDA.CreateBasketItemForPrepare(entity); //写LOG: //CommonService.WriteLog<BasketItemEntity>(entity, " Batch Created BaksetItem ", entity.SysNo.Value.ToString(), (int)LogType.PO_Basket_Insert); ExternalDomainBroker.CreateLog(" Batch Created BaksetItem " , BizEntity.Common.BizLogType.Purchase_Basket_Insert , entity.ItemSysNo.Value , entity.CompanyCode); } } return(itemList); }