示例#1
0
 public void AddFlowDetail(FlowDetail flowDetail)
 {
     if (FlowDetails == null)
     {
         FlowDetails = new List<FlowDetail>();
     }
     FlowDetails.Add(flowDetail);
 }
        //public string Inproportion(string idStr, string weightStr, string totalQtyStr, string adjQtyStr, string Location, string Item)
        public string Inproportion(string idStr, string Location, string Item)
        {
            QuotaSearchModel searchModel=new QuotaSearchModel{Location=Location,Item=Item};
            TempData["QuotaSearchModel"] = searchModel;
            try
            {
                if (string.IsNullOrEmpty(idStr))
                {
                    throw new BusinessException(Resources.EXT.ControllerLan.Con_FlowDetailCanNotBeEmpty);
                }
                string[] idArr = idStr.Split(',');
                //string[] qtyArr = adjQtyStr.Split(',');
                //string[] weightArr = weightStr.Split(',');
                //string[] totalQtyArr = totalQtyStr.Split(',');

                decimal allWeight = 0;
                decimal allTotalQty = 0;
                decimal maxProportion = 0;
                IList<FlowDetail> FlowDetailList = new List<FlowDetail>();
                FlowDetail noNeedAdjDetail = new FlowDetail();
                for (int i = 0; i < idArr.Count(); i++)
                {
                    FlowDetail flowDetail = QueryMgr.FindById<FlowDetail>(Convert.ToInt32(idArr[i]));
                    allWeight += flowDetail.MrpWeight;
                    allTotalQty += flowDetail.MrpTotal;
                    if (flowDetail.MrpTotal / flowDetail.MrpWeight > maxProportion)
                    {
                        maxProportion = flowDetail.MrpTotal / flowDetail.MrpWeight;
                        noNeedAdjDetail = flowDetail;
                    }

                    FlowDetailList.Add(flowDetail);  
                }
                FlowDetailList.Remove(noNeedAdjDetail);
                if (noNeedAdjDetail.MrpTotalAdjust != 0)
                {
                    noNeedAdjDetail.MrpTotalAdjust = 0;
                    GenericMgr.Update(noNeedAdjDetail);
                }

                foreach (var flowDetail in FlowDetailList)
                {
                    flowDetail.MrpTotalAdjust = (noNeedAdjDetail.MrpTotal * flowDetail.MrpWeight) / noNeedAdjDetail.MrpWeight - flowDetail.MrpTotal;
                    GenericMgr.Update(flowDetail);
                }

                //pickListMgr.CreatePickList(orderDetailList);
                SaveSuccessMessage(Resources.MRP.Quota.Quota_Adjusted);
                return "Succeed";
            }
            catch (BusinessException ex)
            {
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode = 500;
                Response.Write(ex.GetMessages()[0].GetMessageString());
                return string.Empty;
            }
        }
示例#3
0
        public KanbanScan CreateKanbanScan(KanbanCard card, FlowDetail matchDetail, User scanUser, DateTime? scanTime)
        {
            KanbanScan scan = new KanbanScan();
            if (card != null && matchDetail != null && scanUser != null)
            {
                scan = Mapper.Map<KanbanCard, KanbanScan>(card);
                scan.ScanUserId = scanUser.Id;
                scan.ScanUserName = scanUser.Name;
                scan.ScanTime = scanTime;
                scan.ReferenceItemCode = card.ReferenceItemCode;
                //用物流中心记工位
                scan.LogisticCenterCode = matchDetail.BinTo;
                //FlowDetail fd = this.genericMgr.FindAll<FlowDetail>("from FlowDetail where Id = ? ", card.FlowDetailId).SingleOrDefault();
                scan.ScanQty = matchDetail.MinUnitCount;
                scan.IsOrdered = false;

                this.genericMgr.Create(scan);
                card.ScanId = scan.Id;
                return scan;
            }
            return scan;
        }
 public ActionResult _DetailNew(FlowDetail flowDetail, string id)
 {
     if (ModelState.IsValid)
     {
         if (false)//暂不做控制
         {
             // base.SaveErrorMessage(Resources.ErrorMessage.Errors_Existing_Code, flowDetail.Code);
         }
         else
         {
             flowDetail.BaseUom = base.genericMgr.FindById<Item>(flowDetail.Item).Uom;
             flowMgr.CreateFlowDetail(flowDetail);
             SaveSuccessMessage(Resources.SCM.FlowDetail.FlowDetail_Added);
             return RedirectToAction("_Detail/" + flowDetail.Flow);
         }
     }
     return PartialView(flowDetail);
 }
 public ActionResult _DetailNew(FlowDetail flowDetail, string id)
 {
     if (ModelState.IsValid)
     {
         if (false)//暂不做控制
         {
             // base.SaveErrorMessage(Resources.SYS.ErrorMessage.Errors_Existing_Code, flowDetail.Code);
         }
         else
         {
             IList<FlowDetail> flowDetailList = this.genericMgr.FindAll<FlowDetail>("select fd from FlowDetail as fd where fd.Flow='" + flowDetail.Flow + "' and fd.Item='" + flowDetail.Item + "'");
             if (flowDetailList.Count > 0)
             {
                 SaveErrorMessage(Resources.EXT.ControllerLan.Con_ItemAlreadyExistsPleaseReselect);
                 return PartialView(flowDetail);
             }
             flowDetail.BaseUom = this.genericMgr.FindById<Item>(flowDetail.Item).Uom;
             flowDetail.RoundUpOption = Sconit.CodeMaster.RoundUpOption.ToUp;
             FlowDetail flowDetailItem = this.genericMgr.FindAllIn<FlowDetail>
                 ("from FlowDetail where Flow = ? ", new object[] { flowDetail.Flow }).OrderByDescending(p=>p.Sequence).FirstOrDefault();
             flowDetail.Sequence = 10;
             if (flowDetailItem != null)
             {
                 flowDetail.Sequence = flowDetail.Sequence + flowDetailItem.Sequence;
             }
             flowMgr.CreateFlowDetail(flowDetail);
             SaveSuccessMessage(Resources.SCM.FlowDetail.FlowDetail_Added);
             return RedirectToAction("_Detail/" + flowDetail.Flow);
         }
     }
     return PartialView(flowDetail);
 }
示例#6
0
        public string CreateProcurementOrderFromXls(Stream inputStream,
            string flowCode, string extOrderNo, string refOrderNo,
            DateTime startTime, DateTime windowTime, CodeMaster.OrderPriority priority)
        {
            #region 导入数据
            if (inputStream.Length == 0)
            {
                throw new BusinessException("Import.Stream.Empty");
            }

            HSSFWorkbook workbook = new HSSFWorkbook(inputStream);

            ISheet sheet = workbook.GetSheetAt(0);
            IEnumerator rows = sheet.GetRowEnumerator();

            ImportHelper.JumpRows(rows, 1);

            #region 列定义
            int colSeqNo = 0;//序号
            int colItem = 1;//物料代码
            //int colItemDescription = 2;// 物料描述
            int colQty = 3;//数量
            int colUom = 4;//单位
            int colUnitCount = 5;//单包装
            int colLocationTo = 6;//来源库位
            #endregion

            IList<OrderDetail> exactOrderDetailList = new List<OrderDetail>();

            var flowMaster = this.genericMgr.FindById<FlowMaster>(flowCode);

            var flowDetailList = this.flowMgr.GetFlowDetailList(flowCode, false, true);

            while (rows.MoveNext())
            {
                HSSFRow row = (HSSFRow)rows.Current;
                if (!ImportHelper.CheckValidDataRow(row, 1, 9))
                {
                    break;//边界
                }
                int seqNo = 0;
                string itemCode = string.Empty;
                decimal qty = 0;
                string uom = string.Empty;
                decimal unitCount = 0;
                Location locationTo = null;

                #region 读取数据

                #region 读取序号
                try
                {
                    seqNo = Convert.ToInt32(row.GetCell(colSeqNo).NumericCellValue);
                }
                catch
                {
                    seqNo = 0;
                }
                #endregion

                #region 读取物料代码
                itemCode = ImportHelper.GetCellStringValue(row.GetCell(colItem));
                if (string.IsNullOrWhiteSpace(itemCode))
                {
                    ImportHelper.ThrowCommonError(row.RowNum, colItem, row.GetCell(colItem));
                }
                #endregion

                #region 读取数量
                try
                {
                    qty = Convert.ToDecimal(row.GetCell(colQty).NumericCellValue);
                }
                catch
                {
                    ImportHelper.ThrowCommonError(row.RowNum, colQty, row.GetCell(colQty));
                }
                #endregion

                #region 读取单位
                uom = ImportHelper.GetCellStringValue(row.GetCell(colUom));
                #endregion

                #region 读取单包装
                try
                {
                    unitCount = Convert.ToDecimal(row.GetCell(colUnitCount).NumericCellValue);
                }
                catch
                {
                    unitCount = 0;
                }
                #endregion

                #region 读取目的库位
                string locationToCode = ImportHelper.GetCellStringValue(row.GetCell(colLocationTo));
                if (!string.IsNullOrWhiteSpace(locationToCode))
                {
                    locationTo = this.genericMgr.FindById<Location>(locationToCode);
                    if (locationTo.Region != flowMaster.PartyTo)
                    {
                        throw new BusinessException("库位{0}不在区域{1}下", locationTo.Code, flowMaster.PartyTo);
                    }
                }
                #endregion

                #endregion

                #region 填充数据
                var flowDetail = flowDetailList.Where(f => f.Item == itemCode && f.LocationTo == locationToCode).FirstOrDefault();
                if (flowDetail == null)
                {
                    if (flowMaster.IsManualCreateDetail)
                    {
                        flowDetail = new FlowDetail();

                        var item = this.genericMgr.FindById<Entity.MD.Item>(itemCode);
                        flowDetail.OrderQty = qty;
                        flowDetail.BaseUom = item.Uom;
                        flowDetail.Item = itemCode;
                        if (seqNo > 0)
                        {
                            flowDetail.ExternalSequence = seqNo;
                        }
                        if (!string.IsNullOrWhiteSpace(uom))
                        {
                            flowDetail.Uom = uom;
                        }
                        else
                        {
                            flowDetail.Uom = item.Uom;
                        }
                        if (unitCount > 0)
                        {
                            flowDetail.UnitCount = unitCount;
                        }
                        else
                        {
                            flowDetail.UnitCount = item.UnitCount;
                        }
                        if (locationToCode == null)
                        {
                            flowDetail.LocationTo = flowMaster.LocationTo;
                        }
                        else
                        {
                            flowDetail.LocationTo = locationTo.Code;
                        }
                    }
                    else
                    {
                        throw new BusinessException("没有找到匹配的物流路线明细", itemCode, uom, unitCount.ToString());
                    }
                }
                else
                {
                    if (seqNo > 0)
                    {
                        flowDetail.ExternalSequence = seqNo;
                    }
                    flowDetail.OrderQty = qty;
                }
                flowMaster.AddFlowDetail(flowDetail);

                #endregion
            }

            #endregion

            #region 创建要货单
            OrderMaster orderMaster = TransferFlow2Order(flowMaster, true);

            orderMaster.ReferenceOrderNo = refOrderNo;
            orderMaster.ExternalOrderNo = extOrderNo;
            orderMaster.StartTime = startTime;
            orderMaster.WindowTime = windowTime;
            orderMaster.Priority = priority;
            this.CreateOrder(orderMaster);

            #endregion

            return orderMaster.OrderNo;
        }
        public IDictionary<string, decimal> GetHuId(FlowDetail flowDetail)
        {
            decimal uc = flowDetail.UnitCount;

            if (flowDetail.HuQty <= flowDetail.MaxUc)
            {
                uc = flowDetail.HuQty;
            }

            var HuIds = GetHuId(flowDetail.LotNo, flowDetail.Item, flowDetail.ManufactureParty, flowDetail.HuQty, uc);

            return HuIds;
        }
示例#8
0
 public void UpdateFlowDetail(FlowDetail flowDetail)
 {
     IList<ItemPackage> itemPackageList = genericMgr.FindAll<ItemPackage>("from ItemPackage as i where i.Item = ? and i.UnitCount = ?", new object[] { flowDetail.Item, flowDetail.UnitCount });
     if (itemPackageList == null || itemPackageList.Count == 0)
     {
         ItemPackage itemPackage = new ItemPackage();
         itemPackage.Item = flowDetail.Item;
         itemPackage.UnitCount = flowDetail.UnitCount;
         itemPackage.Description = string.IsNullOrEmpty(flowDetail.UnitCountDescription) ? string.Empty : flowDetail.UnitCountDescription;
         genericMgr.CreateWithTrim(itemPackage);
     }
     genericMgr.UpdateWithTrim(flowDetail);
 }
