protected override void AfterSave(List <Dictionary <string, string> > list, List <Dictionary <string, string> > deleteList, Base.Logic.Domain.S_UI_List listInfo)
        {
            base.AfterSave(list, deleteList, listInfo);

            var wbsid = GetQueryString("NodeWBSID");
            var wbs   = this.BusinessEntities.Set <S_W_WBS>().FirstOrDefault(a => a.ID == wbsid);

            if (wbs == null)
            {
                throw new BusinessException("未获得WBS节点!");
            }
            var mileStoneList = this.BusinessEntities.Set <S_P_MileStone>().Where(a => a.WBSID == wbsid).ToList();             // wbs.S_I_ProjectInfo.S_P_MileStone.Where(a => a.WBSID == wbs.ID).ToList();
            var planList      = this.BusinessEntities.Set <S_P_CooperationPlan>().Where(a => a.SchemeWBSID == wbsid).ToList(); // wbs.S_I_ProjectInfo.S_P_CooperationPlan.Where(a => a.SchemeWBSID == wbs.ID).ToList();

            foreach (var mileStone in mileStoneList)
            {
                mileStone.Save();
                if (mileStone.MileStoneType == Project.Logic.MileStoneType.Cooperation.ToString())
                {
                    var cooperationPlan = planList.FirstOrDefault(d => d.MileStoneID == mileStone.ID);
                    if (cooperationPlan == null)
                    {
                        cooperationPlan = new S_P_CooperationPlan();
                        cooperationPlan.InMajorValue     = mileStone.OutMajorValue;
                        cooperationPlan.OutMajorValue    = mileStone.MajorValue;
                        cooperationPlan.MileStoneID      = mileStone.ID;
                        cooperationPlan.ID               = FormulaHelper.CreateGuid();
                        cooperationPlan.CooperationValue = mileStone.MileStoneValue;
                        cooperationPlan.OrPlanFinishDate = mileStone.PlanFinishDate;
                    }
                    cooperationPlan.CooperationContent = mileStone.Name;
                    if (!cooperationPlan.OrPlanFinishDate.HasValue)
                    {
                        cooperationPlan.OrPlanFinishDate = mileStone.PlanFinishDate;
                    }
                    cooperationPlan.PlanFinishDate = mileStone.PlanFinishDate;
                    wbs.SaveCooperationPlan(cooperationPlan);
                }
            }
            this.BusinessEntities.SaveChanges();
        }
