private string GetTargetDetail(LogTargetCategory targetCategory, object dTarget)
 {
     string target = string.Empty;
     switch (targetCategory)
     {
         case LogTargetCategory.Student:
             K12.Data.StudentRecord StudentRecod = dTarget as K12.Data.StudentRecord;
             target = "學生「" + StudentRecod.Name + "」,學號「" + StudentRecod.StudentNumber + "」\n";
             break;
         case LogTargetCategory.Class:
             K12.Data.ClassRecord ClassRecod = dTarget as K12.Data.ClassRecord;
             target = "班級「" + ClassRecod.Name + "」\n";
             break;
         case LogTargetCategory.Teacher:
             K12.Data.TeacherRecord TeacherRecod = dTarget as K12.Data.TeacherRecord;
             target = "教師「" + TeacherRecod.Name + "」,暱稱「" + TeacherRecod.Nickname + "」\n";
             break;
         case LogTargetCategory.Course:
             K12.Data.CourseRecord CourseRecod = dTarget as K12.Data.CourseRecord;
             target = "課程「" + CourseRecod.Name + "」,學年度「" + (CourseRecod.SchoolYear + "") + "」,學期「" + EMBACore.DataItems.SemesterItem.GetSemesterByCode(CourseRecod.Semester + "").Name + "」\n";
             break;
         case LogTargetCategory.SystemSetting:
             target = "學年度學期\n";
             break;
         default:
             target = "UFO\n";
             break;
     }
     return target;
 }
        private string GetTargetDetail(LogTargetCategory targetCategory, string targetID)
        {
            if (string.IsNullOrEmpty(targetID))
                return this.TargetDetail;

            string target = string.Empty;
            switch (targetCategory)
            {
                case LogTargetCategory.Student:
                    K12.Data.StudentRecord StudentRecod = K12.Data.Student.SelectByID(targetID);
                    target = "學生「" + StudentRecod.Name + "」,學號「" + StudentRecod.StudentNumber + "」\n";
                    break;
                case LogTargetCategory.Class:
                    K12.Data.ClassRecord ClassRecod = K12.Data.Class.SelectByID(targetID);
                    target = "班級「" + ClassRecod.Name + "」\n";
                    break;
                case LogTargetCategory.Teacher:
                    K12.Data.TeacherRecord TeacherRecod = K12.Data.Teacher.SelectByID(targetID);
                    target = "教師「" + TeacherRecod.Name + "」,暱稱「" + TeacherRecod.Nickname + "」\n";
                    break;
                case LogTargetCategory.Course:
                    K12.Data.CourseRecord CourseRecod = K12.Data.Course.SelectByID(targetID);
                    target = "課程「" + CourseRecod.Name + "」,學年度「" + (CourseRecod.SchoolYear + "") + "」,學期「" + CourseSelection.DataItems.SemesterItem.GetSemesterByCode(CourseRecod.Semester + "").Name + "」\n";
                    break;
                case LogTargetCategory.SystemSetting:
                    target = "學年度學期\n";
                    break;
                default:
                    target = "UFO\n";
                    break;
            }
            return target;
        }
 public void Set(string ActionBy, string PrefixString, string SubfixString, LogTargetCategory LogTargetCategory)
 {
     this.Set(ActionBy, PrefixString, SubfixString, LogTargetCategory, string.Empty);
 }
        public void Set(string ActionBy, string PrefixString, string SubfixString, LogTargetCategory LogTargetCategory, string TargetID)
        {
            this.ActionBy = ActionBy;
            this.PrefixString = PrefixString;
            this.SubfixString = SubfixString;
            this.LogTargetCategory = LogTargetCategory;
            this.TargetID = TargetID;

            StringBuilder sb = new StringBuilder();
            sb.Append(PrefixString);
            foreach (LogValue lv in this.getLogValueList())
            {
                //  ischool desktop log 機制乃記錄使用者對於資料之異動,若資料無異動即不應記錄。
                if (!lv.isSame())
                {
                    if (ActionType == LogActionType.Delete)
                    {
                        sb.Append(lv.getDeleteString1());
                    }
                    else if (ActionType == LogActionType.Update)
                    {
                        sb.Append(lv.getChangeString1());
                    }
                    else if (ActionType == LogActionType.AddNew)
                    {
                        sb.Append(lv.getInsertString1());
                    }
                    sb.Append("\n");
                }
            }
            sb.Append(SubfixString);
            this.LogDetail = sb.ToString();
        }
        /// <summary>
        /// 單筆儲存 Log
        /// </summary>
        /// <param name="ActionBy">來源,格式範例:學生.資料項目.經歷;課程.匯入.課程基本資料</param>        
        /// <param name="prefixString">Log 詳細資料的前置字串</param>        
        /// <param name="subfixString">Log 詳細資料的後置字串</param>        
        /// <param name="targetCategory">資料類別,若內容為 { student, teacher, class, course } 4者之1,則該筆 Log 可於 { 學生, 班級, 教師, 課程 } 對應頁籤中查得</param>
        /// <param name="targetID">被影響的 ID</param>
        public void Save(string ActionBy,  string prefixString, string subfixString, LogTargetCategory targetCategory, string targetID)
        {
            this.Set(ActionBy, prefixString, subfixString, targetCategory, targetID);
            string target_detail = this.GetTargetDetail(targetCategory, targetID);

            string action_type = string.Empty;
            if (ActionType == LogActionType.Delete)
                action_type = "刪除";
            else if (ActionType == LogActionType.Update)
                action_type = "修改";
            else if (ActionType == LogActionType.AddNew)
                action_type = "新增";

            if (!string.IsNullOrWhiteSpace(this.LogDetail))
                FISCA.LogAgent.ApplicationLog.Log(ActionBy, action_type, targetCategory.ToString().ToLower(), targetID, target_detail + this.LogDetail);
        }