Esempio n. 1
0
        public bool CreateSampleOrderByMMInOrder(MMInOrder OrderItem, bool modifyOrNot)
        {
            bool        isSuccess       = false;
            SampleOrder SampleOrderItem = new SampleOrder();

            SampleOrderItem.DefPK          = OrderItem.DefPK;                //物料PK
            SampleOrderItem.LotID          = OrderItem.BatchID;              //批次号
            SampleOrderItem.SampleDate     = OrderItem.SynTime;              //抽样时间
            SampleOrderItem.SourceOrderID  = OrderItem.CheckLot;             //来源单号
            SampleOrderItem.Creator        = OrderItem.Creator;              //创建人
            SampleOrderItem.CreateTime     = OrderItem.SynTime;              //创建时间
            SampleOrderItem.SampleQuantity = 50;                             //样品数量
            SampleOrderItem.SampleType     = SampleTypeEnum.PackagesComming; //样品类型
            SampleOrderItem.CheckType      = CheckTypeEnum.Normal;           //检验类型
            SampleOrderItem.SupPK          = OrderItem.SupPK;                //供应商
            //新建
            if (!modifyOrNot)
            {
                SampleOrderItem.SampleID = EncodeHelper.GetOrderID <SampleOrder>("SampleID", "S");//样品ID
                SampleOrderItem.State    = DataState.New;
            }
            else
            {
                SampleOrderItem.State = DataState.Changed;
            }
            SampleOrderItem.SamplerPK = -1;

            ReturnValue rv = SSIT.EncodeBase.Encode.EncodeData.SaveDatas <SampleOrder>(new EncodeCollection <SampleOrder>(SampleOrderItem));

            if (rv.Success)
            {
                newSampleOrder = SampleOrderItem;
                ReturnValue.ShowMessage("已自动生成样品单!");
                CheckOrder CheckOrderItem = new CheckOrder
                {
                    SampleID      = SampleOrderItem.SampleID,
                    LotID         = SampleOrderItem.LotID,
                    HutPK         = SampleOrderItem.HutPK,
                    DefPK         = SampleOrderItem.DefPK,
                    SourceOrderID = SampleOrderItem.SourceOrderID,
                    SampleDate    = SampleOrderItem.SampleDate,
                    CheckQuantity = 1,
                    CheckType     = CheckTypeEnum.Normal,
                    State         = DataState.New
                };
                string PlanCheckItemString = SSIT.QMBase.DefinitionCheckItemCombine.GetCheckItemstringby(CheckOrderItem.DefPK, SSIT.QMBase.MMTypEnum.QM);
                if (PlanCheckItemString.IsNullOrEmpty())
                {
                    var order = (CheckOrder)CheckOrderItem.Clone();
                    order.IDENTITY     = null;
                    order.CreateTime   = DateTime.Now.ToString(EncodeConst.DateTimeFormat);
                    order.Creator      = null;
                    order.CheckOrderID = EncodeHelper.GetOrderID <CheckOrder>("CheckOrderID", "C");
                    string frontWorker = AllocationWorker(true);
                    order.PlanInspector = frontWorker;
                    rv = SSIT.EncodeBase.Encode.EncodeData.SaveDatas <CheckOrder>(new EncodeCollection <CheckOrder>(order));
                    if (rv.Success)
                    {
                        isSuccess = true;
                        ReturnValue.ShowMessage("已自动生成检测单!");
                    }
                    return(isSuccess);
                }
                Dictionary <int, List <CheckItem> > dick = new Dictionary <int, List <CheckItem> >();
                string[] checkItems = PlanCheckItemString.Split(',');
                foreach (string checkItem in checkItems)
                {
                    CheckItem ci = CheckItem.Instance.Datas.FirstOrDefault(p => p.Enable && p.ParamID == int.Parse(checkItem));
                    if (!dick.ContainsKey(ci.CheckCategoryID))
                    {
                        dick.Add(ci.CheckCategoryID, new List <CheckItem>());
                    }
                    dick[ci.CheckCategoryID].Add(ci);
                }
                //根据dick的数量创建检测单
                foreach (var items in dick.Values)
                {
                    //用linq,根据value查字典的key,即检测大类ID
                    int CheckType = dick.FirstOrDefault(p => p.Value == items).Key;
                    //CheckCategoryID   ——  8包材前道  9包材后道
                    var order = (CheckOrder)CheckOrderItem.Clone();
                    order.IDENTITY = null;
                    var list = items.Select(p => p.ParamID).ToList();
                    order.PlanCheckItemString = list.ListIntToString();
                    if (order.State == DataState.New)
                    {
                        order.CreateTime   = DateTime.Now.ToString(EncodeConst.DateTimeFormat);
                        order.Creator      = null;
                        order.CheckOrderID = EncodeHelper.GetOrderID <CheckOrder>("CheckOrderID", "C");
                        //调用分配函数
                        //包材前道
                        if (CheckType == 8)
                        {
                            string frontWorker = AllocationWorker(true);
                            order.PlanInspector = frontWorker;
                        }
                        //包材后道
                        if (CheckType == 9)
                        {
                            string backWorker = AllocationWorker(false);
                            order.PlanInspector = backWorker;
                        }
                    }
                    rv = SSIT.EncodeBase.Encode.EncodeData.SaveDatas <CheckOrder>(new EncodeCollection <CheckOrder>(order));
                    if (rv.Success)
                    {
                        isSuccess = true;
                        ReturnValue.ShowMessage("已自动生成检测单!");
                    }
                }
            }
            return(isSuccess);
        }