/// <summary> /// 轉回 DAL 用 Content /// </summary> /// <param name="data"></param> /// <returns></returns> public void SetContentData(Dictionary <string, StudBatchUpdateRecContentEntity> data) { XmlElement retValue = new XmlDocument().CreateElement("Content"); Dictionary <string, List <StudBatchUpdateRecContentEntity> > ByGradeYear = new Dictionary <string, List <StudBatchUpdateRecContentEntity> >(); foreach (StudBatchUpdateRecContentEntity sburce in data.Values) { string strGRYear; if (string.IsNullOrEmpty(sburce.GetGradeYear())) { strGRYear = " "; } else { strGRYear = sburce.GetGradeYear(); } if (ByGradeYear.ContainsKey(strGRYear)) { ByGradeYear[strGRYear].Add(sburce); } else { List <StudBatchUpdateRecContentEntity> list = new List <StudBatchUpdateRecContentEntity>(); list.Add(sburce); ByGradeYear.Add(strGRYear, list); } // 清除原 XML UpdateBatchRec.Content.RemoveAll(); XmlElement elemRoot = new XmlDocument().CreateElement("異動名冊"); elemRoot.SetAttribute("學年度", SchoolYear + ""); elemRoot.SetAttribute("學期", Semester + ""); elemRoot.SetAttribute("學校名稱", SchoolName); elemRoot.SetAttribute("學校代號", SchoolCode); elemRoot.SetAttribute("類別", DocType.ToString()); foreach (KeyValuePair <string, List <StudBatchUpdateRecContentEntity> > val in ByGradeYear) { XmlElement elemGrdYear = new XmlDataDocument().CreateElement("清單"); elemGrdYear.SetAttribute("年級", val.Key); elemGrdYear.SetAttribute("科別", ""); foreach (StudBatchUpdateRecContentEntity sburce1 in val.Value) { XmlElement xe = elemGrdYear.OwnerDocument.ImportNode(sburce1.GetXmlData(), true) as XmlElement; elemGrdYear.AppendChild(xe); } XmlElement XmlRootChild = elemRoot.OwnerDocument.ImportNode(elemGrdYear, true) as XmlElement; elemRoot.AppendChild(XmlRootChild); } XmlElement elemRot = UpdateBatchRec.Content.OwnerDocument.ImportNode(elemRoot, true) as XmlElement; UpdateBatchRec.Content.AppendChild(elemRot); } }