当前位置: 首页>>代码示例>>C#>>正文


C# EventDB.AddCourse方法代码示例

本文整理汇总了C#中PurplePen.EventDB.AddCourse方法的典型用法代码示例。如果您正苦于以下问题:C# EventDB.AddCourse方法的具体用法?C# EventDB.AddCourse怎么用?C# EventDB.AddCourse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PurplePen.EventDB的用法示例。


在下文中一共展示了EventDB.AddCourse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DuplicateCourse

        // Duplicate a course with a new name, new course controls (since course controls can't be shared),
        // but all other attributes the same.
        public static Id<Course> DuplicateCourse(EventDB eventDB, Id<Course> oldCourseId, string newName)
        {
            Course oldCourse = eventDB.GetCourse(oldCourseId);
            int newSortOrder = oldCourse.sortOrder + 1;

            // Update existing sort orders after by adding one to existing course orders after the new one.
            foreach (Id<Course> courseToChangeId in eventDB.AllCourseIds.ToList()) {
                int sortOrder = eventDB.GetCourse(courseToChangeId).sortOrder;
                if (sortOrder >= newSortOrder)
                    ChangeCourseSortOrder(eventDB, courseToChangeId, sortOrder + 1);
            }

            // Duplicate the course controls with blank course controls, and record the mapping.
            Dictionary<Id<CourseControl>, Id<CourseControl>> mapCourseControl = new Dictionary<Id<CourseControl>, Id<CourseControl>>();

            foreach (Id<CourseControl> oldCourseControlId in QueryEvent.EnumCourseControlIds(eventDB, new CourseDesignator(oldCourseId))) {
                CourseControl newCourseControl = new CourseControl();
                Id<CourseControl> newCourseControlId = eventDB.AddCourseControl(newCourseControl);
                mapCourseControl[oldCourseControlId] = newCourseControlId;
            }

            // Create a new course with no course controls in it and the new name, sort order.
            Course newCourse = (Course)oldCourse.Clone();
            if (oldCourse.firstCourseControl.IsNotNone)
                newCourse.firstCourseControl = mapCourseControl[oldCourse.firstCourseControl];
            newCourse.name = newName;
            newCourse.sortOrder = newSortOrder;
            Id<Course> newCourseId =  eventDB.AddCourse(newCourse);

            // Now copy all the old course control, updating all the linking fields.

            foreach (Id<CourseControl> oldCourseControlId in QueryEvent.EnumCourseControlIds(eventDB, new CourseDesignator(oldCourseId))) {
                // Add a new course control to the new course.
                CourseControl oldCourseControl = eventDB.GetCourseControl(oldCourseControlId);
                CourseControl newCourseControl = (CourseControl) oldCourseControl.Clone();
                if (newCourseControl.nextCourseControl.IsNotNone)
                    newCourseControl.nextCourseControl = mapCourseControl[newCourseControl.nextCourseControl];
                if (newCourseControl.splitEnd.IsNotNone)
                    newCourseControl.splitEnd = mapCourseControl[newCourseControl.splitEnd];
                if (newCourseControl.splitCourseControls != null) {
                    for (int i = 0; i < newCourseControl.splitCourseControls.Length; ++i) {
                        newCourseControl.splitCourseControls[i] = mapCourseControl[newCourseControl.splitCourseControls[i]];
                    }
                }

                eventDB.ReplaceCourseControl(mapCourseControl[oldCourseControlId], newCourseControl);
            }

            // Duplicate any specials from the old course.
            foreach (Id<Special> specialId in eventDB.AllSpecialIds.ToList()) {
                Special special = eventDB.GetSpecial(specialId);
                if (!special.allCourses) {
                    List<CourseDesignator> addedCourseDesignators = new List<CourseDesignator>();
                    foreach (CourseDesignator designatorWithSpecial in special.courses) {
                        if (designatorWithSpecial.CourseId == oldCourseId) {
                            if (designatorWithSpecial.AllParts)
                                addedCourseDesignators.Add(new CourseDesignator(newCourseId));
                            else
                                addedCourseDesignators.Add(new CourseDesignator(newCourseId, designatorWithSpecial.Part));
                        }
                    }

                    if (addedCourseDesignators.Count > 0) {
                        ChangeDisplayedCourses(eventDB, specialId, special.courses.Concat(addedCourseDesignators).ToArray());
                    }
                }
            }

            return newCourseId;
        }
开发者ID:petergolde,项目名称:PurplePen,代码行数:72,代码来源:ChangeEvent.cs

示例2: CreateCourse

        // Create a new course with the given attributes. The course sorts after all existing courses.
        // If addStartAndFinish is true, then if exact one start control exists, it is added. If exactly one finish control exists, it is added.
        public static Id<Course> CreateCourse(EventDB eventDB, CourseKind courseKind, string name, ControlLabelKind labelKind, int scoreColumn, string secondaryTitle, float printScale, float climb, float? length, DescriptionKind descriptionKind, int firstControlOrdinal, bool addStartAndFinish)
        {
            // Find max sort order in use.
            int maxSortOrder = 0;
            foreach (Course course in eventDB.AllCourses)
                if (course.sortOrder > maxSortOrder)
                    maxSortOrder = course.sortOrder;

            PrintArea printArea = (PrintArea) eventDB.GetEvent().printArea.Clone();

            Course newCourse = new Course(courseKind, name, printScale, maxSortOrder + 1);
            newCourse.secondaryTitle = secondaryTitle;
            newCourse.climb = climb;
            newCourse.overrideCourseLength = length;
            newCourse.descKind = descriptionKind;
            newCourse.labelKind = labelKind;
            newCourse.scoreColumn = scoreColumn;
            newCourse.firstControlOrdinal = firstControlOrdinal;
            newCourse.printArea = printArea;

            Id<Course> newCourseId = eventDB.AddCourse(newCourse);

            if (addStartAndFinish) {
                // Add unique start and finish, if they exist.
                Id<ControlPoint> uniqueStart = FindUniqueControl(eventDB, newCourseId, ControlPointKind.Start);
                if (uniqueStart.IsNotNone)
                    AddStartToCourse(eventDB, uniqueStart, newCourseId, false);

                Id<ControlPoint> uniqueFinish = FindUniqueControl(eventDB, newCourseId, ControlPointKind.Finish);
                if (uniqueFinish.IsNotNone)
                    AddFinishToCourse(eventDB, uniqueFinish, newCourseId, false);
            }

            return newCourseId;
        }
开发者ID:petergolde,项目名称:PurplePen,代码行数:37,代码来源:ChangeEvent.cs


注:本文中的PurplePen.EventDB.AddCourse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。