/// <summary>
        /// 恢复单据
        /// </summary>
        public OPResult RevertBill(BillSubcontractSearchEntity entity)
        {
            var lp   = VMGlobal.ManufacturingQuery.LinqOP;
            var bill = lp.GetById <BillSubcontract>(entity.ID);

            if (bill == null)
            {
                return new OPResult {
                           IsSucceed = false, Message = "未找到相应单据."
                }
            }
            ;
            bill.IsDeleted = false;
            try
            {
                lp.Update <BillSubcontract>(bill);

                return(new OPResult {
                    IsSucceed = true, Message = "恢复成功!"
                });
            }
            catch (Exception ex)
            {
                return(new OPResult {
                    IsSucceed = false, Message = "恢复失败,失败原因:\n" + ex.Message
                });
            }
        }
        /// <summary>
        /// 取消量归零
        /// </summary>
        public OPResult ZeroCancelSubcontractQuantity(BillSubcontractSearchEntity entity)
        {
            var lp     = VMGlobal.ManufacturingQuery.LinqOP;
            var orders = lp.Search <BillSubcontractDetails>(o => o.BillID == entity.ID).ToList();

            orders.ForEach(o =>
            {
                o.QuaCancel = 0;
            });
            try
            {
                lp.Update <BillSubcontractDetails>(orders);
            }
            catch (Exception ex)
            {
                return(new OPResult {
                    IsSucceed = false, Message = "取消量归零失败,失败原因:\n" + ex.Message
                });
            }
            foreach (var d in entity.Details)
            {
                d.QuaCancel = 0;
            }
            return(new OPResult {
                IsSucceed = true, Message = "取消量归零成功!"
            });
        }
        public void SetQuantityForBillEntity(BillSubcontractSearchEntity entity)
        {
            entity.Quantity     = entity.Details.Sum(o => o.Quantity);
            entity.QuaCancel    = entity.Details.Sum(o => o.QuaCancel);
            entity.QuaCompleted = entity.Details.Sum(o => o.QuaCompleted);
            var realSubcontractQuantity = entity.Quantity - entity.QuaCancel;

            entity.StatusName = realSubcontractQuantity == entity.QuaCompleted ? "已完成" : (entity.QuaCompleted == 0 ? "未交货" : (realSubcontractQuantity > entity.QuaCompleted ? "部分已交货" : "数据有误"));
        }