private void frmReplaceQuery_Load(object sender, EventArgs e)
        {
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += (vsender, ve) =>
            {
                if (Calendar.Instance.Teachers.Values.Count == 0)
                    Calendar.Instance.RefreshTeachers();

                //mSelectedSubjects = mSelectedCalendars.GetCalendarSubjects();

                bool IsReplace = false;

                foreach (CalendarRecord vCalendar in mSelectedCalendars)
                    if (!string.IsNullOrEmpty(vCalendar.ReplaceID))
                        IsReplace = true;

                if (IsReplace)
                    throw new Exception("選取行事曆已經代過課!");

                Dictionary<string, Teacher> ReplaceTeachers = new Dictionary<string, Teacher>();

                #region 複製所有教師及教授科目
                foreach (string TeacherName in Calendar.Instance.Teachers.Keys)
                {
                    if (!ReplaceTeachers.ContainsKey(TeacherName))
                        ReplaceTeachers.Add(TeacherName, Calendar.Instance.Teachers[TeacherName]);
                }
                #endregion

                #region 找出交集的教師行事曆,並自清單中移除。
                List<CalendarRecord> Calendars = Calendar.Instance.FindIntersect(null, null, mSelectedCalendars);

                foreach (CalendarRecord vCalendar in Calendars)
                {
                    string TeacherName = vCalendar.TeacherName;

                    if (ReplaceTeachers.ContainsKey(TeacherName))
                        ReplaceTeachers.Remove(TeacherName);
                }
                #endregion

                #region 尋找時段忙碌的教師,並自清單中移除。
                List<TeacherBusy> TeacherBusys = Calendar.Instance
                    .FindBusyTeacher(null, mSelectedCalendars);

                IEnumerable<string> TeacherNames = TeacherBusys.Select(x => x.TeacherName);

                foreach (string TeacherName in TeacherNames)
                    if (ReplaceTeachers.ContainsKey(TeacherName))
                        ReplaceTeachers.Remove(TeacherName);
                #endregion

                //將教師排序
                List<Teacher> Teachers = ReplaceTeachers.Values
                              .ToList().SortByCode();

                ve.Result = Teachers;
            };

            worker.RunWorkerCompleted += (vsender, ve) =>
            {
                if (ve.Error != null)
                {
                    MessageBox.Show(ve.Error.Message);
                    this.Close();
                }
                else
                {
                    decCalendar = new DecCalendar(panelEx1);

                    List<Teacher> Teachers = ve.Result as List<Teacher>;

                    Teacher SelectedTeacher = Calendar.Instance.Teachers.ContainsKey(mSelectedCalendars[0].TeacherName)?
                        Calendar.Instance.Teachers[mSelectedCalendars[0].TeacherName]:null;

                    DisplayReplaceTeachers(Teachers,SelectedTeacher);
                    this.TitleText = "代課查詢";
                }
            };

            this.TitleText = "代課查詢 資料查詢中..";
            worker.RunWorkerAsync();
        }