示例#9
0
        public List<MrpShiftPlan> ReadShiftPlanFromXls(Stream inputStream, DateTime startDate, DateTime endDate, string flow)
        {
            if (inputStream.Length == 0)
            {
                throw new BusinessException("Import.Stream.Empty");
            }

            HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
            ISheet sheet = workbook.GetSheetAt(0);
            IEnumerator rows = sheet.GetRowEnumerator();
            IRow dateRow = sheet.GetRow(2);
            ImportHelper.JumpRows(rows, 3);
            #region 列定义
            int colFlow = 0;// 路线
            int colItemCode = 1;//物料代码或参考物料号
            //int colItemDescription = 2;//物料描述
            int colUom = 3;//单位
            #endregion

            var shiftPlanList = new List<MrpShiftPlan>();
            #region 读取数据
            while (rows.MoveNext())
            {
                string itemCode = null;
                string uomCode = null;
                string flowCode = null;
                HSSFRow row = (HSSFRow)rows.Current;
                if (!ImportHelper.CheckValidDataRow(row, 0, 4))
                {
                    break;//边界
                }
                string rowIndex = (row.RowNum + 1).ToString();

                #region 读取路线
                try
                {
                    flowCode = ImportHelper.GetCellStringValue(row.GetCell(colFlow));
                    if (flowCode == null)
                    {
                        throw new BusinessException("生产线不能为空", rowIndex);
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(flow) && flow != flowCode)
                        {
                            continue;
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new BusinessException(ex.Message);
                }
                #endregion

                #region 读取物料代码
                try
                {
                    itemCode = ImportHelper.GetCellStringValue(row.GetCell(colItemCode));
                    if (itemCode == null)
                    {
                        throw new BusinessException("Import.ShipPlan.ItemCode.Empty", rowIndex);
                    }
                }
                catch
                {
                    throw new BusinessException("Import.ShipPlan.ItemCode.Error", rowIndex);
                }
                #endregion

                #region 读取单位
                try
                {
                    uomCode = ImportHelper.GetCellStringValue(row.GetCell(colUom));
                }
                catch (Exception ex)
                {
                    throw new BusinessException(ex.Message);
                }
                #endregion

                #region 读取数量
                try
                {
                    for (int i = 5; ; i++)
                    {
                        ICell dateCell = dateRow.GetCell(i - ((i - 5) % 3));

                        #region 读取计划日期
                        DateTime planDate = DateTime.Now;
                        string weekOfYear = string.Empty;

                        if (dateCell != null && dateCell.CellType == CellType.NUMERIC)
                        {
                            planDate = dateCell.DateCellValue;
                        }
                        else
                        {
                            break;
                        }
                        if (planDate.Date <= DateTime.Now)
                        {
                            continue;
                        }

                        if (planDate.Date < startDate.Date)
                        {
                            continue;
                        }
                        if (planDate.Date > endDate.Date)
                        {
                            break;
                        }
                        #endregion

                        double qty = 0;
                        if (row.GetCell(i) != null)
                        {
                            if (row.GetCell(i).CellType == CellType.NUMERIC)
                            {
                                qty = row.GetCell(i).NumericCellValue;
                            }
                            else
                            {
                                string qtyValue = ImportHelper.GetCellStringValue(row.GetCell(i));
                                if (qtyValue != null)
                                {
                                    qty = Convert.ToDouble(qtyValue);
                                }
                            }
                        }
                        else
                        {
                            continue;
                        }

                        if (qty < 0)
                        {
                            throw new BusinessException("Import.ShipPlan.Qty.MustGreatThan0", rowIndex);
                        }
                        else if (qty == 0)
                        {
                            continue;
                        }
                        else
                        {
                            var shiftPlan = new MrpShiftPlan();
                            shiftPlan.PlanDate = planDate;
                            shiftPlan.Item = itemCode;
                            shiftPlan.Flow = flowCode;
                            shiftPlan.Uom = uomCode;
                            shiftPlan.Qty = qty;
                            shiftPlanList.Add(shiftPlan);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new BusinessException("Import.ShipPlan.Qty.Error" + ex.Message, rowIndex);
                }
                #endregion
            }
            #endregion

            var flowCodes = shiftPlanList.Select(s => s.Flow).Distinct();
            #region 读取路线
            var flowDetailList = new List<FlowDetail>();
            foreach (var flowCode in flowCodes)
            {
                var flowDetails = this.flowMgr.GetFlowDetailList(flowCode, false, true);
                if (flowDetails == null || flowDetails.Count() == 0)
                {
                    FlowMaster flowMaster = this.genericMgr.FindById<FlowMaster>(flowCode);
                    if (flowMaster.IsManualCreateDetail)
                    {
                        flowDetails = new List<FlowDetail>();
                        var flowDetail = new FlowDetail();
                        flowDetail.CurrentFlowMaster = flowMaster;
                        flowDetails.Add(flowDetail);
                    }
                }
                flowDetailList.AddRange(flowDetails);
            }
            #endregion

            BusinessException bex = new BusinessException();
            #region 校验数据的有效性
            foreach (var shiftPlan in shiftPlanList)
            {
                var flowDetails = flowDetailList.Where(f => f.CurrentFlowMaster.Code == shiftPlan.Flow);
                if (!flowDetails.First().CurrentFlowMaster.IsManualCreateDetail)
                {
                    if (string.IsNullOrWhiteSpace(shiftPlan.Uom))
                    {
                        flowDetails = flowDetails.Where(f => f.Item == shiftPlan.Item);
                        if (flowDetails == null || flowDetails.Count() == 0)
                        {
                            bex.AddMessage("此物料在路线中不存在");
                        }
                        else
                        {
                            shiftPlan.Uom = flowDetails.First().Uom;
                        }
                    }
                    else
                    {
                        flowDetails = flowDetails.Where(f => f.Item == shiftPlan.Item && f.Uom == shiftPlan.Uom);
                        if (flowDetails == null || flowDetails.Count() == 0)
                        {
                            bex.AddMessage("此物料在路线中不存在");
                        }
                    }
                    //shiftPlan.Machine = flowDetails.First().Machine;
                    //Machine machine = this.genericMgr.FindById<Machine>(shiftPlan.Machine);
                    //shiftPlan.ShiftQuota = machine.ShiftQuota;
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(shiftPlan.Uom))
                    {
                        flowDetails = flowDetails.Where(f => f.Item == shiftPlan.Item);
                    }
                    else
                    {
                        flowDetails = flowDetails.Where(f => f.Item == shiftPlan.Item && f.Uom == shiftPlan.Uom);
                    }
                    if (flowDetails != null && flowDetails.Count() > 0)
                    {
                        //shiftPlan.Machine = flowDetails.First().Machine;
                        //shiftPlan.Uom = flowDetails.First().Uom;
                        //Machine machine = this.genericMgr.FindById<Machine>(shiftPlan.Machine);
                        //shiftPlan.ShiftQuota = machine.ShiftQuota;
                    }
                    else
                    {
                        Item item = this.genericMgr.FindById<Item>(shiftPlan.Item);
                        if (!string.IsNullOrWhiteSpace(shiftPlan.Uom))
                        {
                            Uom uom = this.genericMgr.FindById<Uom>(shiftPlan.Uom);
                        }
                        else
                        {
                            shiftPlan.Uom = item.Uom;
                        }
                    }
                }
            }
            #endregion
            if (!bex.HasMessage)
            {
                int planVersion = int.Parse(numberControlMgr.GetNextSequence(com.Sconit.Entity.MRP.BusinessConstants.NUMBERCONTROL_SHIFTPLAN));
                foreach (var shiftPlan in shiftPlanList)
                {
                    var oldShiftPlans = this.genericMgr.FindAll<MrpShiftPlan>
                        ("select d from ShiftPlan as d where d.PlanDate=? and d.Item=? and d.Flow=? and d.Shift=? ",
                        new object[] { shiftPlan.PlanDate, shiftPlan.Item, shiftPlan.Flow, shiftPlan.Shift });
                    if (oldShiftPlans != null && oldShiftPlans.Count() > 0)
                    {
                        //var oldShiftPlan = oldShiftPlans.First();
                        //if (shiftPlan.Machine != oldShiftPlan.Machine
                        //    || shiftPlan.Qty != oldShiftPlan.Qty
                        //    || shiftPlan.ShiftQuota != oldShiftPlan.ShiftQuota
                        //    || shiftPlan.Uom != oldShiftPlan.Uom)
                        //{
                        //    if (oldShiftPlan.OrderQty > 0)
                        //    {
                        //        bex.AddMessage("已转生产单的班产计划不能再进行更改");
                        //    }
                        //    else
                        //    {
                        //        oldShiftPlan.PlanVersion = planVersion;
                        //        oldShiftPlan.Machine = shiftPlan.Machine;
                        //        oldShiftPlan.Qty = shiftPlan.Qty;
                        //        oldShiftPlan.ShiftQuota = shiftPlan.ShiftQuota;
                        //        oldShiftPlan.Uom = shiftPlan.Uom;
                        //        //this.genericMgr.Update(oldShiftPlan);

                        //        //createlog
                        //        var shiftPlanLog = new MrpShiftPlanLog();
                        //        shiftPlanLog.PlanVersion = planVersion;
                        //        shiftPlanLog.PlanId = oldShiftPlan.Id;
                        //        shiftPlanLog.Machine = oldShiftPlan.Machine;
                        //        shiftPlanLog.Qty = oldShiftPlan.Qty;
                        //        shiftPlanLog.ShiftQuota = oldShiftPlan.ShiftQuota;
                        //        shiftPlanLog.Uom = oldShiftPlan.Uom;
                        //        this.genericMgr.Create(shiftPlanLog);
                        //    }
                        //}
                    }
                    else
                    {
                        //shiftPlan.PlanVersion = planVersion;
                        //this.genericMgr.Create(shiftPlan);

                        //var shiftPlanLog = new MrpShiftPlanLog();
                        //shiftPlanLog.PlanVersion = planVersion;
                        //shiftPlanLog.PlanId = shiftPlan.Id;
                        //shiftPlanLog.Machine = shiftPlan.Machine;
                        //shiftPlanLog.Qty = shiftPlan.Qty;
                        //shiftPlanLog.ShiftQuota = shiftPlan.ShiftQuota;
                        //shiftPlanLog.Uom = shiftPlan.Uom;
                        //this.genericMgr.Create(shiftPlanLog);
                    }
                }
            }
            else
            {
                throw bex;
            }
            return shiftPlanList;
        }
        public ActionResult _DetailEdit(FlowDetail flowDetail, int? id)
        {
            if (ModelState.IsValid)
            {
                IList<FlowDetail> flowDetailList = this.genericMgr.FindAll<FlowDetail>("select fd from FlowDetail as fd where fd.Flow='" + flowDetail.Flow + "' and fd.Item='" + flowDetail.Item + "'");
                if (flowDetailList.Count > 0)
                {
                    if (flowDetailList[0].Id == flowDetail.Id)
                    {
                        flowDetail.BaseUom = this.genericMgr.FindById<Item>(flowDetail.Item).Uom;
                        flowMgr.UpdateFlowDetail(flowDetail);
                        SaveSuccessMessage(Resources.SCM.FlowDetail.FlowDetail_Updated);
                    }
                    else
                    {
                        SaveErrorMessage(Resources.EXT.ControllerLan.Con_ItemAlreadyExistsPleaseReselect);
                    }

                }
                else
                {
                    flowDetail.BaseUom = this.genericMgr.FindById<Item>(flowDetail.Item).Uom;
                    flowMgr.UpdateFlowDetail(flowDetail);
                    SaveSuccessMessage(Resources.SCM.FlowDetail.FlowDetail_Updated);
                }
            }

            TempData["TabIndex"] = 2;
            return PartialView(flowDetail);
        }
        public ActionResult _AjaxLoadingTree(TreeViewItem node)
        {
            try
            {
                string parentId = !String.IsNullOrEmpty(node.Value) ? (node.Value) : null;
                IList<TreeViewItemModel> nodes = new List<TreeViewItemModel>();

                if (parentId != null)
                {
                    string[] s = parentId.Split(';');
                    if (s != null && s.Length == 4)
                    {
                        FlowDetail currentFlowDetail = new FlowDetail();
                        currentFlowDetail.Item = s[0];
                        string locationFrom = s[1];
                        currentFlowDetail.Flow = s[2];
                        currentFlowDetail.Bom = s[3];
                        var locationFroms = locationFrom.Split(',');
                        currentFlowDetail.DefaultLocationFrom = locationFroms[0];
                        if (locationFroms.Length == 2)
                        {
                            currentFlowDetail.DefaultExtraLocationFrom = locationFroms[1];
                        }
                        currentFlowDetail.CurrentFlowMaster = this.genericMgr.FindById<FlowMaster>(currentFlowDetail.Flow);

                        var newFlowDetails = new List<FlowDetail>();
                        if (currentFlowDetail.CurrentFlowMaster.Type == CodeMaster.OrderType.Production
                            || currentFlowDetail.CurrentFlowMaster.Type == CodeMaster.OrderType.SubContract)
                        {
                            string bom = string.IsNullOrWhiteSpace(currentFlowDetail.Bom) ? currentFlowDetail.Item : currentFlowDetail.Bom;

                            var bomDetails = bomMgr.GetFlatBomDetail(bom, DateTime.Now);
                            newFlowDetails.AddRange(bomDetails.Select(p => new FlowDetail
                            {
                                Item = p.Item,
                                DefaultLocationFrom = string.IsNullOrWhiteSpace(p.Location) ? currentFlowDetail.DefaultLocationFrom : p.Location,
                                DefaultExtraLocationFrom = currentFlowDetail.DefaultExtraLocationFrom
                            }));
                        }
                        else
                        {
                            newFlowDetails.Add(new FlowDetail
                            {
                                Item = currentFlowDetail.Item,
                                DefaultLocationFrom = currentFlowDetail.DefaultLocationFrom,
                                DefaultExtraLocationFrom = currentFlowDetail.DefaultExtraLocationFrom
                            });
                            if (!string.IsNullOrWhiteSpace(currentFlowDetail.Bom)
                                && currentFlowDetail.CurrentFlowMaster.Type == CodeMaster.OrderType.Procurement)
                            {
                                var bomDetails = bomMgr.GetFlatBomDetail(currentFlowDetail.Bom, DateTime.Now);
                                newFlowDetails.AddRange(bomDetails.Select(p => new FlowDetail
                                {
                                    Item = p.Item,
                                    DefaultLocationFrom = string.IsNullOrWhiteSpace(p.Location) ? currentFlowDetail.DefaultLocationFrom : p.Location,
                                    DefaultExtraLocationFrom = currentFlowDetail.DefaultExtraLocationFrom
                                }));
                            }
                        }

                        var flowDetailList = this.genericMgr.FindAllIn<FlowDetail>
                            (" from FlowDetail where Item in(?", newFlowDetails.Select(p => p.Item).Distinct());
                        foreach (var flowDetail in flowDetailList)
                        {
                            flowDetail.CurrentFlowMaster = genericMgr.FindById<FlowMaster>(flowDetail.Flow);
                            flowDetail.DefaultLocationFrom = string.IsNullOrWhiteSpace(flowDetail.LocationFrom)
                                ? flowDetail.CurrentFlowMaster.LocationFrom : flowDetail.LocationFrom;
                            flowDetail.DefaultLocationTo = string.IsNullOrWhiteSpace(flowDetail.LocationTo)
                                ? flowDetail.CurrentFlowMaster.LocationTo : flowDetail.LocationTo;
                            flowDetail.DefaultExtraLocationFrom = string.IsNullOrWhiteSpace(flowDetail.ExtraLocationFrom)
                                ? flowDetail.CurrentFlowMaster.ExtraLocationFrom : flowDetail.ExtraLocationFrom;
                            flowDetail.DefaultExtraLocationTo = string.IsNullOrWhiteSpace(flowDetail.ExtraLocationTo)
                                ? flowDetail.CurrentFlowMaster.ExtraLocationTo : flowDetail.ExtraLocationTo;
                        }

                        foreach (var newFlowDetail in newFlowDetails)
                        {
                            flowDetailList = flowDetailList.Where(p => p.Item == newFlowDetail.Item).ToList();
                            var nextFlowDetails = flowDetailList.Where(p => newFlowDetail.DefaultLocationFrom == p.DefaultLocationTo);

                            #region 如果没有找到,考虑其他来源库位
                            if (nextFlowDetails.Count() == 0 && !string.IsNullOrWhiteSpace(newFlowDetail.DefaultExtraLocationFrom))
                            {
                                var locations = newFlowDetail.DefaultExtraLocationFrom.Split('|').Distinct();
                                foreach (var location in locations)
                                {
                                    nextFlowDetails = flowDetailList.Where(f => f.DefaultLocationTo == location);
                                    if (nextFlowDetails.Count() > 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            #endregion

                            #region 如果没有找到,考虑其他目的库位
                            if (nextFlowDetails.Count() == 0)
                            {
                                var locations = flowDetailList.Where(p => !string.IsNullOrWhiteSpace(p.DefaultExtraLocationTo))
                                    .SelectMany(p => p.DefaultExtraLocationTo.Split('|')).Distinct();
                                foreach (var location in locations)
                                {
                                    nextFlowDetails = flowDetailList.Where(f => location == newFlowDetail.DefaultLocationFrom);
                                    if (nextFlowDetails.Count() > 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            #endregion

                            FillFlowDetial(nextFlowDetails);
                            foreach (var nextFlowDetail in nextFlowDetails)
                            {
                                Item item = itemMgr.GetCacheItem(nextFlowDetail.Item);
                                TreeViewItemModel tvim = new TreeViewItemModel();
                                tvim.Text = string.Format(Resources.EXT.ControllerLan.Con_LineMaterialLocationFromLocationToMRPweights,
                                    nextFlowDetail.Flow, nextFlowDetail.CurrentFlowMaster.Description, nextFlowDetail.Item,
                                    item.Description, nextFlowDetail.LocationFrom, nextFlowDetail.LocationTo,
                                    nextFlowDetail.MrpWeight, nextFlowDetail.CurrentFlowMaster.FlowTypeDescription);
                                tvim.Value = string.Format("{0};{1};{2};{3}",
                                     nextFlowDetail.Item, nextFlowDetail.LocationFrom, nextFlowDetail.Flow, nextFlowDetail.Bom);
                                tvim.LoadOnDemand = true;
                                nodes.Add(tvim);
                            }
                        }
                    }
                }
                return new JsonResult { Data = nodes };
            }
            catch (Exception ex)
            {
                SaveErrorMessage(ex);
                return new JsonResult { };
            }
        }
示例#12
0
        private KanbanCard GetKanbanCardFromKanbanFlow(FlowMaster fm, Entity.SCM.FlowStrategy fs, FlowDetail fd, string multiSupplyGroup,
            DateTime effDate, User calcUser, Boolean createNow)
        {
            KanbanCard card = new KanbanCard();
            card.Flow = fm.Code;
            card.FlowDetailId = fd.Id;
            //card.KBCalc = fs.KBCalc;

            card.OpRef = fd.BinTo; //工位
            card.LocBin = fd.Dock; // 配送路径
            card.Region = fm.PartyTo;
            card.GroupDesc = fd.ProductionScan;//工位中文描述
            Region r = genericMgr.FindById<Region>(fm.PartyTo);
            card.RegionName = genericMgr.FindById<Region>(fm.PartyTo).Name;

            card.Supplier = fm.PartyFrom;
            Party s = genericMgr.FindById<Party>(fm.PartyFrom);
            if (s != null)
            {
                card.SupplierName = s.Name;
            }
            if (s is Supplier)
            {
                Supplier su = s as Supplier;
                card.SupplierName = string.IsNullOrEmpty(su.ShortCode) ? s.Name.Substring(0, 4) : su.ShortCode;
            }
            card.Item = fd.Item;
            card.ItemType = fd.ItemType;
            Item item = genericMgr.FindById<Item>(card.Item);
            if (item != null)
            {
                card.ItemDescription = item.Description;
                card.ReferenceItemCode = item.ReferenceCode;
                //零件类型
              
            }

            card.Status = KBStatus.Initial;
            card.EffectiveDate = effDate;
            card.FreezeDate = DateTime.Parse("2999-1-1 00:00:00");
            card.LastUseDate = DateTime.Parse("1900-1-1 00:00:00");
            card.NeedReprint = true;
            //上线包装
            card.Qty = fd.MinUnitCount;
            //容器代码
            card.Container = fd.Container;
            card.OpRefSequence = fd.OprefSequence; //看板号

            card.KanbanDeltaNum = 1;
            card.Location = fm.LocationTo;
            return card;
        }
        public ActionResult _DetailEdit(FlowDetail flowDetail, int? id)
        {
            if (ModelState.IsValid)
            {
                flowDetail.BaseUom = this.genericMgr.FindById<Item>(flowDetail.Item).Uom;
                flowDetail.BillTerm = com.Sconit.CodeMaster.OrderBillTerm.ReceivingSettlement;
                flowMgr.UpdateFlowDetail(flowDetail);
                SaveSuccessMessage(Resources.SCM.FlowDetail.FlowDetail_Updated);
            }

            TempData["TabIndex"] = 2;
            return PartialView(flowDetail);
        }
示例#14
0
        private void writeContent(string companyCode, int pageIndex, int num, FlowDetail kanBanCard, int count)
        {
            // HY号:(旧图号)
            this.SetRowCell(pageIndex, 0, 2, kanBanCard.ReferenceItemCode, num);

            // PRP号(新图号)
            this.SetRowCell(pageIndex, 1, 2, kanBanCard.Item, num);

            this.SetRowCell(pageIndex, 1, 3, kanBanCard.Flow, num);
            this.SetRowCell(pageIndex, 2, 2, kanBanCard.ItemDescription, num);
            this.SetRowCell(pageIndex, 3, 2, kanBanCard.ProductionScan, num);
            this.SetRowCell(pageIndex, 3, 3, kanBanCard.Container, num);
            this.SetRowCell(pageIndex, 4, 2, kanBanCard.OprefSequence, num);
            //this.SetRowCell(pageIndex, 4, 2, kanBanCard.Code, num);

            //this.SetRowCell(pageIndex, 3, 3, kanBanCard.PackType, num);
            /*
            else if (hu.Item.Type.Equals("P")) //原材料
            {
                //画方框
                Cell cell1 = this.GetCell(this.GetRowIndexAbsolute(pageIndex, getRowIndex(2, num)), getColumnIndex(4, num));
                CellStyle cellStyle1 = workbook.CreateCellStyle();
                cellStyle1.BorderBottom = NPOI.SS.UserModel.CellBorderType.NONE;
                cellStyle1.BorderLeft = NPOI.SS.UserModel.CellBorderType.THIN;
                cellStyle1.BorderRight = NPOI.SS.UserModel.CellBorderType.THIN;
                cellStyle1.BorderTop = NPOI.SS.UserModel.CellBorderType.THIN;
                cell1.CellStyle = workbook.CreateCellStyle();
                cell1.CellStyle.CloneStyleFrom(cellStyle1);

                CellStyle cellStyle2 = workbook.CreateCellStyle();
                Cell cell2 = this.GetCell(this.GetRowIndexAbsolute(pageIndex, getRowIndex(3, num)), getColumnIndex(4, num));
                cellStyle2.BorderLeft = NPOI.SS.UserModel.CellBorderType.THIN;
                cellStyle2.BorderRight = NPOI.SS.UserModel.CellBorderType.THIN;
                cellStyle2.BorderBottom = NPOI.SS.UserModel.CellBorderType.THIN;
                cellStyle2.BorderTop = NPOI.SS.UserModel.CellBorderType.NONE;
                cell2.CellStyle = workbook.CreateCellStyle();
                cell2.CellStyle.CloneStyleFrom(cellStyle2);

                //hu id内容
                string barCode = Utility.BarcodeHelper.GetBarcodeStr(hu.HuId, this.barCodeFontName);
                this.SetRowCell(pageIndex, 0, 0, barCode, num);
                //hu id内容
                this.SetRowCell(pageIndex, 1, 0, hu.HuId, num);
                //PART NO.内容
                this.SetRowCell(pageIndex, 3, 0, hu.Item.Code, num);
                //批号LotNo
                this.SetRowCell(pageIndex, 5, 0, hu.LotNo, num);
                //QUANTITY.
                this.SetRowCell(pageIndex, 4, 2, "QUANTITY.", num);
                //QUANTITY.
                this.SetRowCell(pageIndex, 5, 2, hu.Qty.ToString("0.########"), num);
                //DESCRIPTION	
                this.SetRowCell(pageIndex, 6, 0, "DESCRIPTION.", num);
                //DESCRIPTION内容
                this.SetRowCell(pageIndex, 7, 0, hu.Item.Description, num);
                //SUPPLIER
                this.SetRowCell(pageIndex, 8, 0, "SUPPLIER.", num);
                //SUPPLIER内容
                this.SetRowCell(pageIndex, 9, 0, hu.ManufactureParty == null ? string.Empty : hu.ManufactureParty.Name, num);
                //PRINTED DATE:内容
                this.SetRowCell(pageIndex, 10, 1, DateTime.Now.ToString("MM/dd/yy"), num);
                //print name 内容
                this.SetRowCell(pageIndex, 10, 3, userName, num);

            }*/
        }
示例#15
0
        public IDictionary<string, decimal> GetHuId(FlowDetail flowDetail)
        {
            //IDictionary<string, decimal> HuIds = new Dictionary<string, decimal>();

            //SqlParameter[] parm = new SqlParameter[5];

            //parm[0] = new SqlParameter("@LotNo", SqlDbType.VarChar, 50);
            //parm[0].Value = flowDetail.LotNo;

            //parm[1] = new SqlParameter("@Item", SqlDbType.VarChar, 50);
            //parm[1].Value = flowDetail.Item;

            //parm[2] = new SqlParameter("@Qty", SqlDbType.Decimal);
            //parm[2].Precision = 18;
            //parm[2].Scale = 8;
            //parm[2].Value = flowDetail.HuQty;

            //parm[3] = new SqlParameter("@UC", SqlDbType.Decimal);
            //parm[3].Precision = 18;
            //parm[3].Scale = 8;
            //parm[3].Value = flowDetail.UnitCount;

            //parm[4] = new SqlParameter("@ManufactureParty", SqlDbType.VarChar, 50);
            //parm[4].Value = flowDetail.ManufactureParty;

            //DataSet ds = sqlDao.GetDatasetByStoredProcedure("usp_GetHuId", parm);
            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            //    HuIds.Add((string)dr.ItemArray[0], (decimal)dr.ItemArray[1]);
            //}

            var HuIds = GetHuId(flowDetail.LotNo, flowDetail.Item, flowDetail.ManufactureParty,
              flowDetail.HuQty, flowDetail.UnitCount);

            return HuIds;
        }
示例#16
0
        public void BatchTransferDetailXls(Stream inputStream)
        {
            if (inputStream.Length == 0)
            {
                throw new BusinessException("Import.Stream.Empty");
            }

            HSSFWorkbook workbook = new HSSFWorkbook(inputStream);

            ISheet sheet = workbook.GetSheetAt(0);
            IEnumerator rows = sheet.GetRowEnumerator();

            ImportHelper.JumpRows(rows, 10);
            BusinessException businessException = new BusinessException();
            #region 列定义

            int colFlow = 1;//路线代码
            int colItem = 2;// 物料代码
            int colSafeStock = 5;//安全库存
            int colMaxStock = 6;//最大库存
            int colRoundUpOption = 7;//圆整系数
            int colIsChangeUnitCount = 8;//是否修改包装
            int colRouting = 9;//捡货库格
            int colIsDelete = 10;//删除
            int rowCount = 10;
            #endregion
            IList<FlowDetail> insertFlowDetailList = new List<FlowDetail>();
            IList<FlowDetail> updateFlowDetailList = new List<FlowDetail>();
            IList<FlowDetail> exactFlowDetailList = new List<FlowDetail>();
            IList<FlowMaster> allFlowMaster = this.genericMgr.FindAll<FlowMaster>();
            IList<FlowDetail> allFlowDet = this.genericMgr.FindEntityWithNativeSql<FlowDetail>("select d.* from SCM_FlowDet as d where exists( select 1 from SCM_FlowMstr as m where m.code=d.Flow and m.Type=2 )");
            while (rows.MoveNext())
            {
                rowCount++;
                HSSFRow row = (HSSFRow)rows.Current;
                if (!ImportHelper.CheckValidDataRow(row, 1, 8))
                {
                    break;//边界
                }
                FlowMaster flowMaster = null;
                string flow = string.Empty;//路线
                string item = string.Empty; ;// 物料
                decimal safeStock = 0;//单包装
                decimal maxStock = 0;//包装描述
                int roundUpOption = 0;//圆整系数
                bool isDelete = true;//删除
                string changeUnitCount = string.Empty;//是否修改包装
                string routing = string.Empty;//捡货库格
                #region 读取数据

                #region 读取Flow
                flow = ImportHelper.GetCellStringValue(row.GetCell(colFlow));
                if (string.IsNullOrWhiteSpace(flow))
                {
                    businessException.AddMessage(string.Format("第{0}行:路线不能为空。", rowCount));
                    continue;
                }
                else
                {
                    flowMaster = allFlowMaster.FirstOrDefault(f => f.Code == flow);
                    if (flowMaster == null)
                    {
                        businessException.AddMessage(string.Format("第{0}行:导入路线{1}不存在系统中,请检查数据的准确性", rowCount, flow));
                        continue;
                    }
                }

                #endregion

                #region Item
                item = ImportHelper.GetCellStringValue(row.GetCell(colItem));
                if (string.IsNullOrWhiteSpace(item))
                {
                    businessException.AddMessage(string.Format("第{0}行:物料编号不能为空。", rowCount));
                    continue;
                }
                IList<Item> itemList = genericMgr.FindAll<Item>(" from Item as i  where i.Code=?", item);
                if (itemList.Count <= 0)
                {
                    businessException.AddMessage(string.Format("第{0}行:导入物料代码{1}不存在系统中,请检查数据的准确性", rowCount, item));
                    continue;
                }
                #endregion

                var e = exactFlowDetailList.Where(p => p.Flow == flow && p.Item == item);
                //文件内也不能出现重复物料
                if (e.Count() > 0)
                {
                    businessException.AddMessage(string.Format("第{2}行:路线{0}存在相同的物料代码{1}超过1行,请检查数据的准确性", flow, item, rowCount));
                    continue;
                }

                #region 读取删除标示
                string isDeleteRead = ImportHelper.GetCellStringValue(row.GetCell(colIsDelete));
                if (isDeleteRead == null || isDeleteRead.Trim() == string.Empty)
                {
                    businessException.AddMessage(string.Format("第{0}行:删除标识不能为空。", rowCount));
                    continue;
                    //rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineFieldCanNotBeNull, colCount.ToString(), Resources.SCM.FlowMaster.FlowMaster_IsActive));
                }
                else
                {
                    switch (isDeleteRead.ToUpper())
                    {
                        case "Y":
                            isDelete = true; //新增
                            break;
                        case "N":
                            isDelete = false;//删除
                            break;
                        default:
                            businessException.AddMessage(string.Format("第{0}行:删除标识{1}不正确。", rowCount, isDeleteRead));
                            break;
                    }
                }
                #endregion


                if (!isDelete)
                {
                    #region 删除
                    var isExists = allFlowDet.Where(a => a.Flow == flow && a.Item == item);
                    if (isExists != null && isExists.Count() > 0)
                    {
                        exactFlowDetailList.Add(isExists.First());
                        continue;
                    }
                    else
                    {
                        businessException.AddMessage(string.Format("第{0}行:路线代码{1}+物料{2}找不到对应的数据。", rowCount, flow, item));
                        continue;
                    }
                    #endregion
                }
                else
                {

                    #region 安全库存
                    //string readSafe = ImportHelper.GetCellStringValue(row.GetCell(colSafeStock));
                    //if (!string.IsNullOrWhiteSpace(readSafe))
                    //{
                    //    decimal.TryParse(readSafe, out safeStock);
                    //    if (safeStock < 0)
                    //    {
                    //        businessException.AddMessage(string.Format("第{0}行:安全库存{1}填写有误。", rowCount, safeStock));
                    //        continue;
                    //    }
                    //}
                    #endregion

                    #region 最大库存
                    //string readMax = ImportHelper.GetCellStringValue(row.GetCell(colMaxStock));
                    //if (!string.IsNullOrWhiteSpace(readMax))
                    //{
                    //    decimal.TryParse(readMax, out maxStock);
                    //    if (maxStock < 0)
                    //    {
                    //        businessException.AddMessage(string.Format("第{0}行:最大库存{1}填写有误。", rowCount, maxStock));
                    //        continue;
                    //    }
                    //}
                    #endregion

                    #region 圆整系数
                    string readRound = ImportHelper.GetCellStringValue(row.GetCell(colRoundUpOption));
                    if (!string.IsNullOrWhiteSpace(readRound))
                    {
                        switch (readRound)
                        {
                            case "0":
                                roundUpOption = 0;
                                break;
                            case "1":
                                roundUpOption = 1;
                                break;
                            case "2":
                                roundUpOption = 2;
                                break;
                            default:
                                businessException.AddMessage(string.Format("第{0}行:圆整系数{1}填写有误。", rowCount, readRound));
                                break;
                        }
                    }
                    else
                    {
                        businessException.AddMessage(string.Format("第{0}行:圆整系数不能为空。", rowCount));
                        continue;
                    }
                    #endregion

                    #region 是否允许修改包装
                    changeUnitCount = ImportHelper.GetCellStringValue(row.GetCell(colIsChangeUnitCount));
                    if (string.IsNullOrWhiteSpace(changeUnitCount))
                    {
                        businessException.AddMessage(string.Format("第{0}行:是否允许修改包装不能为空。", rowCount));
                        continue;
                    }
                    try
                    {
                        Convert.ToBoolean(changeUnitCount);
                    }
                    catch (Exception ex)
                    {
                        businessException.AddMessage(string.Format("第{0}行:导入是否允许修改包装错误,只能导入True,False。", rowCount));
                        continue;
                    }
                    #endregion

                    //捡货库格
                    routing = ImportHelper.GetCellStringValue(row.GetCell(colRouting));


                    FlowDetail flowDetail = new FlowDetail();
                    var flowdets = allFlowDet.Where(a => a.Item == item && a.Flow == flow).ToList();
                    //this.genericMgr.FindAll<FlowDetail>(" select d from FlowDetail as d where d.Item=? and d.Flow=? ", new object[] { item, flow }, new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String });
                    if (flowdets != null && flowdets.Count > 0)
                    {
                        flowDetail = flowdets.First();
                        flowDetail.IsUpdate = true;
                    }
                    flowDetail.Flow = flow;
                    flowDetail.Item = item;
                    flowDetail.ItemDescription = itemList[0].Description;
                    flowDetail.ReferenceItemCode = itemList[0].ReferenceCode;
                    //flowDetail.SafeStock = safeStock;
                    //flowDetail.MaxStock = maxStock;
                    flowDetail.RoundUpOption = (CodeMaster.RoundUpOption)roundUpOption;
                    flowDetail.IsChangeUnitCount = Convert.ToBoolean(changeUnitCount);
                    flowDetail.IsActive = true;
                    //if (flowDetail.Id == 0)
                    //{
                    flowDetail.Container = itemList[0].Container;
                    flowDetail.MinUnitCount = itemList[0].MinUnitCount;
                    flowDetail.UnitCount = itemList[0].MinUnitCount;    //张敏说单包装 跟上线包装一致
                    flowDetail.Uom = itemList[0].Uom;
                    flowDetail.BaseUom = itemList[0].Uom;
                    flowDetail.PartyFrom = flowMaster.PartyFrom;
                    flowDetail.LocationTo = flowMaster.LocationTo;
                    flowDetail.Routing = routing;

                    //}
                    //if (allFlowDet.Where(ef => ef.PartyFrom == flowMaster.PartyFrom && ef.LocationTo == flowMaster.LocationTo && ef.Item == flowDetail.Item && ef.Id != flowDetail.Id).Count() > 0)
                    //{
                    //    businessException.AddMessage(string.Format("第{0}行:来源区域{1}+物料{2}+目的库位{3}已经存在数据库。", rowCount, flowMaster.PartyFrom, item, flowMaster.LocationTo));
                    //    continue;
                    //}

                    #region 来源区域 目的库位 物料 不能在移库路线中存在
                    int checkeSame = this.genericMgr.FindAllWithNativeSql<int>(" select COUNT(*) as countSum  from SCM_FlowDet as d where d.Item=? and exists( select 1 from SCM_FlowMstr as m where m.Code=d.Flow and m.PartyFrom=? and m.PartyTo=? and m.Type=2  ) and d.Id <> ?", new object[] { item, flowMaster.PartyFrom, flowMaster.PartyTo, flowDetail.Id })[0];
                    if (checkeSame > 0)
                    {
                        businessException.AddMessage(string.Format("第{0}行:来源区域{1}+物料{2}+目的区域{3}已经存在数据库。", rowCount, flowMaster.PartyFrom, item, flowMaster.PartyTo));
                        continue;
                    }

                    if (exactFlowDetailList.Where(ef => ef.PartyFrom == flowMaster.PartyFrom && ef.PartyTo == flowMaster.PartyTo && ef.Item == flowDetail.Item && ef.Id != flowDetail.Id && (ef.Id == 0 || ef.IsUpdate)).Count() > 0)
                    {
                        businessException.AddMessage(string.Format("第{0}行:来源区域{1}+物料{2}+目的区域{3}在模板中重复。", rowCount, flowMaster.PartyFrom, item, flowMaster.PartyTo));
                        continue;
                    }

                    #endregion
                    exactFlowDetailList.Add(flowDetail);
                }




                //var flowdets = allFlowDet.Where(a => a.Item == item && a.Flow == flow).ToList();
                ////this.genericMgr.FindAll<FlowDetail>(" select d from FlowDetail as d where d.Item=? and d.Flow=? ", new object[] { item, flow }, new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String });
                //if (flowdets != null && flowdets.Count > 0)
                //{
                //    flowDetail = flowdets.First();
                //    flowDetail.IsUpdate = true;
                //}
                #endregion


            }

            if (businessException.HasMessage)
            {
                throw businessException;
            }

            if (exactFlowDetailList != null && exactFlowDetailList.Count > 0)
            {
                foreach (FlowDetail flowDet in exactFlowDetailList)
                {
                    try
                    {
                        if (flowDet.Id == 0)
                        {
                            this.CreateFlowDetail(flowDet);
                        }
                        else if (flowDet.IsUpdate)
                        {
                            this.UpdateFlowDetail(flowDet);
                        }
                        else
                        {
                            this.genericMgr.Delete(flowDet);
                        }
                        this.genericMgr.FlushSession();
                    }
                    catch (Exception ex)
                    {
                        businessException.AddMessage(ex.Message);
                    }
                    //genericMgr.Update("Update from FlowDetail set MinUnitCount = ? where Item = ?", new object[] { flowDet.MinUnitCount, flowDet.Item });
                }
            }
            else
            {
                throw new BusinessException(string.Format("有效的数据行为0,可能是模板问题"));
            }

        }
示例#17
0
        public void ImportKanBanFlow(Stream inputStream, com.Sconit.CodeMaster.OrderType type)
        {
            if (inputStream.Length == 0)
            {
                throw new BusinessException("Import.Stream.Empty");
            }

            HSSFWorkbook workbook = new HSSFWorkbook(inputStream);

            ISheet sheet = workbook.GetSheetAt(0);
            IEnumerator rows = sheet.GetRowEnumerator();

            ImportHelper.JumpRows(rows, 10);

            #region 列定义
            // FlowMaster
            int colCode = 1; // 路线代码
            int colItem = 2; // 物料号										
            int colRefItemCode = 3; // 旧图号
            int colItemDesc = 4; // 零件名称
            int colOpRef = 5; // 工位代码
            int colOpUseQty = 6; // 工位用量
            int colItemType = 7; // 零件类型
            int colOpRefSeq = 8; // 看板编号
            int colUC = 9; // 单包装
            int colContainer = 10; // 容器代码

            int colContainerDesc = 11; // 容器描述
            int colDock = 12; // 配送路径
            int colCardQty = 13; // 看板卡数量
            int colIsActive = 14; // 是否生效
            int colOpRefDesc = 15; //工位中文描述
            //int colShelf = 13; // 架位
            #endregion

            var errorMessage = new BusinessException();

            IList<Item> ItemsList = new List<Item>();
            IList<FlowMaster> exactFlowList = new List<FlowMaster>();
            IList<FlowStrategy> exactFlowStrategyList = new List<FlowStrategy>();
            IList<FlowDetail> exactFlowDetailList = new List<FlowDetail>();
            IList<FlowDetail> deleteFlowDetailList = new List<FlowDetail>();
            int colCount = 10;

            #region 取所有的路线和路线明细
            var totalFlowMasterList = genericMgr.FindAll<FlowMaster>("from FlowMaster f where f.Type = ? and exists(select 1 from FlowStrategy as fs where fs.Flow=f.Code and fs.Strategy=? )", new object[] { (int)type, (int)CodeMaster.FlowStrategy.ANDON });
            var totalFlowDetailList = genericMgr.FindEntityWithNativeSql<FlowDetail>("select d.* from scm_FlowDet d inner join scm_FlowMstr f on f.Code = d.Flow where f.Type = ? and exists(select 1 from SCM_FlowStrategy as fs where fs.Flow=f.Code and fs.Strategy=?)", new object[] { (int)type, (int)CodeMaster.FlowStrategy.ANDON });
            //var totalFlowStrategyList = genericMgr.FindEntityWithNativeSql<FlowStrategy>("select g.* from scm_FlowStrategy g inner join scm_FlowMstr f on f.Code = g.Flow and f.Type = ? and f.FlowStrategy = ?", new object[] { (int)type, (int)CodeMaster.FlowStrategy.ANDON });
            //var totalSupplierList = genericMgr.FindAll<Supplier>();
            var totalRegionList = genericMgr.FindAll<Region>();
            var totalLocationList = genericMgr.FindAll<Location>();
            //var totalItemList = genericMgr.FindAll<Item>("from Item where IsActive = ?", true);
            #endregion

            while (rows.MoveNext())
            {
                HSSFRow row = (HSSFRow)rows.Current;
                if (!ImportHelper.CheckValidDataRow(row, 1, 14))
                {
                    break;//边界
                }
                colCount++;

                var rowErrors = new List<Message>();

                string code = string.Empty;
                string item = string.Empty;
                string refItemCode = string.Empty;
                string itemDesc = string.Empty;
                string opRef = string.Empty;
                string opUseQty = string.Empty;
                string itemType = string.Empty;
                string opRefSeq = string.Empty;
                string uc = string.Empty;
                string container = string.Empty;
                string dock = string.Empty;
                string containerDesc = string.Empty;
                string cardQty = string.Empty;
                string isActive = string.Empty;
                string opRefDesc = string.Empty;


                #region 读取数据
                //路线
                code = ImportHelper.GetCellStringValue(row.GetCell(colCode));
                if (code == null || code.Trim() == string.Empty)
                {
                    rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineFieldCanNotBeNull, colCount.ToString(), Resources.SCM.FlowMaster.FlowMaster_Code));
                }

                //工位
                opRef = ImportHelper.GetCellStringValue(row.GetCell(colOpRef));
                if (opRef == null || opRef.Trim() == string.Empty)
                {
                    rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineFieldCanNotBeNull, colCount.ToString(), "工位"));
                }

                //零件类型
                itemType = ImportHelper.GetCellStringValue(row.GetCell(colItemType));

                //工位
                opRefSeq = ImportHelper.GetCellStringValue(row.GetCell(colOpRefSeq));
                if (opRefSeq == null || opRefSeq.Trim() == string.Empty)
                {
                    rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineFieldCanNotBeNull, colCount.ToString(), "看板号"));
                }

                uc = ImportHelper.GetCellStringValue(row.GetCell(colUC));
                //cardQty = ImportHelper.GetCellStringValue(row.GetCell(colCardQty));
                decimal ucVar = 0;
                if (uc == null || uc.Trim() == string.Empty || !decimal.TryParse(uc, out ucVar))
                {
                    rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineFieldCanNotBeNull, colCount.ToString(), "单包装数量"));
                }

                //容器代码
                container = ImportHelper.GetCellStringValue(row.GetCell(colContainer));
                if (container == null || container.Trim() == string.Empty)
                {
                    rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineFieldCanNotBeNull, colCount.ToString(), "容器代码"));
                }

                //容器描述
                containerDesc = ImportHelper.GetCellStringValue(row.GetCell(colContainerDesc));

                dock = ImportHelper.GetCellStringValue(row.GetCell(colDock));

                item = ImportHelper.GetCellStringValue(row.GetCell(colItem));
                if (item == null || item.Trim() == string.Empty)
                {
                    rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineFieldCanNotBeNull, colCount.ToString(), Resources.SCM.FlowDetail.FlowDetail_Item));
                }



                opRefDesc = ImportHelper.GetCellStringValue(row.GetCell(colOpRefDesc));

                //containerDesc = ImportHelper.GetCellStringValue(row.GetCell(colContainerDesc));

                //dock = ImportHelper.GetCellStringValue(row.GetCell(colDock));

                isActive = ImportHelper.GetCellStringValue(row.GetCell(colIsActive));
                var isActiveVal = false;
                if (isActive == null || isActive.Trim() == string.Empty)
                {
                    rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineFieldCanNotBeNull, colCount.ToString(), Resources.SCM.FlowMaster.FlowMaster_IsActive));
                }
                else
                {
                    switch (isActive.ToUpper())
                    {
                        case "Y":
                            isActiveVal = true;
                            break;
                        case "N":
                            isActiveVal = false;
                            break;
                        default:
                            rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineBooleanFieldValueError, colCount.ToString(), Resources.SCM.FlowMaster.FlowMaster_IsActive, isActive));
                            break;
                    }
                }
                #endregion

                #region 验证
                if (totalFlowMasterList.FirstOrDefault(c => c.Code.ToUpper() == code.ToUpper()) == null)
                {
                    rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineError, colCount.ToString(), string.Format("路线头{0}不存在,请确认。", code)));
                }

                //物料编号数据存在性
                Item itemInstance = null;
                if (!string.IsNullOrEmpty(item))
                {
                    itemInstance = ValidatItem(ItemsList, item, colCount, rowErrors);
                }

                //数据库中重复性验证
                FlowDetail sameFlowDet = null;
                if (itemInstance != null)
                {
                    var dbFlowDet = totalFlowDetailList.FirstOrDefault(c => c.Flow.ToUpper() == code.ToUpper() && c.Item.ToUpper() == item.ToUpper() && (c.BinTo == null && string.IsNullOrWhiteSpace(opRef) || c.BinTo != null && c.BinTo.ToUpper() == opRef.ToUpper()));
                    //if (dbFlowDet != null && (dbFlowDet.BinTo != null && dbFlowDet.BinTo.Equals(opRef, StringComparison.OrdinalIgnoreCase)))
                    if (dbFlowDet != null)
                    {
                        sameFlowDet = dbFlowDet;
                    }
                }

                FlowMaster flowMaster = this.genericMgr.FindById<FlowMaster>(code);



                #endregion

                #region Instance



                if (itemInstance != null)
                {
                    if (sameFlowDet != null)
                    {
                        sameFlowDet.ItemType = itemType;
                        //sameFlowDet.ContainerDescription = containerDesc;
                        sameFlowDet.BinTo = opRef;
                        sameFlowDet.OprefSequence = opRefSeq;
                        sameFlowDet.Dock = dock;
                        sameFlowDet.ProductionScan = opRefDesc;
                        sameFlowDet.Container = container;
                        sameFlowDet.ContainerDescription = containerDesc;
                        sameFlowDet.MinUnitCount = ucVar;
                        sameFlowDet.PartyFrom = flowMaster.PartyFrom;
                        sameFlowDet.LocationTo = flowMaster.LocationTo;
                        sameFlowDet.FlowMasterStrategy = (int)flowMaster.FlowStrategy;
                        //sameFlowDet.BinTo = binTo;
                        sameFlowDet.IsCreate = false;
                        //sameFlowDet.IsRejectInspect = isRejectInspectVal;
                        //模板中 路线代码+物料编号+工位 不能重复
                        if (exactFlowDetailList.Where(f => f.Flow.ToUpper() == code.ToUpper() && f.BinTo.ToUpper() == opRef.ToUpper() && f.Item.ToUpper() == item.ToUpper()).Count() > 0
                         || deleteFlowDetailList.Where(f => f.Flow.ToUpper() == code.ToUpper() && f.BinTo.ToUpper() == opRef.ToUpper() && f.Item.ToUpper() == item.ToUpper()).Count() > 0)
                        {
                            rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineError, colCount.ToString(), string.Format("路线头{0}+工位{1}+物料编号{2}在模板中重复,请确认。", code, opRef, item)));
                        }

                        if (isActiveVal)
                        {
                            //sameFlowMaster.AddFlowDetail(sameFlowDet);
                            #region 来源区域 目的库位 物料 不能再不同的策略上出现
                            int checkeSame = this.genericMgr.FindAllWithNativeSql<int>(" select COUNT(*) as countSum  from SCM_FlowDet as d where d.Item=? and exists( select 1 from SCM_FlowMstr as m where m.Code=d.Flow and m.PartyFrom=? and m.LocTo=? and m.Type=2 and not exists(select 1 from SCM_FlowStrategy as fs where fs.Flow=m.Code and fs.Strategy=7) ) ", new object[] { item, flowMaster.PartyFrom, flowMaster.LocationTo })[0];
                            if (checkeSame > 0)
                            {
                                rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineError, colCount.ToString(), (string.Format("来源区域{0}+物料{1}+目的库位{2}+在其他策略中已经存在。", flowMaster.PartyFrom, item, flowMaster.LocationTo, sameFlowDet.FlowMasterStrategy))));
                            }
                            if (exactFlowDetailList.Where(ef => ef.PartyFrom == flowMaster.PartyFrom && ef.LocationTo == flowMaster.LocationTo && ef.Item == item && ef.Id != sameFlowDet.Id && ef.FlowMasterStrategy != sameFlowDet.FlowMasterStrategy).Count() > 0)
                            {
                                rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineError, colCount.ToString(), (string.Format("来源区域{0}+物料{1}+目的库位{2}+策略不同{3}在模板中重复。", flowMaster.PartyFrom, item, flowMaster.LocationTo, sameFlowDet.FlowMasterStrategy))));
                            }
                            #endregion

                            exactFlowDetailList.Add(sameFlowDet);
                        }
                        else
                        {
                            deleteFlowDetailList.Add(sameFlowDet);
                        }

                    }
                    else
                    {
                        //if (exactFlowDetailList.FirstOrDefault(f => f.Flow.ToUpper() == code.ToUpper() && f.BinTo.ToUpper() == opRef.ToUpper() && f.Item.ToUpper() == item.ToUpper()) == null)
                        //{
                        sameFlowDet = new FlowDetail
                        {
                            Flow = code,
                            Item = itemInstance.Code,
                            ItemDescription = itemInstance.Description,
                            BaseUom = itemInstance.Uom,
                            Uom = itemInstance.Uom,
                            ReferenceItemCode = itemInstance.ReferenceCode,
                            UnitCount = itemInstance.UnitCount,
                            MinUnitCount = ucVar,
                            //UnitCountDescription = ucDesc,
                            Container = container,
                            ContainerDescription = containerDesc,
                            //SafeStock = safeStockVal,
                            ItemType = itemType,
                            Dock = dock,
                            OprefSequence = opRefSeq,
                            BinTo = opRef,
                            IsCreate = true,
                            PartyFrom = flowMaster.PartyFrom,
                            LocationTo = flowMaster.LocationTo,
                            FlowMasterStrategy = (int)flowMaster.FlowStrategy,
                            ProductionScan = opRefDesc,
                            //IsRejectInspect = isRejectInspectVal
                        };
                        //sameFlowMaster.AddFlowDetail(sameFlowDet);
                        #region 来源区域 目的库位 物料 不能再不同的策略上出现
                        int checkeSame = this.genericMgr.FindAllWithNativeSql<int>(" select COUNT(*) as countSum  from SCM_FlowDet as d where d.Item=? and exists( select 1 from SCM_FlowMstr as m where m.Code=d.Flow and m.PartyFrom=? and m.LocTo=? and m.Type=2 and exists(select 1 from SCM_FlowStrategy as fs where fs.Flow=m.Code and fs.Strategy<>7)) ", new object[] { item, flowMaster.PartyFrom, flowMaster.LocationTo })[0];
                        if (checkeSame > 0)
                        {
                            rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineError, colCount.ToString(), (string.Format("来源区域{0}+物料{1}+目的库位{2}+在其他策略中已经存在", flowMaster.PartyFrom, item, flowMaster.LocationTo, sameFlowDet.FlowMasterStrategy))));
                        }
                        if (exactFlowDetailList.Where(ef => ef.PartyFrom == flowMaster.PartyFrom && ef.LocationTo == flowMaster.LocationTo && ef.Item == item && ef.Id != sameFlowDet.Id && ef.FlowMasterStrategy != sameFlowDet.FlowMasterStrategy).Count() > 0)
                        {
                            rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineError, colCount.ToString(), (string.Format("来源区域{0}+物料{1}+目的库位{2}+策略不同{3}在模板中重复。", flowMaster.PartyFrom, item, flowMaster.LocationTo, sameFlowDet.FlowMasterStrategy))));
                        }
                        #endregion
                        //模板中 路线代码+物料编号+工位 不能重复
                        if (exactFlowDetailList.Where(f => f.Flow.ToUpper() == code.ToUpper() && f.BinTo.ToUpper() == opRef.ToUpper() && f.Item.ToUpper() == item.ToUpper()).Count() > 0
                         || deleteFlowDetailList.Where(f => f.Flow.ToUpper() == code.ToUpper() && f.BinTo.ToUpper() == opRef.ToUpper() && f.Item.ToUpper() == item.ToUpper()).Count() > 0)
                        {
                            rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineError, colCount.ToString(), string.Format("路线头{0}+工位{1}+物料编号{2}在模板中重复,请确认", code, opRef, item)));
                        }
                        exactFlowDetailList.Add(sameFlowDet);
                        //}

                    }

                }
                else
                {
                    rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineError, colCount.ToString(), string.Format("第{0}行:物料编号{1}不存在,请确认", code, opRef, item)));

                }
                #endregion

                errorMessage.AddMessages(rowErrors);
            }

            if (errorMessage.HasMessage)
            {
                throw errorMessage;
            }
            if ((exactFlowDetailList == null || exactFlowDetailList.Count == 0) && (deleteFlowDetailList == null || deleteFlowDetailList.Count == 0))
            {
                throw new BusinessException("模板为空,请确认。");
            }
            #region Save Data
            foreach (FlowDetail instance in exactFlowDetailList)
            {
                instance.IsActive = true;
                if (instance.IsCreate)
                {
                    CreateFlowDetail(instance);
                }
                else
                {
                    UpdateFlowDetail(instance);
                    this.genericMgr.UpdateWithNativeQuery("update KB_KanbanCard set Qty=?,Container=? where FlowDetId=?",
                        new object[] { instance.MinUnitCount, instance.Container, instance.Id },
                        new IType[] { NHibernateUtil.Decimal, NHibernateUtil.String, NHibernateUtil.Int32 });
                }
                this.genericMgr.FlushSession();
            }
            foreach (FlowDetail instance in deleteFlowDetailList)
            {
                genericMgr.Delete(instance);
                genericMgr.Delete("from KanbanCard k where k.FlowDetailId = ?", instance.Id, NHibernate.NHibernateUtil.Int32);
            }

            #endregion
        }
