protected override void Create() { var line = new WarehouseOutLine(); if (WarehouseOutLines.Count <= 0) { line.Id = -1; } else { var lineIdList = WarehouseOutLines.Select(lineId => Math.Abs(lineId.Id)).ToList(); int maxID = lineIdList.Max(); line.Id = -(maxID + 1); } line.IsVerified = IsVerified; line.PackingQuantity = PackingQuantity; line.Quantity = Quantity; line.VerifiedQuantity = VerifiedQuantity; line.WarehouseInLineId = WarehouseInLineId; using ( var warehouseInLineService = SvcClientManager.GetSvcClient<WarehouseInLineServiceClient>(SvcType.WarehouseInLineSvc)) { const string str = "it.Id = @p1"; var parameters = new List<object> { WarehouseInLineId }; List<WarehouseInLine> inLines = warehouseInLineService.Select(str, parameters, new List<string> { "DeliveryLine", "DeliveryLine.Delivery.Quota.Commodity" }); if (inLines.Count > 0) { WarehouseInLine inLine = inLines[0]; line.WarehouseInLine = inLine; } } line.Comment = Comment; line.CommodityTypeId = CommodityTypeId; using ( var commodityTypeService = SvcClientManager.GetSvcClient<CommodityTypeServiceClient>(SvcType.CommodityTypeSvc)) { CommodityType commodityType = commodityTypeService.GetById(CommodityTypeId); line.CommodityType = commodityType; } line.BrandId = BrandId; using (var brandService = SvcClientManager.GetSvcClient<BrandServiceClient>(SvcType.BrandSvc)) { Brand brand = brandService.GetById(BrandId); line.Brand = brand; } line.SpecificationId = SpecificationId; using ( var specificationService = SvcClientManager.GetSvcClient<SpecificationServiceClient>(SvcType.SpecificationSvc)) { Specification specification = specificationService.GetById(SpecificationId); line.Specification = specification; } //提货人信息 line.WarehouseOutDeliveryPersons.Clear(); foreach (WarehouseOutDeliveryPerson deliveryPerson in AllDeliveryPersonList) { line.WarehouseOutDeliveryPersons.Add(deliveryPerson); } #region 把新增的出库行对应的入库行更改清卡状态后的数据存到list里面 var newWarehouseInLine = new WarehouseInLine(); using ( var warehouseInLineService = SvcClientManager.GetSvcClient<WarehouseInLineServiceClient>(SvcType.WarehouseInLineSvc)) { const string str = "it.Id = @p1"; var parameter = new List<object> { WarehouseInLineId }; List<WarehouseInLine> inLines = warehouseInLineService.Select(str, parameter, new List<string> { "DeliveryLine.Delivery.Quota.Contract", "DeliveryLine.Delivery.Quota", "WarehouseIn", "DeliveryLine.Delivery", "DeliveryLine" }); if (inLines.Count > 0) { newWarehouseInLine = inLines[0]; newWarehouseInLine.IsPBCleared = IsPBClear; } } if (WarehouseInLines.Count > 0) { List<WarehouseInLine> warehouseInLines = WarehouseInLines.Where(c => c.Id == WarehouseInLineId).ToList(); if (warehouseInLines.Count > 0) { WarehouseInLine warehouseInLine = warehouseInLines[0]; WarehouseInLines.Remove(warehouseInLine); } } WarehouseInLines.Add(newWarehouseInLine); #endregion if (ValidateAllLine(WarehouseOutLines, line)) { WarehouseOutLines.Add(line); AddWarehouseOutLines.Add(line); } }
protected override void Update() { var outLine = new WarehouseOutLine(); List<WarehouseOutLine> lines = WarehouseOutLines.Where(c => c.Id == ObjectId).ToList(); if (lines.Count > 0) { WarehouseOutLine line = lines[0]; outLine.Id = line.Id; outLine.WarehouseOutId = line.WarehouseOutId; outLine.IsVerified = IsVerified; outLine.PackingQuantity = PackingQuantity; outLine.Quantity = Quantity; outLine.VerifiedQuantity = VerifiedQuantity; outLine.WarehouseInLineId = WarehouseInLine.Id; using ( var warehouseInLineService = SvcClientManager.GetSvcClient<WarehouseInLineServiceClient>(SvcType.WarehouseInLineSvc)) { const string str = "it.Id = @p1"; var parameters = new List<object> { WarehouseInLine.Id }; List<WarehouseInLine> inLines = warehouseInLineService.Select(str, parameters, new List<string> { "DeliveryLine", "DeliveryLine.Delivery.Quota.Commodity" }); if (inLines.Count > 0) { WarehouseInLine inLine = inLines[0]; outLine.WarehouseInLine = inLine; } } outLine.Comment = Comment; outLine.CommodityTypeId = CommodityTypeId; using ( var commodityTypeService = SvcClientManager.GetSvcClient<CommodityTypeServiceClient>(SvcType.CommodityTypeSvc)) { CommodityType commodityType = commodityTypeService.GetById(CommodityTypeId); outLine.CommodityType = commodityType; } outLine.BrandId = BrandId; using (var brandService = SvcClientManager.GetSvcClient<BrandServiceClient>(SvcType.BrandSvc)) { Brand brand = brandService.GetById(BrandId); outLine.Brand = brand; } outLine.SpecificationId = SpecificationId; using ( var specificationService = SvcClientManager.GetSvcClient<SpecificationServiceClient>(SvcType.SpecificationSvc)) { Specification specification = specificationService.GetById(SpecificationId); outLine.Specification = specification; } //提货人信息 outLine.WarehouseOutDeliveryPersons.Clear(); foreach (WarehouseOutDeliveryPerson deliveryPerson in AllDeliveryPersonList) { outLine.WarehouseOutDeliveryPersons.Add(deliveryPerson); } if (ValidateAllLine(WarehouseOutLines, outLine)) { #region 更改对应入库单的清卡状态 if (line.Id > 0) { using ( var warehouseInLineService = SvcClientManager.GetSvcClient<WarehouseInLineServiceClient>(SvcType.WarehouseInLineSvc)) { var inLine = new WarehouseInLine(); const string str = "it.Id = @p1"; var parameter = new List<object> { line.WarehouseInLineId }; List<WarehouseInLine> inLines = warehouseInLineService.Select(str, parameter, new List<string> { "DeliveryLine.Delivery.Quota.Contract", "DeliveryLine.Delivery.Quota", "WarehouseIn", "DeliveryLine.Delivery", "DeliveryLine" }); if (inLines.Count > 0) { inLine = inLines[0]; inLine.IsPBCleared = IsPBClear; } if (line.WarehouseInLineId == WarehouseInLine.Id) { WarehouseInLines.Add(inLine); } else { const string strQuery = "it.Id = @p1"; var parameter1 = new List<object> { WarehouseInLine.Id }; List<WarehouseInLine> newLines = warehouseInLineService.Select(strQuery, parameter1, new List<string> { "DeliveryLine.Delivery.Quota.Contract", "DeliveryLine.Delivery.Quota", "WarehouseIn", "DeliveryLine.Delivery", "DeliveryLine" }); if (newLines.Count > 0) { WarehouseInLine newLine = newLines[0]; newLine.IsPBCleared = IsPBClear; WarehouseInLines.Add(newLine); } inLine.IsPBCleared = false; WarehouseInLines.Add(inLine); } } } else { List<WarehouseInLine> oldInLines = WarehouseInLines.Where(c => c.Id == line.WarehouseInLineId).ToList(); if (oldInLines.Count > 0) { WarehouseInLine oldInLine = oldInLines[0]; WarehouseInLines.Remove(oldInLine); } if (WarehouseInLines.Count > 0) { List<WarehouseInLine> inLines = WarehouseInLines.Where(c => c.Id == WarehouseInLine.Id).ToList(); if (inLines.Count > 0) { WarehouseInLine inLine = inLines[0]; WarehouseInLines.Remove(inLine); } } using ( var warehouseInLineService = SvcClientManager.GetSvcClient<WarehouseInLineServiceClient>(SvcType.WarehouseInLineSvc)) { const string strQuery = "it.Id = @p1"; var parameter1 = new List<object> { WarehouseInLine.Id }; List<WarehouseInLine> newLines = warehouseInLineService.Select(strQuery, parameter1, new List<string> { "DeliveryLine.Delivery.Quota.Contract", "DeliveryLine.Delivery.Quota", "WarehouseIn", "DeliveryLine.Delivery", "DeliveryLine" }); if (newLines.Count > 0) { WarehouseInLine newLine = newLines[0]; newLine.IsPBCleared = IsPBClear; WarehouseInLines.Add(newLine); } } } #endregion WarehouseOutLines.Remove(line); WarehouseOutLines.Add(outLine); if (line.Id < 0) { if (AddWarehouseOutLines.Count > 0) { List<WarehouseOutLine> addOutLines = AddWarehouseOutLines.Where(c => c.Id == line.Id).ToList(); if (addOutLines.Count > 0) { WarehouseOutLine addOutLine = addOutLines[0]; AddWarehouseOutLines.Remove(addOutLine); AddWarehouseOutLines.Add(outLine); } } } else { if (UpdateWarehouseOutLines.Count > 0) { List<WarehouseOutLine> updateOutLines = UpdateWarehouseOutLines.Where(c => c.Id == line.Id).ToList(); if (updateOutLines.Count > 0) { WarehouseOutLine updateOutLine = updateOutLines[0]; UpdateWarehouseOutLines.Remove(updateOutLine); } } UpdateWarehouseOutLines.Add(outLine); } } } }
private bool ValidateAllLine(List<WarehouseOutLine> lines, WarehouseOutLine line) { if (lines.Count > 0) { var listID = new List<int>(); foreach (WarehouseOutLine outLine in WarehouseOutLines) { if (outLine.Id != line.Id) { listID.Add(outLine.WarehouseInLineId); } } if (listID.Contains(line.WarehouseInLineId)) { throw new Exception("一个出库项下的多个出库行不能对应相同的入库行!"); } } return true; }