/// <summary>
        /// 取消出库
        /// </summary>
        /// <param name="orderNo"></param>
        /// <param name="errMessage"></param>
        /// <returns></returns>
        public bool CancelOutStock(string orderNo, out string errMessage)
        {
            var order = new RepositoryFactory <SaleOrderEntity>().Repository().FindEntity("OrderNo", orderNo);

            if (order == null)
            {
                errMessage = string.Format("订单[{0}]数据异常", orderNo);
                return(false);
            }

            if (order.Status != (int)OrderStatus.OutStock)
            {
                errMessage = string.Format("订单{0}不是已出库状态,不能进行取消出库操作<br>", orderNo);
                return(false);
            }

            if (order.IsSuspended)
            {
                errMessage = string.Format("订单{0}已被挂起,不能操作<br>", orderNo);
                return(false);
            }

            //获取到拣货明细
            var pickItemList = _pickItemBLL.GetPickItemListByOrderNo(order.OrderNo);
            var pickMaster   = new RepositoryFactory <PickMasterEntity>().Repository()
                               .FindEntity("PickNo", pickItemList.First().PickNo);

            if (pickMaster == null)
            {
                errMessage = string.Format("订单{0}获取拣货单拣货单[{1}]数据异常", orderNo, pickItemList.First().PickNo);
                return(false);
            }

            IDatabase     database    = DataFactory.Database();
            DbTransaction isOpenTrans = database.BeginTrans();

            try
            {
                if (pickMaster.Status != (int)PickMasterStatus.Initial)
                {
                    pickMaster.Modify(pickMaster.PickId);
                    pickMaster.Status = (int)PickMasterStatus.Initial;
                    var isSuccess = _pickMasterBll.UpdateStatus(pickMaster, PickMasterStatus.Picked, isOpenTrans);
                    if (!isSuccess)
                    {
                        throw new Exception("订单状态更新失败");
                    }
                }

                List <string>          lstOrderNo   = new List <string>();
                List <SaleOrderEntity> listOrderEnt = new List <SaleOrderEntity>();

                foreach (var pick in pickItemList)
                {
                    bool outStock1 = _inventoryLocationBLL.UpdateInventoryByOutStock(pick.WarehouseId, InventoryLocationTransactionType.CancelOutStock, pick.ProductId,
                                                                                     pick.LocationCode, -1 * pick.Qty, isOpenTrans);
                    if (!outStock1)
                    {
                        throw new Exception(string.Format("更新储位{0}库存失败", pick.LocationCode));
                    }

                    bool outStock2 = _inventoryBll.UpdateInventoryByOutStock(order.OrderNo, InventoryTransactionType.CancelOutStock, pick.WarehouseId,
                                                                             order.MerchantId, pick.ProductId, -1 * pick.Qty, isOpenTrans);
                    if (!outStock2)
                    {
                        throw new Exception("更新在库库存失败");
                    }

                    if (!lstOrderNo.Contains(pick.OrderNo))
                    {
                        lstOrderNo.Add(pick.OrderNo);
                        var orderEntity = new RepositoryFactory <SaleOrderEntity>().Repository()
                                          .FindEntity("OrderNo", pick.OrderNo);
                        if (orderEntity == null)
                        {
                            throw new Exception(string.Format("订单[{0}]数据异常", orderNo));
                        }

                        if (orderEntity.IsSuspended)
                        {
                            throw new Exception(string.Format("订单{0}已被挂起,不能操作<br>", orderNo));
                        }
                        listOrderEnt.Add(orderEntity);
                    }
                }

                foreach (string item in lstOrderNo)
                {
                    bool flag = _saleOrderBLL.UpdateOutStockStatus(item, OutStockStatus.Initial, isOpenTrans);
                    if (!flag)
                    {
                        throw new Exception(string.Format("订单[{0}]状态更新失败", item));
                    }
                }
                foreach (var item in listOrderEnt)
                {
                    item.Modify(order.OrderId);
                    item.Status = (int)OrderStatus.WaitOutStock;
                    var isSuccess = _saleOrderBLL.UpdateStatus(item, OrderStatus.OutStock, isOpenTrans);
                    if (!isSuccess)
                    {
                        throw new Exception("订单状态更新失败");
                    }
                }

                database.Commit();
                errMessage = "";
                return(true);
            }
            catch (Exception ex)
            {
                database.Rollback();
                errMessage = ex.Message;
                return(false);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="pickNo"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool PickConfirm(string pickNo, out string message)
        {
            var pickMaster = new RepositoryFactory <PickMasterEntity>().Repository().FindEntity("PickNo", pickNo);

            if (pickMaster == null)
            {
                message = string.Format("拣货单[{0}]数据异常", pickNo);
                return(false);
            }

            if (pickMaster.Status != (int)PickMasterStatus.Initial &&
                pickMaster.Status != (int)PickMasterStatus.Picking)
            {
                message = string.Format("拣货单[{0}]不是初始或开始确认状态,确认失败", pickMaster.PickNo);
                return(false);
            }

            var picks = _pickItemBll.GetPickItemListByPickNo(pickMaster.PickNo);

            IDatabase     database    = DataFactory.Database();
            DbTransaction isOpenTrans = database.BeginTrans();

            try
            {
                pickMaster.Modify(pickMaster.PickId);
                pickMaster.Status = (int)PickMasterStatus.Picked;
                bool isSuccess = _pickMasterBll.UpdateStatus(pickMaster, PickMasterStatus.Picking, isOpenTrans);
                if (!isSuccess)
                {
                    throw new Exception("订单状态更新失败");
                }

                List <string> lstOrderNo = new List <string>();
                foreach (var pick in picks)
                {
                    bool moveIn = _inventoryLocationBLL.UpdateInventoryByMoveIn(pick.WarehouseId, InventoryLocationTransactionType.Picked, pick.ProductId, pick.LocationCode, pick.ToLocationCode, pick.Qty, isOpenTrans);
                    if (!moveIn)
                    {
                        throw new Exception("更新目的储位库存失败");
                    }

                    bool moveOut = _inventoryLocationBLL.UpdateInventoryByPicked(pick.WarehouseId, InventoryLocationTransactionType.Picked, pick.ProductId, pick.ToLocationCode, pick.LocationCode, pick.Qty, isOpenTrans);
                    if (!moveOut)
                    {
                        throw new Exception("更新在库库存失败");
                    }

                    if (!lstOrderNo.Contains(pick.OrderNo))
                    {
                        lstOrderNo.Add(pick.OrderNo);
                    }
                }

                foreach (string orderNo in lstOrderNo)
                {
                    bool flag = _orderBll.UpdateOutStockStatus(orderNo, OutStockStatus.PickFinished, isOpenTrans);
                    if (!flag)
                    {
                        throw new Exception(string.Format("订单[{0}]状态更新失败", orderNo));
                    }
                }

                database.Commit();
                message = string.Format("拣货单[{0}]已确认完成", pickMaster.PickNo);
                return(true);
            }
            catch (Exception ex)
            {
                database.Rollback();
                message = string.Format("拣货单[{0}]确认失败:{1}", pickMaster.PickNo, ex.Message);
                return(false);
            }
        }