示例#18
0
        public void CreateFlowDetail(FlowDetail flowDetail)
        {
            IList<ItemPackage> itemPackageList = genericMgr.FindAll<ItemPackage>("from ItemPackage as i where i.Item = ? and i.UnitCount = ?", new object[] { flowDetail.Item, flowDetail.UnitCount });
            if (itemPackageList == null || itemPackageList.Count == 0)
            {
                ItemPackage itemPackage = new ItemPackage();
                itemPackage.Item = flowDetail.Item;
                itemPackage.UnitCount = flowDetail.UnitCount;
                itemPackage.Description = string.IsNullOrEmpty(flowDetail.UnitCountDescription) ? string.Empty : flowDetail.UnitCountDescription;
                genericMgr.Create(itemPackage);
            }
            genericMgr.Create(flowDetail);

            #region 更新计划协议历史数据,按照路线更新
            FlowMaster flow = genericMgr.FindById<FlowMaster>(flowDetail.Flow);
            ////允许新建的明细肯定是唯一有效的
            //IList<FlowDetail> flowDetailList = this.genericMgr.FindAll<FlowDetail>("select fd from FlowDetail as fd where fd.Item='" + flowDetail.Item + "' and IsActive <> 0 and exists (select 1 from FlowMaster as fm where fm.Code=fd.Flow and fm.PartyFrom='" + flow.PartyFrom + "' and fm.IsActive = 1)");
            //if (flowDetailList.Count == 1)
            //{
            //    Location location = flowDetail.IsActive ? genericMgr.FindById<Location>(flow.LocationTo) : null;
            //    Party partyTo = flowDetail.IsActive ? genericMgr.FindById<Party>(flow.PartyTo) : null;
            //    Address address = flowDetail.IsActive ? genericMgr.FindById<Address>(flow.ShipTo) : null;

            //    string updateMstr = "Update Ord_OrderMstr_8 set Flow = ?,FlowDesc = ?,PartyTo = ?,PartyToNm = ?,ShipTo = ?,ShipToAddr = ?,LocTo = ?,LocToNm = ? where  PartyFrom = ? and exists (select 1 from Ord_OrderDet_8 as d where d.Item = ? and Ord_OrderMstr_8.OrderNo=d.OrderNo)";
            //    genericMgr.FindAllWithNativeSql(updateMstr, new object[] { flow.Code, flow.Description, flow.PartyTo, partyTo.Name, flow.ShipTo, address.AddressContent, flow.LocationTo, location.Name, flow.PartyFrom, flowDetail.Item });
            //    string updateStr = "Update Ord_OrderDet_8 set LocTo = ?,LocToNm = ?,UC = ? where Item = ? and exists (select 1 from Ord_OrderMstr_8 as o where o.PartyFrom = ? and Ord_OrderDet_8.OrderNo=o.OrderNo)";
            //    genericMgr.FindAllWithNativeSql(updateStr, new object[] { flow.LocationTo, location.Name, flowDetail.UnitCount, flowDetail.Item, flow.PartyFrom });
            //}
            #endregion

            #region 将数据插入零件标准包装中间表
            //采购路线只有入库包装,移库路线才有出库/入库包装
            if (flow.Type == CodeMaster.OrderType.Transfer
                || flow.Type == CodeMaster.OrderType.Distribution
                || flow.Type == CodeMaster.OrderType.SubContractTransfer)
            {
                string locationFrom = string.IsNullOrWhiteSpace(flowDetail.LocationFrom) ? flow.LocationFrom : flowDetail.LocationFrom;
                if (string.IsNullOrWhiteSpace(locationFrom))
                {
                    var locTo = this.genericMgr.FindById<Location>(locationFrom);
                    CreateItemStandardPackByType(flowDetail, locTo, "I");
                }
            }

            if (flow.Type == CodeMaster.OrderType.Transfer
                || flow.Type == CodeMaster.OrderType.SubContractTransfer
                || flow.Type == CodeMaster.OrderType.SubContract
                || flow.Type == CodeMaster.OrderType.CustomerGoods
                || flow.Type == CodeMaster.OrderType.Procurement)
            {
                string locationTo = string.IsNullOrWhiteSpace(flowDetail.LocationTo) ? flow.LocationTo : flowDetail.LocationTo;
                if (string.IsNullOrWhiteSpace(locationTo))
                {
                    var locTo = this.genericMgr.FindById<Location>(locationTo);
                    CreateItemStandardPackByType(flowDetail, locTo, "I");
                }
            }
            #endregion
        }
