Ejemplo n.º 1
0
 /// <summary>
 /// 取得註解,目前只適用於班級上
 /// </summary>
 /// <param name="AssocType"></param>
 /// <param name="AssocID"></param>
 /// <returns></returns>
 public static string GetAssocNote(CalendarType AssocType,string AssocID)
 {
     if (AssocType.Equals(CalendarType.Class))
     {
         if (!string.IsNullOrEmpty(AssocID))
         {
             if (Calendar.Instance.Classes.ContainsKey(AssocID))
                 return AssocID + "(" + Calendar.Instance.Classes[AssocID].Note + ")";
             else
                 return AssocID;
         }
         else
             return AssocID;
     }
     else
     {
         return AssocID;
     }
 }
        private DataTable GetExchangeReplaceDetail(
            CalendarType CalendarType, 
            string AssocID,
            List<CalendarRecord> records,
            bool IsDisplayExchangeHistory,
            bool IsDisplayExchangeOriginal,
            bool IsDisplayDate,
            DateTime dteStart,
            DateTime dteEnd)
        {
            DataTable tblResult = new DataTable("調代明細");

            DateTime WeekStartDate = DateTime.Today.StartOfWeek(DayOfWeek.Monday);

            if (records.Count >0)
                WeekStartDate = records[0].StartDateTime.StartOfWeek(DayOfWeek.Monday);

            DataRow rowTitle = tblResult.Rows.Add();

            List<string> Weekdays = new List<string>() { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" };

            for (int i = 0; i < Weekday; i++)
            {
                DataColumn Column = new DataColumn("" + (i + 1));
                tblResult.Columns.Add(Column);
                string strWeekday = Weekdays[i];

                rowTitle.SetField<string>("" + (i + 1), strWeekday);
                WeekStartDate = WeekStartDate.AddDays(1);
            }

            //針對跨週調課做處理,最後判斷若是沒有進行顯示才顯示,避免多角調課問題
            Dictionary<string, string> CrossWeekMessage = new Dictionary<string, string>();

            for (int i = 0; i < PeriodList.Count; i++)
            {
                DataRow Row = tblResult.Rows.Add();

                string strPeriod = PeriodList[i];

                records = records
                    .OrderBy(x => x.LastUpdate)
                    .ToList();

                foreach (CalendarRecord vCalendar in records)
                {
                    if (!string.IsNullOrWhiteSpace(vCalendar.ExchangeID) &&
                        vCalendar.ExchangeCalendar!=null)
                    {
                        if (vCalendar.Period.Equals(strPeriod))
                        {
                            if (CalendarType.Equals(ischedulePlus.CalendarType.Teacher))
                            {
                                if (!vCalendar.TeacherName.Equals(AssocID))
                                {
                                    string strResult = string.Empty;

                                    if (IsDisplayExchangeHistory)
                                    {
                                        strResult =
                                            (IsDisplayDate?vCalendar.MonthDay:"") + "(" + vCalendar.DisplayWeekday + ")" + vCalendar.Period + System.Environment.NewLine +
                                        vCalendar.ClassName + System.Environment.NewLine +
                                        "調至>>" + System.Environment.NewLine +
                                        (IsDisplayDate?vCalendar.ExchangeCalendar.MonthDay:"" ) + "(" + vCalendar.ExchangeCalendar.DisplayWeekday + ")" + vCalendar.ExchangeCalendar.Period;
                                    }
                                    else
                                    {
                                        //strResult = (IsDisplayDate?vCalendar.MonthDay:"") + " " + vCalendar.ClassName + System.Environment.NewLine +
                                        //vCalendar.FullSubject + System.Environment.NewLine + vCalendar.TeacherName + System.Environment.NewLine + "原" + (IsDisplayDate?vCalendar.ExchangeCalendar.MonthDay:"" ) + "(" + vCalendar.ExchangeCalendar.DisplayWeekday + ")" + vCalendar.ExchangeCalendar.Period;
                                    }

                                    if (vCalendar.StartDateTime >= dteStart &&
                                        vCalendar.StartDateTime <= dteEnd)
                                    {
                                        Row.SetField<string>(vCalendar.Weekday, strResult);
                                    }
                                    else
                                    {
                                        string Weekday = vCalendar.Weekday;
                                        string Period = vCalendar.Period;
                                        string Key = Weekday + "-" + Period;

                                        if (!CrossWeekMessage.ContainsKey(Key))
                                            CrossWeekMessage.Add(Key, strResult);
                                    }
                                }
                                else if (vCalendar.Cancel.Equals(false))
                                {
                                    string strResult =
                                    (IsDisplayDate?vCalendar.MonthDay:"") + "(調課)" + System.Environment.NewLine +
                                    vCalendar.ClassName + System.Environment.NewLine +
                                    vCalendar.FullSubject + System.Environment.NewLine +
                                    vCalendar.TeacherName;

                                    if (!string.IsNullOrEmpty(vCalendar.AbsenceName))
                                    {
                                        if (!vCalendar.AbsenceName.Equals("無"))
                                            strResult += "(" + vCalendar.AbsenceName + ")";
                                    }
                                    else
                                        strResult += "(請假)";

                                    //2014/3/26 新增,顯示原調課
                                    if (IsDisplayExchangeOriginal)
                                        strResult += System.Environment.NewLine + "原" + (IsDisplayDate?vCalendar.ExchangeCalendar.MonthDay:"" ) + "(" + vCalendar.ExchangeCalendar.DisplayWeekday + ")" + vCalendar.ExchangeCalendar.Period;

                                    if (vCalendar.StartDateTime >= dteStart &&
                                        vCalendar.StartDateTime <= dteEnd)
                                    {
                                        Row.SetField<string>(vCalendar.Weekday, strResult);
                                    }
                                    else
                                    {
                                        string Weekday = vCalendar.Weekday;
                                        string Period = vCalendar.Period;
                                        string Key = Weekday + "-" + Period;

                                        if (!CrossWeekMessage.ContainsKey(Key))
                                            CrossWeekMessage.Add(Key, strResult);
                                    }
                                }
                            }
                            else if (CalendarType.Equals(ischedulePlus.CalendarType.Class))
                            {
                                if (vCalendar.Cancel.Equals(false))
                                {
                                    string strResult =
                                    (IsDisplayDate?vCalendar.MonthDay:"") + "(調課)" + System.Environment.NewLine +
                                    vCalendar.FullSubject + System.Environment.NewLine +
                                    vCalendar.TeacherName;

                                    if (IsDisplayExchangeOriginal)
                                        strResult += System.Environment.NewLine + "原" + (IsDisplayDate?vCalendar.ExchangeCalendar.MonthDay:"" ) + "(" + vCalendar.ExchangeCalendar.DisplayWeekday + ")" + vCalendar.ExchangeCalendar.Period;

                                    if (vCalendar.StartDateTime >= dteStart &&
                                        vCalendar.StartDateTime <= dteEnd)
                                    {
                                        Row.SetField<string>(vCalendar.Weekday, strResult);
                                    }
                                    else
                                    {
                                        string Weekday = vCalendar.Weekday;
                                        string Period = vCalendar.Period;
                                        string Key = Weekday + "-" + Period;

                                        if (!CrossWeekMessage.ContainsKey(Key))
                                            CrossWeekMessage.Add(Key, strResult);
                                    }
                                }
                            }
                            else
                            {
                                string strResult =
                                (IsDisplayDate?vCalendar.MonthDay:"") + "(調課)" + System.Environment.NewLine +
                                vCalendar.ClassName + System.Environment.NewLine +
                                vCalendar.FullSubject + System.Environment.NewLine +
                                vCalendar.TeacherName;

                                if (IsDisplayExchangeOriginal)
                                    strResult += System.Environment.NewLine + "原" + (IsDisplayDate?vCalendar.ExchangeCalendar.MonthDay:"" ) + "(" + vCalendar.ExchangeCalendar.DisplayWeekday + ")" + vCalendar.ExchangeCalendar.Period;

                                Row.SetField<string>(vCalendar.Weekday, strResult);
                            }
                        }

                        if (vCalendar.ExchangeCalendar.Period.Equals(strPeriod))
                        {
                            if (CalendarType.Equals(ischedulePlus.CalendarType.Teacher))
                            {
                                if (!vCalendar.ExchangeCalendar.TeacherName.Equals(AssocID))
                                {
                                    string strResult = string.Empty;

                                    if (IsDisplayExchangeHistory)
                                    {
                                        strResult =
                                       (IsDisplayDate?vCalendar.ExchangeCalendar.MonthDay:"" ) + "(" + vCalendar.ExchangeCalendar.DisplayWeekday + ")" + vCalendar.ExchangeCalendar.Period + System.Environment.NewLine +
                                       vCalendar.ClassName + System.Environment.NewLine +
                                       "調至>>" + System.Environment.NewLine +
                                       ((IsDisplayDate?vCalendar.MonthDay:"") )+ "(" + vCalendar.DisplayWeekday + ")" + vCalendar.Period;
                                    }
                                    else
                                    {
                                        //strResult = (IsDisplayDate?vCalendar.ExchangeCalendar.MonthDay:"" ) + " " + vCalendar.ExchangeCalendar.ClassName + System.Environment.NewLine +
                                        //vCalendar.ExchangeCalendar.FullSubject + System.Environment.NewLine + vCalendar.ExchangeCalendar.TeacherName + System.Environment.NewLine + "原" + (IsDisplayDate?vCalendar.MonthDay:"") + "(" + vCalendar.DisplayWeekday + ")" + vCalendar.Period;
                                    }

                                    if (vCalendar.ExchangeCalendar.StartDateTime >= dteStart &&
                                       vCalendar.ExchangeCalendar.EndDateTime <= dteEnd)
                                    {
                                        Row.SetField<string>(vCalendar.ExchangeCalendar.Weekday, strResult);
                                    }
                                    else
                                    {
                                        string Weekday = vCalendar.ExchangeCalendar.Weekday;
                                        string Period = vCalendar.ExchangeCalendar.Period;
                                        string Key = Weekday + "-" + Period;

                                        if (!CrossWeekMessage.ContainsKey(Key))
                                            CrossWeekMessage.Add(Key, strResult);
                                    }
                                }
                                else if (vCalendar.ExchangeCalendar.Cancel.Equals(false))
                                {
                                    string strResult =
                                    (IsDisplayDate?vCalendar.ExchangeCalendar.MonthDay:"" ) + "(調課)" + System.Environment.NewLine +
                                    vCalendar.ExchangeCalendar.ClassName + System.Environment.NewLine +
                                    vCalendar.ExchangeCalendar.FullSubject + System.Environment.NewLine +
                                    vCalendar.ExchangeCalendar.TeacherName;

                                    //2014/3/26 新增,顯示原調課
                                    if (IsDisplayExchangeOriginal)
                                        strResult += System.Environment.NewLine + "原" + ((IsDisplayDate?vCalendar.MonthDay:"")) + "(" + vCalendar.DisplayWeekday + ")" + vCalendar.Period;

                                    if (vCalendar.ExchangeCalendar.StartDateTime >= dteStart &&
                                       vCalendar.ExchangeCalendar.EndDateTime <= dteEnd)
                                    {
                                        Row.SetField<string>(vCalendar.ExchangeCalendar.Weekday, strResult);
                                    }
                                    else
                                    {
                                        string Weekday = vCalendar.ExchangeCalendar.Weekday;
                                        string Period = vCalendar.ExchangeCalendar.Period;
                                        string Key = Weekday + "-" + Period;

                                        if (!CrossWeekMessage.ContainsKey(Key))
                                            CrossWeekMessage.Add(Key, strResult);
                                    }
                                }
                            }
                            else if (CalendarType.Equals(ischedulePlus.CalendarType.Class))
                            {
                                if (vCalendar.ExchangeCalendar.Cancel.Equals(false))
                                {
                                    string strResult =
                                    (IsDisplayDate?vCalendar.ExchangeCalendar.MonthDay:"" ) + "(調課)" + System.Environment.NewLine +
                                    vCalendar.ExchangeCalendar.FullSubject + System.Environment.NewLine +
                                    vCalendar.ExchangeCalendar.TeacherName;

                                    if (IsDisplayExchangeOriginal)
                                        strResult += System.Environment.NewLine + "原" + ((IsDisplayDate?vCalendar.MonthDay:"")) + "(" + vCalendar.DisplayWeekday + ")" + vCalendar.Period;

                                    if (vCalendar.ExchangeCalendar.StartDateTime >= dteStart &&
                                        vCalendar.ExchangeCalendar.EndDateTime <= dteEnd)
                                    {
                                        Row.SetField<string>(vCalendar.ExchangeCalendar.Weekday, strResult);
                                    }
                                    else
                                    {
                                        string Weekday = vCalendar.ExchangeCalendar.Weekday;
                                        string Period = vCalendar.ExchangeCalendar.Period;
                                        string Key = Weekday + "-" + Period;

                                        if (!CrossWeekMessage.ContainsKey(Key))
                                            CrossWeekMessage.Add(Key, strResult);
                                    }
                                }
                            }
                            else
                            {
                                string strResult =
                                (IsDisplayDate?vCalendar.ExchangeCalendar.MonthDay:"" ) + "(調課)" + System.Environment.NewLine +
                                vCalendar.ExchangeCalendar.ClassName + System.Environment.NewLine +
                                vCalendar.ExchangeCalendar.FullSubject + System.Environment.NewLine +
                                vCalendar.ExchangeCalendar.TeacherName;

                                if (IsDisplayExchangeOriginal)
                                    strResult += System.Environment.NewLine + "原" + ((IsDisplayDate?vCalendar.MonthDay:"")) + "(" + vCalendar.DisplayWeekday + ")" + vCalendar.Period;

                                Row.SetField<string>(vCalendar.ExchangeCalendar.Weekday, strResult);
                            }
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(vCalendar.ReplaceID))
                    {
                        if (vCalendar.Period.Equals(strPeriod))
                        {
                            if (CalendarType.Equals(CalendarType.Teacher))
                            {
                                string strResult = string.Empty;

                                   if (vCalendar.TeacherName.Equals(AssocID))
                                   {
                                       strResult = (IsDisplayDate?vCalendar.MonthDay:"") + " " + vCalendar.ClassName + "(代課)" + System.Environment.NewLine +
                                         vCalendar.FullSubject + System.Environment.NewLine;

                                       strResult += vCalendar.AbsTeacherName + (!string.IsNullOrWhiteSpace(vCalendar.AbsenceName) ? "(" + vCalendar.AbsenceName + ")" : "(請假)");
                                   }
                                   else
                                   {
                                       strResult = (IsDisplayDate?vCalendar.MonthDay:"") + " " +
                                        vCalendar.ClassName + System.Environment.NewLine +
                                        vCalendar.FullSubject + System.Environment.NewLine;

                                       if (!string.IsNullOrWhiteSpace(vCalendar.TeacherName))
                                           strResult += vCalendar.TeacherName + "(代課)";
                                       else
                                           strResult += "(缺課)";
                                   }

                                Row.SetField<string>(vCalendar.Weekday, strResult);

                                string Weekday = vCalendar.Weekday;
                                string Period = vCalendar.Period;
                                string Key = Weekday + "-" + Period;

                                if (!CrossWeekMessage.ContainsKey(Key))
                                    CrossWeekMessage.Add(Key, strResult);
                            }
                            else if (CalendarType.Equals(CalendarType.Class))
                            {
                                string strResult =
                                   (IsDisplayDate?vCalendar.MonthDay:"") + " " + System.Environment.NewLine +
                                   vCalendar.FullSubject + System.Environment.NewLine;

                                if (!string.IsNullOrWhiteSpace(vCalendar.TeacherName))
                                    strResult += vCalendar.TeacherName + "(代課)";
                                else
                                    strResult += "(缺課)";

                                Row.SetField<string>(vCalendar.Weekday, strResult);

                                string Weekday = vCalendar.Weekday;
                                string Period = vCalendar.Period;
                                string Key = Weekday + "-" + Period;

                                if (!CrossWeekMessage.ContainsKey(Key))
                                    CrossWeekMessage.Add(Key, strResult);
                            }
                            else
                            {

                            }
                        }
                    }
                }
            }

            foreach (string Key in CrossWeekMessage.Keys)
            {
                string[] Keys = Key.Split(new char[] { '-' });

                string Weekday = Keys[0];
                string Period = Keys[1];

                int PeriodIndex = K12.Data.Int.Parse(Period);

                string Value = tblResult.Rows[PeriodIndex].Field<string>(Weekday);

                if (string.IsNullOrWhiteSpace(Value))
                    tblResult.Rows[PeriodIndex].SetField<string>(Weekday , CrossWeekMessage[Key]);
            }

            return tblResult;
        }