示例#1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lvCareRecord.SelectedItems.Count == 1)
            {
                DAO.UDT_CounselCareRecordDef careRec = lvCareRecord.SelectedItems[0].Tag as DAO.UDT_CounselCareRecordDef;
                if (careRec != null)
                {
                    DAO.LogTransfer        logTransfer = new DAO.LogTransfer();
                    K12.Data.StudentRecord studRec     = K12.Data.Student.SelectByID(PrimaryKey);
                    StringBuilder          logData     = new StringBuilder();
                    logData.AppendLine("刪除" + Utility.ConvertString1(studRec));

                    if (FISCA.Presentation.Controls.MsgBox.Show("請問是否確定是刪除優先關懷紀錄?", "刪除優先關懷紀錄", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        // log
                        logData.AppendFormat("代號:" + careRec.CodeName);
                        if (careRec.FileDate.HasValue)
                        {
                            logData.AppendLine("立案日期:" + careRec.FileDate.Value.ToShortDateString());
                        }

                        logData.AppendLine("個案類別:" + careRec.CaseCategory);
                        logData.AppendLine("個案類別備註:" + careRec.CaseCategoryRemark);
                        logData.AppendLine("個案來源:" + careRec.CaseOrigin);
                        logData.AppendLine("個案來源備註:" + careRec.CaseOriginRemark);
                        logData.AppendLine("優勢能力及財力:" + careRec.Superiority);
                        logData.AppendLine("弱勢能力及阻力:" + careRec.Weakness);
                        logData.AppendLine("輔導人員輔導目標:" + careRec.CounselGoal);
                        logData.AppendLine("校外協輔機構:" + careRec.OtherInstitute);
                        logData.AppendLine("輔導人員輔導方式:" + careRec.CounselType);
                        logData.AppendLine("協同輔導人員協助導師事項:" + careRec.AssistedMatter);
                        logData.AppendLine("記錄者:" + careRec.AuthorID);
                        logData.AppendLine("記錄者姓名:" + careRec.AuthorName);

                        _UDTTransfer.DeleteCareRecord(careRec);

                        logTransfer.SaveLog("學生.輔導優先關懷-刪除", "刪除", "student", PrimaryKey, logData);

                        _BGRun();
                    }
                }
            }
            else
            {
                FISCA.Presentation.Controls.MsgBox.Show("請選擇資料.");
            }
        }
        private void btnDel_Click(object sender, EventArgs e)
        {
            // 刪除
            if (lvStudQuizData.SelectedItems.Count == 1)
            {
                DAO.UDT_StudQuizDataDef sqd = lvStudQuizData.SelectedItems[0].Tag as DAO.UDT_StudQuizDataDef;
                if (sqd != null)
                {
                    if (FISCA.Presentation.Controls.MsgBox.Show("請問刪除測驗資料", "刪除測驗資料", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        List <DAO.UDT_StudQuizDataDef> delData = new List <DAO.UDT_StudQuizDataDef> ();
                        delData.Add(sqd);
                        K12.Data.StudentRecord rec     = K12.Data.Student.SelectByID(PrimaryKey);
                        StringBuilder          logData = new StringBuilder();
                        logData.AppendLine("刪除" + Utility.ConvertString1(rec));
                        logData.AppendLine("測驗名稱「 " + lvStudQuizData.SelectedItems[0].SubItems[0].Text + " 」");
                        if (sqd.ImplementationDate.HasValue)
                        {
                            logData.AppendLine("實施日期:" + sqd.ImplementationDate.Value.ToShortDateString());
                        }
                        if (sqd.AnalysisDate.HasValue)
                        {
                            logData.AppendLine("解析日期:" + sqd.AnalysisDate.Value.ToShortDateString());
                        }
                        XElement elmContent = Utility.ConvertStringToXelm1(sqd.Content);
                        if (elmContent != null)
                        {
                            foreach (XElement elm in elmContent.Elements("Item"))
                            {
                                if (elm.Attribute("name") != null && elm.Attribute("value") != null)
                                {
                                    logData.AppendLine("項目名稱:" + elm.Attribute("name").Value + " , 測驗結果:" + elm.Attribute("value").Value);
                                }
                            }
                        }

                        _UDTTransfer.DeleteStudQuizDataLlist(delData);

                        // log
                        _LogTransfer.SaveLog("學生.輔導相關測驗-刪除", "刪除", "student", PrimaryKey, logData);

                        _BGRun();
                    }
                }
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lvCareRecord.SelectedItems.Count == 1)
            {

                DAO.UDT_CounselCareRecordDef careRec = lvCareRecord.SelectedItems[0].Tag as DAO.UDT_CounselCareRecordDef;
                if (careRec != null)
                {
                    DAO.LogTransfer logTransfer = new DAO.LogTransfer();
                    K12.Data.StudentRecord studRec = K12.Data.Student.SelectByID(PrimaryKey);
                    StringBuilder logData = new StringBuilder();
                    logData.AppendLine("刪除" + Utility.ConvertString1(studRec));

                    if (FISCA.Presentation.Controls.MsgBox.Show("請問是否確定是刪除優先關懷紀錄?", "刪除優先關懷紀錄", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        // log
                        logData.AppendFormat("代號:" + careRec.CodeName);
                        if (careRec.FileDate.HasValue)
                            logData.AppendLine("立案日期:"+careRec.FileDate.Value.ToShortDateString());

                        logData.AppendLine("個案類別:" + careRec.CaseCategory);
                        logData.AppendLine("個案類別備註:" + careRec.CaseCategoryRemark);
                        logData.AppendLine("個案來源:" + careRec.CaseOrigin);
                        logData.AppendLine("個案來源備註:" + careRec.CaseOriginRemark);
                        logData.AppendLine("優勢能力及財力:" + careRec.Superiority);
                        logData.AppendLine("弱勢能力及阻力:" + careRec.Weakness);
                        logData.AppendLine("輔導人員輔導目標:" + careRec.CounselGoal);
                        logData.AppendLine("校外協輔機構:" + careRec.OtherInstitute);
                        logData.AppendLine("輔導人員輔導方式:" + careRec.CounselType);
                        logData.AppendLine("協同輔導人員協助導師事項:" + careRec.AssistedMatter);
                        logData.AppendLine("記錄者:" + careRec.AuthorID);
                        logData.AppendLine("記錄者姓名:" + careRec.AuthorName);

                        _UDTTransfer.DeleteCareRecord(careRec);

                        logTransfer.SaveLog("學生.輔導優先關懷-刪除", "刪除", "student", PrimaryKey, logData);

                        _BGRun();
                    }
                }
            }
            else
                FISCA.Presentation.Controls.MsgBox.Show("請選擇資料.");
        }
        public override void InitializeExport(SmartSchool.API.PlugIn.Export.ExportWizard wizard)
        {
            wizard.ExportableFields.AddRange(ExportItemList);
            wizard.ExportPackage += delegate(object sender, SmartSchool.API.PlugIn.Export.ExportPackageEventArgs e)
               {
               // 依學生ID取得晤談紀錄
                List<DAO.UDT_CounselStudentInterviewRecordDef> _StudentInterviewRecordList = _UDTTransfer.GetCounselStudentInterviewRecordByStudentIDList(e.List);

                // 取得教師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>();

                // 學生ID List
                List<int> studIdList = (from data in _StudentInterviewRecordList select data.StudentID).ToList();

                // 取得學生名稱log 用
                Dictionary<string, string> StudentNameDict = new Dictionary<string, string>();
                foreach (KeyValuePair<int, string> data in Utility.GetConvertStringDict1fromDB(studIdList))
                    StudentNameDict.Add(data.Key.ToString(), data.Value);

                // 記錄匯出 log 細項用
                Dictionary<string, StringBuilder> logData = new Dictionary<string, StringBuilder>();

                // 匯出總筆數
                int totalCount = 0;

                foreach (DAO.UDT_CounselStudentInterviewRecordDef csir in _StudentInterviewRecordList)
                {

                    // 取得 XML 解析後
                    item_AttendessDict = Utility.GetConvertCounselXMLVal_Attendees(csir.Attendees);
                    item_CounselTypeDict = Utility.GetConvertCounselXMLVal_CounselType(csir.CounselType);
                    item_CounselTypeKindDict = Utility.GetConvertCounselXMLVal_CounselTypeKind(csir.CounselTypeKind);

                    RowData row = new RowData();
                    row.ID = csir.StudentID.ToString();
                     foreach (string field in e.ExportFields)
                     {
                         if (wizard.ExportableFields.Contains(field))
                         {
                             // 參與人員
                             if (item_AttendessDict.ContainsKey(field))
                                 row.Add(field, item_AttendessDict[field]);

                             // 輔導方式
                             if (item_CounselTypeDict.ContainsKey(field))
                                 row.Add(field, item_CounselTypeDict[field]);

                             // 輔導歸類
                             if (item_CounselTypeKindDict.ContainsKey(field))
                                 row.Add(field, item_CounselTypeKindDict[field]);

                             switch (field)
                             {
                                 case "晤談編號":
                                     row.Add(field, csir.InterviewNo);
                                     break;
                                 case "晤談老師":
                                     // 需轉換
                                   if(TeacherNameDict.ContainsKey(csir.TeacherID))
                                       row.Add(field, TeacherNameDict[csir.TeacherID]);
                                     break;
                                 case "晤談方式":
                                     row.Add(field, csir.InterviewType);
                                     break;
                                 case "晤談對象":
                                     row.Add(field, csir.IntervieweeType);
                                     break;
                                 case "日期":
                                     if(csir.InterviewDate.HasValue )
                                        row.Add(field, csir.InterviewDate.Value.ToShortDateString());
                                     break;
                                 case "時間":
                                     row.Add(field, csir.InterviewTime);
                                     break;
                                 case "地點":
                                     row.Add(field, csir.Place);
                                     break;
                                 case "晤談事由":
                                     row.Add(field, csir.Cause);
                                     break;
                                 case "參與人員":
                                     // 解析 XML
                                     row.Add(field,Utility.AttendeesXMLToString(csir.Attendees));
                                     break;
                                 case "輔導方式":
                                     // 解析 XML
                                     row.Add(field, Utility.CounselTypeXMLToString(csir.CounselType));
                                     break;
                                 case "輔導歸類":
                                     // 解析 XML
                                     row.Add(field, Utility.CounselTypeKindXMLToString(csir.CounselTypeKind));
                                     break;
                                 case "內容要點":
                                     row.Add(field, csir.ContentDigest);
                                     break;

                                 case "記錄者":
                                     row.Add(field, csir.AuthorID);
                                     break;

                                 case "記錄者姓名":
                                     row.Add(field, csir.AuthorName);
                                     break;

                                 case "狀態":
                                     row.Add(field, csir.StudentStatus);
                                     break;

                             }
                         }
                     }
                     e.Items.Add(row);
                }
                // 處理 log 細項
                foreach (RowData rd in e.Items)
                {
                    // 收集 log
                    StringBuilder sb = new StringBuilder();
                    if (StudentNameDict.ContainsKey(rd.ID))
                        sb.AppendLine(StudentNameDict[rd.ID]);
                    sb.AppendLine(this.Text);
                    foreach (KeyValuePair<string, string> data in rd)
                        sb.AppendLine(data.Key + ":" + data.Value);

                    // 加入 log
                    if (logData.ContainsKey(rd.ID))
                    {
                        sb.AppendLine();
                        logData[rd.ID].AppendLine(sb.ToString());
                    }
                    else
                        logData.Add(rd.ID, sb);
                }

                // 寫入 log
                DAO.LogTransfer log = new DAO.LogTransfer();
                foreach (KeyValuePair<string, StringBuilder> data in logData)
                    log.SaveLog("輔導系統." + this.Text, "匯出", "student", data.Key, data.Value);

                StringBuilder sbT = new StringBuilder();
                sbT.AppendLine(this.Text);
                sbT.AppendLine("總共匯出" + logData.Keys.Count + "位學生 , 共" + totalCount + "筆");
                sbT.AppendLine("匯出學生名單..");
                foreach (KeyValuePair<string, string> data in StudentNameDict)
                    if (logData.ContainsKey(data.Key))
                        sbT.AppendLine(data.Value);

                log.SaveLog("輔導系統." + this.Text, "匯出", "student", "", sbT);
               };
        }
示例#5
0
        public override string Import(List <IRowStream> Rows)
        {
            List <DAO.UDT_CounselCaseMeetingRecordDef> InsertData = new List <DAO.UDT_CounselCaseMeetingRecordDef>();
            List <DAO.UDT_CounselCaseMeetingRecordDef> UpdateData = new List <DAO.UDT_CounselCaseMeetingRecordDef>();
            List <DAO.UDT_CounselCaseMeetingRecordDef> HasData    = new List <DAO.UDT_CounselCaseMeetingRecordDef>();

            // 取得教師帳號比對用
            Dictionary <string, string> teacherNameLoginIDDict = Utility.GetTeacherNameLoginIDStatus1();

            // -- 處理 log
            Dictionary <string, StringBuilder> LogData = new Dictionary <string, StringBuilder>();
            // 學生ID List
            List <int> studIdList = new List <int>();

            foreach (IRowStream ir in Rows)
            {
                int i;
                if (ir.Contains("學號") && ir.Contains("狀態"))
                {
                    if (int.TryParse(Utility.GetStudentID(ir.GetValue("學號"), ir.GetValue("狀態")).ToString(), out i))
                    {
                        studIdList.Add(i);
                    }
                }
            }
            // 取得學生名稱log 用
            Dictionary <string, string> StudentNameDict = new Dictionary <string, string>();

            foreach (KeyValuePair <int, string> data in Utility.GetConvertStringDict1fromDB(studIdList))
            {
                StudentNameDict.Add(data.Key.ToString(), data.Value);
            }


            DAO.LogTransfer _LogTransfer = new DAO.LogTransfer();
            int             TotalCount = 0, NewIdx = 0;
            List <string>   StudentIDList = new List <string> ();

            // 取得學生狀態對應
            foreach (IRowStream ir in Rows)
            {
                TotalCount++;
                this.ImportProgress = TotalCount;
                if (ir.Contains("學號") && ir.Contains("狀態"))
                {
                    StudentIDList.Add(Utility.GetStudentID(ir.GetValue("學號"), ir.GetValue("狀態")).ToString());
                }
            }
            // 已有資料
            HasData = _UDTTransfer.GetCaseMeetingRecordListByStudentIDList(StudentIDList);


            foreach (IRowStream ir in Rows)
            {
                DAO.UDT_CounselCaseMeetingRecordDef CounselCaseMeetingRecord = null;
                int sid = 0;
                if (ir.Contains("學號") && ir.Contains("狀態"))
                {
                    string key = ir.GetValue("學號") + "_";
                    if (Global._StudentStatusDBDict.ContainsKey(ir.GetValue("狀態")))
                    {
                        sid = Utility.GetStudentID(ir.GetValue("學號"), ir.GetValue("狀態"));
                    }

                    DateTime dt;
                    // 當同一位學生有相同會議日期與會議事由,當作是更新,否則新增
                    if (DateTime.TryParse(ir.GetValue("會議日期"), out dt))
                    {
                        foreach (DAO.UDT_CounselCaseMeetingRecordDef rec in HasData.Where(x => x.StudentID == sid))
                        {
                            if (rec.MeetingDate.HasValue)
                            {
                                if (rec.MeetingDate.Value.ToShortDateString() == dt.ToShortDateString())
                                {
                                    if (rec.MeetingCause == ir.GetValue("會議事由"))
                                    {
                                        CounselCaseMeetingRecord = rec;
                                    }
                                }
                            }
                        }
                    }

                    bool isNew = false;
                    if (CounselCaseMeetingRecord == null)
                    {
                        CounselCaseMeetingRecord = new DAO.UDT_CounselCaseMeetingRecordDef();
                        isNew = true;
                        NewIdx++;
                    }
                    string StudID    = sid.ToString();
                    string insertKey = "A" + NewIdx;

                    // 學生編號
                    CounselCaseMeetingRecord.StudentID = sid;

                    // 會議日期
                    if (isNew)
                    {
                        _LogTransfer.AddBatchInsertLog(StudID, insertKey, "會議日期", dt.ToShortDateString());
                    }
                    else
                    {
                        _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "會議日期", CounselCaseMeetingRecord.MeetingDate.Value.ToShortDateString(), dt.ToShortDateString());
                    }
                    CounselCaseMeetingRecord.MeetingDate = dt;

                    // 晤談老師
                    if (Global._AllTeacherNameIdDictTemp.ContainsKey(ir.GetValue("晤談老師")))
                    {
                        CounselCaseMeetingRecord.CounselTeacherID = Global._AllTeacherNameIdDictTemp[ir.GetValue("晤談老師")];
                    }

                    if (ir.Contains("個案編號"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "個案編號", ir.GetValue("個案編號"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "個案編號", CounselCaseMeetingRecord.CaseNo, ir.GetValue("個案編號"));
                        }
                        CounselCaseMeetingRecord.CaseNo = ir.GetValue("個案編號");
                    }
                    if (ir.Contains("會議時間"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "會議時間", ir.GetValue("會議時間"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "會議時間", CounselCaseMeetingRecord.MeetigTime, ir.GetValue("會議時間"));
                        }
                        CounselCaseMeetingRecord.MeetigTime = ir.GetValue("會議時間");
                    }

                    if (ir.Contains("會議地點"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "會議地點", ir.GetValue("會議地點"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "會議地點", CounselCaseMeetingRecord.CaseNo, ir.GetValue("會議地點"));
                        }
                        CounselCaseMeetingRecord.Place = ir.GetValue("會議地點");
                    }

                    if (ir.Contains("會議事由"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "會議事由", ir.GetValue("會議事由"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "會議事由", CounselCaseMeetingRecord.MeetingCause, ir.GetValue("會議事由"));
                        }

                        CounselCaseMeetingRecord.MeetingCause = ir.GetValue("會議事由");
                    }


                    StringBuilder sb1 = new StringBuilder();
                    if (ir.Contains("參與人員:學生"))
                    {
                        if (ir.GetValue("參與人員:學生") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "學生");
                            sb1.Append(elm.ToString());

                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:學生", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:學生", "", "1");
                            }
                        }
                    }

                    if (ir.Contains("參與人員:家長"))
                    {
                        if (ir.GetValue("參與人員:家長") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "家長");
                            sb1.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:家長", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:家長", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("參與人員:專家"))
                    {
                        if (ir.GetValue("參與人員:專家") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "專家");
                            sb1.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:專家", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:專家", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("參與人員:醫師"))
                    {
                        if (ir.GetValue("參與人員:醫師") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "醫師");
                            sb1.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:醫師", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:醫師", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("參與人員:社工人員"))
                    {
                        if (ir.GetValue("參與人員:社工人員") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "社工人員");
                            sb1.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:社工人員", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:社工人員", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("參與人員:導師"))
                    {
                        if (ir.GetValue("參與人員:導師") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "導師");
                            sb1.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:導師", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:導師", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("參與人員:教官"))
                    {
                        if (ir.GetValue("參與人員:教官") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "教官");
                            sb1.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:教官", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:教官", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("參與人員:輔導老師"))
                    {
                        if (ir.GetValue("參與人員:輔導老師") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "輔導老師");
                            sb1.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:輔導老師", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:輔導老師", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("參與人員:任課老師"))
                    {
                        if (ir.GetValue("參與人員:任課老師") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "任課老師");
                            sb1.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:任課老師", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:任課老師", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("參與人員:其它"))
                    {
                        if (ir.GetValue("參與人員:其它") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "其它");
                            if (ir.Contains("參與人員:其它備註"))
                            {
                                elm.SetAttributeValue("remark", ir.GetValue("參與人員:其它備註"));
                            }
                            sb1.Append(elm.ToString());

                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:其它", "1");
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:其它備註", ir.GetValue("參與人員:其它備註"));
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:其它", "", "1");
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:其它", "", ir.GetValue("參與人員:其它備註"));
                            }
                        }
                    }

                    CounselCaseMeetingRecord.Attendees = sb1.ToString();

                    StringBuilder sb2 = new StringBuilder();

                    if (ir.Contains("輔導方式:暫時結案"))
                    {
                        if (ir.GetValue("輔導方式:暫時結案") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "暫時結案");
                            sb2.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:暫時結案", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:暫時結案", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("輔導方式:專案輔導"))
                    {
                        if (ir.GetValue("輔導方式:專案輔導") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "專案輔導");
                            sb2.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:專案輔導", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:專案輔導", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("輔導方式:導師輔導"))
                    {
                        if (ir.GetValue("輔導方式:導師輔導") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "導師輔導");
                            sb2.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:導師輔導", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:導師輔導", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("輔導方式:轉介"))
                    {
                        if (ir.GetValue("輔導方式:轉介") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "轉介");

                            if (ir.Contains("輔導方式:轉介備註"))
                            {
                                elm.SetAttributeValue("remark", ir.GetValue("輔導方式:轉介備註"));
                            }
                            sb2.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:轉介", "1");
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:轉介備註", ir.GetValue("輔導方式:轉介備註"));
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:轉介備註", "", ir.GetValue("輔導方式:轉介備註"));
                            }
                        }
                    }


                    if (ir.Contains("輔導方式:就醫"))
                    {
                        if (ir.GetValue("輔導方式:就醫") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "就醫");

                            if (ir.Contains("輔導方式:就醫備註"))
                            {
                                elm.SetAttributeValue("remark", ir.GetValue("輔導方式:就醫備註"));
                            }
                            sb2.Append(elm.ToString());

                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:就醫", "1");
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:就醫備註", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:就醫", "", "1");
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:就醫備註", "", ir.GetValue("輔導方式:就醫備註"));
                            }
                        }
                    }


                    if (ir.Contains("輔導方式:其它"))
                    {
                        if (ir.GetValue("輔導方式:其它") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "其它");


                            if (ir.Contains("輔導方式:其它備註"))
                            {
                                elm.SetAttributeValue("remark", ir.GetValue("輔導方式:其它備註"));
                            }
                            sb2.Append(elm.ToString());

                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:其它", "1");
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:其它備註", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:其它", "", "1");
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:其它備註", "", ir.GetValue("輔導方式:其它備註"));
                            }
                        }
                    }

                    CounselCaseMeetingRecord.CounselType = sb2.ToString();

                    StringBuilder sb3 = new StringBuilder();

                    if (ir.Contains("輔導歸類:違規"))
                    {
                        if (ir.GetValue("輔導歸類:違規") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "違規");
                            sb3.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:違規", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:違規", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("輔導歸類:遲曠"))
                    {
                        if (ir.GetValue("輔導歸類:遲曠") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "遲曠");
                            sb3.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:遲曠", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:遲曠", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("輔導歸類:學習"))
                    {
                        if (ir.GetValue("輔導歸類:學習") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "學習");
                            sb3.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:學習", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:學習", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("輔導歸類:生涯"))
                    {
                        if (ir.GetValue("輔導歸類:生涯") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "生涯");
                            sb3.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:生涯", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:生涯", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("輔導歸類:人"))
                    {
                        if (ir.GetValue("輔導歸類:人") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "人");
                            sb3.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:人", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:人", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("輔導歸類:休退轉"))
                    {
                        if (ir.GetValue("輔導歸類:休退轉") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "休退轉");
                            sb3.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:休退轉", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:休退轉", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("輔導歸類:家庭"))
                    {
                        if (ir.GetValue("輔導歸類:家庭") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "家庭");
                            sb3.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:家庭", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:家庭", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("輔導歸類:師生"))
                    {
                        if (ir.GetValue("輔導歸類:師生") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "師生");
                            sb3.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:師生", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:師生", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("輔導歸類:情感"))
                    {
                        if (ir.GetValue("輔導歸類:情感") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "情感");
                            sb3.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:情感", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:情感", "", "1");
                            }
                        }
                    }
                    if (ir.Contains("輔導歸類:精神"))
                    {
                        if (ir.GetValue("輔導歸類:精神") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "精神");
                            sb3.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:精神", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:精神", "", "1");
                            }
                        }
                    }

                    if (ir.Contains("輔導歸類:其它"))
                    {
                        if (ir.GetValue("輔導歸類:其它") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "其它");
                            if (ir.Contains("輔導歸類:其它備註"))
                            {
                                elm.SetAttributeValue("remark", ir.GetValue("輔導歸類:其它備註"));
                            }
                            sb3.Append(elm.ToString());
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:其它", "1");
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:其它備註", ir.GetValue("輔導歸類:其它備註"));
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:其它", "", "1");
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:其它備註", "", ir.GetValue("輔導歸類:其它備註"));
                            }
                        }
                    }

                    CounselCaseMeetingRecord.CounselTypeKind = sb3.ToString();

                    if (ir.Contains("內容要點"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "內容要點", ir.GetValue("內容要點"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "內容要點", CounselCaseMeetingRecord.ContentDigest, ir.GetValue("內容要點"));
                        }
                        CounselCaseMeetingRecord.ContentDigest = ir.GetValue("內容要點");
                    }
                    if (ir.Contains("記錄者姓名"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "記錄者姓名", ir.GetValue("記錄者姓名"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "記錄者姓名", CounselCaseMeetingRecord.AuthorName, ir.GetValue("記錄者姓名"));
                        }
                        CounselCaseMeetingRecord.AuthorName = ir.GetValue("記錄者姓名");
                    }
                    if (ir.Contains("記錄者"))
                    {
                        // 檢查記錄者如果空的用記錄者姓名比對,有比對到填入記錄者
                        if (string.IsNullOrEmpty(ir.GetValue("記錄者")))
                        {
                            if (teacherNameLoginIDDict.ContainsKey(CounselCaseMeetingRecord.AuthorName))
                            {
                                if (isNew)
                                {
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "記錄者", ir.GetValue("記錄者"));
                                }
                                else
                                {
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "記錄者", CounselCaseMeetingRecord.AuthorID, teacherNameLoginIDDict[CounselCaseMeetingRecord.AuthorName]);
                                }
                                CounselCaseMeetingRecord.AuthorID = teacherNameLoginIDDict[CounselCaseMeetingRecord.AuthorName];
                            }
                        }
                        else
                        {
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "記錄者", ir.GetValue("記錄者"));
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "記錄者", CounselCaseMeetingRecord.AuthorID, ir.GetValue("記錄者"));
                            }
                            CounselCaseMeetingRecord.AuthorID = ir.GetValue("記錄者");
                        }
                    }

                    if (string.IsNullOrEmpty(CounselCaseMeetingRecord.UID))
                    {
                        InsertData.Add(CounselCaseMeetingRecord);
                    }
                    else
                    {
                        UpdateData.Add(CounselCaseMeetingRecord);
                    }
                }
            }
            if (InsertData.Count > 0)
            {
                _UDTTransfer.InsertCaseMeetingRecordList(InsertData);
            }

            if (UpdateData.Count > 0)
            {
                _UDTTransfer.UpdateCaseMeetingRecordList(UpdateData);
            }

            // log
            Dictionary <string, Dictionary <string, Dictionary <string, string> > > insertLogDict = _LogTransfer.GetBatchInsertLog();
            Dictionary <string, Dictionary <string, Dictionary <string, string> > > updateLogDict = _LogTransfer.GetBatchUpdateLog();

            string TitleName = "匯入個案會議";

            // 處理 log 細項
            foreach (KeyValuePair <string, string> data in StudentNameDict)
            {
                if (insertLogDict.Count > 0)
                {
                    if (insertLogDict.ContainsKey(data.Key))
                    {
                        foreach (KeyValuePair <string, Dictionary <string, string> > d1 in insertLogDict[data.Key])
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine(TitleName + "-新增");
                            sb.AppendLine(data.Value);
                            foreach (KeyValuePair <string, string> d2 in d1.Value)
                            {
                                sb.AppendLine(d2.Key + ":" + d2.Value);
                            }

                            if (LogData.ContainsKey(data.Key))
                            {
                                LogData[data.Key].AppendLine();
                                LogData[data.Key].AppendLine(sb.ToString());
                            }
                            else
                            {
                                LogData.Add(data.Key, sb);
                            }
                        }
                    }
                }

                if (updateLogDict.Count > 0)
                {
                    if (updateLogDict.ContainsKey(data.Key))
                    {
                        foreach (KeyValuePair <string, Dictionary <string, string> > d1 in updateLogDict[data.Key])
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine(TitleName + "-修改");
                            sb.AppendLine(data.Value);

                            foreach (KeyValuePair <string, string> d2 in d1.Value)
                            {
                                sb.AppendLine(d2.Key + ":" + d2.Value);
                            }

                            if (LogData.ContainsKey(data.Key))
                            {
                                LogData[data.Key].AppendLine();
                                LogData[data.Key].AppendLine(sb.ToString());
                            }
                            else
                            {
                                LogData.Add(data.Key, sb);
                            }
                        }
                    }
                }
            }


            // 寫入 log
            DAO.LogTransfer log = new DAO.LogTransfer();
            foreach (KeyValuePair <string, StringBuilder> data in LogData)
            {
                log.SaveLog("輔導系統." + TitleName, "匯入", "student", data.Key, data.Value);
            }

            StringBuilder sbT = new StringBuilder();

            sbT.AppendLine(TitleName);
            sbT.AppendLine("總共匯入" + LogData.Keys.Count + "位學生 , 共" + TotalCount + "筆");
            sbT.AppendLine("匯入學生名單..");
            foreach (KeyValuePair <string, string> data in StudentNameDict)
            {
                if (LogData.ContainsKey(data.Key))
                {
                    sbT.AppendLine(data.Value);
                }
            }

            log.SaveLog("輔導系統." + TitleName, "匯入", "student", "", sbT);

            return("");
        }
        /// <summary>
        /// 分批執行匯入
        /// </summary>
        /// <param name="Rows">IRowStream物件列表</param>
        /// <returns>分批匯入完成訊息</returns>
        public override string Import(List<IRowStream> Rows)
        {
            if (mOption.Action == ImportAction.InsertOrUpdate)
            {
                try
                {
                    // log
                    DAO.LogTransfer _logTransfer = new DAO.LogTransfer();

                    List<DAO.UDT_StudQuizDataDef> StudQuizDataList = new List<DAO.UDT_StudQuizDataDef>();
                    List<DAO.UDT_StudQuizDataDef> DelQuizDataList = new List<DAO.UDT_StudQuizDataDef>();
                    List<DAO.UDT_StudQuizDataDef> HasQuizDataList = new List<DAO.UDT_StudQuizDataDef>();
                    // 新增 Log
                    Dictionary<int,StringBuilder> Log_Insert =new Dictionary<int,StringBuilder> ();
                    // 刪除 Log
                    Dictionary<int, StringBuilder> Log_Delete = new Dictionary<int, StringBuilder>();

                    List<string> studentNumberList = new List<string>();
                    List<string> ClassSeatNoList = new List<string>();

                    // 取得試別有學生資料
                    HasQuizDataList = _UDTTransfer.GetStudQuizDataByQuizID(_QuizID);
                    int count = 0;
                    string AuthorID = Utility.GetAuthorID();
                    foreach (IRowStream irs in Rows)
                    {
                        count++;
                        this.ImportProgress = count;
                        int sid = 0;
                        // 依學號比對
                        if (irs.Contains("學號") && irs.Contains("狀態"))
                        {
                            if (Global._StudentStatusDBDict.ContainsKey(irs.GetValue("狀態")))
                            {
                                sid = Utility.GetStudentID(irs.GetValue("學號"), irs.GetValue("狀態"));
                                studentNumberList.Add("學號:"+irs.GetValue("學號"));
                            }
                        }

                        // 依班座比對
                        if (irs.Contains("班級") && irs.Contains("座號") && irs.Contains("狀態"))
                        {
                            if (Global._StudentStatusDBDict.ContainsKey(irs.GetValue("狀態")))
                            {
                                sid = Utility.GetStudentID(irs.GetValue("班級"), irs.GetValue("座號"), irs.GetValue("狀態"));
                                ClassSeatNoList.Add("班級:" + irs.GetValue("班級") + ",座號:" + irs.GetValue("座號"));
                            }
                        }

                            // 比對需要刪除
                            foreach(DAO.UDT_StudQuizDataDef data in HasQuizDataList.Where(x=>x.StudentID ==sid))
                            {
                                DelQuizDataList.Add(data);
                            }

                            DAO.UDT_StudQuizDataDef sqd = new DAO.UDT_StudQuizDataDef();
                            sqd.QuizID = int.Parse(_QuizID);
                            sqd.AuthorID = AuthorID;
                            sqd.StudentID = sid;

                            DateTime dt1, dt2;
                            if (irs.Contains("實施日期"))
                                if (DateTime.TryParse(irs.GetValue("實施日期"), out dt1))
                                    sqd.ImplementationDate = dt1;

                            if (irs.Contains("解析日期"))
                                if (DateTime.TryParse(irs.GetValue("解析日期"), out dt2))
                                    sqd.AnalysisDate = dt2;

                            List<XElement> elmList = new List<XElement>();
                            foreach (string str in _DataFieldNameList)
                            {
                                if (irs.Contains(str))
                                {
                                    XElement elm = new XElement("Item");
                                    elm.SetAttributeValue("name", str);
                                    elm.SetAttributeValue("value", irs.GetValue(str));
                                    elmList.Add(elm);
                                }
                            }
                            sqd.Content = Utility.ConvertXmlListToString1(elmList);

                            StudQuizDataList.Add(sqd);

                    }

                    if (DelQuizDataList.Count > 0)
                    {
                        List<int> intList = (from data in DelQuizDataList select data.StudentID).ToList();
                        Dictionary<int, string> studNameDict = Utility.GetConvertStringDict1fromDB(intList);

                        // 收集 Log
                        foreach (DAO.UDT_StudQuizDataDef data in DelQuizDataList)
                        {
                            if(studNameDict.ContainsKey(data.StudentID))
                            {
                                StringBuilder sb = new StringBuilder();
                                sb.AppendLine("匯入輔導測驗-刪除");
                                sb.AppendLine(studNameDict[data.StudentID]);
                                sb.AppendLine("測驗名稱:" + _QuizName);
                                if (data.ImplementationDate.HasValue)
                                    sb.AppendLine("實施日期:" + data.ImplementationDate.Value.ToShortDateString());

                                if (data.AnalysisDate.HasValue)
                                    sb.AppendLine("解析日期:" + data.AnalysisDate.Value.ToShortDateString());

                                XElement elmContent = Utility.ConvertStringToXelm1(data.Content);
                                if (elmContent != null)
                                {
                                    foreach (XElement elm in elmContent.Elements("Item"))
                                    {
                                        if (elm.Attribute("name") != null && elm.Attribute("value") != null)
                                            sb.AppendLine("項目名稱:" + elm.Attribute("name").Value + " , 測驗結果:" + elm.Attribute("value").Value);
                                    }
                                }

                                if (!Log_Delete.ContainsKey(data.StudentID))
                                    Log_Delete.Add(data.StudentID, sb);
                            }
                        }

                        _UDTTransfer.DeleteStudQuizDataLlist(DelQuizDataList);
                    }
                    if (StudQuizDataList.Count > 0)
                    {
                        List<int> intList = (from data in StudQuizDataList select data.StudentID).ToList();
                        Dictionary<int, string> studNameDict = Utility.GetConvertStringDict1fromDB(intList);

                        // 收集 Log
                        foreach (DAO.UDT_StudQuizDataDef data in StudQuizDataList)
                        {
                            if (studNameDict.ContainsKey(data.StudentID))
                            {
                                StringBuilder sb = new StringBuilder();
                                // 檢查是否有刪除,有放上面
                                if (Log_Delete.ContainsKey(data.StudentID))
                                {
                                    sb.AppendLine(Log_Delete[data.StudentID].ToString());
                                    sb.AppendLine();
                                }

                                sb.AppendLine("匯入輔導測驗-新增");
                                sb.AppendLine(studNameDict[data.StudentID]);
                                sb.AppendLine("測驗名稱:" + _QuizName);
                                if (data.ImplementationDate.HasValue)
                                    sb.AppendLine("實施日期:" + data.ImplementationDate.Value.ToShortDateString());

                                if (data.AnalysisDate.HasValue)
                                    sb.AppendLine("解析日期:" + data.AnalysisDate.Value.ToShortDateString());

                                XElement elmContent = Utility.ConvertStringToXelm1(data.Content);
                                if (elmContent != null)
                                {
                                    foreach (XElement elm in elmContent.Elements("Item"))
                                    {
                                        if (elm.Attribute("name") != null && elm.Attribute("value") != null)
                                            sb.AppendLine("項目名稱:" + elm.Attribute("name").Value + " , 測驗結果:" + elm.Attribute("value").Value);
                                    }
                                }

                                if (!Log_Insert.ContainsKey(data.StudentID))
                                    Log_Insert.Add(data.StudentID, sb);
                            }
                        }

                        _UDTTransfer.InsertStudQuizDataLlist(StudQuizDataList);
                    }

                    // log 資料
                    if (Log_Insert.Count > 0)
                    {
                        foreach (KeyValuePair<int, StringBuilder> data in Log_Insert)
                            _logTransfer.SaveLog("輔導系統-匯入測驗資料", "匯入", "student", data.Key.ToString(), data.Value);
                    }

                    // 總共
                    StringBuilder logData = new StringBuilder();
                    logData.AppendLine("測驗名稱:" + _QuizName);
                    if (ClassSeatNoList.Count > 0)
                    {
                        logData.AppendLine("--依班級座號匯入--");
                        foreach (string str in ClassSeatNoList)
                            logData.AppendLine(str);

                        logData.AppendLine("匯入學生共"+ClassSeatNoList.Count+"人");
                    }
                    if (studentNumberList.Count > 0)
                    {
                        logData.AppendLine("--依學號匯入--");
                        foreach (string str in studentNumberList)
                            logData.AppendLine(str);

                        logData.AppendLine("匯入學生共" + studentNumberList.Count + "人");
                    }
                    // 寫入 log
                    _logTransfer.SaveLog("輔導系統.匯入測驗資料", "匯入", "", "", logData);

                }
                catch(Exception ex)
                {
                    throw ex;
                }
            }
            return "";
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lvCaseMeeting.SelectedItems.Count == 1)
            {

                DAO.UDT_CounselCaseMeetingRecordDef CaseMeetingRecord = lvCaseMeeting.SelectedItems[0].Tag as DAO.UDT_CounselCaseMeetingRecordDef;
                if (CaseMeetingRecord != null)
                {
                    DAO.LogTransfer logTransfer = new DAO.LogTransfer();

                    K12.Data.StudentRecord studRec = K12.Data.Student.SelectByID(PrimaryKey);
                    StringBuilder logData = new StringBuilder();
                    logData.AppendLine("刪除" + Utility.ConvertString1(studRec));

                    // 取得 XML 解析後
                    Dictionary<string, string> item_AttendessDict = Utility.GetConvertCounselXMLVal_Attendees(CaseMeetingRecord.Attendees);
                    Dictionary<string, string> item_CounselTypeDict = Utility.GetConvertCounselXMLVal_CounselType(CaseMeetingRecord.CounselType);
                    Dictionary<string, string> item_CounselTypeKindDict = Utility.GetConvertCounselXMLVal_CounselTypeKind(CaseMeetingRecord.CounselTypeKind);

                    if (FISCA.Presentation.Controls.MsgBox.Show("請問是否確定刪除個案會議?", "刪除個案會議", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        // log
                        logData.AppendLine("個案編號:" + CaseMeetingRecord.CaseNo);

                        if (CaseMeetingRecord.MeetingDate.HasValue)
                            logData.AppendLine("會議日期"+ CaseMeetingRecord.MeetingDate.Value.ToShortDateString());

                        K12.Data.TeacherRecord tRec = K12.Data.Teacher.SelectByID(CaseMeetingRecord.CounselTeacherID.ToString());
                        if (tRec != null)
                            if(string.IsNullOrEmpty(tRec.Nickname))
                                logData.AppendLine("晤談老師:" + tRec.Name);
                            else
                                logData.AppendLine("晤談老師:" + tRec.Name+"("+tRec.Nickname+")");

                        logData.AppendLine("會議時間:" + CaseMeetingRecord.MeetigTime);
                        logData.AppendLine("會議事由:" + CaseMeetingRecord.MeetingCause);
                        logData.AppendLine("會議地點:" + CaseMeetingRecord.Place);
                        logData.AppendLine("內容要點:" + CaseMeetingRecord.ContentDigest);
                        logData.AppendLine("記錄者:" + CaseMeetingRecord.AuthorID);
                        logData.AppendLine("記錄者姓名:" + CaseMeetingRecord.AuthorName);

                        logData.AppendLine("參與人員:");
                        foreach (KeyValuePair<string, string> data in item_AttendessDict)
                            if (!string.IsNullOrEmpty(data.Value))
                                logData.AppendLine(data.Key + ":" + data.Value);

                        logData.AppendLine("輔導方式:");
                        foreach (KeyValuePair<string, string> data in item_CounselTypeDict)
                            if (!string.IsNullOrEmpty(data.Value))
                                logData.AppendLine(data.Key + ":" + data.Value);

                        logData.AppendLine("輔導歸類:");
                        foreach (KeyValuePair<string, string> data in item_CounselTypeKindDict)
                            if (!string.IsNullOrEmpty(data.Value))
                                logData.AppendLine(data.Key + ":" + data.Value);

                        _UDTTransfer.DeleteCaseMeetingRecord(CaseMeetingRecord);
                        logTransfer.SaveLog("學生.輔導個案會議-刪除", "刪除", "student", PrimaryKey, logData);
                        _BGRun();
                    }
                }
            }
            else
                FISCA.Presentation.Controls.MsgBox.Show("請選擇資料.");
        }
        private void btnDel_Click(object sender, EventArgs e)
        {
            if (lvInterview.SelectedItems.Count > 0)
            {
                DAO.UDT_CounselStudentInterviewRecordDef studInterviewRec = lvInterview.SelectedItems[0].Tag as DAO.UDT_CounselStudentInterviewRecordDef;
                if (studInterviewRec != null)
                {
                    DAO.LogTransfer        logTransfer = new DAO.LogTransfer();
                    string                 teacherName = lvInterview.SelectedItems[0].SubItems[colTeacherID.Index].Text;
                    K12.Data.StudentRecord studRec     = K12.Data.Student.SelectByID(PrimaryKey);
                    StringBuilder          logData     = new StringBuilder();
                    logData.AppendLine("刪除" + Utility.ConvertString1(studRec));
                    // 取得 XML 解析後
                    Dictionary <string, string> item_AttendessDict       = Utility.GetConvertCounselXMLVal_Attendees(studInterviewRec.Attendees);
                    Dictionary <string, string> item_CounselTypeDict     = Utility.GetConvertCounselXMLVal_CounselType(studInterviewRec.CounselType);
                    Dictionary <string, string> item_CounselTypeKindDict = Utility.GetConvertCounselXMLVal_CounselTypeKind(studInterviewRec.CounselTypeKind);


                    if (FISCA.Presentation.Controls.MsgBox.Show("請問是否確定是刪除晤談紀錄?", "刪除晤談紀錄", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        // log
                        logData.AppendLine("晤談老師:" + teacherName);
                        logData.AppendLine("晤談對象:" + studInterviewRec.IntervieweeType);
                        logData.AppendLine("晤談方式:" + studInterviewRec.InterviewType);
                        if (studInterviewRec.InterviewDate.HasValue)
                        {
                            logData.AppendLine("日期:" + studInterviewRec.InterviewDate.Value.ToShortDateString());
                        }
                        logData.AppendLine("時間:" + studInterviewRec.InterviewTime);
                        logData.AppendLine("地點:" + studInterviewRec.Place);
                        logData.AppendLine("晤談編號:" + studInterviewRec.InterviewNo);
                        logData.AppendLine("晤談事由:" + studInterviewRec.Cause);

                        logData.AppendLine("參與人員:");
                        foreach (KeyValuePair <string, string> data in item_AttendessDict)
                        {
                            if (!string.IsNullOrEmpty(data.Value))
                            {
                                logData.AppendLine(data.Key + ":" + data.Value);
                            }
                        }

                        logData.AppendLine("輔導方式:");
                        foreach (KeyValuePair <string, string> data in item_CounselTypeDict)
                        {
                            if (!string.IsNullOrEmpty(data.Value))
                            {
                                logData.AppendLine(data.Key + ":" + data.Value);
                            }
                        }

                        logData.AppendLine("輔導歸類:");
                        foreach (KeyValuePair <string, string> data in item_CounselTypeKindDict)
                        {
                            if (!string.IsNullOrEmpty(data.Value))
                            {
                                logData.AppendLine(data.Key + ":" + data.Value);
                            }
                        }

                        logData.AppendLine("內容要點:" + studInterviewRec.ContentDigest);
                        logData.AppendLine("記錄者:" + studInterviewRec.AuthorID);
                        logData.AppendLine("記錄者姓名:" + studInterviewRec.AuthorName);

                        _UDTTransfer.DeleteCounselStudentInterviewRecord(studInterviewRec);

                        logTransfer.SaveLog("學生.輔導晤談紀錄-刪除", "刪除", "student", PrimaryKey, logData);


                        _BGRun();
                    }
                }
            }
            else
            {
                FISCA.Presentation.Controls.MsgBox.Show("請選擇資料.");
            }
        }
示例#9
0
        public override string Import(List <Campus.DocumentValidator.IRowStream> Rows)
        {
            List <DAO.UDT_CounselCareRecordDef> InsertData = new List <DAO.UDT_CounselCareRecordDef>();
            List <DAO.UDT_CounselCareRecordDef> UpdateData = new List <DAO.UDT_CounselCareRecordDef>();
            List <DAO.UDT_CounselCareRecordDef> HasData    = new List <DAO.UDT_CounselCareRecordDef>();

            // -- 處理 log
            Dictionary <string, StringBuilder> LogData = new Dictionary <string, StringBuilder>();
            // 學生ID List
            List <int> studIdList = new List <int> ();

            foreach (IRowStream ir in Rows)
            {
                int i;
                if (ir.Contains("學號") && ir.Contains("狀態"))
                {
                    if (int.TryParse(Utility.GetStudentID(ir.GetValue("學號"), ir.GetValue("狀態")).ToString(), out i))
                    {
                        studIdList.Add(i);
                    }
                }
            }
            // 取得學生名稱log 用
            Dictionary <string, string> StudentNameDict = new Dictionary <string, string>();

            foreach (KeyValuePair <int, string> data in Utility.GetConvertStringDict1fromDB(studIdList))
            {
                StudentNameDict.Add(data.Key.ToString(), data.Value);
            }

            DAO.LogTransfer _LogTransfer = new DAO.LogTransfer();

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

            // 取得學生狀態對應
            foreach (IRowStream ir in Rows)
            {
                if (ir.Contains("學號") && ir.Contains("狀態"))
                {
                    StudentIDList.Add(Utility.GetStudentID(ir.GetValue("學號"), ir.GetValue("狀態")).ToString());
                }
            }
            // 已有資料
            HasData = _UDTTransfer.GetCareRecordsByStudentIDList(StudentIDList);

            // 取得教師帳號比對用
            Dictionary <string, string> teacherNameLoginIDDict = Utility.GetTeacherNameLoginIDStatus1();

            int TotalCount = 0, NewIdx = 0;

            foreach (IRowStream ir in Rows)
            {
                TotalCount++;
                this.ImportProgress = TotalCount;
                DAO.UDT_CounselCareRecordDef CounselCareRecord = null;
                int sid = 0;
                if (ir.Contains("學號") && ir.Contains("狀態"))
                {
                    string key = ir.GetValue("學號") + "_";
                    if (Global._StudentStatusDBDict.ContainsKey(ir.GetValue("狀態")))
                    {
                        sid = Utility.GetStudentID(ir.GetValue("學號"), ir.GetValue("狀態"));
                    }

                    DateTime dt;
                    // 當同一位學生有相同會議日期與會議事由,當作是更新,否則新增
                    if (DateTime.TryParse(ir.GetValue("立案日期"), out dt))
                    {
                        foreach (DAO.UDT_CounselCareRecordDef rec in HasData.Where(x => x.StudentID == sid))
                        {
                            if (rec.FileDate.HasValue)
                            {
                                if (rec.FileDate.Value.ToShortDateString() == dt.ToShortDateString())
                                {
                                    if (rec.CaseCategory == ir.GetValue("個案類別") && rec.CaseOrigin == ir.GetValue("個案來源"))
                                    {
                                        CounselCareRecord = rec;
                                    }
                                }
                            }
                        }
                    }

                    bool isNew = false;
                    if (CounselCareRecord == null)
                    {
                        CounselCareRecord = new DAO.UDT_CounselCareRecordDef();
                        isNew             = true;
                        NewIdx++;
                    }
                    string StudID    = sid.ToString();
                    string insertKey = "A" + NewIdx;
                    // 學生編號
                    CounselCareRecord.StudentID = sid;
                    // 立案日期
                    if (isNew)
                    {
                        _LogTransfer.AddBatchInsertLog(StudID, insertKey, "立案日期", dt.ToShortDateString());
                    }
                    else
                    {
                        _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "立案日期", CounselCareRecord.FileDate.Value.ToShortDateString(), dt.ToShortDateString());
                    }
                    CounselCareRecord.FileDate = dt;

                    if (ir.Contains("代號"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "代號", ir.GetValue("代號"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "代號", CounselCareRecord.CodeName, ir.GetValue("代號"));
                        }
                        CounselCareRecord.CodeName = ir.GetValue("代號");
                    }

                    if (isNew)
                    {
                        _LogTransfer.AddBatchInsertLog(StudID, insertKey, "個案類別", ir.GetValue("個案類別"));
                    }
                    else
                    {
                        _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "個案類別", CounselCareRecord.CaseCategory, ir.GetValue("個案類別"));
                    }
                    CounselCareRecord.CaseCategory = ir.GetValue("個案類別");



                    if (ir.Contains("個案類別備註"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "個案類別備註", ir.GetValue("個案類別備註"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "個案類別備註", CounselCareRecord.CaseCategoryRemark, ir.GetValue("個案類別備註"));
                        }
                        CounselCareRecord.CaseCategoryRemark = ir.GetValue("個案類別備註");
                    }

                    if (isNew)
                    {
                        _LogTransfer.AddBatchInsertLog(StudID, insertKey, "個案來源", ir.GetValue("個案來源"));
                    }
                    else
                    {
                        _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "個案來源", CounselCareRecord.CaseOrigin, ir.GetValue("個案來源"));
                    }
                    CounselCareRecord.CaseOrigin = ir.GetValue("個案來源");

                    if (ir.Contains("個案來源備註"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "個案來源備註", ir.GetValue("個案來源備註"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "個案來源備註", CounselCareRecord.CaseOriginRemark, ir.GetValue("個案來源備註"));
                        }
                        CounselCareRecord.CaseOriginRemark = ir.GetValue("個案來源備註");
                    }
                    if (ir.Contains("優勢能力及財力"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "優勢能力及財力", ir.GetValue("優勢能力及財力"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "優勢能力及財力", CounselCareRecord.Superiority, ir.GetValue("優勢能力及財力"));
                        }
                        CounselCareRecord.Superiority = ir.GetValue("優勢能力及財力");
                    }

                    if (ir.Contains("弱勢能力及財力"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "弱勢能力及財力", ir.GetValue("弱勢能力及財力"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "弱勢能力及財力", CounselCareRecord.Weakness, ir.GetValue("弱勢能力及財力"));
                        }
                        CounselCareRecord.Weakness = ir.GetValue("弱勢能力及財力");
                    }
                    if (ir.Contains("輔導人員輔導目標"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導人員輔導目標", ir.GetValue("輔導人員輔導目標"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "輔導人員輔導目標", CounselCareRecord.CounselGoal, ir.GetValue("輔導人員輔導目標"));
                        }
                        CounselCareRecord.CounselGoal = ir.GetValue("輔導人員輔導目標");
                    }
                    if (ir.Contains("校外協輔機構"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "校外協輔機構", ir.GetValue("校外協輔機構"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "校外協輔機構", CounselCareRecord.OtherInstitute, ir.GetValue("校外協輔機構"));
                        }
                        CounselCareRecord.OtherInstitute = ir.GetValue("校外協輔機構");
                    }
                    if (ir.Contains("輔導人員輔導方式"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導人員輔導方式", ir.GetValue("輔導人員輔導方式"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "輔導人員輔導方式", CounselCareRecord.CounselType, ir.GetValue("輔導人員輔導方式"));
                        }
                        CounselCareRecord.CounselType = ir.GetValue("輔導人員輔導方式");
                    }
                    if (ir.Contains("協同輔導人員協助導師事項"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "協同輔導人員協助導師事項", ir.GetValue("協同輔導人員協助導師事項"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "協同輔導人員協助導師事項", CounselCareRecord.AssistedMatter, ir.GetValue("協同輔導人員協助導師事項"));
                        }
                        CounselCareRecord.AssistedMatter = ir.GetValue("協同輔導人員協助導師事項");
                    }

                    if (ir.Contains("記錄者姓名"))
                    {
                        if (isNew)
                        {
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "記錄者姓名", ir.GetValue("記錄者姓名"));
                        }
                        else
                        {
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "記錄者姓名", CounselCareRecord.AuthorName, ir.GetValue("記錄者姓名"));
                        }
                        CounselCareRecord.AuthorName = ir.GetValue("記錄者姓名");
                    }
                    if (ir.Contains("記錄者"))
                    {
                        // 檢查記錄者如果空的用記錄者姓名比對,有比對到填入記錄者
                        if (string.IsNullOrEmpty(ir.GetValue("記錄者")))
                        {
                            if (teacherNameLoginIDDict.ContainsKey(CounselCareRecord.AuthorName))
                            {
                                if (isNew)
                                {
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "記錄者", ir.GetValue("記錄者"));
                                }
                                else
                                {
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "記錄者", CounselCareRecord.AuthorID, teacherNameLoginIDDict[CounselCareRecord.AuthorName]);
                                }
                                CounselCareRecord.AuthorID = teacherNameLoginIDDict[CounselCareRecord.AuthorName];
                            }
                        }
                        else
                        {
                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "記錄者", ir.GetValue("記錄者"));
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "記錄者", CounselCareRecord.AuthorID, ir.GetValue("記錄者"));
                            }
                            CounselCareRecord.AuthorID = ir.GetValue("記錄者");
                        }
                    }
                    if (string.IsNullOrEmpty(CounselCareRecord.UID))
                    {
                        InsertData.Add(CounselCareRecord);
                    }
                    else
                    {
                        UpdateData.Add(CounselCareRecord);
                    }
                }
            }
            if (InsertData.Count > 0)
            {
                _UDTTransfer.InsertCareRecordList(InsertData);
            }

            if (UpdateData.Count > 0)
            {
                _UDTTransfer.UpdateCareRecordList(UpdateData);
            }

            // log
            Dictionary <string, Dictionary <string, Dictionary <string, string> > > insertLogDict = _LogTransfer.GetBatchInsertLog();
            Dictionary <string, Dictionary <string, Dictionary <string, string> > > updateLogDict = _LogTransfer.GetBatchUpdateLog();

            string TitleName = "匯入優先關懷";

            // 處理 log 細項
            foreach (KeyValuePair <string, string> data in StudentNameDict)
            {
                if (insertLogDict.Count > 0)
                {
                    if (insertLogDict.ContainsKey(data.Key))
                    {
                        foreach (KeyValuePair <string, Dictionary <string, string> > d1 in insertLogDict[data.Key])
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine(TitleName + "-新增");
                            sb.AppendLine(data.Value);
                            foreach (KeyValuePair <string, string> d2 in d1.Value)
                            {
                                sb.AppendLine(d2.Key + ":" + d2.Value);
                            }

                            if (LogData.ContainsKey(data.Key))
                            {
                                LogData[data.Key].AppendLine();
                                LogData[data.Key].AppendLine(sb.ToString());
                            }
                            else
                            {
                                LogData.Add(data.Key, sb);
                            }
                        }
                    }
                }

                if (updateLogDict.Count > 0)
                {
                    if (updateLogDict.ContainsKey(data.Key))
                    {
                        foreach (KeyValuePair <string, Dictionary <string, string> > d1 in updateLogDict[data.Key])
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine(TitleName + "-修改");
                            sb.AppendLine(data.Value);

                            foreach (KeyValuePair <string, string> d2 in d1.Value)
                            {
                                sb.AppendLine(d2.Key + ":" + d2.Value);
                            }

                            if (LogData.ContainsKey(data.Key))
                            {
                                LogData[data.Key].AppendLine();
                                LogData[data.Key].AppendLine(sb.ToString());
                            }
                            else
                            {
                                LogData.Add(data.Key, sb);
                            }
                        }
                    }
                }
            }


            // 寫入 log
            DAO.LogTransfer log = new DAO.LogTransfer();
            foreach (KeyValuePair <string, StringBuilder> data in LogData)
            {
                log.SaveLog("輔導系統." + TitleName, "匯入", "student", data.Key, data.Value);
            }

            StringBuilder sbT = new StringBuilder();

            sbT.AppendLine(TitleName);
            sbT.AppendLine("總共匯入" + LogData.Keys.Count + "位學生 , 共" + TotalCount + "筆");
            sbT.AppendLine("匯入學生名單..");
            foreach (KeyValuePair <string, string> data in StudentNameDict)
            {
                if (LogData.ContainsKey(data.Key))
                {
                    sbT.AppendLine(data.Value);
                }
            }

            log.SaveLog("輔導系統." + TitleName, "匯入", "student", "", sbT);
            return("");
        }
        /// <summary>
        /// 分批執行匯入
        /// </summary>
        /// <param name="Rows">IRowStream物件列表</param>
        /// <returns>分批匯入完成訊息</returns>
        public override string Import(List <IRowStream> Rows)
        {
            if (mOption.Action == ImportAction.InsertOrUpdate)
            {
                try
                {
                    // log
                    DAO.LogTransfer _logTransfer = new DAO.LogTransfer();

                    List <DAO.UDT_StudQuizDataDef> StudQuizDataList = new List <DAO.UDT_StudQuizDataDef>();
                    List <DAO.UDT_StudQuizDataDef> DelQuizDataList  = new List <DAO.UDT_StudQuizDataDef>();
                    List <DAO.UDT_StudQuizDataDef> HasQuizDataList  = new List <DAO.UDT_StudQuizDataDef>();
                    // 新增 Log
                    Dictionary <int, StringBuilder> Log_Insert = new Dictionary <int, StringBuilder> ();
                    // 刪除 Log
                    Dictionary <int, StringBuilder> Log_Delete = new Dictionary <int, StringBuilder>();


                    List <string> studentNumberList = new List <string>();
                    List <string> ClassSeatNoList   = new List <string>();

                    // 取得試別有學生資料
                    HasQuizDataList = _UDTTransfer.GetStudQuizDataByQuizID(_QuizID);
                    int    count    = 0;
                    string AuthorID = Utility.GetAuthorID();
                    foreach (IRowStream irs in Rows)
                    {
                        count++;
                        this.ImportProgress = count;
                        int sid = 0;
                        // 依學號比對
                        if (irs.Contains("學號") && irs.Contains("狀態"))
                        {
                            if (Global._StudentStatusDBDict.ContainsKey(irs.GetValue("狀態")))
                            {
                                sid = Utility.GetStudentID(irs.GetValue("學號"), irs.GetValue("狀態"));
                                studentNumberList.Add("學號:" + irs.GetValue("學號"));
                            }
                        }

                        // 依班座比對
                        if (irs.Contains("班級") && irs.Contains("座號") && irs.Contains("狀態"))
                        {
                            if (Global._StudentStatusDBDict.ContainsKey(irs.GetValue("狀態")))
                            {
                                sid = Utility.GetStudentID(irs.GetValue("班級"), irs.GetValue("座號"), irs.GetValue("狀態"));
                                ClassSeatNoList.Add("班級:" + irs.GetValue("班級") + ",座號:" + irs.GetValue("座號"));
                            }
                        }

                        // 比對需要刪除
                        foreach (DAO.UDT_StudQuizDataDef data in HasQuizDataList.Where(x => x.StudentID == sid))
                        {
                            DelQuizDataList.Add(data);
                        }



                        DAO.UDT_StudQuizDataDef sqd = new DAO.UDT_StudQuizDataDef();
                        sqd.QuizID    = int.Parse(_QuizID);
                        sqd.AuthorID  = AuthorID;
                        sqd.StudentID = sid;

                        DateTime dt1, dt2;
                        if (irs.Contains("實施日期"))
                        {
                            if (DateTime.TryParse(irs.GetValue("實施日期"), out dt1))
                            {
                                sqd.ImplementationDate = dt1;
                            }
                        }

                        if (irs.Contains("解析日期"))
                        {
                            if (DateTime.TryParse(irs.GetValue("解析日期"), out dt2))
                            {
                                sqd.AnalysisDate = dt2;
                            }
                        }

                        List <XElement> elmList = new List <XElement>();
                        foreach (string str in _DataFieldNameList)
                        {
                            if (irs.Contains(str))
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", str);
                                elm.SetAttributeValue("value", irs.GetValue(str));
                                elmList.Add(elm);
                            }
                        }
                        sqd.Content = Utility.ConvertXmlListToString1(elmList);

                        StudQuizDataList.Add(sqd);
                    }

                    if (DelQuizDataList.Count > 0)
                    {
                        List <int> intList = (from data in DelQuizDataList select data.StudentID).ToList();
                        Dictionary <int, string> studNameDict = Utility.GetConvertStringDict1fromDB(intList);

                        // 收集 Log
                        foreach (DAO.UDT_StudQuizDataDef data in DelQuizDataList)
                        {
                            if (studNameDict.ContainsKey(data.StudentID))
                            {
                                StringBuilder sb = new StringBuilder();
                                sb.AppendLine("匯入輔導測驗-刪除");
                                sb.AppendLine(studNameDict[data.StudentID]);
                                sb.AppendLine("測驗名稱:" + _QuizName);
                                if (data.ImplementationDate.HasValue)
                                {
                                    sb.AppendLine("實施日期:" + data.ImplementationDate.Value.ToShortDateString());
                                }

                                if (data.AnalysisDate.HasValue)
                                {
                                    sb.AppendLine("解析日期:" + data.AnalysisDate.Value.ToShortDateString());
                                }

                                XElement elmContent = Utility.ConvertStringToXelm1(data.Content);
                                if (elmContent != null)
                                {
                                    foreach (XElement elm in elmContent.Elements("Item"))
                                    {
                                        if (elm.Attribute("name") != null && elm.Attribute("value") != null)
                                        {
                                            sb.AppendLine("項目名稱:" + elm.Attribute("name").Value + " , 測驗結果:" + elm.Attribute("value").Value);
                                        }
                                    }
                                }

                                if (!Log_Delete.ContainsKey(data.StudentID))
                                {
                                    Log_Delete.Add(data.StudentID, sb);
                                }
                            }
                        }

                        _UDTTransfer.DeleteStudQuizDataLlist(DelQuizDataList);
                    }
                    if (StudQuizDataList.Count > 0)
                    {
                        List <int> intList = (from data in StudQuizDataList select data.StudentID).ToList();
                        Dictionary <int, string> studNameDict = Utility.GetConvertStringDict1fromDB(intList);

                        // 收集 Log
                        foreach (DAO.UDT_StudQuizDataDef data in StudQuizDataList)
                        {
                            if (studNameDict.ContainsKey(data.StudentID))
                            {
                                StringBuilder sb = new StringBuilder();
                                // 檢查是否有刪除,有放上面
                                if (Log_Delete.ContainsKey(data.StudentID))
                                {
                                    sb.AppendLine(Log_Delete[data.StudentID].ToString());
                                    sb.AppendLine();
                                }

                                sb.AppendLine("匯入輔導測驗-新增");
                                sb.AppendLine(studNameDict[data.StudentID]);
                                sb.AppendLine("測驗名稱:" + _QuizName);
                                if (data.ImplementationDate.HasValue)
                                {
                                    sb.AppendLine("實施日期:" + data.ImplementationDate.Value.ToShortDateString());
                                }

                                if (data.AnalysisDate.HasValue)
                                {
                                    sb.AppendLine("解析日期:" + data.AnalysisDate.Value.ToShortDateString());
                                }

                                XElement elmContent = Utility.ConvertStringToXelm1(data.Content);
                                if (elmContent != null)
                                {
                                    foreach (XElement elm in elmContent.Elements("Item"))
                                    {
                                        if (elm.Attribute("name") != null && elm.Attribute("value") != null)
                                        {
                                            sb.AppendLine("項目名稱:" + elm.Attribute("name").Value + " , 測驗結果:" + elm.Attribute("value").Value);
                                        }
                                    }
                                }

                                if (!Log_Insert.ContainsKey(data.StudentID))
                                {
                                    Log_Insert.Add(data.StudentID, sb);
                                }
                            }
                        }

                        _UDTTransfer.InsertStudQuizDataLlist(StudQuizDataList);
                    }

                    // log 資料
                    if (Log_Insert.Count > 0)
                    {
                        foreach (KeyValuePair <int, StringBuilder> data in Log_Insert)
                        {
                            _logTransfer.SaveLog("輔導系統-匯入測驗資料", "匯入", "student", data.Key.ToString(), data.Value);
                        }
                    }

                    // 總共
                    StringBuilder logData = new StringBuilder();
                    logData.AppendLine("測驗名稱:" + _QuizName);
                    if (ClassSeatNoList.Count > 0)
                    {
                        logData.AppendLine("--依班級座號匯入--");
                        foreach (string str in ClassSeatNoList)
                        {
                            logData.AppendLine(str);
                        }

                        logData.AppendLine("匯入學生共" + ClassSeatNoList.Count + "人");
                    }
                    if (studentNumberList.Count > 0)
                    {
                        logData.AppendLine("--依學號匯入--");
                        foreach (string str in studentNumberList)
                        {
                            logData.AppendLine(str);
                        }

                        logData.AppendLine("匯入學生共" + studentNumberList.Count + "人");
                    }
                    // 寫入 log
                    _logTransfer.SaveLog("輔導系統.匯入測驗資料", "匯入", "", "", logData);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return("");
        }
        public override string Import(List<IRowStream> Rows)
        {
            List<DAO.UDT_CounselCaseMeetingRecordDef> InsertData = new List<DAO.UDT_CounselCaseMeetingRecordDef>();
            List<DAO.UDT_CounselCaseMeetingRecordDef> UpdateData = new List<DAO.UDT_CounselCaseMeetingRecordDef>();
            List<DAO.UDT_CounselCaseMeetingRecordDef> HasData = new List<DAO.UDT_CounselCaseMeetingRecordDef>();

            // 取得教師帳號比對用
            Dictionary<string, string> teacherNameLoginIDDict = Utility.GetTeacherNameLoginIDStatus1();

            // -- 處理 log
            Dictionary<string, StringBuilder> LogData = new Dictionary<string, StringBuilder>();
            // 學生ID List
            List<int> studIdList = new List<int>();
            foreach (IRowStream ir in Rows)
            {
                int i;
                if (ir.Contains("學號") && ir.Contains("狀態"))
                {
                    if (int.TryParse(Utility.GetStudentID(ir.GetValue("學號"), ir.GetValue("狀態")).ToString(), out i))
                        studIdList.Add(i);
                }
            }
            // 取得學生名稱log 用
            Dictionary<string, string> StudentNameDict = new Dictionary<string, string>();
            foreach (KeyValuePair<int, string> data in Utility.GetConvertStringDict1fromDB(studIdList))
                StudentNameDict.Add(data.Key.ToString(), data.Value);

            DAO.LogTransfer _LogTransfer = new DAO.LogTransfer();
            int TotalCount = 0, NewIdx=0;
            List<string> StudentIDList = new List<string> ();
            // 取得學生狀態對應
            foreach (IRowStream ir in Rows)
            {
                TotalCount++;
                this.ImportProgress = TotalCount;
                if (ir.Contains("學號") && ir.Contains("狀態"))
                  StudentIDList.Add(Utility.GetStudentID(ir.GetValue("學號"),ir.GetValue("狀態")).ToString ());
            }
                // 已有資料
                HasData= _UDTTransfer.GetCaseMeetingRecordListByStudentIDList(StudentIDList);

                foreach (IRowStream ir in Rows)
                {
                    DAO.UDT_CounselCaseMeetingRecordDef CounselCaseMeetingRecord = null;
                    int sid=0;
                    if (ir.Contains("學號") && ir.Contains("狀態"))
                    {
                        string key =ir.GetValue("學號") + "_";
                        if (Global._StudentStatusDBDict.ContainsKey(ir.GetValue("狀態")))
                            sid = Utility.GetStudentID(ir.GetValue("學號"), ir.GetValue("狀態"));

                        DateTime dt;
                        // 當同一位學生有相同會議日期與會議事由,當作是更新,否則新增
                        if (DateTime.TryParse(ir.GetValue("會議日期"), out dt))
                        {
                            foreach (DAO.UDT_CounselCaseMeetingRecordDef rec in HasData.Where(x => x.StudentID == sid))
                            {
                                if (rec.MeetingDate.HasValue)
                                    if (rec.MeetingDate.Value.ToShortDateString() == dt.ToShortDateString())
                                        if (rec.MeetingCause == ir.GetValue("會議事由"))
                                            CounselCaseMeetingRecord = rec;

                            }
                        }

                        bool isNew = false;
                        if (CounselCaseMeetingRecord == null)
                        {
                            CounselCaseMeetingRecord = new DAO.UDT_CounselCaseMeetingRecordDef();
                            isNew = true;
                            NewIdx++;
                        }
                        string StudID = sid.ToString();
                        string insertKey = "A" + NewIdx;

                        // 學生編號
                        CounselCaseMeetingRecord.StudentID = sid;

                        // 會議日期
                    if (isNew)
                        _LogTransfer.AddBatchInsertLog(StudID, insertKey, "會議日期", dt.ToShortDateString());
                    else
                        _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "會議日期", CounselCaseMeetingRecord.MeetingDate.Value.ToShortDateString(), dt.ToShortDateString());
                        CounselCaseMeetingRecord.MeetingDate = dt;

                        // 晤談老師
                        if (Global._AllTeacherNameIdDictTemp.ContainsKey(ir.GetValue("晤談老師")))
                            CounselCaseMeetingRecord.CounselTeacherID = Global._AllTeacherNameIdDictTemp[ir.GetValue("晤談老師")];

                        if (ir.Contains("個案編號"))
                        {
                            if (isNew)
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "個案編號", ir.GetValue("個案編號"));
                            else
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "個案編號", CounselCaseMeetingRecord.CaseNo, ir.GetValue("個案編號"));
                            CounselCaseMeetingRecord.CaseNo = ir.GetValue("個案編號");

                        }
                        if (ir.Contains("會議時間"))
                        {
                             if (isNew)
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "會議時間", ir.GetValue("會議時間"));
                            else
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "會議時間", CounselCaseMeetingRecord.MeetigTime, ir.GetValue("會議時間"));
                            CounselCaseMeetingRecord.MeetigTime = ir.GetValue("會議時間");
                        }

                        if (ir.Contains("會議地點"))
                        {
                            if (isNew)
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "會議地點", ir.GetValue("會議地點"));
                            else
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "會議地點", CounselCaseMeetingRecord.CaseNo, ir.GetValue("會議地點"));
                            CounselCaseMeetingRecord.Place = ir.GetValue("會議地點");
                        }

                        if (ir.Contains("會議事由"))
                        {
                            if (isNew)
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "會議事由", ir.GetValue("會議事由"));
                            else
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "會議事由", CounselCaseMeetingRecord.MeetingCause, ir.GetValue("會議事由"));

                            CounselCaseMeetingRecord.MeetingCause = ir.GetValue("會議事由");
                        }

                        StringBuilder sb1 = new StringBuilder();
                        if (ir.Contains("參與人員:學生")) if (ir.GetValue("參與人員:學生") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "學生");
                                sb1.Append(elm.ToString());

                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:學生", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:學生","","1");
                            }

                        if (ir.Contains("參與人員:家長")) if (ir.GetValue("參與人員:家長") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "家長");
                                sb1.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:家長", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:家長","","1");
                            }
                        if (ir.Contains("參與人員:專家")) if (ir.GetValue("參與人員:專家") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "專家");
                                sb1.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:專家", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:專家","","1");

                            }
                        if (ir.Contains("參與人員:醫師")) if (ir.GetValue("參與人員:醫師") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "醫師");
                                sb1.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:醫師", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:醫師", "","1");
                            }
                        if (ir.Contains("參與人員:社工人員")) if (ir.GetValue("參與人員:社工人員") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "社工人員");
                                sb1.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:社工人員", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:社工人員","","1");
                            }
                        if (ir.Contains("參與人員:導師")) if (ir.GetValue("參與人員:導師") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "導師");
                                sb1.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:導師", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:導師","","1");
                            }
                        if (ir.Contains("參與人員:教官")) if (ir.GetValue("參與人員:教官") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "教官");
                                sb1.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:教官", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:教官", "", "1");
                            }
                        if (ir.Contains("參與人員:輔導老師")) if (ir.GetValue("參與人員:輔導老師") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "輔導老師");
                                sb1.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:輔導老師", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:輔導老師", "", "1");
                            }
                        if (ir.Contains("參與人員:任課老師")) if (ir.GetValue("參與人員:任課老師") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "任課老師");
                                sb1.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:任課老師", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:任課老師", "", "1");
                            }
                        if (ir.Contains("參與人員:其它")) if (ir.GetValue("參與人員:其它") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "其它");
                                if (ir.Contains("參與人員:其它備註"))
                                    elm.SetAttributeValue("remark", ir.GetValue("參與人員:其它備註"));
                                sb1.Append(elm.ToString());

                                if (isNew)
                                {
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:其它", "1");
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "參與人員:其它備註", ir.GetValue("參與人員:其它備註"));
                                }
                                else
                                {
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:其它", "", "1");
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "參與人員:其它", "", ir.GetValue("參與人員:其它備註"));
                                }
                            }

                        CounselCaseMeetingRecord.Attendees = sb1.ToString();

                        StringBuilder sb2 = new StringBuilder();

                        if (ir.Contains("輔導方式:暫時結案")) if (ir.GetValue("輔導方式:暫時結案") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "暫時結案");
                                sb2.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:暫時結案", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:暫時結案", "", "1");
                            }
                        if (ir.Contains("輔導方式:專案輔導")) if (ir.GetValue("輔導方式:專案輔導") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "專案輔導");
                                sb2.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:專案輔導", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:專案輔導", "", "1");

                            }
                        if (ir.Contains("輔導方式:導師輔導")) if (ir.GetValue("輔導方式:導師輔導") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "導師輔導");
                                sb2.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:導師輔導", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:導師輔導", "", "1");

                            }
                        if (ir.Contains("輔導方式:轉介")) if (ir.GetValue("輔導方式:轉介") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "轉介");

                                if (ir.Contains("輔導方式:轉介備註"))
                                    elm.SetAttributeValue("remark", ir.GetValue("輔導方式:轉介備註"));
                                sb2.Append(elm.ToString());
                                if (isNew)
                                {
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:轉介", "1");
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:轉介備註", ir.GetValue("輔導方式:轉介備註"));
                                }
                                else
                                {
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:轉介備註", "", ir.GetValue("輔導方式:轉介備註"));
                                }
                            }

                        if (ir.Contains("輔導方式:就醫")) if (ir.GetValue("輔導方式:就醫") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "就醫");

                                if (ir.Contains("輔導方式:就醫備註"))
                                    elm.SetAttributeValue("remark", ir.GetValue("輔導方式:就醫備註"));
                                sb2.Append(elm.ToString());

                                if (isNew)
                                {
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:就醫", "1");
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:就醫備註", "1");
                                }
                                else
                                {
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:就醫", "", "1");
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:就醫備註", "", ir.GetValue("輔導方式:就醫備註"));
                                }
                            }

                        if (ir.Contains("輔導方式:其它")) if (ir.GetValue("輔導方式:其它") == "1")
                        {
                            XElement elm = new XElement("Item");
                            elm.SetAttributeValue("name", "其它");

                            if (ir.Contains("輔導方式:其它備註"))
                                elm.SetAttributeValue("remark", ir.GetValue("輔導方式:其它備註"));
                            sb2.Append(elm.ToString());

                            if (isNew)
                            {
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:其它", "1");
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導方式:其它備註", "1");
                            }
                            else
                            {
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:其它", "", "1");
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導方式:其它備註", "", ir.GetValue("輔導方式:其它備註"));
                            }
                        }

                        CounselCaseMeetingRecord.CounselType = sb2.ToString();

                        StringBuilder sb3 = new StringBuilder();

                        if (ir.Contains("輔導歸類:違規")) if (ir.GetValue("輔導歸類:違規") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "違規");
                                sb3.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:違規", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:違規", "", "1");

                            }
                        if (ir.Contains("輔導歸類:遲曠")) if (ir.GetValue("輔導歸類:遲曠") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "遲曠");
                                sb3.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:遲曠", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:遲曠", "", "1");

                            }
                        if (ir.Contains("輔導歸類:學習")) if (ir.GetValue("輔導歸類:學習") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "學習");
                                sb3.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:學習", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:學習", "", "1");
                            }
                        if (ir.Contains("輔導歸類:生涯")) if (ir.GetValue("輔導歸類:生涯") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "生涯");
                                sb3.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:生涯", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:生涯", "", "1");
                            }
                        if (ir.Contains("輔導歸類:人")) if (ir.GetValue("輔導歸類:人") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "人");
                                sb3.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:人", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:人", "", "1");
                            }
                        if (ir.Contains("輔導歸類:休退轉")) if (ir.GetValue("輔導歸類:休退轉") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "休退轉");
                                sb3.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:休退轉", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:休退轉", "", "1");

                            }
                        if (ir.Contains("輔導歸類:家庭")) if (ir.GetValue("輔導歸類:家庭") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "家庭");
                                sb3.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:家庭", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:家庭", "", "1");
                            }
                        if (ir.Contains("輔導歸類:師生")) if (ir.GetValue("輔導歸類:師生") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "師生");
                                sb3.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:師生", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:師生", "", "1");
                            }
                        if (ir.Contains("輔導歸類:情感")) if (ir.GetValue("輔導歸類:情感") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "情感");
                                sb3.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:情感", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:情感", "", "1");
                            }
                        if (ir.Contains("輔導歸類:精神")) if (ir.GetValue("輔導歸類:精神") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "精神");
                                sb3.Append(elm.ToString());
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:精神", "1");
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:精神", "", "1");
                            }

                        if (ir.Contains("輔導歸類:其它")) if (ir.GetValue("輔導歸類:其它") == "1")
                            {
                                XElement elm = new XElement("Item");
                                elm.SetAttributeValue("name", "其它");
                                if (ir.Contains("輔導歸類:其它備註"))
                                    elm.SetAttributeValue("remark", ir.GetValue("輔導歸類:其它備註"));
                                sb3.Append(elm.ToString());
                                if (isNew)
                                {
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:其它", "1");
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導歸類:其它備註", ir.GetValue("輔導歸類:其它備註"));
                                }
                                else
                                {
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:其它", "", "1");
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "輔導歸類:其它備註", "", ir.GetValue("輔導歸類:其它備註"));
                                }
                            }

                        CounselCaseMeetingRecord.CounselTypeKind = sb3.ToString();

                        if(ir.Contains("內容要點"))
                        {
                            if (isNew)
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "內容要點", ir.GetValue("內容要點"));
                            else
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "內容要點", CounselCaseMeetingRecord.ContentDigest, ir.GetValue("內容要點"));
                            CounselCaseMeetingRecord.ContentDigest=ir.GetValue("內容要點");
                        }
                    if (ir.Contains("記錄者姓名"))
                    {
                        if (isNew)
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "記錄者姓名", ir.GetValue("記錄者姓名"));
                        else
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "記錄者姓名", CounselCaseMeetingRecord.AuthorName, ir.GetValue("記錄者姓名"));
                        CounselCaseMeetingRecord.AuthorName = ir.GetValue("記錄者姓名");
                    }
                    if (ir.Contains("記錄者"))
                    {

                        // 檢查記錄者如果空的用記錄者姓名比對,有比對到填入記錄者
                        if (string.IsNullOrEmpty(ir.GetValue("記錄者")))
                        {
                            if (teacherNameLoginIDDict.ContainsKey(CounselCaseMeetingRecord.AuthorName))
                            {
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "記錄者", ir.GetValue("記錄者"));
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "記錄者", CounselCaseMeetingRecord.AuthorID, teacherNameLoginIDDict[CounselCaseMeetingRecord.AuthorName]);
                                CounselCaseMeetingRecord.AuthorID = teacherNameLoginIDDict[CounselCaseMeetingRecord.AuthorName];
                            }
                        }
                        else
                        {
                            if (isNew)
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "記錄者", ir.GetValue("記錄者"));
                            else
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCaseMeetingRecord.UID, "記錄者", CounselCaseMeetingRecord.AuthorID, ir.GetValue("記錄者"));
                            CounselCaseMeetingRecord.AuthorID = ir.GetValue("記錄者");
                        }
                    }

                        if (string.IsNullOrEmpty(CounselCaseMeetingRecord.UID))
                            InsertData.Add(CounselCaseMeetingRecord);
                        else
                            UpdateData.Add(CounselCaseMeetingRecord);
                    }
                }
                if (InsertData.Count > 0)
                    _UDTTransfer.InsertCaseMeetingRecordList(InsertData);

                if (UpdateData.Count > 0)
                    _UDTTransfer.UpdateCaseMeetingRecordList(UpdateData);

                // log
                Dictionary<string, Dictionary<string, Dictionary<string, string>>> insertLogDict = _LogTransfer.GetBatchInsertLog();
                Dictionary<string, Dictionary<string, Dictionary<string, string>>> updateLogDict = _LogTransfer.GetBatchUpdateLog();

                string TitleName = "匯入個案會議";
                // 處理 log 細項
                foreach (KeyValuePair<string, string> data in StudentNameDict)
                {
                    if (insertLogDict.Count > 0)
                    {
                        if (insertLogDict.ContainsKey(data.Key))
                        {
                            foreach (KeyValuePair<string, Dictionary<string, string>> d1 in insertLogDict[data.Key])
                            {
                                StringBuilder sb = new StringBuilder();
                                sb.AppendLine(TitleName + "-新增");
                                sb.AppendLine(data.Value);
                                foreach (KeyValuePair<string, string> d2 in d1.Value)
                                    sb.AppendLine(d2.Key + ":" + d2.Value);

                                if (LogData.ContainsKey(data.Key))
                                {
                                    LogData[data.Key].AppendLine();
                                    LogData[data.Key].AppendLine(sb.ToString());
                                }
                                else
                                    LogData.Add(data.Key, sb);

                            }
                        }
                    }

                    if (updateLogDict.Count > 0)
                    {
                        if (updateLogDict.ContainsKey(data.Key))
                        {

                            foreach (KeyValuePair<string, Dictionary<string, string>> d1 in updateLogDict[data.Key])
                            {
                                StringBuilder sb = new StringBuilder();
                                sb.AppendLine(TitleName + "-修改");
                                sb.AppendLine(data.Value);

                                foreach (KeyValuePair<string, string> d2 in d1.Value)
                                    sb.AppendLine(d2.Key + ":" + d2.Value);

                                if (LogData.ContainsKey(data.Key))
                                {
                                    LogData[data.Key].AppendLine();
                                    LogData[data.Key].AppendLine(sb.ToString());
                                }
                                else
                                    LogData.Add(data.Key, sb);
                            }
                        }
                    }

                }

                // 寫入 log
                DAO.LogTransfer log = new DAO.LogTransfer();
                foreach (KeyValuePair<string, StringBuilder> data in LogData)
                    log.SaveLog("輔導系統." + TitleName, "匯入", "student", data.Key, data.Value);

                StringBuilder sbT = new StringBuilder();
                sbT.AppendLine(TitleName);
                sbT.AppendLine("總共匯入" + LogData.Keys.Count + "位學生 , 共" + TotalCount + "筆");
                sbT.AppendLine("匯入學生名單..");
                foreach (KeyValuePair<string, string> data in StudentNameDict)
                    if (LogData.ContainsKey(data.Key))
                        sbT.AppendLine(data.Value);

                log.SaveLog("輔導系統." + TitleName, "匯入", "student", "", sbT);

            return "";
        }
        public override void InitializeExport(SmartSchool.API.PlugIn.Export.ExportWizard wizard)
        {
            wizard.ExportableFields.AddRange(ExportItemList);
            wizard.ExportPackage += delegate(object sender,SmartSchool.API.PlugIn.Export.ExportPackageEventArgs e)
            {
                // 依學生ID取得優先關懷
                List<DAO.UDT_CounselCareRecordDef> _CounselCareRecordList = _UDTTransfer.GetCareRecordsByStudentIDList(e.List);

                // 學生ID List
                List<int> studIdList = (from data in _CounselCareRecordList select data.StudentID).ToList();

                // 取得學生名稱log 用
                Dictionary<string, string> StudentNameDict = new Dictionary<string, string>();
                foreach (KeyValuePair<int, string> data in Utility.GetConvertStringDict1fromDB(studIdList))
                    StudentNameDict.Add(data.Key.ToString(), data.Value);

                // 記錄匯出 log 細項用
                Dictionary<string, StringBuilder> logData = new Dictionary<string, StringBuilder>();

                // 匯出總筆數
                int totalCount = 0;

                foreach (DAO.UDT_CounselCareRecordDef ccrd in _CounselCareRecordList)
                {
                    RowData row = new RowData();
                    totalCount++;

                    row.ID = ccrd.StudentID.ToString();
                    foreach (string field in e.ExportFields)
                    {
                        if (wizard.ExportableFields.Contains(field))
                        {
                            switch(field)
                            {
                                case "代號":
                                    row.Add(field, ccrd.CodeName);
                                    break;
                                case "立案日期":
                                    if(ccrd.FileDate.HasValue)
                                        row.Add(field, ccrd.FileDate.Value.ToShortDateString());
                                    break;
                                case "個案類別":
                                    row.Add(field, ccrd.CaseCategory);
                                    break;
                                case "個案類別備註":
                                    row.Add(field, ccrd.CaseCategoryRemark);
                                    break;
                                case "個案來源":
                                    row.Add(field, ccrd.CaseOrigin);
                                    break;
                                case "個案來源備註":
                                    row.Add(field, ccrd.CaseOriginRemark);
                                    break;
                                case "優勢能力及財力":
                                    row.Add(field, ccrd.Superiority);
                                    break;
                                case "弱勢能力及財力":
                                    row.Add(field, ccrd.Weakness);
                                    break;
                                case "輔導人員輔導目標":
                                    row.Add(field, ccrd.CounselGoal);
                                    break;
                                case "校外協輔機構":
                                    row.Add(field, ccrd.OtherInstitute);
                                    break;
                                case "輔導人員輔導方式":
                                    row.Add(field, ccrd.CounselType);
                                    break;
                                case "協同輔導人員協助導師事項":
                                    row.Add(field, ccrd.AssistedMatter);
                                    break;
                                case "記錄者":
                                    row.Add(field, ccrd.AuthorID);
                                    break;
                                case "記錄者姓名":
                                    row.Add(field, ccrd.AuthorName);
                                    break;
                                case "狀態":
                                    row.Add(field, ccrd.StudentStatus);
                                    break;
                            }
                        }
                    }
                    e.Items.Add(row);
                }
                // 處理 log 細項
                foreach (RowData rd in e.Items)
                {
                    // 收集 log
                    StringBuilder sb = new StringBuilder();
                    if (StudentNameDict.ContainsKey(rd.ID))
                        sb.AppendLine(StudentNameDict[rd.ID]);
                    sb.AppendLine(this.Text);
                    foreach (KeyValuePair<string, string> data in rd)
                        sb.AppendLine(data.Key + ":" + data.Value);

                    // 加入 log
                    if (logData.ContainsKey(rd.ID))
                    {
                        sb.AppendLine();
                        logData[rd.ID].AppendLine(sb.ToString());
                    }
                    else
                        logData.Add(rd.ID, sb);
                }

                // 寫入 log
                DAO.LogTransfer log = new DAO.LogTransfer();
                foreach (KeyValuePair<string, StringBuilder> data in logData)
                    log.SaveLog("輔導系統." + this.Text, "匯出", "student", data.Key, data.Value);

                StringBuilder sbT= new StringBuilder ();
                sbT.AppendLine(this.Text);
                sbT.AppendLine("總共匯出"+logData.Keys.Count+"位學生 , 共"+totalCount+"筆");
                sbT.AppendLine("匯出學生名單..");
                foreach (KeyValuePair<string, string> data in StudentNameDict)
                    if (logData.ContainsKey(data.Key))
                        sbT.AppendLine(data.Value);

                log.SaveLog("輔導系統." + this.Text, "匯出","student","",sbT);

            };
        }
        public override string Import(List<Campus.DocumentValidator.IRowStream> Rows)
        {
            List<DAO.UDT_CounselCareRecordDef> InsertData = new List<DAO.UDT_CounselCareRecordDef>();
            List<DAO.UDT_CounselCareRecordDef> UpdateData = new List<DAO.UDT_CounselCareRecordDef>();
            List<DAO.UDT_CounselCareRecordDef> HasData = new List<DAO.UDT_CounselCareRecordDef>();

            // -- 處理 log
            Dictionary<string, StringBuilder> LogData = new Dictionary<string, StringBuilder>();
            // 學生ID List
             List<int> studIdList= new List<int> ();
            foreach (IRowStream ir in Rows)
            {
                int i;
                if (ir.Contains("學號") && ir.Contains("狀態"))
                {
                    if (int.TryParse(Utility.GetStudentID(ir.GetValue("學號"), ir.GetValue("狀態")).ToString(), out i))
                        studIdList.Add(i);
                }
            }
            // 取得學生名稱log 用
            Dictionary<string, string> StudentNameDict = new Dictionary<string, string>();
            foreach (KeyValuePair<int, string> data in Utility.GetConvertStringDict1fromDB(studIdList))
                StudentNameDict.Add(data.Key.ToString(), data.Value);

            DAO.LogTransfer _LogTransfer = new DAO.LogTransfer();

            List<string> StudentIDList = new List<string>();
            // 取得學生狀態對應
            foreach (IRowStream ir in Rows)
            {
                if (ir.Contains("學號") && ir.Contains("狀態"))
                    StudentIDList.Add(Utility.GetStudentID(ir.GetValue("學號"), ir.GetValue("狀態")).ToString());
            }
            // 已有資料
            HasData = _UDTTransfer.GetCareRecordsByStudentIDList(StudentIDList);

            // 取得教師帳號比對用
            Dictionary<string, string> teacherNameLoginIDDict = Utility.GetTeacherNameLoginIDStatus1();

            int TotalCount = 0, NewIdx = 0;

            foreach (IRowStream ir in Rows)
            {
                TotalCount++;
                this.ImportProgress = TotalCount;
                DAO.UDT_CounselCareRecordDef CounselCareRecord = null;
                int sid = 0;
                if (ir.Contains("學號") && ir.Contains("狀態"))
                {
                    string key =ir.GetValue("學號") + "_";
                    if (Global._StudentStatusDBDict.ContainsKey(ir.GetValue("狀態")))
                        sid = Utility.GetStudentID(ir.GetValue("學號"), ir.GetValue("狀態"));

                    DateTime dt;
                    // 當同一位學生有相同會議日期與會議事由,當作是更新,否則新增
                    if (DateTime.TryParse(ir.GetValue("立案日期"), out dt))
                    {
                        foreach (DAO.UDT_CounselCareRecordDef rec in HasData.Where(x => x.StudentID == sid))
                        {
                            if (rec.FileDate.HasValue)
                                if (rec.FileDate.Value.ToShortDateString() == dt.ToShortDateString())
                                    if (rec.CaseCategory == ir.GetValue("個案類別") && rec.CaseOrigin==ir.GetValue("個案來源"))
                                        CounselCareRecord = rec;
                        }
                    }

                    bool isNew = false;
                    if (CounselCareRecord == null)
                    {
                        CounselCareRecord = new DAO.UDT_CounselCareRecordDef();
                        isNew = true;
                        NewIdx++;
                    }
                    string StudID=sid.ToString();
                    string insertKey = "A" + NewIdx;
                    // 學生編號
                    CounselCareRecord.StudentID = sid;
                    // 立案日期
                    if (isNew)
                        _LogTransfer.AddBatchInsertLog(StudID, insertKey, "立案日期", dt.ToShortDateString());
                    else
                        _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "立案日期", CounselCareRecord.FileDate.Value.ToShortDateString(), dt.ToShortDateString());
                     CounselCareRecord.FileDate = dt;

                     if (ir.Contains("代號"))
                     {
                         if (isNew)
                             _LogTransfer.AddBatchInsertLog(StudID, insertKey, "代號", ir.GetValue("代號"));
                         else
                             _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "代號", CounselCareRecord.CodeName, ir.GetValue("代號"));
                         CounselCareRecord.CodeName = ir.GetValue("代號");
                     }

                     if (isNew)
                         _LogTransfer.AddBatchInsertLog(StudID, insertKey, "個案類別", ir.GetValue("個案類別"));
                     else
                         _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "個案類別", CounselCareRecord.CaseCategory, ir.GetValue("個案類別"));
                    CounselCareRecord.CaseCategory = ir.GetValue("個案類別");

                    if (ir.Contains("個案類別備註"))
                    {
                        if (isNew)
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "個案類別備註", ir.GetValue("個案類別備註"));
                        else
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "個案類別備註", CounselCareRecord.CaseCategoryRemark, ir.GetValue("個案類別備註"));
                        CounselCareRecord.CaseCategoryRemark = ir.GetValue("個案類別備註");
                    }

                    if (isNew)
                        _LogTransfer.AddBatchInsertLog(StudID, insertKey, "個案來源", ir.GetValue("個案來源"));
                    else
                        _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "個案來源", CounselCareRecord.CaseOrigin, ir.GetValue("個案來源"));
                    CounselCareRecord.CaseOrigin = ir.GetValue("個案來源");

                    if (ir.Contains("個案來源備註"))
                    {
                        if (isNew)
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "個案來源備註", ir.GetValue("個案來源備註"));
                        else
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "個案來源備註", CounselCareRecord.CaseOriginRemark, ir.GetValue("個案來源備註"));
                        CounselCareRecord.CaseOriginRemark = ir.GetValue("個案來源備註");
                    }
                    if (ir.Contains("優勢能力及財力"))
                    {
                        if (isNew)
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "優勢能力及財力", ir.GetValue("優勢能力及財力"));
                        else
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "優勢能力及財力", CounselCareRecord.Superiority, ir.GetValue("優勢能力及財力"));
                        CounselCareRecord.Superiority = ir.GetValue("優勢能力及財力");
                    }

                    if (ir.Contains("弱勢能力及財力"))
                    {
                        if (isNew)
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "弱勢能力及財力", ir.GetValue("弱勢能力及財力"));
                        else
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "弱勢能力及財力", CounselCareRecord.Weakness, ir.GetValue("弱勢能力及財力"));
                        CounselCareRecord.Weakness = ir.GetValue("弱勢能力及財力");
                    }
                    if (ir.Contains("輔導人員輔導目標"))
                    {
                        if (isNew)
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導人員輔導目標", ir.GetValue("輔導人員輔導目標"));
                        else
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "輔導人員輔導目標", CounselCareRecord.CounselGoal, ir.GetValue("輔導人員輔導目標"));
                        CounselCareRecord.CounselGoal = ir.GetValue("輔導人員輔導目標");
                    }
                    if (ir.Contains("校外協輔機構"))
                    {
                        if (isNew)
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "校外協輔機構", ir.GetValue("校外協輔機構"));
                        else
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "校外協輔機構", CounselCareRecord.OtherInstitute, ir.GetValue("校外協輔機構"));
                        CounselCareRecord.OtherInstitute = ir.GetValue("校外協輔機構");
                    }
                    if (ir.Contains("輔導人員輔導方式"))
                    {
                        if (isNew)
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "輔導人員輔導方式", ir.GetValue("輔導人員輔導方式"));
                        else
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "輔導人員輔導方式", CounselCareRecord.CounselType, ir.GetValue("輔導人員輔導方式"));
                        CounselCareRecord.CounselType = ir.GetValue("輔導人員輔導方式");
                    }
                    if (ir.Contains("協同輔導人員協助導師事項"))
                    {
                        if (isNew)
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "協同輔導人員協助導師事項", ir.GetValue("協同輔導人員協助導師事項"));
                        else
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "協同輔導人員協助導師事項", CounselCareRecord.AssistedMatter, ir.GetValue("協同輔導人員協助導師事項"));
                        CounselCareRecord.AssistedMatter = ir.GetValue("協同輔導人員協助導師事項");
                    }

                    if (ir.Contains("記錄者姓名"))
                    {
                        if (isNew)
                            _LogTransfer.AddBatchInsertLog(StudID, insertKey, "記錄者姓名", ir.GetValue("記錄者姓名"));
                        else
                            _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "記錄者姓名", CounselCareRecord.AuthorName, ir.GetValue("記錄者姓名"));
                        CounselCareRecord.AuthorName = ir.GetValue("記錄者姓名");
                    }
                    if (ir.Contains("記錄者"))
                    {

                        // 檢查記錄者如果空的用記錄者姓名比對,有比對到填入記錄者
                        if (string.IsNullOrEmpty(ir.GetValue("記錄者")))
                        {
                            if (teacherNameLoginIDDict.ContainsKey(CounselCareRecord.AuthorName))
                            {
                                if (isNew)
                                    _LogTransfer.AddBatchInsertLog(StudID, insertKey, "記錄者", ir.GetValue("記錄者"));
                                else
                                    _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "記錄者", CounselCareRecord.AuthorID, teacherNameLoginIDDict[CounselCareRecord.AuthorName]);
                                CounselCareRecord.AuthorID = teacherNameLoginIDDict[CounselCareRecord.AuthorName];
                            }
                        }
                        else
                        {
                            if (isNew)
                                _LogTransfer.AddBatchInsertLog(StudID, insertKey, "記錄者", ir.GetValue("記錄者"));
                            else
                                _LogTransfer.AddBatchUpdateLog(StudID, CounselCareRecord.UID, "記錄者", CounselCareRecord.AuthorID, ir.GetValue("記錄者"));
                            CounselCareRecord.AuthorID = ir.GetValue("記錄者");
                        }
                    }
                    if (string.IsNullOrEmpty(CounselCareRecord.UID))
                        InsertData.Add(CounselCareRecord);
                    else
                        UpdateData.Add(CounselCareRecord);
                }
            }
            if (InsertData.Count > 0)
                _UDTTransfer.InsertCareRecordList(InsertData);

            if (UpdateData.Count > 0)
                _UDTTransfer.UpdateCareRecordList(UpdateData);

            // log
            Dictionary<string, Dictionary<string, Dictionary<string, string>>> insertLogDict = _LogTransfer.GetBatchInsertLog();
            Dictionary<string,Dictionary<string,Dictionary<string,string>>> updateLogDict = _LogTransfer.GetBatchUpdateLog();

            string TitleName = "匯入優先關懷";
            // 處理 log 細項
            foreach (KeyValuePair<string, string> data in StudentNameDict)
            {
                if (insertLogDict.Count > 0)
                {
                    if (insertLogDict.ContainsKey(data.Key))
                    {
                        foreach (KeyValuePair<string, Dictionary<string, string>> d1 in insertLogDict[data.Key])
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine(TitleName+"-新增");
                            sb.AppendLine(data.Value);
                            foreach (KeyValuePair<string, string> d2 in d1.Value)
                                sb.AppendLine(d2.Key + ":" + d2.Value);

                            if (LogData.ContainsKey(data.Key))
                            {
                                LogData[data.Key].AppendLine();
                                LogData[data.Key].AppendLine(sb.ToString());
                            }
                            else
                                LogData.Add(data.Key, sb);

                        }
                    }
                }

                if (updateLogDict.Count > 0)
                {
                    if (updateLogDict.ContainsKey(data.Key))
                    {

                        foreach (KeyValuePair<string, Dictionary<string, string>> d1 in updateLogDict[data.Key])
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine(TitleName+"-修改");
                            sb.AppendLine(data.Value);

                            foreach (KeyValuePair<string, string> d2 in d1.Value)
                                sb.AppendLine(d2.Key + ":" + d2.Value);

                            if (LogData.ContainsKey(data.Key))
                            {
                                LogData[data.Key].AppendLine();
                                LogData[data.Key].AppendLine(sb.ToString());
                            }
                            else
                                LogData.Add(data.Key, sb);
                        }
                    }
                }

            }

            // 寫入 log
            DAO.LogTransfer log = new DAO.LogTransfer();
            foreach (KeyValuePair<string, StringBuilder> data in LogData)
                log.SaveLog("輔導系統."+TitleName, "匯入", "student", data.Key, data.Value);

            StringBuilder sbT = new StringBuilder();
            sbT.AppendLine(TitleName);
            sbT.AppendLine("總共匯入" + LogData.Keys.Count + "位學生 , 共" + TotalCount + "筆");
            sbT.AppendLine("匯入學生名單..");
            foreach (KeyValuePair<string, string> data in StudentNameDict)
                if (LogData.ContainsKey(data.Key))
                    sbT.AppendLine(data.Value);

            log.SaveLog("輔導系統." + TitleName, "匯入", "student", "", sbT);
            return "";
        }
