public bool ValidBizProgress(WorkOrderViewModel workOrder, out string err)
        {
            err = string.Empty;

            if (workOrder.CusId <= 0)
            {
                err = "必选项无效";
                return(false);
            }

            if (_customer.GetCustomer(workOrder.CusId) == null)
            {
                err = "必选项为空";
                return(false);
            }

            return(true);
        }
Exemple #2
0
        public WorkOrder SaveWorkOrder(WorkOrderViewModel workOrder)
        {
            WorkOrder wo = null;

            if (workOrder.WoId > 0)
            {
                wo = this.GetWorkOrder(workOrder.WoId);
            }
            else
            {
                wo            = new WorkOrder();
                wo.CreateTime = DateTime.Now;
                wo.Creator    = _identity.GetUserName();
                wo.State      = WorkOrderState.New;
            }

            //业务项目
            WorkOrderItem[] woItems = wo.WorkOrderItems.ToArray();
            for (int i = woItems.Count() - 1; i >= 0; i--)
            {
                //先删除旧记录
                wo.WorkOrderItems.Remove(woItems[i]);
            }
            string[] items = workOrder.BizItemIds.Split(',');
            foreach (string i in items)
            {
                //添加关联项目
                WorkOrderItem woi = new WorkOrderItem();
                woi.WorkOrder         = wo;
                woi.BizItem           = _setting.GetBizItem(Convert.ToInt32(i));
                wo.CommercialExpense += woi.BizItem.ServicePrice;
                wo.WorkOrderItems.Add(woi);

                //生成进度步骤
                foreach (BizSteps s in woi.BizItem.BizSteps)
                {
                    WorkProgress p = new WorkProgress();
                    p.WorkOrder          = wo;
                    p.BizItem            = woi.BizItem;
                    p.BizStep            = s;
                    p.CompletedTime      = null;
                    p.ResultDesc         = null;
                    p.AdvanceExpenditure = 0;
                    p.Creator            = _identity.GetUserName();
                    p.CreateTime         = DateTime.Now;
                    wo.WorkProgresses.Add(p);
                }
            }

            //校验客户编号的有效性
            wo.Customer           = _customer.GetCustomer(workOrder.CusId);
            wo.ContractTime       = workOrder.ContractTime;
            wo.Remark             = workOrder.Remark;
            wo.BizManager         = workOrder.BizManager;
            wo.BizOperations      = workOrder.BizOperations;
            wo.Recommend          = workOrder.Recommend;
            wo.PreferentialAmount = workOrder.PreferentialAmount;
            wo.Priority           = (WorkOrderPriority)workOrder.Priority;
            wo.FinishTime         = workOrder.FinishTime;

            _context.WorkOrders.AddOrUpdate(wo);
            _context.SaveChanges();

            return(wo);
        }