示例#19
0
 private IList<FlowDetail> GetFlowDetails(FlowMaster flowMaster)
 {
     #region 读取路线
     var flowDetails = this.flowMgr.GetFlowDetailList(flowMaster, false, true);
     if (flowDetails == null || flowDetails.Count() == 0)
     {
         if (flowMaster.IsManualCreateDetail)
         {
             flowDetails = new List<FlowDetail>();
             var flowDetail = new FlowDetail();
             flowDetail.CurrentFlowMaster = flowMaster;
             flowDetails.Add(flowDetail);
         }
     }
     #endregion
     return flowDetails;
 }
示例#20
0
        public void UpdateFlowDetail(FlowDetail flowDetail)
        {
            #region 零件标准包装
            var dbFlowDetail = this.genericMgr.FindById<FlowDetail>(flowDetail.Id);
            this.genericMgr.CleanSession();

            var flow = genericMgr.FindById<FlowMaster>(flowDetail.Flow);
            var locFrom = string.IsNullOrWhiteSpace(flowDetail.LocationFrom) ? flow.LocationFrom : flowDetail.LocationFrom;
            var locTo = string.IsNullOrWhiteSpace(flowDetail.LocationTo) ? flow.LocationTo : flowDetail.LocationTo;
            if (dbFlowDetail.Item != flowDetail.Item || dbFlowDetail.UnitCount != flowDetail.UnitCount || dbFlowDetail.UnitCountDescription != flowDetail.UnitCountDescription)
            {
                if (!string.IsNullOrWhiteSpace(locFrom))
                {
                    UpdateItemStandardPackByType(flowDetail, locFrom, "O");
                }
                if (!string.IsNullOrWhiteSpace(locTo))
                {
                    UpdateItemStandardPackByType(flowDetail, locTo, "I");
                }
            }
            else if (dbFlowDetail.LocationFrom != flowDetail.LocationFrom)
            {
                if (!string.IsNullOrWhiteSpace(locFrom))
                {
                    UpdateItemStandardPackByType(flowDetail, locFrom, "O");
                }
            }
            else if (dbFlowDetail.LocationTo != flowDetail.LocationTo)
            {
                if (!string.IsNullOrWhiteSpace(locTo))
                {
                    UpdateItemStandardPackByType(flowDetail, locTo, "I");
                }
            }

            #endregion

            IList<ItemPackage> itemPackageList = genericMgr.FindAll<ItemPackage>("from ItemPackage as i where i.Item = ? and i.UnitCount = ?", new object[] { flowDetail.Item, flowDetail.UnitCount });
            if (itemPackageList == null || itemPackageList.Count == 0)
            {
                ItemPackage itemPackage = new ItemPackage();
                itemPackage.Item = flowDetail.Item;
                itemPackage.UnitCount = flowDetail.UnitCount;
                itemPackage.Description = string.IsNullOrEmpty(flowDetail.UnitCountDescription) ? string.Empty : flowDetail.UnitCountDescription;
                genericMgr.Create(itemPackage);
            }
            genericMgr.Update(flowDetail);
        }
