public bool EditAllot(string id, string status, string operater, out string strResult)
        {
            strResult = string.Empty;
            bool result = false;

            string[]    ids   = id.Split(',');
            string      strId = "";
            InBillAllot allot = null;

            var employee = EmployeeRepository.GetQueryable().FirstOrDefault(e => e.UserName == operater);

            for (int i = 0; i < ids.Length; i++)
            {
                strId = ids[i].ToString();
                allot = InBillAllotRepository.GetQueryable().ToArray().FirstOrDefault(a => strId == a.ID.ToString());
                if (allot != null)
                {
                    if (allot.Status == "0" && status == "1" ||
                        allot.Status == "1" && status == "0" ||
                        allot.Status == "1" && status == "2")
                    {
                        try
                        {
                            allot.Status = status;
                            if (operater != "")
                            {
                                allot.Operator = employee.EmployeeName;
                            }
                            else
                            {
                                allot.Operator = "";
                            }
                            InBillAllotRepository.SaveChanges();
                            result = true;
                        }
                        catch (Exception ex)
                        {
                            strResult = "原因:" + ex.Message;
                        }
                    }
                    else
                    {
                        strResult = "原因:操作错误!";
                    }
                }
                else
                {
                    strResult = "原因:未找到该记录!";
                }
            }
            return(result);
        }
        public bool AllotDelete(string billNo, long id, out string strResult)
        {
            bool result = false;
            var  ibm    = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo && i.Status == "3");

            if (ibm != null)
            {
                if (string.IsNullOrEmpty(ibm.LockTag))
                {
                    var allotDetail = ibm.InBillAllots.Single(a => a.ID == (int)id);
                    if (string.IsNullOrEmpty(allotDetail.Storage.LockTag))
                    {
                        try
                        {
                            allotDetail.InBillDetail.AllotQuantity -= allotDetail.AllotQuantity;
                            allotDetail.Storage.InFrozenQuantity   -= allotDetail.AllotQuantity;
                            allotDetail.Storage.LockTag             = string.Empty;
                            ibm.InBillAllots.Remove(allotDetail);
                            InBillAllotRepository.Delete(allotDetail);
                            if (ibm.InBillAllots.Count == 0)
                            {
                                ibm.Status     = "2";
                                ibm.UpdateTime = DateTime.Now;
                            }
                            InBillAllotRepository.SaveChanges();
                            strResult = "";
                            result    = true;
                        }
                        catch (Exception)
                        {
                            strResult = "当前储位或订单其他人正在操作,请稍候重试!";
                        }
                    }
                    else
                    {
                        strResult = "当前储位其他人正在操作,请稍候重试!";
                    }
                }
                else
                {
                    strResult = "当前订单其他人正在操作,请稍候重试!";
                }
            }
            else
            {
                strResult = "当前订单状态不是已分配,或当前订单不存在!";
            }
            return(result);
        }
