Пример #1
0
        public bool Delete(string BillNo, out string errorInfo)
        {
            errorInfo = string.Empty;
            var ibm = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "1");

            if (ibm != null)
            {
                try
                {
                    //Del(OutBillDetailRepository, ibm.OutBillAllots);
                    Del(OutBillDetailRepository, ibm.OutBillDetails);
                    OutBillMasterRepository.Delete(ibm);
                    OutBillMasterRepository.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    errorInfo = "删除失败!原因:" + e.Message;
                    return(false);
                }
            }
            else
            {
                errorInfo = "删除失败!未找到当前需要删除的数据!";
                return(false);
            }
        }
Пример #2
0
        public bool Delete(string id, ref string errorInfo)
        {
            try
            {
                Guid ID = new Guid(id);
                var  sortOrderDispatch = SortWorkDispatchRepository.GetQueryable().FirstOrDefault(s => s.ID == ID);
                if (sortOrderDispatch == null)
                {
                    errorInfo = "当前选择的调度记录不存在,未能删除!";
                    return(false);
                }
                if (sortOrderDispatch.DispatchStatus != "1")
                {
                    errorInfo = "当前选择的调度记录不是已调度,未能删除!";
                    return(false);
                }
                if (sortOrderDispatch.OutBillMaster.Status != "1")
                {
                    errorInfo = "当前选择的调度记录出库单不是已录入,未能删除!";
                    return(false);
                }
                if (sortOrderDispatch.MoveBillMaster.Status != "1")
                {
                    errorInfo = "当前选择的调度记录移库单不是已录入,未能删除!";
                    return(false);
                }

                using (var scope = new TransactionScope())
                {
                    //解锁移库冻结量
                    var moveDetail = MoveBillDetailRepository.GetQueryable()
                                     .Where(m => m.BillNo
                                            == sortOrderDispatch.MoveBillNo);

                    var sourceStorages = moveDetail.Select(m => m.OutStorage).ToArray();
                    var targetStorages = moveDetail.Select(m => m.InStorage).ToArray();

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

                    moveDetail.AsParallel().ForAll(
                        (Action <MoveBillDetail>) delegate(MoveBillDetail m)
                    {
                        if (m.InStorage.ProductCode == m.ProductCode &&
                            m.OutStorage.ProductCode == m.ProductCode &&
                            m.InStorage.InFrozenQuantity >= m.RealQuantity &&
                            m.OutStorage.OutFrozenQuantity >= m.RealQuantity)
                        {
                            m.InStorage.InFrozenQuantity   -= m.RealQuantity;
                            m.OutStorage.OutFrozenQuantity -= m.RealQuantity;
                            m.InStorage.LockTag             = string.Empty;
                            m.OutStorage.LockTag            = string.Empty;
                        }
                        else
                        {
                            throw new Exception("储位的卷烟或移库冻结量与当前分配不符,信息可能被异常修改,不能删除!");
                        }
                    }
                        );

                    Del(MoveBillDetailRepository, sortOrderDispatch.MoveBillMaster.MoveBillDetails); //删除移库细单
                    MoveBillMasterRepository.Delete(sortOrderDispatch.MoveBillMaster);               //删除移库主单

                    Del(OutBillDetailRepository, sortOrderDispatch.OutBillMaster.OutBillDetails);    //删除出库细单
                    OutBillMasterRepository.Delete(sortOrderDispatch.OutBillMaster);                 //删除出库主单

                    //修改线路调度表中作业状态
                    var sortDisp = SortOrderDispatchRepository.GetQueryable()
                                   .Where(s => s.SortWorkDispatchID
                                          == sortOrderDispatch.ID);
                    foreach (var item in sortDisp.ToArray())
                    {
                        item.WorkStatus         = "1";
                        item.SortWorkDispatchID = null;
                    }
                    SortWorkDispatchRepository.Delete(sortOrderDispatch);
                    SortWorkDispatchRepository.SaveChanges();
                    scope.Complete();
                    return(true);
                }
            }
            catch (Exception e)
            {
                errorInfo = "删除失败,详情:" + e.Message;
                return(false);
            }
        }
