Esempio n. 1
0
        private void MatchHu(Hu hu)
        {
            base.CheckHu(hu);

            if (!base.isCancel)
            {
                //if (hu.Status != HuStatus.Location)
                //{
                //    throw new BusinessException("条码不在库位中");
                //}
                //新的条码逻辑
                if (this.flowMaster.IsShipScanHu && hu.Status != HuStatus.Location)
                {
                    throw new BusinessException("条码不在库位中");
                }

                if (!this.flowMaster.IsShipScanHu && this.flowMaster.IsReceiveScanHu)
                {
                    throw new BusinessException("快速移库不支持数量发货条码收货的配置");
                }

                if (hu.QualityType == QualityType.Inspect)
                {
                    throw new BusinessException("待验条码不能移库");
                }

                if (hu.QualityType == QualityType.Reject)
                {
                    throw new BusinessException("不合格条码不能移库");
                }

                FlowDetail matchedFlowDetail = new FlowDetail();
                var flowDetails = this.flowMaster.FlowDetails;

                if (string.IsNullOrEmpty(this.flowMaster.Code))
                {
                    if (flowDetails == null)
                    {
                        flowDetails = new List<FlowDetail>().ToArray();
                        this.flowMaster.LocationFrom = hu.Location;
                        this.flowMaster.PartyFrom = hu.Region;
                    }
                    else
                    {
                        if (!this.flowMaster.LocationFrom.Equals(hu.Location, StringComparison.OrdinalIgnoreCase))
                        {
                            throw new BusinessException("当前条码{0}的来源库位{1}与其他物料的来源库位{2}不一致。", hu.HuId, hu.Location, this.flowMaster.LocationFrom);
                        }
                    }

                    var q = flowDetails
                        .Where(f => f.Item.Equals(hu.Item, StringComparison.OrdinalIgnoreCase)
                            && f.Uom.Equals(hu.Uom, StringComparison.OrdinalIgnoreCase)
                            && f.UnitCount == hu.UnitCount);
                    if (q.Count() > 0)
                    {
                        matchedFlowDetail = q.Single();
                    }
                    else
                    {
                        //检查权限
                        if (!Utility.HasPermission(user.Permissions, OrderType.Transfer, false, true, null, hu.Region))
                        {
                            throw new BusinessException("没有此移库路线的权限");
                        }
                        matchedFlowDetail.Id = FindMinId() - 1;
                        matchedFlowDetail.Item = hu.Item;
                        //matchedFlowDetail.Sequence++;
                        matchedFlowDetail.ReferenceItemCode = hu.ReferenceItemCode;
                        matchedFlowDetail.UnitCount = hu.UnitCount;
                        matchedFlowDetail.Uom = hu.Uom;

                        var flowDetailList = new List<FlowDetail>();
                        if (this.flowMaster.FlowDetails != null)
                        {
                            flowDetailList = this.flowMaster.FlowDetails.ToList();
                        }
                        flowDetailList.Add(matchedFlowDetail);
                        this.flowMaster.FlowDetails = flowDetailList.ToArray();
                    }
                }
                else
                {
                    #region 物料匹配

                    if (flowMaster.IsManualCreateDetail)
                    {
                        if (flowDetails != null)
                        {
                            var q = flowDetails.Where(f => f.Item.Equals(hu.Item, StringComparison.OrdinalIgnoreCase));
                            if (q.Count() > 0)
                            {
                                matchedFlowDetail = q.First();
                                //matchedFlowDetail.CurrentQty += hu.Qty;
                                //matchedFlowDetail.Carton++;
                            }
                            else
                            {
                                List<FlowDetail> flowDetailList = flowDetails.ToList();
                                if (flowMaster.FlowDetails != null)
                                {
                                    flowDetailList = flowMaster.FlowDetails.ToList();
                                }
                                matchedFlowDetail = this.Hu2FlowDetail(flowMaster, hu);
                                flowDetailList.Add(matchedFlowDetail);
                                flowMaster.FlowDetails = flowDetailList.ToArray();
                            }
                        }
                        else
                        {
                            List<FlowDetail> flowDetailList = new List<FlowDetail>();
                            if (flowMaster.FlowDetails != null)
                            {
                                flowDetailList = flowMaster.FlowDetails.ToList();
                            }
                            matchedFlowDetail = this.Hu2FlowDetail(flowMaster, hu);
                            flowDetailList.Add(matchedFlowDetail);
                            flowMaster.FlowDetails = flowDetailList.ToArray();
                        }
                    }
                    else
                    {
                        if (this.flowMaster.FlowDetails == null)
                        {
                            throw new BusinessException("没有找到和条码{0}的零件号{1}匹配的订单明细。", hu.HuId, hu.Item);
                        }

                        var matchedOrderDetailList = flowDetails.Where(o => o.Item == hu.Item);
                        if (matchedOrderDetailList == null || matchedOrderDetailList.Count() == 0)
                        {
                            throw new BusinessException("没有找到和条码{0}的零件号{1}匹配的订单明细。", hu.HuId, hu.Item);
                        }

                        matchedOrderDetailList = matchedOrderDetailList.Where(o => o.Uom.Equals(hu.Uom, StringComparison.OrdinalIgnoreCase));
                        if (matchedOrderDetailList == null || matchedOrderDetailList.Count() == 0)
                        {
                            throw new BusinessException("没有找到和条码{0}的单位{1}匹配的订单明细。", hu.HuId, hu.Uom);
                        }

                        if (this.flowMaster.IsOrderFulfillUC)
                        {
                            matchedOrderDetailList = matchedOrderDetailList.Where(o => o.UnitCount == hu.UnitCount);
                            if (matchedOrderDetailList == null || matchedOrderDetailList.Count() == 0)
                            {
                                throw new BusinessException("没有找到和条码{0}的包装数{1}匹配的订单明细。", hu.HuId, hu.UnitCount.ToString());
                            }
                        }
                        matchedFlowDetail = matchedOrderDetailList.First();
                    }
                    #endregion
                }

                FlowDetailInput input = new FlowDetailInput();
                input.HuId = hu.HuId;
                input.Qty = hu.Qty;
                input.LotNo = hu.LotNo;

                List<FlowDetailInput> flowDetailInputs = new List<FlowDetailInput>();
                if (matchedFlowDetail.FlowDetailInputs != null)
                {
                    flowDetailInputs = matchedFlowDetail.FlowDetailInputs.ToList();
                }
                flowDetailInputs.Add(input);
                matchedFlowDetail.FlowDetailInputs = flowDetailInputs.ToArray();
                matchedFlowDetail.CurrentQty += hu.Qty;
                matchedFlowDetail.Carton++;
                //
                base.hus.Insert(0, hu);
            }
            else
            {
                this.CancelHu(hu);
            }
            this.gvListDataBind();
        }