Exemple #3
0
        private bool FinishInBillTask(Task task)
        {
            var inAllot = InBillAllotRepository.GetQueryable()
                          .Where(i => i.BillNo == task.OrderID &&
                                 i.ID == task.AllotID &&
                                 i.Status == "1")
                          .FirstOrDefault();

            if (inAllot != null &&
                (inAllot.InBillMaster.Status == "4" ||
                 inAllot.InBillMaster.Status == "5"
                ))
            {
                decimal quantity = inAllot.AllotQuantity;
                if (string.IsNullOrEmpty(inAllot.Storage.LockTag) &&
                    inAllot.AllotQuantity >= quantity &&
                    inAllot.Storage.InFrozenQuantity >= quantity)
                {
                    inAllot.Status                     = "2";
                    inAllot.Storage.Rfid               = "";
                    inAllot.RealQuantity              += quantity;
                    inAllot.Storage.Quantity          += quantity;
                    inAllot.Storage.StorageTime        = DateTime.Now;
                    inAllot.Storage.InFrozenQuantity  -= quantity;
                    inAllot.InBillDetail.RealQuantity += quantity;
                    inAllot.InBillMaster.Status        = "5";
                    inAllot.FinishTime                 = DateTime.Now;
                    if (inAllot.InBillMaster.InBillAllots.All(c => c.Status == "2"))
                    {
                        inAllot.InBillMaster.Status = "6";
                    }
                    InBillAllotRepository.SaveChanges();
                    return(true);
                }
                else
                {
                    //"需确认入库的数据别人在操作或完成的数量不对,完成出错!";
                    return(false);
                }
            }
            else
            {
                //"需确认入库的数据查询为空或者主单状态不对,完成出错!";
                return(false);
            }
        }
        public bool AllotEdit(string billNo, long id, string cellCode, decimal allotQuantity, out string strResult)
        {
            bool result = false;
            var  ibm    = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo && i.Status == "3");
            var  cell   = CellRepository.GetQueryable().Single(c => c.CellCode == cellCode);

            if (ibm != null)
            {
                if (string.IsNullOrEmpty(ibm.LockTag))
                {
                    var allotDetail = ibm.InBillAllots.Single(a => a.ID == (int)id);
                    if (string.IsNullOrEmpty(allotDetail.Storage.LockTag))
                    {
                        Storage storage;
                        if (allotDetail.CellCode == cellCode)
                        {
                            storage = allotDetail.Storage;
                        }
                        else
                        {
                            storage = Locker.LockEmpty(cell);
                            if (storage != null && (storage.Quantity != 0 || storage.InFrozenQuantity != 0))
                            {
                                storage.LockTag = string.Empty;
                                StorageRepository.SaveChanges();
                                storage = null;
                            }
                        }
                        if (storage != null)
                        {
                            decimal q1 = allotDetail.InBillDetail.BillQuantity - allotDetail.InBillDetail.AllotQuantity;
                            decimal q2 = allotQuantity * allotDetail.Unit.Count;
                            if (q1 >= q2 || q1 == 0)
                            {
                                try
                                {
                                    allotDetail.InBillDetail.AllotQuantity -= allotDetail.AllotQuantity;
                                    allotDetail.Storage.InFrozenQuantity   -= allotDetail.AllotQuantity;
                                    allotDetail.InBillDetail.AllotQuantity += q2;
                                    storage.ProductCode       = allotDetail.ProductCode;
                                    storage.InFrozenQuantity += q2;
                                    storage.LockTag           = string.Empty;
                                    allotDetail.CellCode      = storage.Cell.CellCode;
                                    allotDetail.StorageCode   = storage.StorageCode;
                                    allotDetail.AllotQuantity = q2;
                                    InBillAllotRepository.SaveChanges();
                                    strResult = "保存修改成功!";
                                    result    = true;
                                }
                                catch (Exception)
                                {
                                    strResult = "保存修改失败,订单或储位其他人正在操作!";
                                }
                            }
                            else
                            {
                                strResult = "分配数量超过订单数量!";
                            }
                        }
                        else
                        {
                            strResult = "当前选择的储位不可用,其他人正在操作或已有库存!";
                        }
                    }
                    else
                    {
                        strResult = "当前储位其他人正在操作,请稍候重试!";
                    }
                }
                else
                {
                    strResult = "当前订单其他人正在操作,请稍候重试!";
                }
            }
            else
            {
                strResult = "当前订单状态不是已分配,或当前订单不存在!";
            }
            return(result);
        }
        public bool AllotCancel(string billNo, out string strResult)
        {
            Locker.LockKey = billNo;
            bool result = false;
            var  ibm    = InBillMasterRepository.GetQueryable()
                          .FirstOrDefault(i => i.BillNo == billNo &&
                                          i.Status == "3");

            if (ibm != null)
            {
                if (string.IsNullOrEmpty(ibm.LockTag))
                {
                    try
                    {
                        using (var scope = new TransactionScope())
                        {
                            var inAllot = InBillAllotRepository.GetQueryable()
                                          .Where(o => o.BillNo == ibm.BillNo)
                                          .ToArray();

                            var storages = inAllot.Select(i => i.Storage).ToArray();

                            if (!Locker.Lock(storages))
                            {
                                strResult = "锁定储位失败,储位其他人正在操作,无法取消分配请稍候重试!";
                                return(false);
                            }

                            inAllot.AsParallel().ForAll(
                                (Action <InBillAllot>) delegate(InBillAllot i)
                            {
                                if (i.Storage.ProductCode == i.ProductCode &&
                                    i.Storage.InFrozenQuantity >= i.AllotQuantity)
                                {
                                    lock (i.InBillDetail)
                                    {
                                        i.InBillDetail.AllotQuantity -= i.AllotQuantity;
                                    }
                                    i.Storage.InFrozenQuantity -= i.AllotQuantity;
                                    i.Storage.LockTag           = string.Empty;
                                }
                                else
                                {
                                    throw new Exception("储位的卷烟或入库冻结量与当前分配不符,信息可能被异常修改,不能取消当前入库分配!");
                                }
                            }
                                );

                            InBillAllotRepository.SaveChanges();

                            InBillAllotRepository.GetObjectSet()
                            .DeleteEntity(i => i.BillNo == ibm.BillNo);
                            //InBillAllotRepository.GetObjectQuery()
                            //    .DeleteAll(i => i.BillNo == ibm.BillNo,null);

                            ibm.Status     = "2";
                            ibm.UpdateTime = DateTime.Now;
                            InBillMasterRepository.SaveChanges();
                            result    = true;
                            strResult = "取消分配成功!";

                            scope.Complete();
                        }
                    }
                    catch (Exception e)
                    {
                        strResult = "取消分配失败,详情:" + e.Message;
                    }
                }
                else
                {
                    strResult = "当前订单其他人正在操作,请稍候重试!";
                }
            }
            else
            {
                strResult = "当前订单状态不是已分配,或当前订单不存在!";
            }
            return(result);
        }