Exemple #2
0
        public JsonResult SaveData(string WBSInfo, string ProjectInfoID)
        {
            var list          = JsonHelper.ToList(WBSInfo);
            var mileStoneList = this.entities.Set <S_P_MileStone>().Where(a => a.ProjectInfoID == ProjectInfoID).ToList();
            var coopPlanList  = this.entities.Set <S_P_CooperationPlan>().Where(a => a.ProjectInfoID == ProjectInfoID).ToList();

            foreach (var item in list)
            {
                var wbs = this.GetEntityByID <S_W_WBS>(item.GetValue("ID"));
                if (wbs == null)
                {
                    continue;
                }
                S_P_CooperationPlan oldPlan = null;
                var oldMileStone            = JsonHelper.ToList(wbs.RelateMileStone).FirstOrDefault();
                if (oldMileStone != null)
                {
                    oldPlan = coopPlanList.FirstOrDefault(a => a.MileStoneID == oldMileStone.GetValue("ID"));
                }
                this.UpdateEntity <S_W_WBS>(wbs, item);
                var      mileStoneIDs = JsonHelper.ToList(wbs.RelateMileStone).Select(a => a.GetValue("ID"));
                var      mileStones = mileStoneList.Where(a => mileStoneIDs.Contains(a.ID)).ToList();
                DateTime?bStart = DateTime.MinValue, bFinish = DateTime.MaxValue;
                if (oldPlan != null)
                {
                    oldPlan.WBSID     = wbs.RootNode.ID;
                    oldPlan.WBSFullID = wbs.RootNode.FullID;
                }
                if (mileStones.Count > 0)
                {
                    foreach (var mileStone in mileStones)
                    {
                        if (mileStone.PlanStartDate != null && (mileStone.PlanStartDate > bStart))
                        {
                            bStart = mileStone.PlanStartDate;
                        }
                        if (mileStone.PlanFinishDate != null && (mileStone.PlanFinishDate < bFinish))
                        {
                            bFinish = mileStone.PlanFinishDate;
                        }
                        var newPlan = coopPlanList.FirstOrDefault(a => a.MileStoneID == mileStone.ID);
                        if (newPlan != null)
                        {
                            newPlan.WBSID     = wbs.ID;
                            newPlan.WBSFullID = wbs.FullID;
                        }
                    }
                    if (bStart != DateTime.MinValue)
                    {
                        wbs.BasePlanStartDate = bStart;
                        if (wbs.PlanStartDate > wbs.BasePlanStartDate)
                        {
                            throw new Formula.Exceptions.BusinessValidationException("【" + wbs.Name + "】节点的计划开始时间不能小于关联里程碑的最大计划开始时间【" + ((DateTime)wbs.BasePlanStartDate).ToShortDateString() + "】。");
                        }
                    }
                    if (bFinish != DateTime.MaxValue)
                    {
                        wbs.BasePlanEndDate = bFinish;
                        if (wbs.PlanEndDate > wbs.BasePlanEndDate)
                        {
                            throw new Formula.Exceptions.BusinessValidationException("【" + wbs.Name + "】节点的计划完成时间不能大于关联里程碑的最小计划完成时间【" + ((DateTime)wbs.BasePlanEndDate).ToShortDateString() + "】。");
                        }
                    }
                }
                else
                {
                    wbs.BasePlanStartDate = null;
                    wbs.BasePlanEndDate   = null;
                }
                if (wbs.StructNodeInfo.S_T_WBSStructRole.Count > 0)
                {
                    var roleDefineChange = wbs.StructNodeInfo.S_T_WBSStructRole.FirstOrDefault(c => c.SychWBS == true.ToString() &&
                                                                                               (string.IsNullOrEmpty(c.SychWBSField) || c.SychWBSField == "ChargeUserID"));
                    if (roleDefineChange != null)
                    {
                        if (!String.IsNullOrEmpty(wbs.ChargeUserID))
                        {
                            wbs.SetUser(roleDefineChange.RoleCode, wbs.ChargeUserID);
                        }
                        else
                        {
                            wbs.RemoveUser(roleDefineChange.RoleCode);
                        }
                    }
                    var otherRoleDefines = wbs.StructNodeInfo.S_T_WBSStructRole.Where(c => c.SychWBS != true.ToString()).ToList();
                    foreach (var roleDefine in otherRoleDefines)
                    {
                        var userID = item.GetValue(roleDefine.RoleCode + "UserID");
                        if (!String.IsNullOrEmpty(userID))
                        {
                            wbs.SetUsers(roleDefine.RoleCode, userID.Split(','), false, true, false, true);
                        }
                        else
                        {
                            wbs.RemoveUser(roleDefine.RoleCode);
                        }
                    }
                }
                wbs.Save(false);
            }
            var project = this.GetEntityByID <S_I_ProjectInfo>(ProjectInfoID);
            var majors  = project.S_W_WBS.Where(a => a.WBSType == WBSNodeType.Major.ToString()).Select(a => a.WBSValue).Distinct();

            project.SynchMajorData(string.Join(",", majors));
            project.ResetOBSUserFromRBS();
            if (project.State == ProjectCommoneState.Plan.ToString())
            {
                project.State = ProjectCommoneState.Execute.ToString();
            }
            this.entities.SaveChanges();
            return(Json(""));
        }