Ejemplo n.º 1
0
        /// <summary>
        /// 根据VersionID 获取VersionDetail
        /// </summary>
        /// <param name="versionID"></param>
        /// <returns></returns>
        public JsonResult GetVersionDetail(string versionID)
        {
            List <ApplyStageVersionDetailWrap>   versionDetailList = new List <ApplyStageVersionDetailWrap>();
            ApplyStageVersionDetailEntity        parentDetail      = null;
            List <ApplyStageVersionDetailEntity> childDetails      = null;

            Guid VersionID = new Guid(versionID);

            //如果VersionDetail 表中没有该Version的Detail,则默认从ApplyStages中抓数据过来,否则就可以直接从VersionDetail表中抓数据了
            if (repository.ApplyStageVersionDetail.Count(a => a.VersionID == new Guid(versionID)) <= 0)
            {
                //如果没有VersionID,就创建一个
                if (VersionID == Guid.Empty || VersionID == null)
                {
                    VersionID = Guid.NewGuid();
                }
                //遍历所有StageClass为1 的阶段
                foreach (ApplyStagesEntity parent in repository.ApplyStages.Where(a => a.StageClass == 1))
                {
                    parentDetail = this.TranStageToDetail(Guid.NewGuid(), VersionID, parent);
                    //根据父阶段的No 查找所有子阶段,并转化为VersionDetailEntity
                    childDetails = repository.ApplyStages
                                   .Where(a => a.ParentNo == parent.StageNo)
                                   .OrderBy(a => a.StageNo)
                                   .ToList()
                                   .Select(a => this.TranStageToDetail(Guid.NewGuid(), VersionID, a))
                                   .ToList <ApplyStageVersionDetailEntity>();

                    //添加到ApplyStageVersionDetailWrap List 中
                    versionDetailList.Add(new ApplyStageVersionDetailWrap {
                        ParentVersionDetail = parentDetail, ChildVersionDetails = childDetails
                    });
                }
            }
            else
            {
                foreach (ApplyStageVersionDetailEntity parent in repository.ApplyStageVersionDetail.Where(a => a.VersionID == VersionID && a.StageClass == 1))
                {
                    parentDetail = parent;
                    childDetails = repository.ApplyStageVersionDetail
                                   .Where(a => a.VersionID == VersionID && a.ParentNo == parent.StageNo)
                                   .OrderBy(a => a.StageNo)
                                   .ToList <ApplyStageVersionDetailEntity>();

                    //添加到ApplyStageVersionDetailWrap List 中
                    versionDetailList.Add(new ApplyStageVersionDetailWrap {
                        ParentVersionDetail = parentDetail, ChildVersionDetails = childDetails
                    });
                }
            }
            return(Json(versionDetailList.OrderBy(v => v.ParentVersionDetail.StageNo), JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据版本ID 返回VersionDetailList
        /// </summary>
        /// <param name="versionID">版本ID</param>
        /// <returns></returns>
        List <ApplyStageVersionDetailWrap> GetVersionDetailList(Guid versionID)
        {
            List <ApplyStageVersionDetailWrap>   versionDetailList = new List <ApplyStageVersionDetailWrap>();
            ApplyStageVersionDetailEntity        parentDetail      = null;
            List <ApplyStageVersionDetailEntity> childDetails      = null;

            foreach (ApplyStageVersionDetailEntity parent in repository.ApplyStageVersionDetail.Where(a => a.VersionID == versionID && a.StageClass == 1))
            {
                parentDetail = parent;
                childDetails = repository.ApplyStageVersionDetail
                               .Where(a => a.VersionID == versionID && a.ParentNo == parent.StageNo)
                               .OrderBy(a => a.StageNo)
                               .ToList <ApplyStageVersionDetailEntity>();

                //添加到ApplyStageVersionDetailWrap List 中
                versionDetailList.Add(new ApplyStageVersionDetailWrap {
                    ParentVersionDetail = parentDetail, ChildVersionDetails = childDetails
                });
            }

            return(versionDetailList.OrderBy(a => a.ParentVersionDetail.StageNo).ToList());
        }
Ejemplo n.º 3
0
        public JsonResult ScheduleApply(IEnumerable <StudentApplyStageWrap> ajaxData)
        {
            if (ajaxData == null)
            {
                return(Json(new { SaveResult = false }));
            }

            Guid studentID = ajaxData.FirstOrDefault().ParentStage.StudentID;
            //根据月、日进行筛选,并选出符合条件的第一个Entity,通过比较Month与Day两值相加的值来排序比较
            ApplyStageVersionEntity suitableVersion = GetApplyVersionByStudentID(studentID);

            List <ApplyStageVersionDetailEntity> versionDetailList = repository.ApplyStageVersionDetail.Where(a => a.VersionID == suitableVersion.VersionID).ToList();
            List <StudentApplyStageEntity>       applyStageList    = new List <StudentApplyStageEntity>();
            ApplyStageVersionDetailEntity        currentStage      = null;

            //将列表按父阶段的StageNo进行排序
            ajaxData = ajaxData.OrderBy(w => w.ParentStage.StageNo);
            int i = 0;

            foreach (StudentApplyStageWrap applyStageWrap in ajaxData.OrderBy(s => s.ParentStage.StageNo))
            {
                if (applyStageWrap.ParentStage.IsForbid)
                {
                    continue;
                }

                currentStage = versionDetailList.Single(a => a.StageNo == applyStageWrap.ParentStage.StageNo);
                applyStageWrap.ParentStage.ID                   = Guid.NewGuid();
                applyStageWrap.ParentStage.StageNameEn          = currentStage.StageNameEn;
                applyStageWrap.ParentStage.ParentNo             = currentStage.ParentNo;
                applyStageWrap.ParentStage.StatusOption         = currentStage.StatusOption;
                applyStageWrap.ParentStage.CurrentOption        = currentStage.BeginOption;
                applyStageWrap.ParentStage.BeginOption          = currentStage.BeginOption;
                applyStageWrap.ParentStage.EndOption            = currentStage.EndOption;
                applyStageWrap.ParentStage.CanForbid            = currentStage.CanForbid;
                applyStageWrap.ParentStage.CanChangeDate        = currentStage.CanChangeDate;
                applyStageWrap.ParentStage.CanChangeName        = currentStage.CanChangeName;
                applyStageWrap.ParentStage.IsDateSameWithParent = currentStage.IsDateSameWithParent;

                foreach (StudentApplyStageEntity childStage in applyStageWrap.ChildStages)
                {
                    if (childStage.IsForbid)
                    {
                        continue;
                    }

                    currentStage = versionDetailList.Single(a => a.StageNo == childStage.StageNo);

                    childStage.ID                   = Guid.NewGuid();
                    childStage.StageNameEn          = currentStage.StageNameEn;
                    childStage.ParentNo             = currentStage.ParentNo;
                    childStage.StatusOption         = currentStage.StatusOption;
                    childStage.CurrentOption        = currentStage.BeginOption;
                    childStage.BeginOption          = currentStage.BeginOption;
                    childStage.EndOption            = currentStage.EndOption;
                    childStage.Percentage           = 0;
                    childStage.CanForbid            = currentStage.CanForbid;
                    childStage.CanChangeDate        = currentStage.CanChangeDate;
                    childStage.CanChangeName        = currentStage.CanChangeName;
                    childStage.IsDateSameWithParent = currentStage.IsDateSameWithParent;
                }

                //如果是第一个ParentStage,则设其Percentage为1
                //同时,如果子阶段无时间限制,则设所有子阶段的Percentage为1,否则仅设第一个子阶段的Percentage为1
                //并同时设置阶段的CurrentOption
                if (i++ == 0)
                {
                    applyStageWrap.ParentStage.CurrentOption = applyStageWrap.ParentStage.StatusOption.Split(',').ElementAt(1);
                    applyStageWrap.ParentStage.Percentage    = 1;
                    if (applyStageWrap.ParentStage.IsDateSameWithParent)
                    {
                        foreach (StudentApplyStageEntity childItem in applyStageWrap.ChildStages)
                        {
                            childItem.CurrentOption = childItem.StatusOption.Split(',').ElementAt(1);
                            childItem.Percentage    = 1;
                        }
                    }
                    //applyStageWrap.ChildStages.ForEach(s => s.Percentage = 1);
                    else
                    {
                        applyStageWrap.ChildStages[0].CurrentOption = applyStageWrap.ChildStages[0].StatusOption.Split(',').ElementAt(1);
                        applyStageWrap.ChildStages[0].Percentage    = 1;
                    }
                }

                applyStageList.Add(applyStageWrap.ParentStage);
                applyStageList.AddRange(applyStageWrap.ChildStages);
            }
            repository.NewStudentApplyStages(applyStageList);
            AppRelationsEntity appRelation = repository.AppRelations.SingleOrDefault(s => s.StudentID == studentID);

            appRelation.HasScheduleApply = true;
            repository.SaveStudentInfo(repository.StudentsInfo.SingleOrDefault(s => s.StudentID == studentID), appRelation);

            return(Json(new { SaveResult = true }));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="stageNo">当前阶段ID</param>
        /// <param name="refBeginDate">基准开始日期</param>
        /// <param name="refEndDate">基准结束日期</param>
        /// <param name="currentDetail">当前阶段Detail</param>
        /// <param name="studentID">学生ID</param>
        /// <param name="isDateSameWithParent">是否和父阶段日期一样</param>
        /// <returns></returns>
        StudentApplyStageEntity CalApplyStage(
            int stageNo,
            DateTime refBeginDate,
            DateTime?refEndDate,
            ApplyStageVersionDetailEntity currentDetail,
            Guid studentID,
            bool isDateSameWithParent,
            DateTime signDate)
        {
            StudentApplyStageEntity applyStage = new StudentApplyStageEntity
            {
                ID                   = Guid.NewGuid(),
                StudentID            = studentID,
                StageNo              = stageNo,
                StageName            = currentDetail.StageName,
                StageNameEn          = currentDetail.StageNameEn,
                StageClass           = currentDetail.StageClass,
                ParentNo             = currentDetail.ParentNo,
                IsForbid             = currentDetail.IsForbid,
                StatusOption         = currentDetail.StatusOption,
                BeginOption          = currentDetail.BeginOption,
                EndOption            = currentDetail.EndOption,
                CurrentOption        = currentDetail.BeginOption,
                CanForbid            = currentDetail.CanForbid,
                CanChangeDate        = currentDetail.CanChangeDate,
                CanChangeName        = currentDetail.CanChangeName,
                IsDateSameWithParent = currentDetail.IsDateSameWithParent
            };

            //如果当前阶段的日期与父阶段一样,则直接赋值即可
            if (isDateSameWithParent)
            {
                applyStage.BeginDate = refBeginDate;
                applyStage.EndDate   = Convert.ToDateTime(refEndDate);
            }
            else
            {
                //如果当前阶段的开始日期需要计算,则在基准开始日期上加上给定天数
                if (Convert.ToBoolean(currentDetail.IsCalBeginDate))
                {
                    applyStage.BeginDate = refBeginDate.AddDays(Convert.ToInt16(currentDetail.BeginDate));
                }
                else    //否则,则拼接年、月、日 来计算日期。下面算法的结果是,计算出给定月份的最后一天的日期值
                {
                    int year  = (signDate.Month > currentDetail.BeginDate) ? signDate.Year + 1 : signDate.Year;
                    int month = Convert.ToInt16(currentDetail.BeginDate) + 1;
                    if (month > 12)
                    {
                        year += 1;
                        month = 1;
                    }
                    int day = 1;
                    applyStage.BeginDate = new DateTime(year, month, day).AddDays(-1);
                }

                //如果当前阶段的结束日期需要计算,则在基准结束日期上加上给定天数
                if (Convert.ToBoolean(currentDetail.IsCalEndDate))
                {
                    applyStage.EndDate = applyStage.BeginDate.AddDays(Convert.ToInt16(currentDetail.EndDate));
                }
                else    //否则,则拼接年、月、日 来计算日期。下面算法的结果是,计算出给定月份的最后一天的日期值
                {
                    int year  = (signDate.Month > currentDetail.EndDate) ? signDate.Year + 1 : signDate.Year;
                    int month = Convert.ToInt16(currentDetail.EndDate) + 1;
                    if (month > 12)
                    {
                        year += 1;
                        month = 1;
                    }
                    int day = 1;
                    applyStage.EndDate = new DateTime(year, month, day).AddDays(-1);
                }
            }
            return(applyStage);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 根据VersionDetailList 计算出ApplySchedule,新的哦!
        /// </summary>
        /// <param name="VersionDetailList"></param>
        /// <returns></returns>
        List <StudentApplyStageWrap> CalApplyStageWrapList(Guid studentID, DateTime signDate, Guid versionID)
        {
            //函数的返回值
            List <StudentApplyStageWrap> applyStageWrapList = new List <StudentApplyStageWrap>();

            //定义函数中会用到的两个局部变量
            StudentApplyStageEntity parentStage = null;
            StudentApplyStageEntity childStage  = null;

            //用于暂时性的存储已经完成初始化的ApplyStage的List
            List <StudentApplyStageEntity> resultStageList = new List <StudentApplyStageEntity>();
            //根据版本ID 从数据库中获取IsForbid 为false 的 VersionDetailList
            List <ApplyStageVersionDetailEntity> versionDetailList =
                repository.ApplyStageVersionDetail
                .Where(a => a.VersionID == versionID && a.IsForbid == false)
                .ToList();

            //获取StageClass = 1 的StageNo数组
            int[] parentStageArray = versionDetailList.Where(a => a.StageClass == 1).OrderBy(a => a.StageNo).Select(a => a.StageNo).ToArray();
            //遍历父阶段
            for (int i = 0; i < parentStageArray.Length; i++)
            {
                //下面初始化两个局部变量
                DateTime refBeginDate = DateTime.Now;
                DateTime refEndDate   = DateTime.Now;

                int parentStageNo = parentStageArray[i];
                //根据StageNo 取出VersionDetail
                ApplyStageVersionDetailEntity currentParentDetail = versionDetailList.SingleOrDefault(v => v.StageNo == parentStageNo);

                //如果当前父阶段为同辈阶段的第一个,则基准开始时间设为签约日期
                if (i == 0 || currentParentDetail.IsCalBeginDate == false)
                {
                    refBeginDate = signDate;
                }
                else    //否则,基准开始日期为兄长阶段的结束日期
                {
                    refBeginDate = resultStageList.SingleOrDefault(s => s.StageNo == Convert.ToInt16(parentStageArray[i - 1])).EndDate;
                }
                //父阶段调用该方法时,最后一个参数全为false
                parentStage = CalApplyStage(parentStageNo, refBeginDate, null, currentParentDetail, studentID, false, signDate);
                if (parentStage.BeginDate > parentStage.EndDate)
                {
                    parentStage.EndDate = parentStage.BeginDate.AddMonths(1);
                }

                //获取当前阶段的子阶段的StageNo 数组
                int[] childClass = versionDetailList.Where(a => a.ParentNo == parentStageNo && a.IsForbid == false).OrderBy(a => a.StageNo).Select(a => a.StageNo).ToArray();
                for (int j = 0; j < childClass.Length; j++)
                {
                    //将子阶段的StageNo 由字符串转换为数字
                    int childStageNo = childClass[j];
                    //根据StageNo 取出VersionDetail
                    ApplyStageVersionDetailEntity currentChildDetail = versionDetailList.SingleOrDefault(v => v.StageNo == childStageNo);

                    //如果子阶段的开始结束日期与父阶段一样的话,基准开始结束日期均与父阶段一致
                    if (currentChildDetail.IsDateSameWithParent)
                    {
                        childStage = CalApplyStage(childStageNo, parentStage.BeginDate, parentStage.EndDate, currentChildDetail, studentID, true, signDate);
                    }
                    else
                    {
                        //如果当前子阶段为同辈阶段的第一个,则基准开始时间设为父阶段的开始日期
                        if (j == 0)
                        {
                            refBeginDate = parentStage.BeginDate;
                        }
                        else     //否则,基准开始日期为兄长阶段的结束日期
                        {
                            refBeginDate = resultStageList.SingleOrDefault(s => s.StageNo == childClass[j - 1]).EndDate;
                        }
                        childStage = CalApplyStage(childStageNo, refBeginDate, null, currentChildDetail, studentID, false, signDate);
                    }

                    //把当前阶段的信息存储到resultStageList中,同辈间遍历的时候会用到
                    resultStageList.Add(childStage);
                }

                //如果当前父阶段的子阶段有时间限制,则把最后一个子阶段的EndDate值赋给父阶段的EndDate
                if (!currentParentDetail.IsDateSameWithParent && childClass.Length > 0)
                {
                    parentStage.EndDate = resultStageList.SingleOrDefault(s => s.StageNo == childClass.Last()).EndDate;
                }

                //把当前阶段的信息存储到resultStageList中,同辈间遍历的时候会用到
                resultStageList.Add(parentStage);
            }

            //最后,将resultStageList 按封装成StudentApplyStageWrap 对象列表
            foreach (StudentApplyStageEntity parentStageItem in resultStageList.Where(s => s.ParentNo == 1))
            {
                applyStageWrapList.Add(new StudentApplyStageWrap {
                    ParentStage = parentStageItem,
                    ChildStages = resultStageList
                                  .Where(s => s.ParentNo == parentStageItem.StageNo)
                                  .OrderBy(r => r.StageNo)
                                  .ToList()
                });
            }

            return(applyStageWrapList);
        }