public StudABCardReportForm(SelectType selType,List<string> StudentIDList)
 {
     InitializeComponent();
     _UserSelectType = selType;
     _UDTTransfer = new UDTTransfer();
     _bgWorker = new BackgroundWorker();
     _dtTable = new DataTable();
     _StudentIDList = StudentIDList;
     _bgWorker.WorkerReportsProgress = true;
     _bgWorker.DoWork += new DoWorkEventHandler(_bgWorker_DoWork);
     _bgWorker.ProgressChanged += new ProgressChangedEventHandler(_bgWorker_ProgressChanged);
     _bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_bgWorker_RunWorkerCompleted);
 }
 public StudentInfoTransfer()
 {
     _StudentInfoList = new List<StudentInfo>();
     _StudentHistoryDict = new Dictionary<string, List<SchoolYearSemester>>();
     _updateRecList = new List<UpdateRecordRecord>();
     _StudQuizDataDefList = new List<UDT_StudQuizDataDef>();
     _UDTTransfer = new UDTTransfer();
     _QuizDef = new List<UDT_QuizDef>();
 }
 public StudInterviewDataReportForm(SelectType type)
 {
     InitializeComponent();
     _UDTTransfer = new UDTTransfer();
     _studIDList = new List<string>();
     _TeacherIDList = new List<string>();
     _studDataDict = new Dictionary<string, StudentRecord>();
     _bgWorker= new BackgroundWorker ();
     _dataDictList= new List<Dictionary<string,string>>();
     _UserSelectType = type;
     _bgWorker.DoWork+=new DoWorkEventHandler(_bgWorker_DoWork);
     _bgWorker.RunWorkerCompleted+=new RunWorkerCompletedEventHandler(_bgWorker_RunWorkerCompleted);
 }
        void _bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            UDTTransfer _UDTTransfer = new UDTTransfer();
            // 清空暫存 table
            _dtTable.Clear();
            _dtTable.Columns.Clear();
            _ErrorList.Clear();
            // 新增欄位
            AddTableSColumn();

            Document docTemplae = new Document();

            // 檢查所使用樣板
            if(_SelectTemplateType == SelectTemplateType.預設)
                docTemplae = new Document(new MemoryStream(Properties.Resources.輔導資料紀錄表範本));

            if (_SelectTemplateType == SelectTemplateType.自訂)
                docTemplae = _Config.Template.ToDocument();

            _bgWorker.ReportProgress(1);
            // 加入樣板內合併欄位名稱
            _TemplateFieldDict.Clear();
            foreach (string name in docTemplae.MailMerge.GetFieldNames())
                if (!_TemplateFieldDict.ContainsKey(name))
                    _TemplateFieldDict.Add(name, 1);

            // word 資料合併
            Document doc = new Document();
            doc.Sections.Clear();

            // 讀取需要資料並建立索引
            _StudRecDict.Clear();
            foreach (StudentRecord rec in Student.SelectByIDs(_StudentIDList))
                _StudRecDict.Add(rec.ID, rec);

            // 學習歷程
            _SemesterHistoryRecordDict.Clear();
            foreach (SemesterHistoryRecord rec in SemesterHistory.SelectByStudentIDs(_StudentIDList))
            {
                if (!_SemesterHistoryRecordDict.ContainsKey(rec.RefStudentID))
                    // 排序
                    rec.SemesterHistoryItems = (from data in rec.SemesterHistoryItems orderby data.SchoolYear, data.Semester select data).ToList();
                    _SemesterHistoryRecordDict.Add(rec.RefStudentID, rec);
            }

            // 建立地址
            _AddressRecordDict.Clear();
            foreach (AddressRecord rec in Address.SelectByStudentIDs(_StudentIDList))
                _AddressRecordDict.Add(rec.RefStudentID, rec);

            // 建立電話
            _PhoneRecordDict.Clear();
            foreach (PhoneRecord rec in Phone.SelectByStudentIDs(_StudentIDList))
                _PhoneRecordDict.Add(rec.RefStudentID, rec);

            // 建立異動
            _UpdateRecordRecordDict.Clear();
            foreach (UpdateRecordRecord rec in UpdateRecord.SelectByStudentIDs(_StudentIDList))
            {
                if (!_UpdateRecordRecordDict.ContainsKey(rec.StudentID))
                    _UpdateRecordRecordDict.Add(rec.StudentID, new List<UpdateRecordRecord>());

                _UpdateRecordRecordDict[rec.StudentID].Add(rec);

            }
            _UpdateRecordRecordInfoDict.Clear();
            _UpdateRecordRecordInfoDict = Utility.GetUpdateRecordInfo(_StudentIDList);

            // 建立AutoSummary
            _AutoSummaryRecordDict.Clear();
            foreach (K12.BusinessLogic.AutoSummaryRecord rec in K12.BusinessLogic.AutoSummary.Select(_StudentIDList, null))
            {
                if (!_AutoSummaryRecordDict.ContainsKey(rec.RefStudentID))
                    _AutoSummaryRecordDict.Add(rec.RefStudentID, new List<K12.BusinessLogic.AutoSummaryRecord>());

                _AutoSummaryRecordDict[rec.RefStudentID].Add(rec);
            }

            // 建立文字評量
            _StudentTextScoreDict.Clear();
            _StudentTextScoreDict = Utility.GetABCard_StudentTextScoreDict(_StudentIDList);

            //// 建立缺曠
            //_AttendanceRecordDict.Clear();
            //foreach (AttendanceRecord rec in Attendance.SelectByStudentIDs(_StudentIDList))
            //{
            //    if (!_AttendanceRecordDict.ContainsKey(rec.RefStudentID))
            //        _AttendanceRecordDict.Add(rec.RefStudentID, new List<AttendanceRecord>());

            //    _AttendanceRecordDict[rec.RefStudentID].Add(rec);
            //}

            // 學期
            _SemesterScoreRecordDict.Clear();
            foreach (SemesterScoreRecord data in SemesterScore.SelectByStudentIDs(_StudentIDList))
            {
                if (!_SemesterScoreRecordDict.ContainsKey(data.RefStudentID))
                    _SemesterScoreRecordDict.Add(data.RefStudentID,new List<SemesterScoreRecord> ());

                _SemesterScoreRecordDict[data.RefStudentID].Add(data);
            }

            _SemesterDomainScoreDict.Clear();
            // 國中
            _SemesterDomainScoreDict = Utility.GetSemeterDomainScoreByStudentIDList(_StudentIDList);
            // 高中
            _SemesterEnrtyScoreDict = Utility.GetSemeterEntryScoreByStudentIDList(_StudentIDList);
            _SemesterEnrtyScoreSchoolYearDict = Utility.GetSemeterSchoolYearScoreByStudentIDList(_StudentIDList);

            // 國中畢業成績
            _GradeScoreDict.Clear();
            _GradeScoreDict = Utility.GetStudGraduateDictJH(_StudentIDList);

            // 高中畢業
            _GradeScoreSHDict.Clear();
            _GradeScoreSHDict = Utility.GetGradeScoreSHByStudentIDList(_StudentIDList);

            // 建立獎懲明細
            _DisciplineRecordDict.Clear();
            foreach (DisciplineRecord rec in Discipline.SelectByStudentIDs(_StudentIDList))
            {
                if(!_DisciplineRecordDict.ContainsKey(rec.RefStudentID))
                    _DisciplineRecordDict.Add(rec.RefStudentID, new List<DisciplineRecord>());

                _DisciplineRecordDict[rec.RefStudentID].Add(rec);
            }
            // 入學照片
            _FreshmanPhotoDict.Clear();
            _FreshmanPhotoDict = K12.Data.Photo.SelectFreshmanPhoto(_StudentIDList);

            // 畢業照片
            _GraduatePhotoDict.Clear();
            _GraduatePhotoDict = K12.Data.Photo.SelectGraduatePhoto(_StudentIDList);

            // 學校名稱
            string SchoolName = K12.Data.School.ChineseName;

            // 輔導資料
            // 建立心理測驗
            _QuizDefDict.Clear();
            foreach(UDT_QuizDef da in _UDTTransfer.GetAllQuizData())
            {
                int id=int.Parse(da.UID);
                _QuizDefDict.Add(id, da);
            }

            _StudQuizDataDict.Clear();
            foreach (UDT_StudQuizDataDef data in _UDTTransfer.GetStudQuizDataByStudentIDList(_StudentIDList))
            {
                string sid = data.StudentID.ToString();
                if (!_StudQuizDataDict.ContainsKey(sid))
                    _StudQuizDataDict.Add(sid, new List<UDT_StudQuizDataDef>());

                _StudQuizDataDict[sid].Add(data);
            }

            // 建立晤談記錄
            _CounselStudentInterviewRecordDict.Clear();
            foreach (UDT_CounselStudentInterviewRecordDef data in _UDTTransfer.GetCounselStudentInterviewRecordByStudentIDList(_StudentIDList))
            {
                string key = data.StudentID.ToString();
                if (!_CounselStudentInterviewRecordDict.ContainsKey(key))
                    _CounselStudentInterviewRecordDict.Add(key, new List<UDT_CounselStudentInterviewRecordDef>());

                _CounselStudentInterviewRecordDict[key].Add(data);
            }

            // 個案會議
            _CounselCaseMeetingRecordDict.Clear();
            foreach (UDT_CounselCaseMeetingRecordDef data in _UDTTransfer.GetCaseMeetingRecordListByStudentIDList(_StudentIDList))
            {
                string key = data.StudentID.ToString();
                if (!_CounselCaseMeetingRecordDict.ContainsKey(key))
                    _CounselCaseMeetingRecordDict.Add(key, new List<UDT_CounselCaseMeetingRecordDef>());

                _CounselCaseMeetingRecordDict[key].Add(data);
            }

            // 優先關懷
            _CounselCareRecordDict.Clear();
            foreach (UDT_CounselCareRecordDef data in _UDTTransfer.GetCareRecordsByStudentIDList(_StudentIDList))
            {
                string key = data.StudentID.ToString();
                if (!_CounselCareRecordDict.ContainsKey(key))
                    _CounselCareRecordDict.Add(key, new List<UDT_CounselCareRecordDef>());

                _CounselCareRecordDict[key].Add(data);
            }

            // 綜合紀錄表-單值
            _SingleRecordDict.Clear();
            foreach (UDTSingleRecordDef data in UDTTransfer.ABUDTSingleRecordSelectByStudentIDList(_StudentIDList))
            {
                string key = data.StudentID.ToString();
                if (!_SingleRecordDict.ContainsKey(key))
                    _SingleRecordDict.Add(key, new List<UDTSingleRecordDef>());

                _SingleRecordDict[key].Add(data);

            }

            // 綜合紀錄表-多值
            _MultipleRecordDict.Clear();
            foreach (UDTMultipleRecordDef data in UDTTransfer.ABUDTMultipleRecordSelectByStudentIDList(_StudentIDList))
            {
                string key = data.StudentID.ToString();
                if (!_MultipleRecordDict.ContainsKey(key))
                    _MultipleRecordDict.Add(key, new List<UDTMultipleRecordDef>());

                _MultipleRecordDict[key].Add(data);
            }

            // 綜合紀錄表-學期
            _SemesterDataDict.Clear();
            foreach (UDTSemesterDataDef data in UDTTransfer.ABUDTSemesterDataSelectByStudentIDList(_StudentIDList))
            {
                string key = data.StudentID.ToString();
                if (!_SemesterDataDict.ContainsKey(key))
                    _SemesterDataDict.Add(key, new List<UDTSemesterDataDef>());

                _SemesterDataDict[key].Add(data);
            }

            // 綜合紀錄表-學年
            _YearlyDataDict.Clear();
            foreach (UDTYearlyDataDef data in UDTTransfer.ABUDTYearlyDataSelectByStudentIDList(_StudentIDList))
            {
                string key = data.StudentID.ToString();
                if (!_YearlyDataDict.ContainsKey(key))
                    _YearlyDataDict.Add(key, new List<UDTYearlyDataDef>());

                _YearlyDataDict[key].Add(data);
            }

            // 綜合紀錄表-直系血親
            _RelativeDict.Clear();
            foreach (UDTRelativeDef data in UDTTransfer.ABUDTRelativeSelectByStudentIDList(_StudentIDList))
            {
                string key = data.StudentID.ToString();
                if (!_RelativeDict.ContainsKey(key))
                    _RelativeDict.Add(key, new List<UDTRelativeDef>());

                _RelativeDict[key].Add(data);
            }

            // 綜合紀錄表-兄弟姊妹
            _SiblingDict.Clear();
            foreach (UDTSiblingDef data in UDTTransfer.ABUDTSiblingSelectByStudentIDList(_StudentIDList))
            {
                string key = data.StudentID.ToString();
                if (!_SiblingDict.ContainsKey(key))
                    _SiblingDict.Add(key, new List<UDTSiblingDef>());

                _SiblingDict[key].Add(data);
            }

            // 綜合紀錄表-優先順序
            _PriorityDataDict.Clear();
            foreach (UDTPriorityDataDef data in UDTTransfer.ABUDTPriorityDataSelectByStudentIDList(_StudentIDList))
            {
                string key = data.StudentID.ToString();
                if (!_PriorityDataDict.ContainsKey(key))
                    _PriorityDataDict.Add(key, new List<UDTPriorityDataDef>());

                _PriorityDataDict[key].Add(data);
            }

            _bgWorker.ReportProgress(30);

            // 儲存獎懲明細使用
            StringBuilder sbDisciplineRecord = new StringBuilder();

            // 開始填入資料
            int idx = 1;
            foreach (string StudID in _StudentIDList)
            {
                _ErrMsg1 = "";
                DataRow row = _dtTable.NewRow();

                row["學校名稱"] = SchoolName;

                row["姓名"] = "";
                row["性別"] = "";
                row["學號"] = "";
                row["身分證號"] = "";
                row["生日"] = "";
                row["生日2"] = "";
                row["出生地"] = "";
                if (_StudRecDict.ContainsKey(StudID))
                {
                    _ErrMsg1=_StudRecDict[StudID].Name+":";
                    row["姓名"] = _StudRecDict[StudID].Name;
                    row["性別"] = _StudRecDict[StudID].Gender;
                    row["學號"] = _StudRecDict[StudID].StudentNumber;
                    row["身分證號"] = _StudRecDict[StudID].IDNumber;
                    if (_StudRecDict[StudID].Birthday.HasValue)
                    {
                        row["生日"] = _StudRecDict[StudID].Birthday.Value.ToShortDateString();
                        // 100/1/1
                        row["生日2"] = (_StudRecDict[StudID].Birthday.Value.Year - 1911) + "/" + _StudRecDict[StudID].Birthday.Value.Month + "/" + _StudRecDict[StudID].Birthday.Value.Day;
                    }
                    row["出生地"] = _StudRecDict[StudID].BirthPlace;
                }

                row["入學照片"] = "";
                row["入學照片2"] = "";

                if (_FreshmanPhotoDict.ContainsKey(StudID))
                {
                    row["入學照片"] = _FreshmanPhotoDict[StudID];
                    row["入學照片2"] = _FreshmanPhotoDict[StudID];
                }
                if(_GraduatePhotoDict.ContainsKey(StudID))
                {
                    row["畢業照片"] = _GraduatePhotoDict[StudID];
                    row["畢業照片2"] = _GraduatePhotoDict[StudID];
                }

                row["戶籍地址"] = "";
                row["聯絡地址"] = "";
                row["戶籍電話"] = "";
                row["聯絡電話"] = "";
                if (_AddressRecordDict.ContainsKey(StudID))
                {
                    row["戶籍地址"] = _AddressRecordDict[StudID].PermanentAddress;
                    row["聯絡地址"] = _AddressRecordDict[StudID].MailingAddress;
                }
                if (_PhoneRecordDict.ContainsKey(StudID))
                {
                    row["戶籍電話"] = _PhoneRecordDict[StudID].Permanent;
                    row["聯絡電話"] = _PhoneRecordDict[StudID].Contact;
                }

                idx = 1;
                // 學習歷程
                foreach (SemesterHistoryItem item in _SemesterHistoryRecordDict[StudID].SemesterHistoryItems)
                {
                    // 檢查料是否超過可合併欄位
                    ChechMapFieldName("學習歷程_學年度", idx);
                    ChechMapFieldName("學習歷程_學期", idx);
                    ChechMapFieldName("學習歷程_班級", idx);
                    ChechMapFieldName("學習歷程_班導師", idx);

                    row["學習歷程_學年度" + idx] = item.SchoolYear;
                    row["學習歷程_學期" + idx] = item.Semester;
                    row["學習歷程_班級" + idx] = item.ClassName;
                    row["學習歷程_班導師" + idx] = item.Teacher;
                    idx++;
                }

                row["入學年月"] = "";
                row["入學學校"] = "";
                row["畢業年月"] = "";
                row["學籍核准文號"] = "";
                row["畢業證書字號"] = "";
                idx = 1;
                // 異動高中
                if (_UpdateRecordRecordDict.ContainsKey(StudID) && _UpdateRecordRecordDict[StudID].Count>0)
                {

                    DateTime dtLast = DateTime.MinValue;
                    int lastUID = 0;
                    foreach (UpdateRecordRecord rec in _UpdateRecordRecordDict[StudID])
                    {
                        if (rec.UpdateCode.Length < 3)
                            continue;

                        int code = int.Parse(rec.UpdateCode);
                        DateTime dt = DateTime.Parse(rec.UpdateDate);

                        // 新生
                        if (code < 100)
                        {
                            row["入學年月"] = dt.Year + string.Format("{0:00}", dt.Month);

                            if (_UpdateRecordRecordInfoDict[rec.ID].Element("GraduateSchool") != null)
                                row["入學學校"] = _UpdateRecordRecordInfoDict[rec.ID].Element("GraduateSchool").Value;  // 畢

                            if(row["學籍核准文號"].ToString()=="")
                                row["學籍核准文號"] = rec.ADNumber;

                            //row["入學學校"] = rec.;  // 畢業國中
                        }
                        else if (code == 501)
                        {
                            // 畢業
                            row["畢業年月"] = dt.Year + string.Format("{0:00}", dt.Month);
                            //row["畢業證書字號"] = rec.GraduateCertificateNumber;
                        }
                        else
                        {
                            // 找最後一筆
                            DateTime dtL;
                            if (DateTime.TryParse(rec.LastADDate, out dtL))
                            {
                                if (dtLast == null)
                                    dtLast = dtL;
                                int uid = int.Parse(rec.ID);
                                if (dtL >=dtLast)
                                {
                                    if (uid > lastUID)
                                    {
                                        row["學籍核准文號"] = rec.LastADNumber;
                                        dtLast = dtL;
                                        lastUID = uid;
                                    }
                                }
                            }
                            // 檢查料是否超過可合併欄位
                            ChechMapFieldName("異動日期", idx);
                            ChechMapFieldName("異動原因", idx);
                            row["異動日期" + idx] = dt.ToShortDateString();
                            row["異動原因" + idx] = rec.UpdateDescription;
                            idx++;
                        }
                    }
                }

                // 異動國中
                if (_UpdateRecordRecordDict.ContainsKey(StudID) && _UpdateRecordRecordDict[StudID].Count > 0)
                {
                    DateTime dtLast1 = DateTime.MinValue;
                    int lastUID1=0;
                    foreach (UpdateRecordRecord rec in _UpdateRecordRecordDict[StudID])
                    {
                        if (rec.UpdateCode.Length > 1)
                            continue;

                        int code = int.Parse(rec.UpdateCode);
                        DateTime dt = DateTime.Parse(rec.UpdateDate);

                        // 新生
                        if (code == 1)
                        {
                            if (_UpdateRecordRecordInfoDict.ContainsKey(rec.ID))
                            {
                                if (_UpdateRecordRecordInfoDict[rec.ID].Element("EnrollmentSchoolYear") != null)
                                    row["入學年月"] = _UpdateRecordRecordInfoDict[rec.ID].Element("EnrollmentSchoolYear").Value;
                                if (_UpdateRecordRecordInfoDict[rec.ID].Element("GraduateSchool") != null)
                                    row["入學學校"] = _UpdateRecordRecordInfoDict[rec.ID].Element("GraduateSchool").Value;  // 畢

                                if (row["學籍核准文號"].ToString() == "")
                                    row["學籍核准文號"] = rec.ADNumber;
                            }
                        }
                        else if (code == 2)
                        {
                            // 畢業
                            if (_UpdateRecordRecordInfoDict.ContainsKey(rec.ID))
                            {
                                if (_UpdateRecordRecordInfoDict[rec.ID].Element("GraduateSchoolYear") != null)
                                    row["畢業年月"] = _UpdateRecordRecordInfoDict[rec.ID].Element("GraduateSchoolYear").Value;

                                if (_UpdateRecordRecordInfoDict[rec.ID].Element("GraduateCertificateNumber") != null)
                                    row["畢業證書字號"] = _UpdateRecordRecordInfoDict[rec.ID].Element("GraduateCertificateNumber").Value;
                            }
                            //row["畢業年月"] = rec.GraduateSchoolYear;
                            //row["畢業證書字號"] = rec.GraduateCertificateNumber;
                        }
                        else
                        {
                            //// 找最後一筆
                            //DateTime dtL;
                            //if (DateTime.TryParse(rec.LastADDate, out dtL))
                            //{
                            //    if (dtLast1 == null)
                            //        dtLast1 = dtL;

                            //    if (dtL >= dtLast1)
                            //    {
                            //        row["學籍核准文號"] = rec.LastADNumber;
                            //        dtLast1 = dtL;
                            //    }
                            //}
                            // 檢查料是否超過可合併欄位
                            ChechMapFieldName("異動日期", idx);
                            ChechMapFieldName("異動原因", idx);
                            row["異動日期" + idx] = dt.ToShortDateString();
                            row["異動原因" + idx] = rec.UpdateDescription;
                            idx++;
                        }
                        // 找最後一筆
                        DateTime dtL;
                        if (DateTime.TryParse(rec.LastADDate, out dtL))
                        {
                            int uid=int.Parse(rec.ID);
                            if (dtLast1 == null)
                                dtLast1 = dtL;

                            if (dtL >= dtLast1)
                            {
                                if (uid > lastUID1)
                                {
                                    row["學籍核准文號"] = rec.LastADNumber;
                                    dtLast1 = dtL;
                                    lastUID1 = uid;
                                }
                            }
                        }
                    }
                }

                if (_SemesterScoreRecordDict.ContainsKey(StudID))
                {
                    List<SemesterScoreRecord> dataList = (from da in _SemesterScoreRecordDict[StudID] orderby da.SchoolYear, da.Semester select da).ToList();
                    int i = 1;
                    foreach (SemesterScoreRecord rec in dataList)
                    {
                        // 國中成績
                        if (_SemesterDomainScoreDict.ContainsKey(rec.ID))
                        {

                            // 檢查料是否超過可合併欄位
                            ChechMapFieldName("學年學期", i);
                            ChechMapFieldName("學期成績", i);
                            List<string> strList = new List<string>();

                            row["學年學期" + i] = rec.SchoolYear + "學年第" + rec.Semester + "學期";

                            if (_SemesterDomainScoreDict[rec.ID].Element("Domains") != null)
                            {
                                foreach (XElement elm in _SemesterDomainScoreDict[rec.ID].Element("Domains").Elements("Domain"))
                                {
                                    string str = elm.Attribute("領域").Value + ":" + elm.Attribute("成績").Value;
                                    strList.Add(str);
                                }
                            }
                            if (strList.Count > 0)
                                row["學期成績" + i] = string.Join(",", strList.ToArray());
                            i++;
                        }
                    }
                }
                    // 高中分項
                    if (_SemesterEnrtyScoreSchoolYearDict.ContainsKey(StudID))
                    {
                        List<AB_SchoolYearSemesterIdx> dataList = (from da in _SemesterEnrtyScoreSchoolYearDict[StudID] orderby da.SchoolYear, da.Semester select da).ToList();
                        int i = 1;
                        foreach (AB_SchoolYearSemesterIdx rec in dataList)
                        {
                            if (_SemesterEnrtyScoreDict.ContainsKey(rec.id))
                            {
                                    if (_SemesterEnrtyScoreDict[rec.id].Elements("Entry").Count() > 0)
                                    {
                                        // 檢查料是否超過可合併欄位
                                        ChechMapFieldName("學年學期", i);
                                        ChechMapFieldName("學期成績", i);
                                        List<string> strList = new List<string>();

                                        row["學年學期" + i] = rec.SchoolYear + "學年第" + rec.Semester + "學期";

                                        foreach (XElement elm in _SemesterEnrtyScoreDict[rec.id].Elements("Entry"))
                                        {
                                            string str = elm.Attribute("分項").Value + ":" + elm.Attribute("成績").Value;
                                            strList.Add(str);
                                        }

                                        if (strList.Count > 0)
                                            row["學期成績" + i] = string.Join(",", strList.ToArray());
                                        i++;
                                    }
                            }
                        }
                    }

                // 國中畢業成績
                if (_GradeScoreDict.ContainsKey(StudID))
                {
                    if (_GradeScoreDict[StudID].Count > 0)
                    {
                        List<string> strList = new List<string>();

                        foreach (KeyValuePair<string, decimal?> data in _GradeScoreDict[StudID])
                        {
                            if (data.Value.HasValue)
                                strList.Add(data.Key + ":" + data.Value.Value);
                        }
                        row["畢業成績"] = string.Join(",", strList.ToArray());
                    }
                }

                // 高中畢業成績
                if (_GradeScoreSHDict.ContainsKey(StudID))
                {
                    if (_GradeScoreSHDict[StudID].Elements("EntryScore").Count() > 0)
                    {
                        List<string> strList = new List<string>();
                        foreach (XElement elm in _GradeScoreSHDict[StudID].Elements("EntryScore"))
                        {
                            if (elm.Attribute("Entry").Value == "德行")
                                continue;

                            string str = elm.Attribute("Entry").Value + ":" + elm.Attribute("Score").Value;
                            strList.Add(str);
                        }
                        row["畢業成績"] = string.Join(",", strList.ToArray());
                    }
                }

                row["導師評語"] = "";
                // 文字評量
                if (_StudentTextScoreDict.ContainsKey(StudID))
                {
                    List<string> strList = new List<string>();
                    foreach (ABCard_StudentTextScore sts in _StudentTextScoreDict[StudID])
                    {
                        string str = "";
                        switch (sts.GradeYear)
                        {
                            case 1: str = "一"; break;
                            case 2: str = "二"; break;
                            case 3: str = "三"; break;
                            case 4: str = "四"; break;
                            case 5: str = "五"; break;
                            case 6: str = "六"; break;
                            case 7: str = "一"; break;
                            case 8: str = "二"; break;
                            case 9: str = "三"; break;
                        }

                        if (str != "")
                        {
                            if (sts.Semester == 1)
                                str += "上:";

                            if (sts.Semester == 2)
                                str += "下:";
                            strList.Add(str + sts.sb_Comment + sts.DailyLifeRecommend);
                        }

                    }
                    if (strList.Count > 0)
                        row["導師評語"] = string.Join("\n", strList.ToArray());
                }

                // 處理AutoSummary
                if (_AutoSummaryRecordDict.ContainsKey(StudID))
                {
                    List<K12.BusinessLogic.AutoSummaryRecord> dataList = (from da in _AutoSummaryRecordDict[StudID] orderby da.SchoolYear, da.Semester select da).ToList();
                    int i=1;
                    foreach (K12.BusinessLogic.AutoSummaryRecord data in dataList)
                    {
                        List<string> strList = new List<string> ();
                        foreach (K12.BusinessLogic.AbsenceCountRecord rec in data.AbsenceCounts)
                            strList.Add(rec.PeriodType+":"+rec.Name + rec.Count + "節");

                        if (strList.Count > 0)
                        {
                            // 檢查料是否超過可合併欄位
                            ChechMapFieldName("缺曠統計", i);
                            row["缺曠統計" + i] =data.SchoolYear+"學年第"+data.Semester+"學期:"+ string.Join(",", strList.ToArray());
                            i++;
                        }
                    }
                }

                // 獎懲
                if (_DisciplineRecordDict.ContainsKey(StudID))
                {
                    sbDisciplineRecord.Clear();

                    int i=1,ia = 1,ib=1;
                    List<DisciplineRecord> dataList = (from da in _DisciplineRecordDict[StudID] orderby da.OccurDate select da).ToList();
                    foreach (DisciplineRecord data in dataList)
                    {
                        string str = "";
                        // 檢查料是否超過可合併欄位
                        if (!_TemplateFieldDict.ContainsKey("獎懲明細"))
                        {
                            ChechMapFieldName("獎懲日期", i);
                            ChechMapFieldName("獎懲類別支數", i);
                            ChechMapFieldName("獎懲事由", i);
                        }
                        string spstr1 = "";
                        string spstr2 = "";
                        string spstr3 = "";

                        if (data.MeritFlag == "0" || data.MeritFlag == "2")
                        {
                            str = "";
                            if (data.DemeritA.HasValue && data.DemeritA.Value>0)
                                str += "大過 " + data.DemeritA.Value;

                            if (data.DemeritB.HasValue && data.DemeritB.Value>0)
                                str += "小過 " + data.DemeritB.Value;

                            if (data.DemeritC.HasValue && data.DemeritC.Value>0)
                                str += "警告 " + data.DemeritC.Value;

                            row["懲戒日期" + ia] = data.OccurDate.ToShortDateString();
                            row["懲戒類別支數" + ia] = str;
                            row["懲戒事由" + ia] = data.Reason;

                            row["獎懲日期" + i] = data.OccurDate.ToShortDateString();
                            row["獎懲類別支數" + i] = str;
                            row["獎懲事由" + i] = data.Reason;

                            spstr1 = data.OccurDate.ToShortDateString();
                            spstr2 = str;
                            spstr3 = data.Reason;

                            if (data.MeritFlag == "2")
                            {
                                row["懲戒類別支數" + ia] = "留校察看";
                                row["獎懲類別支數" + i] = "留校察看";
                                spstr2 = "留校察看";
                            }
                            if (data.ClearDate.HasValue)
                            {
                                row["懲戒日期" + ia] = data.ClearDate.Value.ToShortDateString();
                                row["懲戒類別支數" + ia] = "銷過";
                                row["懲戒事由" + ia] = data.ClearReason;

                                row["獎懲日期" + i] = data.ClearDate.Value.ToShortDateString();
                                row["獎懲類別支數" + i] = "銷過";
                                row["獎懲事由" + i] = data.ClearReason;

                                spstr1 = data.ClearDate.Value.ToShortDateString();
                                spstr2 = "銷過";
                                spstr3 = data.ClearReason;
                            }
                            i++;
                            ia++;
                        }
                        if (data.MeritFlag == "1")
                        {
                            str = "";
                            if (data.MeritA.HasValue && data.MeritA.Value >0)
                                str += "大功 " + data.MeritA.Value;

                            if (data.MeritB.HasValue && data.MeritB.Value>0)
                                str += "小功 " + data.MeritB.Value;

                            if (data.MeritC.HasValue && data.MeritC.Value >0)
                                str += "嘉獎 " + data.MeritC.Value;

                            row["獎勵日期" + ib] = data.OccurDate.ToShortDateString();
                            row["獎勵類別支數" + ib] = str;
                            row["獎勵事由" + ib] = data.Reason;

                            row["獎懲日期" + i] = data.OccurDate.ToShortDateString();
                            row["獎懲類別支數" + i] = str;
                            row["獎懲事由" + i] = data.Reason;

                            spstr1 = data.OccurDate.ToShortDateString();
                            spstr2 = str;
                            spstr3 = data.Reason;

                            i++;
                            ib++;
                        }
                        sbDisciplineRecord.AppendLine(spstr1 + " " + spstr2 + " " + spstr3);
                    }
                    row["獎懲明細"] = sbDisciplineRecord.ToString();
                }

                // 單值
                if (_SingleRecordDict.ContainsKey(StudID))
                {
                    foreach (UDTSingleRecordDef data in _SingleRecordDict[StudID])
                    {
                        switch (data.Key)
                        {
                            case "本人概況_血型": row["血型"] = data.Data; break;
                            case "本人概況_宗教": row["宗教"] = data.Data; break;
                            case "家庭狀況_監護人_姓名": row["監護人_姓名"] = data.Data; break;
                            case "家庭狀況_監護人_關係": row["監護人_關係"] = data.Data; break;
                            case "家庭狀況_監護人_通訊地址": row["監護人_通訊地址"] = data.Data; break;
                            case "家庭狀況_監護人_電話": row["監護人_電話"] = data.Data; break;
                            case "自傳_家中最了解我的人": row["家中最了解我的人"] = data.Data; break;
                            case "自傳_常指導我做功課的人": row["常指導我做功課的人"] = data.Data; break;
                            case "自傳_讀過且印象最深刻的課外書": row["讀過且印象最深刻的課外書"] = data.Data; break;
                            case "自傳_喜歡的人": row["喜歡的人"] = data.Data; break;
                            case "自傳_喜歡的人_因為": row["喜歡的人_因為"] = data.Data; break;
                            case "自傳_最要好的朋友": row["最要好的朋友"] = data.Data; break;
                            case "自傳_他是怎樣的人": row["他是怎樣的人"] = data.Data; break;
                            case "自傳_最喜歡做的事": row["最喜歡做的事"] = data.Data; break;
                            case "自傳_最喜歡做的事_因為":row["最喜歡做的事_因為"] = data.Data; break;
                            case "自傳_最不喜歡做的事": row["最不喜歡做的事"] = data.Data; break;
                            case "自傳_最不喜歡做的事_因為": row["最不喜歡做的事_因為"] = data.Data; break;
                            case "自傳_國中時的學校生活": row["國中時的學校生活"] = data.Data; break;
                            case "自傳_最快樂的回憶": row["最快樂的回憶"] = data.Data; break;
                            case "自傳_最痛苦的回憶": row["最痛苦的回憶"] = data.Data; break;
                            case "自傳_最足以描述自己的幾句話": row["最足以描述自己的幾句話"] = data.Data; break;

                            case "自我認識_需要改進的地方_1": row["自我認識_需要改進的地方_1"] = data.Data; break;
                            case "自我認識_優點_1": row["自我認識_優點_1"] = data.Data; break;
                            case "自我認識_個性_1": row["自我認識_個性_1"] = data.Data; break;
                            case "自我認識_需要改進的地方_2": row["自我認識_需要改進的地方_2"] = data.Data; break;
                            case "自我認識_優點_2": row["自我認識_優點_2"] = data.Data; break;
                            case "自我認識_個性_2": row["自我認識_個性_2"] = data.Data; break;
                            case "自我認識_需要改進的地方_3": row["自我認識_需要改進的地方_3"] = data.Data; break;
                            case "自我認識_優點_3": row["自我認識_優點_3"] = data.Data; break;
                            case "自我認識_個性_3": row["自我認識_個性_3"] = data.Data; break;
                            case "生活感想_內容3_1": row["生活感想_內容3_1"] = data.Data; break;
                            case "生活感想_內容2_1": row["生活感想_內容2_1"] = data.Data; break;
                            case "生活感想_內容1_1": row["生活感想_內容1_1"] = data.Data; break;
                            case "生活感想_內容3_2": row["生活感想_內容3_2"] = data.Data; break;
                            case "生活感想_內容2_2": row["生活感想_內容2_2"] = data.Data; break;
                            case "生活感想_內容1_2": row["生活感想_內容1_2"] = data.Data; break;
                            case "備註_備註": row["備註_備註"] = data.Data; break;
                        }
                    }
                }

                // 學年型
                if (_YearlyDataDict.ContainsKey(StudID))
                {
                    // 組合方式一
                    foreach(UDTYearlyDataDef data in _YearlyDataDict[StudID])
                    {
                        switch (data.Key)
                        {
                            case "家庭狀況_父母關係": row["父母關係"] = Utility.Counsel_Yearly_Parse1(data); break;
                            case "家庭狀況_家庭氣氛": row["家庭氣氛"] = Utility.Counsel_Yearly_Parse1(data); break;
                            case "家庭狀況_父親管教方式": row["父管教方式"] = Utility.Counsel_Yearly_Parse1(data); break;
                            case "家庭狀況_母親管教方式": row["母管教方式"] = Utility.Counsel_Yearly_Parse1(data); break;
                            case "家庭狀況_居住環境":row["居住環境"] = Utility.Counsel_Yearly_Parse1(data); break;
                            case "家庭狀況_本人住宿":row["本人住宿"] = Utility.Counsel_Yearly_Parse1(data); break;
                            case "家庭狀況_經濟狀況": row["經濟狀況"] = Utility.Counsel_Yearly_Parse1(data); break;
                            case "家庭狀況_每星期零用錢": row["零用金"] = Utility.Counsel_Yearly_Parse1(data); break;
                            case "家庭狀況_每星期零用錢(元)": row["零用金"] = Utility.Counsel_Yearly_Parse1(data); break;
                            case "家庭狀況_我覺得是否足夠":row["零用金是否足夠"] = Utility.Counsel_Yearly_Parse1(data); break;
                            case "學習狀況_特殊專長": row["特殊專長"] = Utility.Counsel_Yearly_Parse1(data); break;
                            case "學習狀況_休閒興趣": row["休閒興趣"] = Utility.Counsel_Yearly_Parse1(data); break;
                            case "學習狀況_最喜歡的學科": row["最喜歡的學科"] = Utility.Counsel_Yearly_Parse1(data); break;
                            case "學習狀況_最感困難的學科": row["最感困難的學科"] = Utility.Counsel_Yearly_Parse1(data); break;
                        }
                    }

                    // 組合方式二
                    foreach (UDTYearlyDataDef data in _YearlyDataDict[StudID])
                    {
                        switch (data.Key)
                        {
                            case "適應情形_生活習慣":
                                for( int i=1;i<=6;i++)
                                    row["生活習慣"+i] = Utility.Counsel_Yearly_Parse2(data, i); break;

                            case "適應情形_人際關係":
                                for (int i = 1; i <= 6; i++)
                                    row["人際關係"+i] = Utility.Counsel_Yearly_Parse2(data,i); break;
                            case "適應情形_外向行為":
                                for (int i = 1; i <= 6; i++)
                                row["外向行為"+i] = Utility.Counsel_Yearly_Parse2(data,i); break;
                            case "適應情形_內向行為":
                                for (int i = 1; i <= 6; i++)
                                row["內向行為"+i] = Utility.Counsel_Yearly_Parse2(data, i); break;
                            case "適應情形_學習動機":
                                for (int i = 1; i <= 6; i++)
                                row["學習動機"+i] = Utility.Counsel_Yearly_Parse2(data, i); break;
                            case "適應情形_服務熱忱":
                                for (int i = 1; i <= 6; i++)
                                row["服務熱忱"+i] = Utility.Counsel_Yearly_Parse2(data, i); break;
                            case "適應情形_人生態度":
                                for (int i = 1; i <= 6; i++)
                                row["人生態度"+i] = Utility.Counsel_Yearly_Parse2(data, i); break;
                        }
                    }
                }

                // 多值
                if (_MultipleRecordDict.ContainsKey(StudID))
                {
                    row["生理狀態"] = Utility.Counsel_Multiple_Parse(_MultipleRecordDict[StudID], "本人概況_生理缺陷");
                    row["特殊疾病"] = Utility.Counsel_Multiple_Parse(_MultipleRecordDict[StudID], "本人概況_曾患特殊疾病");

                    row["升學意願"] = Utility.Counsel_Multiple_Parse(_MultipleRecordDict[StudID], "畢業後計畫_升學意願");
                    row["就業意願"] = Utility.Counsel_Multiple_Parse(_MultipleRecordDict[StudID], "畢業後計畫_就業意願");
                    row["職訓種類"] = Utility.Counsel_Multiple_Parse(_MultipleRecordDict[StudID], "畢業後計畫_參加職業訓練");
                    row["受訓地區"] = Utility.Counsel_Multiple_Parse(_MultipleRecordDict[StudID], "畢業後計畫_受訓地區");
                }
                // 優先順序
                if (_PriorityDataDict.ContainsKey(StudID))
                {
                    foreach (UDTPriorityDataDef data in _PriorityDataDict[StudID])
                    {
                        switch (data.Key)
                        {
                            case "畢業後計畫_將來職業": row["職業意願"] = Utility.Counsel_PriorityData_Parse1(data); break;
                            case "畢業後計畫_就業地區": row["就業地區"] = Utility.Counsel_PriorityData_Parse1(data); break;
                        }
                    }
                }

                // 直系血親
                if (_RelativeDict.ContainsKey(StudID))
                {
                    int i = 1;
                    foreach (UDTRelativeDef data in _RelativeDict[StudID])
                    {
                        // 檢查料是否超過可合併欄位
                        ChechMapFieldName("家長親屬_稱謂", i);
                        ChechMapFieldName("家長親屬_姓名", i);
                        ChechMapFieldName("家長親屬_出生年", i);
                        ChechMapFieldName("家長親屬_存歿", i);
                        ChechMapFieldName("家長親屬_教育程度", i);
                        ChechMapFieldName("家長親屬_職業", i);
                        ChechMapFieldName("家長親屬_工作機構", i);
                        ChechMapFieldName("家長親屬_職稱", i);

                        row["家長親屬_稱謂" + i] = data.Title;
                        row["家長親屬_姓名" + i] = data.Name;
                        row["家長親屬_出生年" + i] = data.BirthYear;
                        row["家長親屬_存歿" + i]="存";
                        if (data.IsAlive.HasValue && data.IsAlive.Value == false)
                            row["家長親屬_存歿" + i] = "歿";
                        row["家長親屬_教育程度" + i] = data.EduDegree;
                        row["家長親屬_職業" + i] = data.Job;
                        row["家長親屬_工作機構" + i] = data.Institute;
                        row["家長親屬_職稱" + i] = data.JobTitle;
                        i++;
                    }
                }

                // 兄弟姊妹
                if (_SiblingDict.ContainsKey(StudID))
                {
                    int i = 1;
                    foreach (UDTSiblingDef data in _SiblingDict[StudID])
                    {
                        // 檢查料是否超過可合併欄位
                        ChechMapFieldName("兄弟姊妹_稱謂", i);
                        ChechMapFieldName("兄弟姊妹_姓名", i);
                        ChechMapFieldName("兄弟姊妹_出生年", i);
                        ChechMapFieldName("兄弟姊妹_畢肄業學校", i);

                        row["兄弟姊妹_稱謂" + i] = data.Title;
                        row["兄弟姊妹_姓名" + i] = data.Name;
                        row["兄弟姊妹_出生年" + i] = data.BirthYear;
                        row["兄弟姊妹_畢肄業學校" + i] = data.SchoolName;
                        i++;
                    }
                }

                // 學期型
                if (_SemesterDataDict.ContainsKey(StudID))
                {
                    foreach (UDTSemesterDataDef data in _SemesterDataDict[StudID])
                    {
                        switch (data.Key)
                        {
                            case "本人概況_身高":
                                for (int i = 1; i <= 6; i++)
                                    row["身高" + i] = Utility.Counsel_SemesterData_Parse1(data,i);break;
                            case "本人概況_體重":
                                for (int i = 1; i <= 6; i++)
                                    row["體重" + i] = Utility.Counsel_SemesterData_Parse1(data,i);break;
                        }
                    }
                }

                // 心理測驗
                if (_StudQuizDataDict.ContainsKey(StudID))
                {
                    int i = 1;
                    List<UDT_StudQuizDataDef> dataList = (from da in _StudQuizDataDict[StudID] orderby da.ImplementationDate select da).ToList();
                    foreach (UDT_StudQuizDataDef data in dataList)
                    {
                        // 檢查料是否超過可合併欄位
                        ChechMapFieldName("測驗名稱", i);
                        ChechMapFieldName("測驗日期", i);
                        ChechMapFieldName("測驗結果", i);

                        row["測驗名稱" + i] = "";
                        if (_QuizDefDict.ContainsKey(data.QuizID))
                            row["測驗名稱" + i] = _QuizDefDict[data.QuizID].QuizName;
                        if (data.ImplementationDate.HasValue)
                            row["測驗日期" + i] = data.ImplementationDate.Value.ToShortDateString();
                        else
                            row["測驗日期" + i] = "";

                        row["測驗結果" + i] = Utility.CounselStudQuizXmlParse1(data.Content);

                        i++;
                    }
                }

                // 晤談紀錄
                if (_CounselStudentInterviewRecordDict.ContainsKey(StudID))
                {
                    int i1 = 1;
                    List<UDT_CounselStudentInterviewRecordDef> dataList = (from da in _CounselStudentInterviewRecordDict[StudID] orderby da.InterviewDate select da).ToList();
                    foreach (UDT_CounselStudentInterviewRecordDef data in dataList)
                    {
                        // 檢查料是否超過可合併欄位
                        ChechMapFieldName("晤談紀錄日期", i1);
                        ChechMapFieldName("晤談紀錄對象", i1);
                        ChechMapFieldName("晤談紀錄方式", i1);
                        ChechMapFieldName("晤談紀錄內容要點", i1);
                        ChechMapFieldName("晤談紀錄記錄者姓名", i1);

                        row["晤談紀錄日期"+i1]=data.InterviewDate.Value.ToShortDateString();
                        row["晤談紀錄對象" + i1] = data.IntervieweeType;
                        row["晤談紀錄方式" + i1] = data.InterviewType;
                        row["晤談紀錄內容要點" + i1] = data.ContentDigest;
                        row["晤談紀錄記錄者姓名" + i1] = data.AuthorName;
                        i1++;
                    }

                }

                // 個案會議
                if (_CounselCaseMeetingRecordDict.ContainsKey(StudID))
                {
                    int i2 = 1;
                    List<UDT_CounselCaseMeetingRecordDef> dataList = (from da in _CounselCaseMeetingRecordDict[StudID] orderby da.MeetingDate select da).ToList();
                    foreach (UDT_CounselCaseMeetingRecordDef data in dataList)
                    {
                        // 檢查料是否超過可合併欄位
                        ChechMapFieldName("個案會議會議日期", i2);
                        ChechMapFieldName("個案會議會議事由", i2);
                        ChechMapFieldName("個案會議內容要點", i2);
                        ChechMapFieldName("個案會議記錄者姓名", i2);

                        row["個案會議會議日期" + i2] = data.MeetingDate.Value.ToShortDateString();
                        row["個案會議會議事由" + i2] = data.MeetingCause;
                        row["個案會議內容要點" + 2] = data.ContentDigest;
                        row["個案會議記錄者姓名" + i2] = data.AuthorName;

                        i2++;
                    }
                }

                // 優先關懷
                if (_CounselCareRecordDict.ContainsKey(StudID))
                {
                    int i3 = 1;
                    List<UDT_CounselCareRecordDef> dataList = (from da in _CounselCareRecordDict[StudID] orderby da.FileDate select da).ToList();
                    foreach (UDT_CounselCareRecordDef data in dataList)
                    {
                        // 檢查料是否超過可合併欄位
                        ChechMapFieldName("優先關懷立案日期", i3);
                        ChechMapFieldName("優先關懷個案類別", i3);
                        ChechMapFieldName("優先關懷個案來源", i3);
                        ChechMapFieldName("優先關懷記錄者姓名", i3);

                        row["優先關懷立案日期" + i3] = data.FileDate.Value.ToShortDateString();
                        row["優先關懷個案類別" + i3] = data.CaseCategory;
                        row["優先關懷個案來源" + i3] = data.CaseOrigin;
                        row["優先關懷記錄者姓名" + i3] = data.AuthorName;
                        i3++;
                    }
                }

                _dtTable.Rows.Add(row);
            }
            Document document = new Document();
            document = docTemplae;

            doc.Sections.Add(doc.ImportNode(document.Sections[0], true));

            doc.MailMerge.MergeField += new Aspose.Words.Reporting.MergeFieldEventHandler(MailMerge_MergeField);
            doc.MailMerge.Execute(_dtTable);
            doc.MailMerge.RemoveEmptyParagraphs = true;
            doc.MailMerge.DeleteFields();
            _bgWorker.ReportProgress(95);
            e.Result = doc;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 轉換晤談資料至AB表輔導資料
        /// </summary>
        /// <param name="StudentIDList"></param>
        /// <returns></returns>
        public static Dictionary<string, List<DAO.AB_RptCounselData>> ParseInterViewDataToABRptData(List<string> StudentIDList)
        {
            Dictionary<string, List<DAO.AB_RptCounselData>> retVal = new Dictionary<string, List<DAO.AB_RptCounselData>>();
            if (StudentIDList.Count > 0)
            {
                DAO.UDTTransfer _UDTTransfer = new DAO.UDTTransfer();
                // 依學生ID取得晤談紀錄
                List<DAO.UDT_CounselStudentInterviewRecordDef> _CounselCareRecordList = _UDTTransfer.GetCounselStudentInterviewRecordByStudentIDList(StudentIDList);
                 // 取得教師ID與名稱對照
                Dictionary<int, string> TeacherNameDict = Utility.GetTeacherIDNameDict();

                Dictionary<string, string> item_AttendessDict = new Dictionary<string, string>();
                Dictionary<string, string> item_CounselTypeDict = new Dictionary<string, string>();
                Dictionary<string, string> item_CounselTypeKindDict = new Dictionary<string, string>();

                foreach (string studId in StudentIDList)
                {
                    int sid = int.Parse(studId);
                    List<DAO.AB_RptCounselData> studData = new List<DAO.AB_RptCounselData>();
                    foreach (DAO.UDT_CounselStudentInterviewRecordDef csir in (from data in _CounselCareRecordList where data.StudentID==sid orderby data.InterviewDate select data))
                    {
                        DAO.AB_RptCounselData data = new DAO.AB_RptCounselData();
                        // 取得 XML 解析後
                        item_AttendessDict = GetConvertCounselXMLVal_Attendees(csir.Attendees);
                        item_CounselTypeDict = GetConvertCounselXMLVal_CounselType(csir.CounselType);
                        item_CounselTypeKindDict = GetConvertCounselXMLVal_CounselTypeKind(csir.CounselTypeKind);

                        if(csir.InterviewDate.HasValue)
                            data.DataDict.Add("晤談日期",csir.InterviewDate.Value.ToShortDateString());

                        data.DataDict.Add("晤談對象", csir.IntervieweeType);
                        data.DataDict.Add("晤談事由", csir.Cause);
                        data.DataDict.Add("記錄者帳號", csir.AuthorID);

                        data.OtherDataList = AB_Counset_AddString("晤談編號", csir.InterviewNo, data.OtherDataList);
                        
                        if(TeacherNameDict.ContainsKey(csir.TeacherID))
                            data.OtherDataList = AB_Counset_AddString("晤談老師", TeacherNameDict[csir.TeacherID], data.OtherDataList);
                        
                        data.OtherDataList = AB_Counset_AddString("晤談方式", csir.InterviewType, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("晤談時間", csir.InterviewTime, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("晤談地點", csir.Place, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("內容要點", csir.ContentDigest, data.OtherDataList);

                        data.OtherDataList.AddRange(AB_Counsel_Item_Add(item_AttendessDict));

                        data.OtherDataList.AddRange(AB_Counsel_Item_Add(item_CounselTypeDict));

                        data.OtherDataList.AddRange(AB_Counsel_Item_Add(item_CounselTypeKindDict));

                        studData.Add(data);
                    }
                    retVal.Add(studId, studData);
                }
            }
            return retVal;        
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 轉換優先關懷資料至AB表輔導資料
        /// </summary>
        /// <param name="StudentIDList"></param>
        /// <returns></returns>
        public static Dictionary<string, List<DAO.AB_RptCounselData>> ParseCareRecordToABRptData(List<string> StudentIDList)
        {
            Dictionary<string, List<DAO.AB_RptCounselData>> retVal = new Dictionary<string, List<DAO.AB_RptCounselData>>();
            if (StudentIDList.Count > 0)
            {
                DAO.UDTTransfer _UDTTransfer = new DAO.UDTTransfer();
                List<DAO.UDT_CounselCareRecordDef> _CounselCareRecordList = _UDTTransfer.GetCareRecordsByStudentIDList(StudentIDList);
                                
                foreach (string studId in StudentIDList)
                {
                    int sid = int.Parse(studId);
                    List<DAO.AB_RptCounselData> studData = new List<DAO.AB_RptCounselData>();
                    foreach (DAO.UDT_CounselCareRecordDef ccrd in (from data in _CounselCareRecordList where data.StudentID== sid orderby data.FileDate select data))
                    {
                        DAO.AB_RptCounselData data = new DAO.AB_RptCounselData();
                        if (ccrd.FileDate.HasValue)
                            data.DataDict.Add("立案日期", ccrd.FileDate.Value.ToShortDateString());
                        
                        data.StudentID = studId;
                        
                        data.DataDict.Add("個案類別", ccrd.CaseCategory);
                        data.DataDict.Add("記錄者帳號",ccrd.AuthorID);

                        data.OtherDataList = AB_Counset_AddString("代號", ccrd.CodeName, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("個案類別備註", ccrd.CaseCategoryRemark, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("個案來源", ccrd.CaseOrigin, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("個案來源備註", ccrd.CaseOriginRemark, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("優勢能力及財力", ccrd.Superiority, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("弱勢能力及財力", ccrd.Weakness, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("輔導人員輔導目標", ccrd.CounselGoal, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("校外協輔機構", ccrd.OtherInstitute, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("輔導人員輔導方式", ccrd.CounselType, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("協同輔導人員協助導師事項", ccrd.AssistedMatter, data.OtherDataList);

                        studData.Add(data);
                    }

                    retVal.Add(studId, studData);
                }
            }
            return retVal;        
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 轉換個案會議資料至AB表輔導資料
        /// </summary>
        /// <param name="StudentIDList"></param>
        /// <returns></returns>
        public static Dictionary<string,List<DAO.AB_RptCounselData>> ParseCaseMeetingRecordToABRptData(List<string> StudentIDList)
        { 
            Dictionary<string,List<DAO.AB_RptCounselData>> retVal = new Dictionary<string,List<DAO.AB_RptCounselData>> ();
            if (StudentIDList.Count > 0)
            {
                DAO.UDTTransfer _UDTTransfer = new DAO.UDTTransfer();
                List<DAO.UDT_CounselCaseMeetingRecordDef> CounselCaseMeetingRecordList = _UDTTransfer.GetCaseMeetingRecordListByStudentIDList(StudentIDList);
                // 取得教師ID與名稱對照
                Dictionary<int, string> TeacherNameDict = Utility.GetTeacherIDNameDict();
                // 參與人員
                Dictionary<string, string> item_AttendessDict = new Dictionary<string, string>();
                // 輔導方式
                Dictionary<string, string> item_CounselTypeDict = new Dictionary<string, string>();
                // 輔導歸類
                Dictionary<string, string> item_CounselTypeKindDict = new Dictionary<string, string>();

                // 解析並排序
                foreach (string studId in StudentIDList)
                {
                    int sid=int.Parse(studId);
                    List<DAO.AB_RptCounselData> studData = new List<DAO.AB_RptCounselData> ();
                    foreach (DAO.UDT_CounselCaseMeetingRecordDef ccmrd in (from data in CounselCaseMeetingRecordList where data.StudentID == sid orderby data.MeetingDate select data ))
                    {
                        DAO.AB_RptCounselData data = new DAO.AB_RptCounselData ();
                        // 取得 XML 解析後
                        item_AttendessDict = GetConvertCounselXMLVal_Attendees(ccmrd.Attendees);
                        item_CounselTypeDict = GetConvertCounselXMLVal_CounselType(ccmrd.CounselType);
                        item_CounselTypeKindDict = GetConvertCounselXMLVal_CounselTypeKind(ccmrd.CounselTypeKind);

                        data.StudentID = studId;
                        
                        if(ccmrd.MeetingDate.HasValue)
                            data.DataDict.Add("會議日期", ccmrd.MeetingDate.Value.ToShortDateString());

                        data.DataDict.Add("會議事由", ccmrd.MeetingCause);
                        data.DataDict.Add("記錄者帳號", ccmrd.AuthorID);                      

                        // 記錄其它
                        data.OtherDataList = AB_Counset_AddString("個案編號", ccmrd.CaseNo, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("內容要點", ccmrd.ContentDigest, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("會議時間", ccmrd.MeetigTime, data.OtherDataList);
                        data.OtherDataList = AB_Counset_AddString("晤談地點", ccmrd.Place, data.OtherDataList);
                        if (TeacherNameDict.ContainsKey(ccmrd.CounselTeacherID))
                            data.OtherDataList=AB_Counset_AddString("晤談老師", TeacherNameDict[ccmrd.CounselTeacherID],data.OtherDataList);
                        
                        data.OtherDataList.AddRange(AB_Counsel_Item_Add(item_AttendessDict));

                        data.OtherDataList.AddRange(AB_Counsel_Item_Add(item_CounselTypeDict));

                        data.OtherDataList.AddRange(AB_Counsel_Item_Add(item_CounselTypeKindDict));
                        
                        studData.Add(data);                       
                    }
                    retVal.Add(studId,studData);
                }
            }
            return retVal;        
        }