/// <summary>
        /// 新增损益单明细
        /// </summary>
        /// <param name="profitLossBillDetail">损益单细表</param>
        /// <returns></returns>
        public bool Add(ProfitLossBillDetail profitLossBillDetail, out string strResult)
        {
            bool result = false;

            try
            {
                IQueryable <ProfitLossBillDetail> profitLossBillDetailQuery = ProfitLossBillDetailRepository.GetQueryable();
                var unit    = UnitRepository.GetQueryable().FirstOrDefault(u => u.UnitCode == profitLossBillDetail.UnitCode);
                var cell    = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == profitLossBillDetail.CellCode);
                var product = ProductRepository.GetQueryable().FirstOrDefault(p => p.ProductCode == profitLossBillDetail.ProductCode);
                var storage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == profitLossBillDetail.StorageCode);
                if (Locker.LockStorage(storage, product) != null)
                {
                    if (IsQuntityRight(profitLossBillDetail.Quantity * unit.Count, storage.InFrozenQuantity, storage.OutFrozenQuantity, cell.MaxQuantity * unit.Count, storage.Quantity))
                    {
                        var pbd = new ProfitLossBillDetail();
                        pbd.BillNo      = profitLossBillDetail.BillNo;
                        pbd.CellCode    = profitLossBillDetail.CellCode;
                        pbd.StorageCode = profitLossBillDetail.StorageCode;
                        pbd.ProductCode = profitLossBillDetail.ProductCode;
                        pbd.UnitCode    = profitLossBillDetail.UnitCode;
                        pbd.Price       = profitLossBillDetail.Price;
                        pbd.Quantity    = profitLossBillDetail.Quantity * unit.Count;
                        pbd.Description = profitLossBillDetail.Description;
                        if (profitLossBillDetail.Quantity > 0)
                        {
                            storage.InFrozenQuantity += profitLossBillDetail.Quantity * unit.Count;
                        }
                        else
                        {
                            storage.OutFrozenQuantity += Math.Abs(profitLossBillDetail.Quantity * unit.Count);
                        }

                        ProfitLossBillDetailRepository.Add(pbd);
                        ProfitLossBillDetailRepository.SaveChanges();
                        storage.LockTag = string.Empty;
                        StorageRepository.SaveChanges();
                        result = true;
                    }
                }
                strResult = resultStr == "" ? "该库存的当前库存-出库冻结量小于0或者已经处于编辑状态!" : resultStr;
            }
            catch (Exception ex)
            {
                strResult = "新增失败,原因:" + ex.Message;
            }
            return(result);
        }
        /// <summary>
        /// 盘点确认
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <returns></returns>
        public bool confirmCheck(string billNo, string userName, out string errorInfo)
        {
            bool result = false;

            errorInfo = string.Empty;
            var checkbm     = CheckBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);
            var checkDetail = CheckBillDetailRepository.GetQueryable().Where(c => c.BillNo == checkbm.BillNo &&
                                                                             c.ProductCode == c.RealProductCode &&
                                                                             c.Quantity != c.RealQuantity &&
                                                                             c.Status == "2");

            using (var scope = new TransactionScope())
            {
                try
                {
                    if (checkDetail.Count() > 0)
                    {
                        string billno = GenProfitLossBillNo(userName).ToString();
                        //添加损益主表
                        var pbm      = new ProfitLossBillMaster();
                        var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);
                        if (employee != null)
                        {
                            pbm.BillNo          = billno;
                            pbm.BillDate        = DateTime.Now;
                            pbm.BillTypeCode    = "5002";
                            pbm.WarehouseCode   = checkbm.WarehouseCode;
                            pbm.OperatePersonID = employee.ID;
                            pbm.Status          = "1";
                            pbm.IsActive        = "1";
                            pbm.UpdateTime      = DateTime.Now;

                            ProfitLossBillMasterRepository.Add(pbm);
                            ProfitLossBillMasterRepository.SaveChanges();
                        }

                        //添加损益细表
                        foreach (var item in checkDetail.ToArray())
                        {
                            decimal differQuantity = item.RealQuantity - item.Quantity;        //损益数量
                            if (Locker.LockNoEmptyStorage(item.Storage, item.Product) != null) //锁库存
                            {
                                var pbd = new ProfitLossBillDetail();
                                pbd.BillNo      = billno;
                                pbd.CellCode    = item.CellCode;
                                pbd.StorageCode = item.StorageCode;
                                pbd.ProductCode = item.ProductCode;
                                pbd.UnitCode    = item.UnitCode;
                                pbd.Price       = item.Product != null ? item.Product.CostPrice : 0;
                                pbd.Quantity    = differQuantity;

                                if (differQuantity > 0)
                                {
                                    item.Storage.InFrozenQuantity += differQuantity;
                                }
                                else
                                {
                                    item.Storage.OutFrozenQuantity += Math.Abs(differQuantity);
                                }
                                ProfitLossBillDetailRepository.Add(pbd);
                                item.Storage.LockTag = string.Empty;
                                ProfitLossBillDetailRepository.SaveChanges();
                            }
                            scope.Complete();
                        }
                    }

                    var checkBillDetail = CheckBillDetailRepository.GetQueryable().Where(c => c.BillNo == checkbm.BillNo);//解锁盘点锁定
                    foreach (var item in checkBillDetail.ToArray())
                    {
                        item.Storage.IsLock = "0";
                    }
                    if (checkbm != null && checkbm.Status == "4")
                    {
                        checkbm.Status     = "5";
                        checkbm.VerifyDate = DateTime.Now;
                        checkbm.UpdateTime = DateTime.Now;
                        CheckBillMasterRepository.SaveChanges();
                        result = true;
                    }
                }
                catch (Exception e)
                {
                    errorInfo = "确认盘点损益失败!原因:" + e.Message;
                }
                scope.Complete();
            }
            return(result);
        }