C#自定义日历系统-设计建议

时间:2018-11-22 04:16:41

标签: c# calendar

在C#中,我使用MonthCalendar工具使用日历制作日历。我设计了用作每周课程(任命)的对象,并且在这些课程中列出了可以标记为存在或不存在的名称列表。

我现在的问题是,如何在整个日历中有效且正确地创建约会实例?

第一次打开日历时,我使用以下代码进行测试:

        public Schedule(BindingList<Lesson> lessons, BindingList<Student> students)
    {
        InitializeComponent();
        LoadData();
        allLessons = lessons;
        allStudents = students;
        CreateInstances();
    }

    //this needs to be massively reworked into efficient loops to check for duplicates after saving/loading is implemented
    public void CreateInstances()
    {
        foreach (Lesson l in allLessons)
        {
            DateTime date = new DateTime();
            date = DateTime.Now;
            while (date.DayOfWeek.ToString() != l.Day)
            {
                date = date.AddDays(1);
            }
            List<Student> absent = new List<Student>();
            List<Student> attend = new List<Student>();
            foreach (Student s in l.Members)
            {
                attend.Add(s);
            }
            i1 = new LessonInstance(allInstances.Count + 1, l.Lvl, l.Day, l.Hour, l.Minute, date, l.Teacher, l.Room, l.Members, attend, absent);

            bool exists = false;
            foreach (LessonInstance p in allInstances)
            {
                if (p.LessonTime.Day == i1.LessonTime.Day && p.ID == i1.ID)
                {
                    exists = true;
                }
            }
            if (!exists)
            {
                allInstances.Add(i1);
            }
            date = date.AddDays(7);
            List<Student> absent2 = new List<Student>();
            List<Student> attend2 = new List<Student>();
            foreach (Student s in l.Members)
            {
                attend2.Add(s);
            }
            i2 = new LessonInstance(allInstances.Count + 1, l.Lvl, l.Day, l.Hour, l.Minute, date, l.Teacher, l.Room, l.Members, attend2, absent2);
            allInstances.Add(i2);
            date = date.AddDays(7);
            List<Student> absent3 = new List<Student>();
            List<Student> attend3 = new List<Student>();
            foreach (Student s in l.Members)
            {
                attend3.Add(s);
            }
            i3 = new LessonInstance(allInstances.Count + 1, l.Lvl, l.Day, l.Hour, l.Minute, date, l.Teacher, l.Room, l.Members, attend3, absent3);
            allInstances.Add(i3);
            date = date.AddDays(7);
            List<Student> absent4 = new List<Student>();
            List<Student> attend4 = new List<Student>();
            foreach (Student s in l.Members)
            {
                attend4.Add(s);
            }
            LessonInstance i4 = new LessonInstance(allInstances.Count + 1, l.Lvl, l.Day, l.Hour, l.Minute, date, l.Teacher, l.Room, l.Members, attend4, absent4);
            allInstances.Add(i4);
        }
    }

这真的很混乱而且很有限。我如何最好地创建可以延伸到未来的实例,以响应新创建的每周课程并保持持久性?仅提供一些一般性建议将非常有帮助。预先感谢。

0 个答案:

没有答案