Пример #3
0
        public bool Add(DateTime datetime, out string strResult)
        {
            bool result = false;

            strResult = string.Empty;

            var outBillMaster = OutBillMasterRepository.GetQueryable().Where(i => i.BillDate <= datetime);
            var outBillDetail = OutBillDetailRepository.GetQueryable().Where(i => i.OutBillMaster.BillDate <= datetime);
            var outBillAllot  = OutBillAllotRepository.GetQueryable().Where(i => i.OutBillMaster.BillDate <= datetime);

            if (outBillMaster.Any())
            {
                #region 主表移入历史表
                try
                {
                    foreach (var item in outBillMaster.ToArray())
                    {
                        OutBillMasterHistory history = new OutBillMasterHistory();
                        history.BillNo          = item.BillNo;
                        history.BillDate        = item.BillDate;
                        history.BillTypeCode    = item.BillTypeCode;
                        history.WarehouseCode   = item.WarehouseCode;
                        history.OperatePersonID = item.OperatePersonID;
                        history.Status          = item.Status;
                        history.VerifyPersonID  = item.VerifyPersonID;
                        history.VerifyDate      = item.VerifyDate;
                        history.Description     = item.Description;
                        history.IsActive        = item.IsActive;
                        history.UpdateTime      = item.UpdateTime;
                        history.Origin          = item.Origin;
                        history.TargetCellCode  = item.TargetCellCode;
                        OutBillMasterHistoryRepository.Add(history);
                    }
                    result = true;
                }
                catch (Exception e)
                {
                    strResult = "主库单:" + e.InnerException.ToString();
                    result    = false;
                }
                #endregion

                if (outBillDetail.Any())
                {
                    #region 细表移入历史表
                    try
                    {
                        foreach (var item in outBillDetail.ToArray())
                        {
                            OutBillDetailHistory history = new OutBillDetailHistory();
                            history.ID            = item.ID;
                            history.BillNo        = item.BillNo;
                            history.ProductCode   = item.ProductCode;
                            history.UnitCode      = item.UnitCode;
                            history.Price         = item.Price;
                            history.BillQuantity  = item.BillQuantity;
                            history.AllotQuantity = item.AllotQuantity;
                            history.RealQuantity  = item.RealQuantity;
                            history.Description   = item.Description;
                            OutBillDetailHistoryRepository.Add(history);
                        }
                        result = true;
                    }
                    catch (Exception e)
                    {
                        strResult = "细库单" + e.InnerException.ToString();
                        return(false);
                    }
                    #endregion

                    if (outBillAllot.Any())
                    {
                        #region 分配表移入历史表
                        try
                        {
                            foreach (var item3 in outBillAllot.ToArray())
                            {
                                OutBillAllotHistory history3 = new OutBillAllotHistory();
                                history3.BillNo          = item3.BillNo;
                                history3.ProductCode     = item3.ProductCode;
                                history3.OutBillDetailId = item3.OutBillDetailId;
                                history3.CellCode        = item3.CellCode;
                                history3.StorageCode     = item3.StorageCode;
                                history3.UnitCode        = item3.UnitCode;
                                history3.AllotQuantity   = item3.AllotQuantity;
                                history3.RealQuantity    = item3.RealQuantity;
                                history3.OperatePersonID = item3.OperatePersonID;
                                history3.Operator        = item3.Operator;
                                history3.StartTime       = item3.StartTime;
                                history3.FinishTime      = item3.FinishTime;
                                history3.Status          = item3.Status;
                                OutBillAllotHistoryRepository.Add(history3);
                            }
                            result = true;
                        }
                        catch (Exception e)
                        {
                            strResult = "分配单:" + e.InnerException.ToString();
                            result    = false;
                        }
                        #endregion
                    }
                }
                if (result == true)
                {
                    #region  除主细分配表
                    try
                    {
                        foreach (var item in outBillMaster.ToList())
                        {
                            Del(OutBillAllotRepository, item.OutBillAllots);
                            Del(OutBillDetailRepository, item.OutBillDetails);
                            OutBillMasterRepository.Delete(item);

                            result = true;
                        }
                    }
                    catch (Exception e)
                    {
                        strResult = "删除情况:" + e.InnerException.ToString();
                    }
                    OutBillMasterHistoryRepository.SaveChanges();
                    #endregion
                }
            }
            else
            {
                strResult = "数据不存在!";
            }
            return(result);
        }