Exemplo n.º 1
0
        /// <summary>
        /// 當某一節次被按下時
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dec_OnPeriodClicked(object sender, PeriodEventArgs e)
        {
            if (sender is DecPeriod)
            {
                DecPeriod Period = (DecPeriod)sender;

                int WeekDay = e.Weekday;
                int PeriodNo = e.Period;

                //若是星期或節次小於或等於0則不繼續執行
                if (WeekDay <= 0 || PeriodNo <= 0) return;

                #region 若為可調課顏色則進行調課
                if (Period.BackColor.Equals(SchedulerColor.lvSchedulableBackColor))
                {
                    List<CalendarRecord> vSrcCalendars = this.selectedCalendars;

                    List<CalendarRecord> vDesCalendars = new List<CalendarRecord>();

                    vDesCalendars.Add(Period.Data[0]);

                    #region 尋找相對應的行事曆
                    if (vSrcCalendars.Count > 1)
                    {
                        CalendarRecord vDesCalendar = Period.Data[0];

                        int intPeriod = K12.Data.Int.Parse(vDesCalendar.Period);

                        for (int i = 1; i < vSrcCalendars.Count; i++)
                        {
                            string NextPeriodKey = vDesCalendar.Weekday + "_" + (intPeriod + 1);  // +"_" + vDesCalendar.FullSubject + "_" + vDesCalendar.TeacherName;
                            string PrevPeriodKey = vDesCalendar.Weekday + "_" + (intPeriod - 1);  //+"_" + vDesCalendar.FullSubject + "_" + vDesCalendar.TeacherName;

                            if (decPeriods.ContainsKey(NextPeriodKey))
                            {
                                DecPeriod NextPeriod = decPeriods[NextPeriodKey];

                                CalendarRecord NextCalendar = NextPeriod.Data[0];

                                if (NextCalendar.FullSubject.Equals(vDesCalendar.FullSubject) &&
                                    NextCalendar.TeacherName.Equals(vDesCalendar.TeacherName))
                                {
                                    if (NextPeriod.BackColor == SchedulerColor.lvSchedulableBackColor)
                                        vDesCalendars.Add(NextPeriod.Data[0]);
                                }
                            }

                            if (decPeriods.ContainsKey(PrevPeriodKey))
                            {
                                DecPeriod PrevPeriod = decPeriods[PrevPeriodKey];

                                CalendarRecord PrevCalendar = PrevPeriod.Data[0];

                                if (PrevCalendar.FullSubject.Equals(vDesCalendar.FullSubject) &&
                                    PrevCalendar.TeacherName.Equals(vDesCalendar.TeacherName))
                                {

                                    if (PrevPeriod.BackColor == SchedulerColor.lvSchedulableBackColor)
                                        vDesCalendars.Add(PrevPeriod.Data[0]);
                                }
                            }
                        }
                    }
                    #endregion

                    //若來源事曆
                    if (vSrcCalendars.Count == vDesCalendars.Count)
                    {
                        frmExchangeConfirm ExchangeConfirm = new frmExchangeConfirm(vSrcCalendars, vDesCalendars);

                        if (ExchangeConfirm.ShowDialog() == DialogResult.OK)
                        {
                            List<ExchangeCalendarPair> Pairs = ExchangeConfirm.SelectedExchangeCalendarPairs;

                            List<string> NewSrcUIDs = new List<string>();

                            StringBuilder strBuilder = new StringBuilder();
                            StringBuilder strError = new StringBuilder();

                            foreach (ExchangeCalendarPair Pair in Pairs)
                            {
                                if (!K12.Data.Utility.Utility.IsNullOrEmpty(Pair.Calendar) &&
                                    !K12.Data.Utility.Utility.IsNullOrEmpty(Pair.ExchangeCalendar))
                                {
                                    string AbsenceName = ExchangeConfirm.AbsenceName;
                                    string Comment = ExchangeConfirm.Comment;
                                    bool NoRecord = ExchangeConfirm.NoRecord;

                                    Pair.Calendar = Pair.Calendar
                                        .OrderBy(x => x.Period)
                                        .ToList();

                                    Pair.ExchangeCalendar = Pair.ExchangeCalendar
                                        .OrderBy(x => x.Period)
                                        .ToList();

                                    try
                                    {
                                        for (int i = 0; i < Pair.Calendar.Count; i++)
                                        {
                                            Tuple<bool, string> result = Calendar.Instance.Exchange(
                                               Pair.Calendar[i],
                                               Pair.ExchangeCalendar[i],
                                               NoRecord,
                                               AbsenceName,
                                               Comment);

                                            if (!result.Item1)
                                                strError.AppendLine(result.Item2);
                                            else
                                            {
                                                strBuilder.AppendLine("《請假課程》");
                                                strBuilder.AppendLine(Pair.Calendar[i].ToString());
                                                strBuilder.AppendLine("《調課課程》");
                                                strBuilder.AppendLine(Pair.ExchangeCalendar[i].ToString());
                                                strBuilder.AppendLine("《假別註記》");
                                                strBuilder.AppendLine("假別:" + AbsenceName + ",註記:" + Comment);

                                                if (NoRecord)
                                                    strBuilder.AppendLine("*此筆調課為直接調課,未儲存調課記錄。");
                                            }
                                        }
                                    }
                                    catch (Exception ve)
                                    {
                                        MessageBox.Show("調課發生錯誤,詳細訊息如下。" + System.Environment.NewLine + ve.Message);
                                    }
                                }
                            }

                            if (strError.Length > 0)
                                MessageBox.Show(strError.ToString());

                            if (strBuilder.Length > 0)
                            {
                                FISCA.LogAgent.ApplicationLog.Log(Logs.調代課,Logs.調課作業, strBuilder.ToString());
                                MotherForm.SetStatusBarMessage("已成功執行調課!");
                                CalendarEvents.RaiseExchangeEvent();

                                List<string> SrcUIDs = new List<string>();

                                foreach (ExchangeCalendarPair Pair in Pairs)
                                {
                                    SrcUIDs.AddRange(Pair.Calendar.Select(x => x.UID));
                                }

                                #region 是否列印調課單
                                if (ExchangeConfirm.IsPrint)
                                {

                                    QueryHelper vHelper = Utility.QueryHelper;

                                    string strSQL = "select uid from $scheduler.course_calendar where exchange_id in (" + string.Join(",", SrcUIDs.ToArray()) + ")";

                                    DataTable table = vHelper.Select(strSQL);

                                    if (table.Rows.Count > 0)
                                    {
                                        List<string> ExchangeIDs = new List<string>();

                                        foreach (DataRow row in table.Rows)
                                        {
                                            string ExchangeID = "" + row["uid"];

                                            ExchangeIDs.Add(ExchangeID);
                                        }

                                        List<CalendarRecord> records = Calendar.Instance.FindExchangeRecords(ExchangeIDs);

                                        Dictionary<string, List<CalendarRecord>> result = new Dictionary<string, List<CalendarRecord>>();

                                        foreach (CalendarRecord record in records)
                                        {
                                            string Key =
                                                record.StartDateTime.ToShortDateString() + "-" +
                                                record.FullSubject + "-" +
                                                record.TeacherName;

                                            if (!result.ContainsKey(Key))
                                                result.Add(Key, new List<CalendarRecord>());

                                            result[Key].Add(record);
                                        }
                                    }
                                }
                                #endregion
                            }
                        }
                    }
                }
                else if (
                    Period.IsBusy &&
                    this.Type.Equals(CalendarType.Teacher))
                {
                    int vWeekday = Period.Weekday;
                    int vPeriod = Period.Period;

                    List<TeacherBusy> RemoveBusys = new List<TeacherBusy>();

                    if (!K12.Data.Utility.Utility.IsNullOrEmpty(this.TeacherBusys))
                    {
                        foreach (TeacherBusy vTeacherBusy in this.TeacherBusys)
                        {
                            int TeacherBusyWeekday = vTeacherBusy.StartDateTime.GetWeekday();

                            if (TeacherBusyWeekday.Equals(vWeekday))
                            {
                                PeriodSetting vPeriodSetting = periods.Find(x => x.Period.Equals(vPeriod));

                                if (vPeriodSetting != null)
                                {
                                    if (vPeriodSetting.IsIntersect(vTeacherBusy))
                                    {
                                        RemoveBusys.Add(vTeacherBusy);
                                    }
                                }
                            }
                        }
                    }

                    if (RemoveBusys.Count > 0)
                    {
                        StringBuilder strBuilder = new StringBuilder();
                        StringBuilder strSQL = new StringBuilder();

                        strSQL.Append("select busy.uid,(CASE WHEN tea.nickname is null or tea.nickname='' THEN tea.teacher_name ELSE tea.teacher_name || '(' || tea.nickname || ')'  END) as teacher_name,begin_date_time,end_date_time from $scheduler.teacher_busy_date as busy inner join $scheduler.teacher_ex as tea on tea.uid=busy.ref_teacher_id where ");

                        foreach (TeacherBusy RemoveBusy in RemoveBusys)
                        {
                            strBuilder.AppendLine(RemoveBusy.ToString());
                            strSQL.Append("teacher_name='" + RemoveBusy.TeacherName + "' and begin_date_time='" + RemoveBusy.StartDateTime.GetDateTimeString() + "' and end_date_time='" + RemoveBusy.EndDateTime.GetDateTimeString() + "'");
                        }

                        if (MessageBox.Show("您是否要刪除以下的不調代時段(此動作將無法復原)?" + System.Environment.NewLine +
                            strBuilder.ToString(), "刪除不調代時段提醒", MessageBoxButtons.YesNo) ==
                            DialogResult.Yes)
                        {
                            BackgroundWorker workder = new BackgroundWorker();

                            workder.DoWork += (vsender, ve) =>
                            {
                                QueryHelper mHelper = Utility.QueryHelper;

                                DataTable table = mHelper.Select(strSQL.ToString());

                                List<string> TeacherBusyIDs = new List<string>();

                                foreach (DataRow row in table.Rows)
                                {
                                    string UID = row.Field<string>("uid");
                                    TeacherBusyIDs.Add(UID);
                                }

                                UpdateHelper mUpdateHelper = new UpdateHelper();

                                StringBuilder strDelete = new StringBuilder();

                                strDelete.AppendLine("delete from $scheduler.teacher_busy_date where uid in (" + string.Join(",", TeacherBusyIDs.ToArray()) + ")");

                                int ExecuteCount = mUpdateHelper.Execute(strDelete.ToString());

                                ApplicationLog.Log(Logs.調代課 ,Logs.刪除不調代時段,strBuilder.ToString());
                            };

                            workder.RunWorkerCompleted += (vsender, ve) =>
                            {
                                if (ve.Error == null)
                                    CalendarEvents.RaiseWeekChangeEvent(this.Type,this.AssocID);
                                else
                                    MessageBox.Show(ve.Error.Message);
                            };

                            workder.RunWorkerAsync();
                        }
                    }
                }
                #endregion
                else
                {
                    #region 單選情況
                    List<CalendarRecord> CurrentSelectedCalendars = new List<CalendarRecord>();
                    CurrentSelectedCalendars.AddRange(e.Value);
                    #endregion

                    if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                    {
                        foreach (string key in this.decPeriods.Keys)
                        {
                            if (this.decPeriods[key].IsSelected)
                                CurrentSelectedCalendars.AddRange(this.decPeriods[key].Data);
                        }
                    }

                    if (!IsCanMultipleExchange(CurrentSelectedCalendars))
                    {
                        CurrentSelectedCalendars.Clear();
                        CurrentSelectedCalendars.AddRange(e.Value);
                    }

                    this.SelectedCalendars = CurrentSelectedCalendars;
                    this.UpdateUI();

                    e.Value = CurrentSelectedCalendars;

                    BackgroundWorker worker = new BackgroundWorker();

                    worker.DoWork += (vsender, ve) => CalendarEvents.RaisePeriodSelected(e);

                    worker.RunWorkerAsync();

                    //Cursor.Current = Cursors.WaitCursor;

                    //Cursor.Current = Cursors.Arrow;
                }
            }
            else if (sender is PictureBox)
            {
                PictureBox vPictureBox = sender as PictureBox;

                string strTag = "" + vPictureBox.Tag;

                int WeekDay = e.Weekday;
                int PeriodNo = e.Period;

                //若是星期或節次小於或等於0則不繼續執行
                if (WeekDay <= 0 || PeriodNo <= 0) return;

                if (strTag.Equals("delete"))
                {
                    //Cursor.Current = Cursors.WaitCursor;

                    //Cursor.Current = Cursors.Arrow;
                }
                else if (strTag.Equals("busy"))
                {

                }
                else
                {
                    //Cursor.Current = Cursors.WaitCursor;

                    //Cursor.Current = Cursors.Arrow;
                }
            }
            else if (sender is Label)
            {
                Label vLabel = sender as Label;

                string strTag = "" + vLabel.Tag;

                if (!string.IsNullOrEmpty(strTag))
                {
                    string[] strEvents = strTag.Split(new char[] { ':' });

                    if (strEvents.Length == 2)
                    {
                        string AssocType = strEvents[0];
                        string AssocID = strEvents[1];
                        string SelectedTab = MainForm.Instance.GetSelectedType();
                        List<CalendarRecord> CalendarRecords = new List<CalendarRecord>();

                        if (!string.IsNullOrEmpty(AssocType) &&
                            !string.IsNullOrEmpty(AssocID))
                        {
                            if (AssocType.Equals("Teacher"))
                            {
                                switch (SelectedTab)
                                {
                                    case "Teacher":
                                        MainForm.Instance.OpenTeacherCalendarContent(CalendarType.Teacher, AssocID, true);
                                        break;
                                    case "Class":
                                        MainForm.Instance.OpenClassCalendarContent(CalendarType.Teacher, AssocID, true);
                                        break;
                                    case "Classroom":
                                        MainForm.Instance.OpenClassroomCalendarContent(CalendarType.Teacher, AssocID, true);
                                        break;
                                }
                            }
                            else if (AssocType.Equals("Class"))
                            {
                                switch (SelectedTab)
                                {
                                    case "Teacher":
                                        MainForm.Instance.OpenTeacherCalendarContent(CalendarType.Class,AssocID,true);
                                        break;
                                    case "Class":
                                        MainForm.Instance.OpenClassCalendarContent(CalendarType.Class, AssocID, true);
                                        break;
                                    case "Classroom":
                                        MainForm.Instance.OpenClassroomCalendarContent(CalendarType.Class, AssocID, true);
                                        break;
                                }
                            }
                            else if (AssocType.Equals("Classroom"))
                            {
                                switch (SelectedTab)
                                {
                                    case "Teacher":
                                        MainForm.Instance.OpenTeacherCalendarContent(CalendarType.Classroom, AssocID, true);
                                        break;
                                    case "Class":
                                        MainForm.Instance.OpenClassCalendarContent(CalendarType.Classroom, AssocID, true);
                                        break;
                                    case "Classroom":
                                        MainForm.Instance.OpenClassroomCalendarContent(CalendarType.Classroom, AssocID, true);
                                        break;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 void ganttControl1_GanttRowAreaSelected(object sender, PeriodEventArgs e)
 {
     MessageBox.Show(e.SelectionStart.ToString("0:HH:mm d.MM.yyyy") + " -> " + e.SelectionEnd.ToString("0:HH:mm d.MM.yyyy"));
 }
Exemplo n.º 3
0
 /// <summary>
 /// 引發排課課程更新事件
 /// </summary>
 public static void RaisePeriodSelected(PeriodEventArgs Period)
 {
     if (PeriodSelected!=null)
         PeriodSelected(null,Period);
 }
Exemplo n.º 4
0
 private void ganttControl1_GanttRowAreaSelected(object sender, PeriodEventArgs e)
 {
     MessageBox.Show(e.SelectionStart.ToString() + " -> " + e.SelectionEnd.ToString());
 }
Exemplo n.º 5
0
        private void CalendarEvents_PeriodSelected(object sender, PeriodEventArgs e)
        {
            grdTeacherCalendar.SelectionChanged -= grdTeacherCalendar_SelectionChanged;
            grdClassCalendar.SelectionChanged -= grdClassCalendar_SelectionChanged;
            grdPlaceCalendar.SelectionChanged -= grdClassroomCalendar_SelectionChanged;

            List<string> CalendarUIDs = e.Value.Select(x=>x.UID).ToList();

            if (tabTeacher.IsSelected)
            {
               foreach(DataGridViewRow Row in grdTeacherCalendar.Rows)
               {
                   CalendarRecord vCalendar = Row.DataBoundItem as CalendarRecord;

                   Row.Selected = CalendarUIDs.Contains(vCalendar.UID);
               }
            }else if (tabClass.IsSelected)
            {
               foreach(DataGridViewRow Row in grdClassCalendar.Rows)
               {
                   CalendarRecord vCalendar = Row.DataBoundItem as CalendarRecord;
                   Row.Selected = CalendarUIDs.Contains(vCalendar.UID);
               }
            }
            else if (tabPlace.IsSelected)
            {
                foreach (DataGridViewRow Row in grdPlaceCalendar.Rows)
                {
                    CalendarRecord vCalendar = Row.DataBoundItem as CalendarRecord;
                    Row.Selected = CalendarUIDs.Contains(vCalendar.UID);
                }
            }

            grdTeacherCalendar.SelectionChanged += grdTeacherCalendar_SelectionChanged;
            grdClassCalendar.SelectionChanged += grdClassCalendar_SelectionChanged;
            grdPlaceCalendar.SelectionChanged += grdClassroomCalendar_SelectionChanged;
        }