Example #2
0
        /// <summary>
        /// 更新場地行事曆內容
        /// </summary>
        /// <param name="Calendars"></param>
        /// <param name="AssocID"></param>
        public void OpenClassroomCalendarContent(
            CalendarType AssocType,
            string AssocID,
            bool OpenNew=false)
        {
            TabItem SelectedTab = null;
            TabControlPanel SelectedPanel = null;
            DecCalendar vDecCalendar = null;

            //假設不是開新分頁,強制指到第一頁。
            if (!OpenNew)
            {
                SelectedTab = tabClassroomCalendar.Tabs[0];
                SelectedPanel = SelectedTab.AttachedControl as TabControlPanel;
                tabClassroomCalendar.SelectedTab = SelectedTab;
            }
            else
            {
                bool IsFind = false;

                if (tabClassroomCalendar.Tabs.Count > 1)
                {
                    for (int i = 1; i < tabClassroomCalendar.Tabs.Count; i++)
                    {
                        TabItem vTabItem = tabClassroomCalendar.Tabs[i];

                        if (vTabItem.Visible.Equals(false))
                        {
                            SelectedTab = vTabItem;
                            SelectedPanel = SelectedTab.AttachedControl as TabControlPanel;

                            tabClassroomCalendar.SelectedTab = SelectedTab;
                            IsFind = true;
                            break;
                        }
                    }
                }

                if (!IsFind)
                {
                    SelectedTab = tabClassroomCalendar.CreateTab(AssocID);
                    SelectedTab.CloseButtonVisible = true;
                    tabClassroomCalendar.SelectedTab = SelectedTab;
                    SelectedPanel = tabClassroomCalendar.SelectedPanel;
                }
            }

            if (SelectedPanel.Tag == null)
                vDecCalendar = new DecCalendar(SelectedPanel);

            DateTime StartDate = SchoolYearSemesterOption.Instance.StartDate;
            DateTime EndDate = SchoolYearSemesterOption.Instance.EndDate;

            string DisplayText = Utility.GetAssocNote(AssocType, AssocID) + " " + StartDate.Month + "/" + StartDate.Day + "~" + EndDate.Month +"/" + EndDate.Day;
            SelectedTab.Text = AssocID;

            //取得功課表
            vDecCalendar = SelectedPanel.Tag as DecCalendar;
            vDecCalendar.Type = AssocType;
            vDecCalendar.AssocID = AssocID;
            vDecCalendar.UpdateContent();                //在指定資料來源時清空內容

            if (!SelectedTab.Visible)
            {
                SelectedTab.Visible = true;
                SelectedPanel.Visible = true;
            }
        }
Example #3
0
        /// <summary>
        /// 更新教師行事曆內容
        /// </summary>
        /// <param name="Calendars"></param>
        /// <param name="AssocID"></param>
        public void OpenTeacherCalendarContent(
            CalendarType AssocType,
            string AssocID
            ,bool OpenNew=false)
        {
            Stopwatch vWatch = Stopwatch.StartNew();

            TabItem SelectedTab = null;
            TabControlPanel SelectedPanel = null;
            DecCalendar vDecCalendar = null;

            //假設不是開新分頁,強制指到第一頁。
            if (!OpenNew)
            {
                SelectedTab = tabTeacherCalendar.Tabs[0];
                SelectedPanel = SelectedTab.AttachedControl as TabControlPanel;
                tabTeacherCalendar.SelectedTab = SelectedTab;
            }
            else
            {
                bool IsFind = false;

                #region 尋找是否有現有資料表
                if (tabTeacherCalendar.Tabs.Count >1)
                {
                    for(int i=1;i<tabTeacherCalendar.Tabs.Count;i++)
                    {
                        TabItem vTabItem = tabTeacherCalendar.Tabs[i];

                        if (vTabItem.Visible.Equals(false))
                        {
                            SelectedTab = vTabItem;
                            SelectedPanel = SelectedTab.AttachedControl as TabControlPanel;
                            tabTeacherCalendar.SelectedTab = SelectedTab;
                            IsFind = true;
                            break;
                        }
                    }
                }
                #endregion

                if (!IsFind)
                {
                    SelectedTab = tabTeacherCalendar.CreateTab(AssocID);
                    SelectedTab.CloseButtonVisible = true;

                    tabTeacherCalendar.SelectedTab = SelectedTab;
                    SelectedPanel = tabTeacherCalendar.SelectedPanel;
                }
            }

            if (SelectedPanel.Tag == null)
                vDecCalendar = new DecCalendar(SelectedPanel);

            SelectedTab.Text = AssocID;

            //取得功課表
            vDecCalendar = SelectedPanel.Tag as DecCalendar;
            vDecCalendar.Type = AssocType;
            vDecCalendar.AssocID = AssocID;
            vDecCalendar.UpdateContent();                   //在指定資料來源時清空內容

            if (!SelectedTab.Visible)
            {
                SelectedTab.Visible = true;
                SelectedPanel.Visible = true;
            }

            vWatch.Stop();
        }
Example #4
0
        private void PrepareTabControl(DevComponents.DotNetBar.TabControl TabControl)
        {
            foreach (TabItem vTabItem in TabControl.Tabs)
            {
                TabControlPanel Panel = vTabItem.AttachedControl as TabControlPanel;

                if (Panel.Tag == null)
                {
                    DecCalendar vCalendar = new DecCalendar(Panel);

                    if (vTabItem.CloseButtonVisible == true)
                        vTabItem.Visible = false;
                }
            }
        }