//<Morality Face=\"誠實地面對自己\">橙</Morality> //<Morality Face=\"誠實地對待他人\">橙</Morality> //<Morality Face=\"自我尊重\">橙</Morality> //<Morality Face=\"尊重他人\">橙</Morality> //<Morality Face=\"承諾\">橙</Morality> //<Morality Face=\"責任\">橙</Morality> //<Morality Face=\"榮譽\">橙</Morality> //<Morality Face=\"感謝\">橙</Morality> private Dictionary <string, string> GetTextScore(SHMoralScoreRecord MScore) { Dictionary <string, string> studTextScore = new Dictionary <string, string>(); foreach (XmlElement each in MScore.TextScore.SelectNodes("Morality")) { string key = each.Attributes["Face"].InnerText; if (!studTextScore.ContainsKey(key)) { studTextScore.Add(key, each.InnerText); } } return(studTextScore); }
/// <summary> /// 修改後的XML資料 /// </summary> public void SetNew(SHMoralScoreRecord MSR) { _MSR = MSR; _NewInfo = _MSR.TextScore; if (_NewInfo != null) { foreach (XmlElement each in _NewInfo.SelectNodes("Morality")) { if (_List.Contains(each.GetAttribute("Face"))) { _NewDic[each.GetAttribute("Face")] = each.InnerText; } } } }
/// <summary> /// 修改後的XML資料 /// </summary> public void SetNew(SHMoralScoreRecord MSR) { _MSR = MSR; _NewString = MSR.Comment; }
/// <summary> /// 修改前的XML資料 /// </summary> public void SetOld(SHMoralScoreRecord MSR) { _OldString = MSR.Comment; }
/// <summary> /// 傳入MoralScore與Row,以建立資料狀態 /// </summary> private XmlElement GetUpdateTextScore(SHMoralScoreRecord SSR, IRowStream Row) { XmlDocument XmlDoc = new XmlDocument(); #region TextScores內容為空,則建立一個預設根節點 if (SSR.TextScore != null) { if (!string.IsNullOrEmpty(SSR.TextScore.OuterXml)) { XmlDoc.LoadXml(SSR.TextScore.OuterXml); } else { XmlDoc.LoadXml("<Content/>"); } } else { XmlDoc.LoadXml("<Content/>"); } #endregion XmlElement XmlElementB1; #region 把Content置換成TextScore if (XmlDoc.DocumentElement.Name == "Content") { XmlElementB1 = (XmlElement)XmlDoc.SelectSingleNode("Content"); } else if (XmlDoc.DocumentElement.Name == "TextScore") { XmlDocument copy = new XmlDocument(); copy.LoadXml("<Content/>"); XmlElement Xmlaa = (XmlElement)XmlDoc.SelectSingleNode("TextScore"); foreach (XmlElement Xmlbb in Xmlaa.SelectNodes("Morality")) { XmlElement cc = copy.CreateElement("Morality"); cc.SetAttribute("Face", Xmlbb.GetAttribute("Face")); cc.InnerText = Xmlbb.InnerText; copy.DocumentElement.AppendChild(cc); } XmlDoc = copy; XmlElementB1 = (XmlElement)XmlDoc.DocumentElement;//.SelectSingleNode("Content"); } else { XmlElementB1 = XmlDoc.DocumentElement; } #endregion //以設定檔為主,掃瞄Xml內容 foreach (string each in faceDic.Keys) { if (mOption.SelectedFields.Contains(each)) //如果使用者選擇該欄位 { XmlElement elmMorality = (XmlElement)XmlElementB1.SelectSingleNode("Morality[@Face='" + each + "']"); if (elmMorality != null) //包含此內容 { if (elmMorality.GetAttribute("Face") == each) { elmMorality.InnerText = Row.GetValue(each); } } else //如果Xml內不包含此資料欄位,則新增於Xml內 { elmMorality = (XmlElement)XmlDoc.CreateElement("Morality"); elmMorality.SetAttribute("Face", each); elmMorality.InnerText = Row.GetValue(each); XmlElementB1.AppendChild(elmMorality); } } else //使用者未選擇該欄位,則不進行更動 { //.... } } return(XmlDoc.DocumentElement); }
/// <summary> /// 每1000筆資料,分批執行匯入 /// Return是Log資訊 /// </summary> public override string Import(List <Campus.DocumentValidator.IRowStream> Rows) { List <MoralScoreLogRobot> LogList = new List <MoralScoreLogRobot>(); //取得匯入資料中,所有學生編號下的的日常生活表現資料 List <SHMoralScoreRecord> MoralScoreList = GetMoralScoreList(Rows); List <SHMoralScoreRecord> InsertList = new List <SHMoralScoreRecord>(); List <SHMoralScoreRecord> UpdateList = new List <SHMoralScoreRecord>(); int NochangeCount = 0; //未處理資料記數 if (mOption.Action == ImportAction.InsertOrUpdate) { foreach (IRowStream Row in Rows) { int SchoolYear = int.Parse(Row.GetValue("學年度")); int Semester = int.Parse(Row.GetValue("學期")); string StudentNumber = Row.GetValue("學號"); SHStudentRecord student = StudentRecordByStudentNumber[StudentNumber]; SHMoralScoreRecord SSR = GetMoralScoreRecord(MoralScoreList, StudentNumber, SchoolYear, Semester); //Log機器人 MoralScoreLogRobot log = new MoralScoreLogRobot(student, faceDic.Keys.ToList()); if (SSR == null) //新增SHMoralScoreRecord { SHMoralScoreRecord newRecord = new SHMoralScoreRecord(); newRecord.RefStudentID = student.ID; newRecord.SchoolYear = SchoolYear; newRecord.Semester = Semester; newRecord.TextScore = GetInsertTextScore(Row); //Log log.SetOldLost(); log.SetNew(newRecord); InsertList.Add(newRecord); } else //已存在資料需要修改 or 覆蓋 { //Log(old) log.SetOld(SSR); //取得新的Xml結構 SSR.TextScore = GetUpdateTextScore(SSR, Row); //Log(New) log.SetNew(SSR); if (!string.IsNullOrEmpty(log.LogToString())) { UpdateList.Add(SSR); } } LogList.Add(log); } } if (InsertList.Count > 0) { try { SHMoralScore.Insert(InsertList); } catch (Exception ex) { MsgBox.Show("於新增資料時發生錯誤!!\n" + ex.Message); } } if (UpdateList.Count > 0) { try { SHMoralScore.Update(UpdateList); } catch (Exception ex) { MsgBox.Show("於更新資料時發生錯誤!!\n" + ex.Message); } } //批次記錄Log LogSaver Batch = FISCA.LogAgent.ApplicationLog.CreateLogSaverInstance(); foreach (MoralScoreLogRobot each in LogList) { if (!string.IsNullOrEmpty(each.LogToString())) { Batch.AddBatch("學務系統.匯入文字評量", "student", each._student.ID, each.LogToString()); } else { NochangeCount++; } } Batch.LogBatch(true); //Summary Log StringBuilder sbSummary = new StringBuilder(); sbSummary.AppendLine("匯入文字評量操作:"); sbSummary.AppendLine("新增:" + InsertList.Count + "筆資料"); sbSummary.AppendLine("更新:" + UpdateList.Count + "筆資料"); sbSummary.AppendLine("未更動:" + NochangeCount + "筆資料"); FISCA.LogAgent.ApplicationLog.Log("學務系統.匯入文字評量", "匯入", sbSummary.ToString()); //StringBuilder sbSummary2 = new StringBuilder(); //sbSummary2.AppendLine("匯入文字評量操作:"); //sbSummary2.AppendLine("新增:" + InsertList.Count + "筆資料"); //sbSummary2.AppendLine("更新:" + UpdateList.Count + "筆資料"); //sbSummary2.AppendLine("未更動:" + NochangeCount + "筆資料"); return(""); }