示例#21
0
        public FlowMaster GetReverseFlow(FlowMaster flow, IList<string> itemCodeList)
        {
            FlowMaster reverseFlow = new FlowMaster();
            Mapper.Map(flow, reverseFlow);
            reverseFlow.PartyFrom = flow.PartyTo;
            reverseFlow.PartyTo = flow.PartyFrom;
            reverseFlow.IsCheckPartyFromAuthority = flow.IsCheckPartyToAuthority;
            reverseFlow.IsCheckPartyToAuthority = flow.IsCheckPartyFromAuthority;
            reverseFlow.ShipFrom = flow.ShipTo;
            reverseFlow.ShipTo = flow.ShipFrom;
            reverseFlow.LocationFrom = flow.LocationTo;
            reverseFlow.LocationTo = flow.LocationFrom;
            reverseFlow.IsShipScanHu = flow.IsReceiveScanHu;
            reverseFlow.IsReceiveScanHu = flow.IsShipScanHu;
            reverseFlow.IsShipFifo = flow.IsReceiveFifo;
            reverseFlow.IsReceiveFifo = flow.IsShipFifo;
            reverseFlow.IsShipExceed = flow.IsReceiveExceed;
            reverseFlow.IsReceiveExceed = flow.IsShipExceed;
            //reverseFlow.IsShipFulfillUC = flow.IsReceiveFulfillUC;
            //reverseFlow.IsReceiveFulfillUC = flow.IsShipFulfillUC;
            reverseFlow.IsInspect = flow.IsRejectInspect;
            reverseFlow.IsRejectInspect = flow.IsInspect;
            reverseFlow.IsCreatePickList = false;
            reverseFlow.IsShipByOrder = true;
            //以后有什么字段再加

            #region 路线明细
            if (flow.FlowDetails == null || flow.FlowDetails.Count == 0)
            {
                string hql = "from FlowDetail where Flow = ?";
                IList<object> parm = new List<object>();
                parm.Add(flow.Code);
                if (itemCodeList != null && itemCodeList.Count() > 0)
                {
                    string whereHql = string.Empty;
                    foreach (string itemCode in itemCodeList.Distinct())
                    {
                        if (whereHql == string.Empty)
                        {
                            whereHql = " and Item in (?";
                        }
                        else
                        {
                            whereHql += ",?";
                        }
                        parm.Add(itemCode);
                    }
                    whereHql += ")";
                    hql += whereHql;
                }
                hql += " order by Sequence";

                flow.FlowDetails = this.genericMgr.FindAll<FlowDetail>(hql, parm.ToArray());
            }

            if (flow.FlowDetails != null && flow.FlowDetails.Count > 0)
            {
                IList<FlowDetail> reverseFlowDetailList = new List<FlowDetail>();
                foreach (FlowDetail flowDetail in flow.FlowDetails)
                {
                    FlowDetail reverseFlowDetail = new FlowDetail();
                    Mapper.Map(flowDetail, reverseFlowDetail);
                    reverseFlowDetail.LocationFrom = flowDetail.LocationTo;
                    reverseFlowDetail.LocationTo = flowDetail.LocationFrom;
                    reverseFlowDetail.IsRejectInspect = flowDetail.IsInspect;
                    reverseFlowDetail.IsInspect = flowDetail.IsRejectInspect;
                    //PartyFrom?
                    reverseFlowDetailList.Add(reverseFlowDetail);
                }
                reverseFlow.FlowDetails = reverseFlowDetailList;
            }
            #endregion

            return reverseFlow;
        }