Esempio n. 2
0
        private void MatchHu(Hu hu)
        {
            base.CheckHu(hu);
            if (!Utility.HasPermission(user.Permissions, null, true, false, hu.Region, null))
            {
                throw new BusinessException("没有此条码的权限");
            }
            if (!base.isCancel)
            {
                if (hu.Status != HuStatus.Location)
                {
                    //throw new BusinessException("条码不在库位中");
                }

                if (hu.QualityType == QualityType.Inspect)
                {
                    throw new BusinessException("待验条码不能移库");
                }

                if (this.hus.Count > 0 && hu.QualityType != this.hus[0].QualityType)
                {
                    throw new BusinessException("质量状态不一致的条码不能混合移库");
                }

                FlowDetail matchedFlowDetail = new FlowDetail();
                var flowDetails = this.flowMaster.FlowDetails;

                #region 物料匹配
                if (flowMaster.IsManualCreateDetail)
                {
                    if (flowDetails != null)
                    {
                        var q = flowDetails.Where(f => f.Item.Equals(hu.Item, StringComparison.OrdinalIgnoreCase));
                        if (q.Count() > 0)
                        {
                            matchedFlowDetail = q.First();
                            //matchedFlowDetail.CurrentQty += hu.Qty;
                            //matchedFlowDetail.Carton++;
                        }
                        else
                        {
                            List<FlowDetail> flowDetailList = flowDetails.ToList();
                            if (flowMaster.FlowDetails != null)
                            {
                                flowDetailList = flowMaster.FlowDetails.ToList();
                            }
                            matchedFlowDetail = this.Hu2FlowDetail(flowMaster, hu);
                            flowDetailList.Add(matchedFlowDetail);
                            flowMaster.FlowDetails = flowDetailList.ToArray();
                        }
                    }
                    else
                    {
                        List<FlowDetail> flowDetailList = new List<FlowDetail>();
                        if (flowMaster.FlowDetails != null)
                        {
                            flowDetailList = flowMaster.FlowDetails.ToList();
                        }
                        matchedFlowDetail = this.Hu2FlowDetail(flowMaster, hu);
                        flowDetailList.Add(matchedFlowDetail);
                        flowMaster.FlowDetails = flowDetailList.ToArray();
                    }
                }
                else
                {
                    if (this.flowMaster.FlowDetails == null)
                    {
                        throw new BusinessException("没有找到和条码{0}的物料号{1}匹配的订单明细。", hu.HuId, hu.Item);
                    }

                    var matchedOrderDetailList = flowDetails.Where(o => o.Item == hu.Item);
                    if (matchedOrderDetailList == null || matchedOrderDetailList.Count() == 0)
                    {
                        throw new BusinessException("没有找到和条码{0}的物料号{1}匹配的订单明细。", hu.HuId, hu.Item);
                    }

                    matchedOrderDetailList = matchedOrderDetailList.Where(o => o.Uom.Equals(hu.Uom, StringComparison.OrdinalIgnoreCase));
                    if (matchedOrderDetailList == null || matchedOrderDetailList.Count() == 0)
                    {
                        throw new BusinessException("没有找到和条码{0}的单位{1}匹配的订单明细。", hu.HuId, hu.Uom);
                    }

                    if (this.flowMaster.IsOrderFulfillUC)
                    {
                        matchedOrderDetailList = matchedOrderDetailList.Where(o => o.UnitCount == hu.UnitCount);
                        if (matchedOrderDetailList == null || matchedOrderDetailList.Count() == 0)
                        {
                            throw new BusinessException("没有找到和条码{0}的包装数{1}匹配的订单明细。", hu.HuId, hu.UnitCount.ToString());
                        }
                    }
                    matchedFlowDetail = matchedOrderDetailList.First();
                }
                #endregion

                FlowDetailInput input = new FlowDetailInput();
                input.HuId = hu.HuId;
                input.Qty = hu.Qty;
                input.LotNo = hu.LotNo;
                input.Direction = hu.Direction;

                List<FlowDetailInput> flowDetailInputs = new List<FlowDetailInput>();
                if (matchedFlowDetail.FlowDetailInputs != null)
                {
                    flowDetailInputs = matchedFlowDetail.FlowDetailInputs.ToList();
                }
                flowDetailInputs.Add(input);
                matchedFlowDetail.FlowDetailInputs = flowDetailInputs.ToArray();
                matchedFlowDetail.CurrentQty += hu.Qty;
                matchedFlowDetail.Carton++;
                //
                base.hus.Insert(0, hu);
            }
            else
            {
                this.CancelHu(hu);
            }
            this.gvListDataBind();
        }