示例#14
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lvCaseMeeting.SelectedItems.Count == 1)
            {
                DAO.UDT_CounselCaseMeetingRecordDef CaseMeetingRecord = lvCaseMeeting.SelectedItems[0].Tag as DAO.UDT_CounselCaseMeetingRecordDef;
                if (CaseMeetingRecord != null)
                {
                    DAO.LogTransfer logTransfer = new DAO.LogTransfer();

                    K12.Data.StudentRecord studRec = K12.Data.Student.SelectByID(PrimaryKey);
                    StringBuilder          logData = new StringBuilder();
                    logData.AppendLine("刪除" + Utility.ConvertString1(studRec));

                    // 取得 XML 解析後
                    Dictionary <string, string> item_AttendessDict       = Utility.GetConvertCounselXMLVal_Attendees(CaseMeetingRecord.Attendees);
                    Dictionary <string, string> item_CounselTypeDict     = Utility.GetConvertCounselXMLVal_CounselType(CaseMeetingRecord.CounselType);
                    Dictionary <string, string> item_CounselTypeKindDict = Utility.GetConvertCounselXMLVal_CounselTypeKind(CaseMeetingRecord.CounselTypeKind);

                    if (FISCA.Presentation.Controls.MsgBox.Show("請問是否確定刪除個案會議?", "刪除個案會議", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        // log
                        logData.AppendLine("個案編號:" + CaseMeetingRecord.CaseNo);

                        if (CaseMeetingRecord.MeetingDate.HasValue)
                        {
                            logData.AppendLine("會議日期" + CaseMeetingRecord.MeetingDate.Value.ToShortDateString());
                        }

                        K12.Data.TeacherRecord tRec = K12.Data.Teacher.SelectByID(CaseMeetingRecord.CounselTeacherID.ToString());
                        if (tRec != null)
                        {
                            if (string.IsNullOrEmpty(tRec.Nickname))
                            {
                                logData.AppendLine("晤談老師:" + tRec.Name);
                            }
                            else
                            {
                                logData.AppendLine("晤談老師:" + tRec.Name + "(" + tRec.Nickname + ")");
                            }
                        }

                        logData.AppendLine("會議時間:" + CaseMeetingRecord.MeetigTime);
                        logData.AppendLine("會議事由:" + CaseMeetingRecord.MeetingCause);
                        logData.AppendLine("會議地點:" + CaseMeetingRecord.Place);
                        logData.AppendLine("內容要點:" + CaseMeetingRecord.ContentDigest);
                        logData.AppendLine("記錄者:" + CaseMeetingRecord.AuthorID);
                        logData.AppendLine("記錄者姓名:" + CaseMeetingRecord.AuthorName);

                        logData.AppendLine("參與人員:");
                        foreach (KeyValuePair <string, string> data in item_AttendessDict)
                        {
                            if (!string.IsNullOrEmpty(data.Value))
                            {
                                logData.AppendLine(data.Key + ":" + data.Value);
                            }
                        }

                        logData.AppendLine("輔導方式:");
                        foreach (KeyValuePair <string, string> data in item_CounselTypeDict)
                        {
                            if (!string.IsNullOrEmpty(data.Value))
                            {
                                logData.AppendLine(data.Key + ":" + data.Value);
                            }
                        }

                        logData.AppendLine("輔導歸類:");
                        foreach (KeyValuePair <string, string> data in item_CounselTypeKindDict)
                        {
                            if (!string.IsNullOrEmpty(data.Value))
                            {
                                logData.AppendLine(data.Key + ":" + data.Value);
                            }
                        }


                        _UDTTransfer.DeleteCaseMeetingRecord(CaseMeetingRecord);
                        logTransfer.SaveLog("學生.輔導個案會議-刪除", "刪除", "student", PrimaryKey, logData);
                        _BGRun();
                    }
                }
            }
            else
            {
                FISCA.Presentation.Controls.MsgBox.Show("請選擇資料.");
            }
        }
        public override void InitializeExport(SmartSchool.API.PlugIn.Export.ExportWizard wizard)
        {
            wizard.ExportableFields.AddRange(ExportItemList);
            wizard.ExportPackage += delegate(object sender, SmartSchool.API.PlugIn.Export.ExportPackageEventArgs e)
            {
                // 透過學生編號取得個案會議
                List <DAO.UDT_CounselCaseMeetingRecordDef> CounselCaseMeetingRecordList = _UDTTransfer.GetCaseMeetingRecordListByStudentIDList(e.List);

                // 取得教師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>();

                // 學生ID List
                List <int> studIdList = (from data in CounselCaseMeetingRecordList select data.StudentID).ToList();

                // 取得學生名稱log 用
                Dictionary <string, string> StudentNameDict = new Dictionary <string, string>();
                foreach (KeyValuePair <int, string> data in Utility.GetConvertStringDict1fromDB(studIdList))
                {
                    StudentNameDict.Add(data.Key.ToString(), data.Value);
                }

                // 記錄匯出 log 細項用
                Dictionary <string, StringBuilder> logData = new Dictionary <string, StringBuilder>();

                // 匯出總筆數
                int totalCount = 0;


                foreach (DAO.UDT_CounselCaseMeetingRecordDef ccmrd in CounselCaseMeetingRecordList)
                {
                    RowData row = new RowData();
                    row.ID = ccmrd.StudentID.ToString();

                    // 取得 XML 解析後
                    item_AttendessDict       = Utility.GetConvertCounselXMLVal_Attendees(ccmrd.Attendees);
                    item_CounselTypeDict     = Utility.GetConvertCounselXMLVal_CounselType(ccmrd.CounselType);
                    item_CounselTypeKindDict = Utility.GetConvertCounselXMLVal_CounselTypeKind(ccmrd.CounselTypeKind);



                    foreach (string field in e.ExportFields)
                    {
                        if (wizard.ExportableFields.Contains(field))
                        {
                            // 參與人員
                            if (item_AttendessDict.ContainsKey(field))
                            {
                                row.Add(field, item_AttendessDict[field]);
                            }

                            // 輔導方式
                            if (item_CounselTypeDict.ContainsKey(field))
                            {
                                row.Add(field, item_CounselTypeDict[field]);
                            }

                            // 輔導歸類
                            if (item_CounselTypeKindDict.ContainsKey(field))
                            {
                                row.Add(field, item_CounselTypeKindDict[field]);
                            }

                            switch (field)
                            {
                            case "個案編號":
                                row.Add(field, ccmrd.CaseNo);
                                break;

                            case "晤談老師":
                                // 需轉換
                                if (TeacherNameDict.ContainsKey(ccmrd.CounselTeacherID))
                                {
                                    row.Add(field, TeacherNameDict[ccmrd.CounselTeacherID]);
                                }
                                break;

                            case "會議日期":
                                if (ccmrd.MeetingDate.HasValue)
                                {
                                    row.Add(field, ccmrd.MeetingDate.Value.ToShortDateString());
                                }
                                break;

                            case "會議時間":
                                row.Add(field, ccmrd.MeetigTime);
                                break;

                            case "會議事由":
                                row.Add(field, ccmrd.MeetingCause);
                                break;

                            case "內容要點":
                                row.Add(field, ccmrd.ContentDigest);
                                break;

                            case "記錄者":
                                row.Add(field, ccmrd.AuthorID);
                                break;

                            case "記錄者姓名":
                                row.Add(field, ccmrd.AuthorName);
                                break;

                            case "狀態":
                                row.Add(field, ccmrd.StudentStatus);
                                break;
                            }
                        }
                    }
                    e.Items.Add(row);
                }
                // 處理 log 細項
                foreach (RowData rd in e.Items)
                {
                    // 收集 log
                    StringBuilder sb = new StringBuilder();
                    if (StudentNameDict.ContainsKey(rd.ID))
                    {
                        sb.AppendLine(StudentNameDict[rd.ID]);
                    }
                    sb.AppendLine(this.Text);
                    foreach (KeyValuePair <string, string> data in rd)
                    {
                        sb.AppendLine(data.Key + ":" + data.Value);
                    }

                    // 加入 log
                    if (logData.ContainsKey(rd.ID))
                    {
                        sb.AppendLine();
                        logData[rd.ID].AppendLine(sb.ToString());
                    }
                    else
                    {
                        logData.Add(rd.ID, sb);
                    }
                }

                // 寫入 log
                DAO.LogTransfer log = new DAO.LogTransfer();
                foreach (KeyValuePair <string, StringBuilder> data in logData)
                {
                    log.SaveLog("輔導系統." + this.Text, "匯出", "student", data.Key, data.Value);
                }

                StringBuilder sbT = new StringBuilder();
                sbT.AppendLine(this.Text);
                sbT.AppendLine("總共匯出" + logData.Keys.Count + "位學生 , 共" + totalCount + "筆");
                sbT.AppendLine("匯出學生名單..");
                foreach (KeyValuePair <string, string> data in StudentNameDict)
                {
                    if (logData.ContainsKey(data.Key))
                    {
                        sbT.AppendLine(data.Value);
                    }
                }

                log.SaveLog("輔導系統." + this.Text, "匯出", "student", "", sbT);
            };
        }
        private void btnDel_Click(object sender, EventArgs e)
        {
            if (lvInterview.SelectedItems.Count > 0)
            {
                DAO.UDT_CounselStudentInterviewRecordDef studInterviewRec = lvInterview.SelectedItems[0].Tag as DAO.UDT_CounselStudentInterviewRecordDef;
                if (studInterviewRec != null)
                {
                    DAO.LogTransfer logTransfer = new DAO.LogTransfer();
                    string teacherName = lvInterview.SelectedItems[0].SubItems[colTeacherID.Index].Text;
                    K12.Data.StudentRecord studRec=K12.Data.Student.SelectByID(PrimaryKey);
                    StringBuilder logData = new StringBuilder();
                    logData.AppendLine("刪除" + Utility.ConvertString1(studRec));
                    // 取得 XML 解析後
                    Dictionary<string, string> item_AttendessDict = Utility.GetConvertCounselXMLVal_Attendees(studInterviewRec.Attendees);
                    Dictionary<string, string> item_CounselTypeDict = Utility.GetConvertCounselXMLVal_CounselType(studInterviewRec.CounselType);
                    Dictionary<string, string> item_CounselTypeKindDict = Utility.GetConvertCounselXMLVal_CounselTypeKind(studInterviewRec.CounselTypeKind);

                    if (FISCA.Presentation.Controls.MsgBox.Show("請問是否確定是刪除晤談紀錄?", "刪除晤談紀錄", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        // log
                        logData.AppendLine("晤談老師:"+ teacherName);
                        logData.AppendLine("晤談對象:"+ studInterviewRec.IntervieweeType);
                        logData.AppendLine("晤談方式:"+ studInterviewRec.InterviewType);
                        if (studInterviewRec.InterviewDate.HasValue)
                            logData.AppendLine("日期:"+ studInterviewRec.InterviewDate.Value.ToShortDateString());
                        logData.AppendLine("時間:"+ studInterviewRec.InterviewTime);
                        logData.AppendLine("地點:"+ studInterviewRec.Place);
                        logData.AppendLine("晤談編號:"+ studInterviewRec.InterviewNo);
                        logData.AppendLine("晤談事由:"+ studInterviewRec.Cause);

                        logData.AppendLine("參與人員:");
                        foreach (KeyValuePair<string, string> data in item_AttendessDict)
                            if (!string.IsNullOrEmpty(data.Value))
                                logData.AppendLine(data.Key + ":" + data.Value);

                        logData.AppendLine("輔導方式:");
                        foreach (KeyValuePair<string, string> data in item_CounselTypeDict)
                            if (!string.IsNullOrEmpty(data.Value))
                                logData.AppendLine(data.Key + ":" + data.Value);

                        logData.AppendLine("輔導歸類:");
                        foreach (KeyValuePair<string, string> data in item_CounselTypeKindDict)
                            if (!string.IsNullOrEmpty(data.Value))
                                logData.AppendLine(data.Key + ":" + data.Value);

                        logData.AppendLine("內容要點:"+ studInterviewRec.ContentDigest);
                        logData.AppendLine("記錄者:"+ studInterviewRec.AuthorID);
                        logData.AppendLine("記錄者姓名:"+ studInterviewRec.AuthorName);

                        _UDTTransfer.DeleteCounselStudentInterviewRecord(studInterviewRec);

                        logTransfer.SaveLog("學生.輔導晤談紀錄-刪除", "刪除", "student", PrimaryKey, logData);

                        _BGRun();
                    }
                }
            }
            else
                FISCA.Presentation.Controls.MsgBox.Show ("請選擇資料.");
        }