Esempio n. 1
0
        public ActionResult Add(Epm_Plan model)
        {
            ResultView <int> view = new ResultView <int>();

            //表单校验
            if (!model.ProjectId.HasValue || model.ProjectId.Value == 0 || string.IsNullOrWhiteSpace(model.ProjectName))
            {
                view.Flag    = false;
                view.Message = "项目名称不能为空";
                return(Json(view));
            }
            if (string.IsNullOrEmpty(model.Name))
            {
                view.Flag    = false;
                view.Message = "计划名称不能为空";
                return(Json(view));
            }
            if (!model.StartTime.HasValue || model.StartTime.Value == DateTime.MinValue)
            {
                view.Flag    = false;
                view.Message = "开始时间不能为空";
                return(Json(view));
            }
            if (!model.EndTime.HasValue || model.EndTime.Value == DateTime.MinValue)
            {
                view.Flag    = false;
                view.Message = "结束时间不能为空";
                return(Json(view));
            }
            if (model.StartTime.Value > model.EndTime.Value)
            {
                view.Flag    = false;
                view.Message = "开始时间不能大于结束时间";
                return(Json(view));
            }
            if (string.IsNullOrEmpty(model.BatchNo))
            {
                view.Flag    = false;
                view.Message = "批次号不能为空";
                return(Json(view));
            }
            if (model.MilepostId == 0 || string.IsNullOrEmpty(model.MilepostName))
            {
                view.Flag    = false;
                view.Message = "工程节点不能为空";
                return(Json(view));
            }
            if (string.IsNullOrEmpty(model.PlanContent))
            {
                view.Flag    = false;
                view.Message = "计划说明不能为空";
                return(Json(view));
            }

            List <Epm_PlanComponent> planComponentIds = new List <Epm_PlanComponent>();
            string dataComponentIds = Request.Form["PlanBim"];

            if (!string.IsNullOrWhiteSpace(dataComponentIds))
            {
                planComponentIds = JsonConvert.DeserializeObject <List <Epm_PlanComponent> >(dataComponentIds);
            }

            Result <int> result = new Result <int>();

            using (ClientSiteClientProxy proxy = new ClientSiteClientProxy(ProxyEx(Request)))
            {
                DateTime startTime = Convert.ToDateTime(model.StartTime.Value.ToString("yyyy-MM-dd") + " 00:00:00");
                DateTime endTime   = Convert.ToDateTime(model.EndTime.Value.ToString("yyyy-MM-dd") + " 23:59:59");
                TimeSpan ts        = endTime - startTime;

                model.State     = (int)(ApprovalState.WaitAppr);
                model.BuildDays = ts.Days;

                result = proxy.AddPlan(model, planComponentIds);
            }
            return(Json(result.ToResultView()));
        }