示例#22
0
        private void SaveItemStandardPack(FlowDetail flowDetail, string type, string sapLoc)
        {
            var itemStandardPackList = this.genericMgr.FindAll<ItemStandardPackDAT>("from ItemStandardPackDAT as p where p.FlowDetId=?", flowDetail.Id);

            var itemStandardPackO = itemStandardPackList.FirstOrDefault(c => c.IOType == type);
            if (itemStandardPackO != null)
            {
                itemStandardPackO.Item = flowDetail.Item;
                itemStandardPackO.Pack = flowDetail.UnitCountDescription;
                //itemStandardPackO.UC = flowDetail.UnitCount;
                itemStandardPackO.UC = type == "O" ? flowDetail.MinUnitCount : flowDetail.UnitCount;
                itemStandardPackO.CreateDate = DateTime.Now;
                itemStandardPackO.CreateDATDate = null;
                itemStandardPackO.DATFileName = null;
                itemStandardPackO.Location = sapLoc;
                genericMgr.Update(itemStandardPackO);
            }
            else
            {
                this.genericMgr.Create(new ItemStandardPackDAT
                {
                    Item = flowDetail.Item,
                    FlowDetId = flowDetail.Id,
                    Pack = flowDetail.UnitCountDescription,
                    //UC = flowDetail.UnitCount,
                    UC = type == "O" ? flowDetail.MinUnitCount : flowDetail.UnitCount,
                    IOType = type,
                    Location = sapLoc,
                    Plant = GetSAPPlant(),
                    CreateDate = DateTime.Now
                });
            }
        }
