Esempio n. 1
0
        /// <summary>
        /// 开始盘点
        /// </summary>
        /// <param name="inputDto">开始盘点时,传给后台的数据</param>
        /// <returns></returns>
        public ReturnInfo AddAssInventoryResult(AddAIResultInputDto inputDto)
        {
            ReturnInfo    RInfo = new ReturnInfo();
            StringBuilder sb    = new StringBuilder();

            if (IsExist(inputDto.IID))
            {
                RInfo.IsSuccess = true;
                RInfo.ErrorInfo = sb.ToString();
                return(RInfo);
            }
            else
            {
                try
                {
                    //更新盘点单状态为盘点中
                    var inventory = _assInventoryRepository.GetAssInventoryByID(inputDto.IID).FirstOrDefault();
                    if (inventory != null)
                    {
                        //添加当前的盘点单行项
                        List <string> assList = _assetsRepository.GetInventoryAssetses(inventory.LOCATIONID, inventory.TYPEID, inventory.DEPARTMENTID).Select(a => a.ASSID).ToList();
                        inventory.STATUS      = (int)InventoryStatus.盘点中;
                        inventory.TOTAL       = assList.Count;
                        inventory.RESULTCOUNT = 0;
                        _unitOfWork.RegisterDirty(inventory);

                        foreach (var asset in assList)
                        {
                            AssInventoryResult result = new AssInventoryResult
                            {
                                IID        = inputDto.IID,
                                ASSID      = asset,
                                RESULT     = 0,
                                CREATEDATE = DateTime.Now,
                                CREATEUSER = inputDto.UserId,
                                MODIFYDATE = DateTime.Now,
                                MODIFYUSER = inputDto.UserId
                            };
                            _unitOfWork.RegisterNew(result);

                            //更新盘点的物品状态为锁定
                            var assets = _assetsRepository.GetByID(asset).FirstOrDefault();
                            if (assets != null)
                            {
                                assets.ISLOCKED = 1;
                                _unitOfWork.RegisterDirty(assets);
                            }
                        }
                    }
                    _unitOfWork.Commit();
                    RInfo.IsSuccess = true;
                    RInfo.ErrorInfo = sb.ToString();
                    return(RInfo);
                }
                catch (Exception ex)
                {
                    _unitOfWork.Rollback();
                    sb.Append(ex.Message);
                    RInfo.IsSuccess = false;
                    RInfo.ErrorInfo = sb.ToString();
                    return(RInfo);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 更新盘点单
        /// </summary>
        /// <param name="inputDto">盘点单信息</param>
        /// <returns></returns>
        public ReturnInfo UpdateInventory(AssInventoryInputDto inputDto)
        {
            ReturnInfo    rInfo     = new ReturnInfo();
            StringBuilder sb        = new StringBuilder();
            var           inventory = _assInventoryRepository.GetAssInventoryByID(inputDto.IID).FirstOrDefault();

            if (inventory == null)
            {
                sb.Append("未找到该编号的盘点单.");
                rInfo.IsSuccess = false;
                rInfo.ErrorInfo = sb.ToString();
                return(rInfo);
            }
            else
            {
                if (inventory.STATUS == (int)InventoryStatus.盘点结束)
                {
                    sb.Append("该盘点单已经盘点结束.");
                    rInfo.IsSuccess = false;
                    rInfo.ErrorInfo = sb.ToString();
                    return(rInfo);
                }
                try
                {
                    List <string> assList = _assInventoryResultRepository.GetResultsByStatus(inputDto.IID, null).Select(a => a.ASSID).ToList();
                    int           count   = inputDto.AssDictionary.Count;
                    //更新盘点单结果行项
                    foreach (var key in inputDto.AssDictionary.Keys)
                    {
                        if (assList.Contains(key))
                        {
                            //更新
                            var inventoryresult = _assInventoryResultRepository.GetResultsByAssId(inputDto.IID, key)
                                                  .FirstOrDefault();
                            if (inventoryresult != null)
                            {
                                inventoryresult.RESULT = inputDto.AssDictionary[key];
                                if (inventoryresult.RESULT == (int)ResultStatus.待盘点)
                                {
                                    count--;
                                }
                            }

                            _unitOfWork.RegisterDirty(inventoryresult);
                        }
                        else
                        {
                            //添加
                            AssInventoryResult result = new AssInventoryResult
                            {
                                IID        = inputDto.IID,
                                ASSID      = key,
                                RESULT     = inputDto.AssDictionary[key],
                                CREATEDATE = DateTime.Now,
                                MODIFYDATE = DateTime.Now,
                                CREATEUSER = inputDto.MODIFYUSER,
                                MODIFYUSER = inputDto.MODIFYUSER
                            };
                            _unitOfWork.RegisterNew(result);
                        }
                        if (inputDto.IsEnd)
                        {
                            //如果盘点结束,就更新资产状态为非锁定
                            var assets = _assetsRepository.GetByID(key).FirstOrDefault();
                            if (assets != null)
                            {
                                assets.ISLOCKED = 0;
                                _unitOfWork.RegisterDirty(assets);
                            }
                        }
                    }
                    //如果盘点结束,就更新盘点单状态
                    inventory.MODIFYUSER  = inputDto.MODIFYUSER;
                    inventory.MODIFYDATE  = DateTime.Now;
                    inventory.RESULTCOUNT = count;
                    if (inputDto.IsEnd)
                    {
                        inventory.STATUS = (int)InventoryStatus.盘点结束;
                    }
                    _unitOfWork.RegisterDirty(inventory);

                    _unitOfWork.Commit();
                    rInfo.IsSuccess = true;
                    rInfo.ErrorInfo = sb.ToString();
                    return(rInfo);
                }
                catch (Exception ex)
                {
                    _unitOfWork.Rollback();
                    sb.Append(ex.Message);
                    rInfo.IsSuccess = false;
                    rInfo.ErrorInfo = sb.ToString();
                    return(rInfo);
                }
            }
        }