示例#23
0
        public void ImportFlow(Stream inputStream, CodeMaster.OrderType flowType)
        {
            if (inputStream.Length == 0)
            {
                throw new BusinessException("Import.Stream.Empty");
            }

            HSSFWorkbook workbook = new HSSFWorkbook(inputStream);

            ISheet sheet = workbook.GetSheetAt(0);
            IEnumerator rows = sheet.GetRowEnumerator();

            ImportHelper.JumpRows(rows, 10);

            #region 列定义
            // FlowMaster
            int colType = 1;//路线类型
            int colCode = 2; // 路线代码
            int colDesc = 3; // 路线描述


            // FlowDet
            int colItem = 4; // 物料
            int colUom = 5; // 单位
            int colUnitCount = 6; // 单包装
            int colUcDesc = 7; // 单包装
            int colMinStock = 8;//
            int colMaxStock = 9;//

            // FlowStrategy
            int colLeadTime = 10; // 提前期
            #endregion

            var errorMessage = new BusinessException();
            int colCount = 10;
            List<List<string>> rowDataList = new List<List<string>>();
            var items = this.genericMgr.FindAll<Item>().ToDictionary(d => d.Code, d => d);
            #region 读取数据
            while (rows.MoveNext())
            {
                HSSFRow row = (HSSFRow)rows.Current;
                if (!ImportHelper.CheckValidDataRow(row, 1, 8))
                {
                    break;//边界
                }
                colCount++;

                var rowData = new List<string>();

                #region FlowMaster
                rowData.Add("0");
                rowData.Add(((int)flowType).ToString());
                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colCode)));
                if (string.IsNullOrWhiteSpace(rowData[2]))
                {
                    rowData[0] = "1";
                    errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.FlowCodeShouldNotEmpty, colCount.ToString()));
                }
                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colDesc)));
                if (string.IsNullOrWhiteSpace(rowData[3]))
                {
                    rowData[0] = "1";
                    errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.FlowDescShouldNotEmpty, colCount.ToString()));
                }
                #endregion

                #region FlowDetail
                Item item = null;
                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colItem)));
                if (!string.IsNullOrWhiteSpace(rowData[4]))
                {
                    item = items.ValueOrDefault(rowData[4]);
                }
                if (item == null)
                {
                    rowData[0] = "1";
                    errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineItemNotFound,
                        colCount.ToString(), rowData[4]));
                    continue;
                }

                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colUom)));
                if (string.IsNullOrWhiteSpace(rowData[5]))
                {
                    rowData[5] = item.Uom;
                }
                else
                {
                    try
                    {
                        Uom uom = this.genericMgr.FindById<Uom>(rowData[5].ToUpper());
                        rowData[5] = uom.Code;
                    }
                    catch (Exception)
                    {
                        rowData[0] = "1";
                        errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineUomNotFound,
                            colCount.ToString(), rowData[5]));
                    }
                }
                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colUnitCount)));
                if (string.IsNullOrWhiteSpace(rowData[6]))
                {
                    rowData[6] = item.UnitCount.ToString();
                }
                else
                {
                    decimal unitCount = item.UnitCount;
                    if (!decimal.TryParse(rowData[6], out unitCount))
                    {
                        rowData[0] = "1";
                        errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineUCIsNotNum, colCount.ToString()));
                    }
                    rowData[6] = unitCount == 0 ? item.UnitCount.ToString() : unitCount.ToString();
                }
                //7
                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colUcDesc)));

                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colMinStock)));
                if (string.IsNullOrWhiteSpace(rowData[8]))
                {
                    rowData[8] = "0";
                }
                else
                {
                    decimal decVal = 0m;
                    if (!decimal.TryParse(rowData[8], out decVal))
                    {
                        rowData[0] = "1";
                        errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineSafeInvIsNotNum, colCount.ToString()));
                    }
                    rowData[8] = decVal.ToString();
                }

                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colMaxStock)));
                if (string.IsNullOrWhiteSpace(rowData[9]))
                {
                    rowData[9] = "0";
                }
                else
                {
                    decimal decVal = 0m;
                    if (!decimal.TryParse(rowData[9], out decVal))
                    {
                        rowData[0] = "1";
                        errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineMaxInvIsNotNum, colCount.ToString()));
                    }
                    rowData[9] = decVal.ToString();
                }
                #endregion

                #region FlowStrategy
                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colLeadTime)));
                if (string.IsNullOrWhiteSpace(rowData[10]))
                {
                    rowData[10] = "0";
                }
                else
                {
                    decimal leadTimeVal = 0m;
                    if (!decimal.TryParse(rowData[10], out leadTimeVal))
                    {
                        rowData[0] = "1";
                        errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineLeantimeIsNotNum, colCount.ToString()));
                    }
                    rowData[10] = leadTimeVal.ToString();
                }
                #endregion

                rowData.Add(item.Description);//11
                rowData.Add(item.Uom);//12
                rowData.Add(item.ReferenceCode);//13

                rowDataList.Add(rowData);
            }
            #endregion

            #region 验证

            //Excle中重复性验证
            var flowItems = rowDataList.Where(p => p[0] == "0")
                            .Select(p => new
                           {
                               Type = (CodeMaster.OrderType)(int.Parse(p[1])),
                               Flow = p[2],
                               FlowDescription = p[3],
                               Item = p[4],
                               Uom = p[5],
                               UnitCount = decimal.Parse(p[6]),
                               UcDesc = p[7],
                               MinStock = decimal.Parse(p[8]),
                               MaxStock = decimal.Parse(p[9]),
                               LeadTime = decimal.Parse(p[10]),
                               ItemDescription = p[11],
                               BaseUom = p[12],
                               ReferenceCode = p[13]
                           });

            if (flowItems == null || flowItems.Count() == 0)
            {
                errorMessage.AddMessage(Resources.EXT.ServiceLan.TheImportIsNotEffect);
                throw errorMessage;
            }
            var flowItemGroup = flowItems.GroupBy(p => new { p.Flow, p.Item, p.Uom, p.UnitCount }, (k, g) => new { k, Count = g.Count() })
                .Where(p => p.Count > 1).Select(p => new { p.k.Flow, p.k.Item });
            foreach (var flowItem in flowItemGroup)
            {
                errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error,
                    Resources.EXT.ServiceLan.DuplicateFlowDetail, flowItem.Flow, flowItem.Item));
            }

            var distinctFlowItems = flowItems.GroupBy(p => new { p.Flow, p.Item }, (k, g) => new { k, j = g.First() })
                .Select(p => p.j);

            var excelFlowMasterList = distinctFlowItems.GroupBy(p => p.Flow, (k, g) => new
                                    {
                                        Code = k,
                                        List = g
                                    });
            var flowMasterDic = this.genericMgr.FindAllIn<FlowMaster>("from FlowMaster where Code in(?",
                excelFlowMasterList.Select(p => p.Code)).ToDictionary(d => d.Code, d => d);

            var flowStrategyDic = this.genericMgr.FindAllIn<FlowStrategy>("from FlowStrategy where Flow in(?",
                excelFlowMasterList.Select(p => p.Code)).ToDictionary(d => d.Flow, d => d);

            var allParty = this.genericMgr.FindAll<Party>().ToDictionary(d => d.Code, d => d.Code);
            var allPriceList = this.genericMgr.FindAll<PriceListMaster>().ToDictionary(d => d.Code, d => d.Code);
            var allAddress = this.genericMgr.FindAll<Address>().ToDictionary(d => d.Code, d => d.Code);
            var allLocation = this.genericMgr.FindAll<Location>().ToDictionary(d => d.Code, d => d.Code);

            foreach (var excelFlowMaster in excelFlowMasterList)
            {
                var firstFlowItem = excelFlowMaster.List.First();
                var flowMaster = flowMasterDic.ValueOrDefault(excelFlowMaster.Code);
                var flowStrategy = flowStrategyDic.ValueOrDefault(excelFlowMaster.Code);

                if (flowType != firstFlowItem.Type)
                {
                    errorMessage.AddMessage(Resources.EXT.ServiceLan.FlowTypeIsNotCorrect, firstFlowItem.Type.ToString());
                    continue;
                }
                #region flowMaster
                if (flowMaster == null)
                {
                    #region FlowMaster赋值
                    var flowCodeSplits = excelFlowMaster.Code.Split('-');
                    var flowDescriptionSplits = firstFlowItem.FlowDescription.Split('-');
                    var newFlowMaster = new FlowMaster();
                    newFlowMaster.Code = excelFlowMaster.Code;
                    newFlowMaster.Type = firstFlowItem.Type;
                    newFlowMaster.Description = firstFlowItem.FlowDescription;

                    newFlowMaster.IsListDet = true;
                    newFlowMaster.IsPrintOrder = true;
                    newFlowMaster.IsPrintAsn = true;
                    newFlowMaster.IsPrintRceipt = true;
                    newFlowMaster.IsShipExceed = true;
                    newFlowMaster.IsShipFifo = true;
                    newFlowMaster.IsAllowProvEstRec = true;
                    newFlowMaster.ReceiveGapTo = CodeMaster.ReceiveGapTo.AdjectLocFromInv;
                    //Code	Desc1	IsActive	Type	RefFlow	PartyFrom	PartyTo	ShipFrom	ShipTo	LocFrom	LocTo	BillAddr	
                    //PriceList	Routing	ReturnRouting	Dock	IsAutoCreate	IsAutoRelease	IsAutoStart	IsAutoShip	IsAutoReceive
                    //IsAutoBill	IsListDet	IsManualCreateDet	IsListPrice	IsPrintOrder	IsPrintAsn	IsPrintRcpt	IsShipExceed	
                    //IsRecExceed	IsOrderFulfillUC	IsShipFulfillUC	IsRecFulfillUC	IsShipScanHu	IsRecScanHu	IsCreatePL	
                    //IsInspect	IsShipFifo	IsRejInspect	IsRecFifo	IsShipByOrder	IsAsnUniqueRec	IsMRP	IsCheckPartyFromAuth	
                    //IsCheckPartyToAuth	RecGapTo	RecTemplate	OrderTemplate	AsnTemplate	HuTemplate	BillTerm	CreateHuOpt	
                    //MaxOrderCount	MRPOpt	IsPause	PauseTime	FlowStrategy	ExtraDmdSource	PickStrategy	CreateUser	CreateUserNm
                    //CreateDate	LastModifyUser	LastModifyUserNm	LastModifyDate	DAUAT	LastRefreshDate	ResourceGroup	
                    //IsAllowProvEstRec	UcDeviation	OrderDeviation


                    if (firstFlowItem.Type == CodeMaster.OrderType.Procurement
                        || firstFlowItem.Type == CodeMaster.OrderType.CustomerGoods
                        || firstFlowItem.Type == CodeMaster.OrderType.SubContract)
                    {
                        newFlowMaster.PartyFrom = flowCodeSplits[0];
                        var location = this.genericMgr.FindById<Location>(flowCodeSplits[1]);
                        newFlowMaster.PartyTo = location.Region;
                        if (firstFlowItem.Type == CodeMaster.OrderType.SubContract)
                        {
                            newFlowMaster.LocationFrom = newFlowMaster.PartyFrom;
                        }
                        newFlowMaster.LocationTo = location.Code;
                        newFlowMaster.BillAddress = newFlowMaster.PartyFrom;
                        newFlowMaster.PriceList = newFlowMaster.PartyFrom;
                        newFlowMaster.IsReceiveScanHu = true;
                        newFlowMaster.OrderTemplate = "ORD_Purchase.xls";
                        newFlowMaster.AsnTemplate = "ASN_Purchase.xls";
                        newFlowMaster.ReceiptTemplate = "REC_Receipt.xls";
                        newFlowMaster.HuTemplate = "BarCodePurchase2D.xls";
                        newFlowMaster.BillTerm = CodeMaster.OrderBillTerm.ReceivingSettlement;
                        newFlowMaster.CreateHuOption = CodeMaster.CreateHuOption.None;
                        newFlowMaster.IsListPrice = true;
                        newFlowMaster.IsAsnUniqueReceive = true;
                        newFlowMaster.IsAllowProvEstRec = true;
                    }
                    else if (firstFlowItem.Type == CodeMaster.OrderType.Distribution
                        || firstFlowItem.Type == CodeMaster.OrderType.SubContractTransfer)
                    {
                        var location = this.genericMgr.FindById<Location>(flowCodeSplits[0]);
                        newFlowMaster.LocationFrom = location.Code;
                        newFlowMaster.PartyFrom = location.Region;
                        newFlowMaster.PartyTo = flowCodeSplits[1];
                        if (firstFlowItem.Type == CodeMaster.OrderType.SubContractTransfer)
                        {
                            newFlowMaster.LocationTo = newFlowMaster.PartyTo;
                            newFlowMaster.OrderTemplate = "ASN_Transfer.xls";
                            newFlowMaster.AsnTemplate = "ASN_Transfer.xls";
                            newFlowMaster.ReceiptTemplate = "REC_InvOut.xls";
                            newFlowMaster.HuTemplate = "BarCodeMI2D.xls";
                        }
                        else
                        {
                            newFlowMaster.BillAddress = newFlowMaster.PartyTo;
                            newFlowMaster.PriceList = newFlowMaster.PartyTo;
                            newFlowMaster.OrderTemplate = "ORD_Sale.xls";
                            newFlowMaster.AsnTemplate = "ASN_Sale.xls";
                            newFlowMaster.ReceiptTemplate = "REC_Sale.xls";
                            newFlowMaster.HuTemplate = "BarCodeFI2D.xls";
                            newFlowMaster.BillTerm = CodeMaster.OrderBillTerm.ReceivingSettlement;
                            newFlowMaster.CreateHuOption = CodeMaster.CreateHuOption.None;
                        }
                        newFlowMaster.IsRejectInspect = true;
                        newFlowMaster.IsShipScanHu = true;
                        newFlowMaster.IsCreatePickList = false;

                    }
                    else if (firstFlowItem.Type == CodeMaster.OrderType.Production)
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.TheProdLineNotFound, excelFlowMaster.Code);
                    }
                    else if (firstFlowItem.Type == CodeMaster.OrderType.Transfer)
                    {
                        var locationFrom = this.genericMgr.FindById<Location>(flowCodeSplits[0]);
                        var locationTo = this.genericMgr.FindById<Location>(flowCodeSplits[1]);
                        newFlowMaster.PartyFrom = locationFrom.Region;
                        newFlowMaster.PartyTo = locationTo.Region;
                        newFlowMaster.LocationFrom = locationFrom.Code;
                        newFlowMaster.LocationTo = locationTo.Code;
                        newFlowMaster.IsShipScanHu = true;
                        newFlowMaster.IsReceiveScanHu = true;
                        newFlowMaster.IsCreatePickList = false;
                        newFlowMaster.OrderTemplate = "ASN_Transfer.xls";
                        newFlowMaster.AsnTemplate = "ASN_Transfer.xls";
                        newFlowMaster.ReceiptTemplate = "REC_InvOut.xls";
                        newFlowMaster.HuTemplate = "BarCodeEX2D.xls";
                        newFlowMaster.CreateHuOption = CodeMaster.CreateHuOption.None;
                    }
                    newFlowMaster.ShipFrom = newFlowMaster.PartyFrom;
                    newFlowMaster.ShipTo = newFlowMaster.PartyTo;
                    #endregion

                    #region 校验
                    bool isMark = false;
                    if (!allParty.ContainsKey(newFlowMaster.PartyFrom))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.ThePartyFromNotFound, newFlowMaster.PartyFrom);
                        isMark = true;
                    }
                    if (!allParty.ContainsKey(newFlowMaster.PartyTo))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.ThePartyToNotFound, newFlowMaster.PartyTo);
                        isMark = true;
                    }
                    if (!string.IsNullOrWhiteSpace(newFlowMaster.LocationFrom) && !allLocation.ContainsKey(newFlowMaster.LocationFrom))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.TheLocFromNotFound, newFlowMaster.LocationFrom);
                        isMark = true;
                    }
                    if (!string.IsNullOrWhiteSpace(newFlowMaster.LocationTo) && !allLocation.ContainsKey(newFlowMaster.LocationTo))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.TheLocToNotFound, newFlowMaster.LocationTo);
                        isMark = true;
                    }
                    if (!string.IsNullOrWhiteSpace(newFlowMaster.PriceList) && !allPriceList.ContainsKey(newFlowMaster.PriceList))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.ThePriceListNotFound, newFlowMaster.PriceList);
                        isMark = true;
                    }
                    if (!string.IsNullOrWhiteSpace(newFlowMaster.BillAddress) && !allAddress.ContainsKey(newFlowMaster.BillAddress))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.TheBillAddrNotFound, newFlowMaster.BillAddress);
                        isMark = true;
                    }
                    if (!allAddress.ContainsKey(newFlowMaster.ShipFrom))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.TheShipAddrNotFound, newFlowMaster.ShipFrom);
                        isMark = true;
                    }
                    if (!allAddress.ContainsKey(newFlowMaster.ShipTo))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.TheShipToNotFound, newFlowMaster.ShipTo);
                        isMark = true;
                    }
                    #endregion

                    if (!isMark && !errorMessage.HasMessage)
                    {
                        try
                        {
                            this.genericMgr.Create(newFlowMaster);
                        }
                        catch (Exception ex)
                        {
                            errorMessage.AddMessage(ex.Message);
                        }
                    }
                }
                else
                {
                    if (flowMaster.Description != firstFlowItem.FlowDescription && !errorMessage.HasMessage)
                    {
                        flowMaster.Description = firstFlowItem.FlowDescription;
                        this.genericMgr.Update(flowMaster);
                    }
                }
                #endregion

                #region FlowStrategy
                if (!errorMessage.HasMessage)
                {
                    if (flowStrategy == null)
                    {
                        //Flow	Strategy	Desc1	LeadTime	EmLeadTime	TimeUnit	
                        var newFlowStrategy = new FlowStrategy();
                        newFlowStrategy.Flow = excelFlowMaster.Code;
                        newFlowStrategy.Description = firstFlowItem.FlowDescription;
                        newFlowStrategy.LeadTime = firstFlowItem.LeadTime;
                        newFlowStrategy.TimeUnit = CodeMaster.TimeUnit.Hour;
                        this.genericMgr.Create(newFlowStrategy);
                    }
                    else
                    {
                        flowStrategy.LeadTime = firstFlowItem.LeadTime;
                        this.genericMgr.Update(flowStrategy);
                    }
                }
                #endregion

                #region FlowDetail
                if (!errorMessage.HasMessage)
                {
                    var flowDetailDic = this.genericMgr.FindAllIn<FlowDetail>
                        ("from FlowDetail where Flow = ? and Item in(? ",
                        excelFlowMaster.List.Select(p => p.Item), new object[] { excelFlowMaster.Code })
                        .GroupBy(p => p.Item, (k, g) => new { Item = k, FlowDetails = g })
                        .ToDictionary(d => d.Item, d => d.FlowDetails);
                    var maxSeq = 10;
                    var maxItemSeq = this.genericMgr.FindAllIn<FlowDetail>
                        ("from FlowDetail where Flow = ? ", new object[] { excelFlowMaster.Code }).Select(p => p.Sequence).Max();
                    if (flowDetailDic.Values != null && flowDetailDic.Values.Count > 0)
                    {
                        maxSeq = flowDetailDic.Values.Max(p => p.Max(q => q.Sequence));
                    }
                    foreach (var flowItem in excelFlowMaster.List)
                    {
                        //Id	Flow	Seq	Item	RefItemCode	Uom	BaseUom	UC	UCDesc	MinUC	StartDate	EndDate	Bom	LocFrom	LocTo	
                        //BillAddr	PriceList	Routing	ReturnRouting	Strategy	ProdScan	Container	ContainerDesc	IsAutoCreate	
                        //IsInspect	IsRejInspect	SafeStock	MaxStock	MinLotSize	OrderLotSize	RecLotSize	BatchSize	RoundUpOpt	
                        //BillTerm	MrpWeight	MrpTotal	MrpTotalAdj	ExtraDmdSource	PickStrategy	EBELN	EBELP	CreateUser	
                        //CreateUserNm	CreateDate	LastModifyUser	LastModifyUserNm	LastModifyDate	BinTo	IsChangeUC	Machine	Uom1
                        //var item = this.genericMgr.FindById<Item>(flowItem.Item);
                        try
                        {
                            //todo check Details
                            var flowDetail = (flowDetailDic.ValueOrDefault(flowItem.Item) ?? new List<FlowDetail>())
                                .FirstOrDefault(p => p.UnitCount == flowItem.UnitCount);
                            if (flowDetail == null)
                            {
                                var newFlowDetail = new FlowDetail();
                                newFlowDetail.Flow = flowItem.Flow;
                                newFlowDetail.Item = flowItem.Item;
                                newFlowDetail.BaseUom = flowItem.BaseUom;
                                newFlowDetail.Uom = flowItem.Uom;
                                //newFlowDetail.ReferenceItemCode = flowItem.ReferenceCode;
                                newFlowDetail.UnitCount = flowItem.UnitCount;
                                newFlowDetail.MinUnitCount = flowItem.UnitCount;
                                newFlowDetail.UnitCountDescription = flowItem.UcDesc;
                                newFlowDetail.Sequence = maxSeq+maxItemSeq;
                                newFlowDetail.SafeStock = flowItem.MinStock;
                                newFlowDetail.MaxStock = flowItem.MaxStock;
                                newFlowDetail.MrpWeight = 1;
                                newFlowDetail.RoundUpOption = Sconit.CodeMaster.RoundUpOption.ToUp;
                                maxSeq += 10;
                                this.genericMgr.Create(newFlowDetail);
                            }
                            else
                            {
                                flowDetail.BaseUom = flowItem.BaseUom;
                                flowDetail.Uom = flowItem.Uom;
                                flowDetail.UnitCount = flowItem.UnitCount;
                                flowDetail.MinUnitCount = flowItem.UnitCount;
                                flowDetail.UnitCountDescription = flowItem.UcDesc;
                                flowDetail.SafeStock = flowItem.MinStock;
                                flowDetail.MaxStock = flowItem.MaxStock;
                                this.genericMgr.Update(flowDetail);
                            }
                        }
                        catch (Exception ex)
                        {
                            errorMessage.AddMessage(ex.Message);
                        }
                    }
                }
                #endregion
            }
            #endregion

            if (errorMessage.HasMessage)
            {
                throw errorMessage;
            }
        }
示例#24
0
 private void CreateItemStandardPackByType(FlowDetail flowDetail, Location loc, string type)
 {
     if (loc.SAPLocation == "1000")
     {
         this.genericMgr.Create(new ItemStandardPackDAT
         {
             Item = flowDetail.Item,
             FlowDetId = flowDetail.Id,
             Pack = flowDetail.UnitCountDescription,
             UC = type == "O" ? flowDetail.MinUnitCount : flowDetail.UnitCount,
             IOType = type,
             Location = loc.SAPLocation,
             Plant = GetSAPPlant(),
             CreateDate = DateTime.Now
         });
     }
 }
示例#25
0
 public decimal GetRoundOrderQty(FlowDetail flowDetail, decimal orderQty)
 {
     if (flowDetail.MinLotSize > 0 && orderQty < flowDetail.MinLotSize)
     {
         orderQty = flowDetail.MinLotSize;
     }
     if (flowDetail.UnitCount > 0)
     {
         if (flowDetail.RoundUpOption == CodeMaster.RoundUpOption.ToUp)
         {
             orderQty = Math.Ceiling(orderQty / flowDetail.UnitCount) * flowDetail.UnitCount;
         }
         else if (flowDetail.RoundUpOption == CodeMaster.RoundUpOption.ToDown)
         {
             orderQty = Math.Floor(orderQty / flowDetail.UnitCount) * flowDetail.UnitCount;
         }
     }
     int decimalLength = int.Parse(systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.DecimalLength));
     return Math.Round(orderQty, decimalLength);
 }
示例#26
0
 private void UpdateItemStandardPackByType(FlowDetail flowDetail, string loc, string type)
 {
     var locfrom = this.genericMgr.FindById<Location>(loc);
     SaveItemStandardPack(flowDetail, type, locfrom.SAPLocation);
 }
 public ActionResult _DetailNew(string id)
 {
     FlowDetail flowDetail = new FlowDetail();
     FlowMaster flowMaster = this.genericMgr.FindById<FlowMaster>(id);
     flowDetail.LocationTo = flowMaster.LocationTo;
     flowDetail.LocationFrom = flowMaster.LocationFrom;
     flowDetail.Flow = id;
     return PartialView(flowDetail);
 }
示例#28
0
        public void CreateFlowDetailXls(Stream inputStream)
        {
            if (inputStream.Length == 0)
            {
                throw new BusinessException("Import.Stream.Empty");
            }

            HSSFWorkbook workbook = new HSSFWorkbook(inputStream);

            ISheet sheet = workbook.GetSheetAt(0);
            IEnumerator rows = sheet.GetRowEnumerator();

            ImportHelper.JumpRows(rows, 10);
            BusinessException businessException = new BusinessException();
            #region 列定义

            int colItem = 6;// 物料
            //int colMinUnitCount = 10;//上线包装
            int colFlow = 11;//路线
            int colUnitCount = 12;//单包装
            int colUnitCountDescription = 13;//包装描述
            int colContainerDescription = 14;//容器描述
            int colIsChangeUnitCount = 15;//是否修改包装
            int colIsDelete = 18;//删除标示
            int colRoundUpOption = 16;//圆整系数
            int colRouting = 17;//捡货库格
            int rowCount = 10;
            int colSapLocation = 19;//SapLocation
            int colLocation = 20;//来源库位
            #endregion
            //IList<FlowDetail> insertFlowDetailList = new List<FlowDetail>();
            //IList<FlowDetail> updateFlowDetailList = new List<FlowDetail>();
            IList<FlowDetail> exactFlowDetailList = new List<FlowDetail>();
            IList<FlowMaster> allFlowMaster = this.genericMgr.FindAll<FlowMaster>();
            IList<FlowDetail> allFlowDet = this.genericMgr.FindEntityWithNativeSql<FlowDetail>("select d.* from SCM_FlowDet as d where exists( select 1 from SCM_FlowMstr as m where m.code=d.Flow and m.Type=1 )");
            IList<Location> allLocation = this.genericMgr.FindAll<Location>();
            while (rows.MoveNext())
            {
                rowCount++;
                HSSFRow row = (HSSFRow)rows.Current;
                if (!ImportHelper.CheckValidDataRow(row, 5, 14))
                {
                    break;//边界
                }

                FlowMaster flowMaster = null;
                string flow = string.Empty;//路线
                string item = string.Empty; ;// 物料
                double unitCount = 0;//单包装
                string unitCountDescription = string.Empty;//包装描述
                string containerDescription = string.Empty;//容器描述
                string changeUnitCount = string.Empty;//是否修改包装
                bool isDelete = true;//是否删除
                int roundUpOption = 111;//圆整系数
                string routing = string.Empty;//捡货库格
                string sapLocation = string.Empty;
                string location = string.Empty;

                #region 读取数据
                #region 读取Flow
                flow = ImportHelper.GetCellStringValue(row.GetCell(colFlow));
                if (string.IsNullOrWhiteSpace(flow))
                {
                    businessException.AddMessage(string.Format("第{0}行:路线不能为空。", rowCount));
                    continue;
                }
                else
                {
                    flowMaster = allFlowMaster.FirstOrDefault(f => f.Code == flow);
                    if (flowMaster == null)
                    {
                        businessException.AddMessage(string.Format("第{0}行:导入路线{1}不存在系统中,请检查数据的准确性", rowCount, flow));
                        continue;
                    }
                }

                #endregion

                #region Item
                item = ImportHelper.GetCellStringValue(row.GetCell(colItem));
                if (string.IsNullOrWhiteSpace(item))
                {
                    businessException.AddMessage(string.Format("第{0}行:物料编号不能为空。", rowCount));
                    continue;
                }
                IList<Item> itemList = genericMgr.FindAll<Item>(" from Item as i  where i.Code=?", item);
                if (itemList.Count <= 0)
                {
                    businessException.AddMessage(string.Format("第{0}行:导入物料代码{1}不存在系统中,请检查数据的准确性", rowCount, item));
                    continue;
                }
                #endregion

                var e = exactFlowDetailList.Where(p => p.Flow == flow && p.Item == item);
                //文件内也不能出现重复物料
                if (e.Count() > 0)
                {
                    businessException.AddMessage(string.Format("第{2}行:路线{0}存在相同的物料代码{1}超过1行,请检查数据的准确性", flow, item, rowCount));
                    continue;
                }

                #region 读取删除标示
                string isDeleteRead = ImportHelper.GetCellStringValue(row.GetCell(colIsDelete));
                if (isDeleteRead == null || isDeleteRead.Trim() == string.Empty)
                {
                    businessException.AddMessage(string.Format("第{0}行:删除标识不能为空。", rowCount));
                    continue;
                    //rowErrors.Add(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.ErrorMessage.Errors_Import_LineFieldCanNotBeNull, colCount.ToString(), Resources.SCM.FlowMaster.FlowMaster_IsActive));
                }
                else
                {
                    switch (isDeleteRead.ToUpper())
                    {
                        case "Y":
                            isDelete = true; //新增
                            break;
                        case "N":
                            isDelete = false;//删除
                            break;
                        default:
                            businessException.AddMessage(string.Format("第{0}行:删除标识{1}不正确。", rowCount, isDeleteRead));
                            break;
                    }
                }
                #endregion

                if (!isDelete)
                {
                    #region 删除
                    var isExists = allFlowDet.Where(a => a.Flow == flow && a.Item == item);
                    if (isExists != null && isExists.Count() > 0)
                    {
                        exactFlowDetailList.Add(isExists.First());
                        continue;
                    }
                    else
                    {
                        businessException.AddMessage(string.Format("第{0}行:路线代码{1}+物料{2}不存在,请确认。", rowCount, flow, item));
                        continue;
                    }
                    #endregion
                }
                else
                {

                    #region 单包装
                    string ucRead = ImportHelper.GetCellStringValue(row.GetCell(colUnitCount));
                    //if (string.IsNullOrWhiteSpace(ucRead))
                    //{
                    //    businessException.AddMessage(string.Format("第{0}行:单包装不能为空。", rowCount));
                    //    continue;
                    //}
                    //else
                    //{
                    //    double.TryParse(ucRead, out unitCount);
                    //    if (unitCount <= 0)
                    //    {
                    //        businessException.AddMessage(string.Format("第{0}行:单包装{1}填写有误。", rowCount, ucRead));
                    //        continue;
                    //    }
                    //}
                    if (!string.IsNullOrWhiteSpace(ucRead))
                    {
                        if (!double.TryParse(ucRead, out unitCount))
                        {
                            businessException.AddMessage(string.Format("第{0}行:单包装{1}填写有误。", rowCount, ucRead));
                            continue;
                        }
                    }
                    #endregion
                    #region 包装描述

                    unitCountDescription = ImportHelper.GetCellStringValue(row.GetCell(colUnitCountDescription));
                    //if (string.IsNullOrWhiteSpace(unitCountDescription))
                    //{
                    //    businessException.AddMessage(string.Format("第{0}行:包装描述不能为空。", rowCount));
                    //}
                    #endregion
                    #region 容器描述
                    containerDescription = ImportHelper.GetCellStringValue(row.GetCell(colContainerDescription));
                    //if (string.IsNullOrWhiteSpace(containerDescription))
                    //{
                    //    businessException.AddMessage(string.Format("第{0}行:容器描述不能为空。", rowCount));
                    //}
                    #endregion
                    #region 是否允许修改包装
                    changeUnitCount = ImportHelper.GetCellStringValue(row.GetCell(colIsChangeUnitCount));
                    //if (string.IsNullOrWhiteSpace(changeUnitCount))
                    //{
                    //    businessException.AddMessage(string.Format("第{0}行:是否允许修改包装不能为空。", rowCount));
                    //    continue;
                    //}
                    if (!string.IsNullOrWhiteSpace(changeUnitCount))
                    {
                        try
                        {
                            Convert.ToBoolean(changeUnitCount);
                        }
                        catch (Exception ex)
                        {
                            businessException.AddMessage(string.Format("第{0}行:导入是否允许修改包装错误,只能导入True,False。", rowCount));
                            continue;
                        }
                    }
                    #endregion

                    #region 圆整系数
                    string readRound = ImportHelper.GetCellStringValue(row.GetCell(colRoundUpOption));
                    if (!string.IsNullOrWhiteSpace(readRound))
                    {
                        switch (readRound)
                        {
                            case "0":
                                roundUpOption = 0;
                                break;
                            case "1":
                                roundUpOption = 1;
                                break;
                            case "2":
                                roundUpOption = 2;
                                break;
                            default:
                                businessException.AddMessage(string.Format("第{0}行:圆整系数{1}填写有误。", rowCount, readRound));
                                break;
                        }
                    }
                    #endregion

                    #region 捡货库格
                    routing = ImportHelper.GetCellStringValue(row.GetCell(colRouting));
                    #endregion

                    #region sap发货库位
                    sapLocation = ImportHelper.GetCellStringValue(row.GetCell(colSapLocation));
                    if (!string.IsNullOrEmpty(flowMaster.AsnConfirmMoveType) && string.IsNullOrEmpty(sapLocation))
                    {
                        businessException.AddMessage(string.Format("第{0}行:ASN发货确认移动类型有值,sap发货工厂不能为空。", rowCount));
                        continue;
                    }
                    #endregion

                    #region 来源库位
                    location = ImportHelper.GetCellStringValue(row.GetCell(colLocation));
                    if (!string.IsNullOrEmpty(location) )
                    {
                        var loc = allLocation.Where(l => l.Code == location);
                        if (loc == null || loc.Count() == 0)
                        {
                            businessException.AddMessage(string.Format("第{0}行:来源库位填写不正确。", rowCount));
                            continue;
                        }
                    }
                    #endregion


                    FlowDetail flowDetail = new FlowDetail();
                    var flowdets = this.genericMgr.FindAll<FlowDetail>(" select d from FlowDetail as d where d.Item=? and d.Flow=? ", new object[] { item, flow }, new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String });
                    if (flowdets != null && flowdets.Count > 0)
                    {
                        flowDetail = flowdets.First();
                        flowDetail.IsUpdate = true;
                    }
                    flowDetail.Flow = flow;
                    flowDetail.Item = item;
                    if (flowDetail.IsUpdate)
                    {
                        flowDetail.UnitCount = unitCount != 0 ? Convert.ToDecimal(unitCount) : flowDetail.UnitCount;
                        flowDetail.UnitCountDescription = !string.IsNullOrWhiteSpace(unitCountDescription) ? unitCountDescription : flowDetail.UnitCountDescription;
                        flowDetail.ContainerDescription = !string.IsNullOrWhiteSpace(containerDescription) ? containerDescription : flowDetail.ContainerDescription;
                        flowDetail.IsChangeUnitCount = !string.IsNullOrWhiteSpace(changeUnitCount) ? Convert.ToBoolean(changeUnitCount) : flowDetail.IsChangeUnitCount;
                        flowDetail.RoundUpOption = (roundUpOption == 0 || roundUpOption == 1 || roundUpOption == 2) ? (CodeMaster.RoundUpOption)roundUpOption : flowDetail.RoundUpOption;

                        flowDetail.Routing = !string.IsNullOrWhiteSpace(routing) ? routing : flowDetail.Routing;
                    }
                    else
                    {
                        if (unitCount == 0)
                        {
                            businessException.AddMessage(string.Format("第{0}行:新增行单包装不能为空。", rowCount));
                            continue;
                        }
                        if (string.IsNullOrWhiteSpace(unitCountDescription))
                        {
                            businessException.AddMessage(string.Format("第{0}行:新增行包装描述不能为空。", rowCount));
                            continue;
                        }
                        if (string.IsNullOrWhiteSpace(containerDescription))
                        {
                            businessException.AddMessage(string.Format("第{0}行:新增行容器描述不能为空。", rowCount));
                            continue;
                        }
                        if (string.IsNullOrWhiteSpace(changeUnitCount))
                        {
                            businessException.AddMessage(string.Format("第{0}行:是否允许修改包装不能为空。", rowCount));
                            continue;
                        }
                        flowDetail.UnitCount = Convert.ToDecimal(unitCount);
                        flowDetail.UnitCountDescription = unitCountDescription;
                        flowDetail.ContainerDescription = containerDescription;
                        flowDetail.RoundUpOption = (roundUpOption == 0 || roundUpOption == 1 || roundUpOption == 2) ? (CodeMaster.RoundUpOption)roundUpOption : (CodeMaster.RoundUpOption)0;
                        flowDetail.Routing = routing;
                    }
                    flowDetail.IsChangeUnitCount = Convert.ToBoolean(changeUnitCount);
                    //flowDetail.MinUnitCount = Convert.ToDecimal(minUnitCount);
                    flowDetail.ItemDescription = itemList[0].Description;
                    flowDetail.Container = itemList[0].Container;
                    flowDetail.MinUnitCount = itemList[0].MinUnitCount;
                    flowDetail.Uom = itemList[0].Uom;
                    flowDetail.BaseUom = itemList[0].Uom;
                    flowDetail.ReferenceItemCode = itemList[0].ReferenceCode;
                    flowDetail.IsActive = true;
                    flowDetail.PartyFrom = flowMaster.PartyFrom;
                    flowDetail.LocationTo = flowMaster.LocationTo;
                    flowDetail.ShipLocation = sapLocation;

                    #region 来源区域 目的库位 物料 不能在路线中存在
                    //int checkeSame = this.genericMgr.FindAllWithNativeSql<int>(" select COUNT(*) as countSum  from SCM_FlowDet as d where d.Item=? and exists( select 1 from SCM_FlowMstr as m where m.Code=d.Flow and m.PartyFrom=? and m.LocTo=? and m.Type=1  ) and d.Id <> ?", new object[] { item, flowMaster.PartyFrom, flowMaster.LocationTo, flowDetail.Id })[0];
                    //if (checkeSame > 0)
                    //{
                    //    businessException.AddMessage(string.Format("第{0}行:来源区域{1}+物料{2}+目的库位{3}已经存在数据库。", rowCount, flowMaster.PartyFrom, item, flowMaster.LocationTo));
                    //    continue;
                    //}

                    //if (exactFlowDetailList.Where(ef => ef.PartyFrom == flowMaster.PartyFrom && ef.LocationTo == flowMaster.LocationTo && ef.Item == flowDetail.Item && ef.Id != flowDetail.Id && (ef.Id == 0 || ef.IsUpdate)).Count() > 0)
                    //{
                    //    businessException.AddMessage(string.Format("第{0}行:来源区域{1}+物料{2}+目的库位{3}在模板中重复。", rowCount, flowMaster.PartyFrom, item, flowMaster.LocationTo));
                    //    continue;
                    //}

                    #endregion
                    exactFlowDetailList.Add(flowDetail);

                }


                ////更新物料主数据以及物料所在所有路线的上线包装 2012-11-20 张敏提出
                //Item newItem = genericMgr.FindAll<Item>(" from Item as i where i.Code=?", itemList[0].Code)[0];
                //newItem.MinUnitCount = Convert.ToDecimal(minUnitCount);
                //genericMgr.Update(newItem);

                #endregion
            }

            if (businessException.HasMessage)
            {
                throw businessException;
            }

            if (exactFlowDetailList != null && exactFlowDetailList.Count > 0)
            {
                foreach (FlowDetail flowDet in exactFlowDetailList)
                {
                    try
                    {
                        if (flowDet.Id == 0)
                        {
                            this.CreateFlowDetail(flowDet);
                        }
                        else if (flowDet.IsUpdate)
                        {
                            this.UpdateFlowDetail(flowDet);
                        }
                        else
                        {
                            this.genericMgr.Delete(flowDet);
                        }
                        this.genericMgr.FlushSession();
                    }
                    catch (Exception ex)
                    {
                        businessException.AddMessage(ex.Message);
                    }
                    //genericMgr.Update("Update from FlowDetail set MinUnitCount = ? where Item = ?", new object[] { flowDet.MinUnitCount, flowDet.Item });
                }
            }
            else
            {
                throw new BusinessException(string.Format("有效的数据行为0,可能是模板问题"));
            }

        }
        public ActionResult _DetailEdit(FlowDetail flowDetail, int? id)
        {
            if (ModelState.IsValid)
            {
                flowDetail.BaseUom = this.genericMgr.FindById<Item>(flowDetail.Item).Uom;
                flowMgr.UpdateFlowDetail(flowDetail);
                SaveSuccessMessage(Resources.SCM.FlowDetail.FlowDetail_Updated);
            }

            TempData["TabIndex"] = 2;
            return PartialView(flowDetail);
        }
 public ActionResult _DetailNew(string id)
 {
     FlowDetail flowDetail = new FlowDetail();
     FlowMaster flowMaster = base.genericMgr.FindById<FlowMaster>(id);
     flowDetail.LocationFrom = flowMaster.LocationFrom;
     flowDetail.Flow = id;
     flowDetail.IsCreatePickList = flowMaster.IsCreatePickList;
     return PartialView(flowDetail);
 }