private void LoadPreference() { #region 讀取 Preference //XmlElement config = CurrentUser.Instance.Preference["獎懲通知單"]; Campus.Configuration.ConfigData cd = Campus.Configuration.Config.User[ConfigName一般設定]; XmlElement config = cd.GetXml("XmlData", null); if (config != null) { _useDefaultTemplate = bool.Parse(config.GetAttribute("Default")); XmlElement customize = (XmlElement)config.SelectSingleNode("CustomizeTemplate"); XmlElement dateRangeMode = (XmlElement)config.SelectSingleNode("DateRangeMode"); XmlElement receive = (XmlElement)config.SelectSingleNode("Receive"); XmlElement conditions = (XmlElement)config.SelectSingleNode("Conditions"); XmlElement PrintStudentList = (XmlElement)config.SelectSingleNode("PrintStudentList"); if (customize != null) { string templateBase64 = customize.InnerText; _buffer = Convert.FromBase64String(templateBase64); _template = new MemoryStream(_buffer); } //列印學生清單 if (PrintStudentList != null) { if (PrintStudentList.HasAttribute("Checked")) { _PrintStudentList = bool.Parse(PrintStudentList.GetAttribute("Checked")); } } else { XmlElement newPrintStudentList = config.OwnerDocument.CreateElement("PrintStudentList"); newPrintStudentList.SetAttribute("Checked", "False"); config.AppendChild(newPrintStudentList); cd.SetXml("XmlData", config); } if (receive != null) { _receiveName = receive.GetAttribute("Name"); _receiveAddress = receive.GetAttribute("Address"); } else { XmlElement newReceive = config.OwnerDocument.CreateElement("Receive"); newReceive.SetAttribute("Name", ""); newReceive.SetAttribute("Address", ""); config.AppendChild(newReceive); cd.SetXml("XmlData", config); //CurrentUser.Instance.Preference["獎懲通知單"] = config; } if (conditions != null) { if (conditions.HasAttribute("ConditionName") && conditions.HasAttribute("ConditionNumber")) { _conditionName = conditions.GetAttribute("ConditionName"); _conditionNumber = conditions.GetAttribute("ConditionNumber"); } else { _conditionName = "大功"; _conditionNumber = "1"; } } else { XmlElement newConditions = config.OwnerDocument.CreateElement("Conditions"); newConditions.SetAttribute("ConditionName", ""); newConditions.SetAttribute("ConditionNumber", "1"); config.AppendChild(newConditions); cd.SetXml("XmlData", config); //CurrentUser.Instance.Preference["獎懲通知單"] = config; } if (dateRangeMode != null) { _mode = (DateRangeMode)int.Parse(dateRangeMode.InnerText); if (_mode != DateRangeMode.Custom) { dateTimeInput2.Enabled = false; } else { dateTimeInput2.Enabled = true; } } else { XmlElement newDateRangeMode = config.OwnerDocument.CreateElement("DateRangeMode"); newDateRangeMode.InnerText = ((int)_mode).ToString(); config.AppendChild(newDateRangeMode); cd.SetXml("XmlData", config); //CurrentUser.Instance.Preference["獎懲通知單"] = config; } } else { #region 產生空白設定檔 config = new XmlDocument().CreateElement("XmlData"); config.SetAttribute("Default", "true"); XmlElement customize = config.OwnerDocument.CreateElement("CustomizeTemplate"); XmlElement dateRangeMode = config.OwnerDocument.CreateElement("DateRangeMode"); XmlElement receive = config.OwnerDocument.CreateElement("Receive"); XmlElement conditions = config.OwnerDocument.CreateElement("Conditions"); XmlElement printStudentList = config.OwnerDocument.CreateElement("PrintStudentList"); dateRangeMode.InnerText = ((int)_mode).ToString(); receive.SetAttribute("Name", ""); receive.SetAttribute("Address", ""); conditions.SetAttribute("ConditionName", ""); conditions.SetAttribute("ConditionNumber", "1"); printStudentList.SetAttribute("Checked", "false"); config.AppendChild(customize); config.AppendChild(dateRangeMode); config.AppendChild(receive); config.AppendChild(conditions); config.AppendChild(printStudentList); cd.SetXml("XmlData", config); //CurrentUser.Instance.Preference["獎懲通知單"] = config; _useDefaultTemplate = true; #endregion } cd.Save(); //儲存組態資料。 #endregion _preferenceLoaded = true; }
/// <summary> /// 背景模式 /// </summary> void BGW_DoWork(object sender, DoWorkEventArgs e) { paperForStudent = new SmartSchool.ePaper.ElectronicPaper(School.DefaultSchoolYear + "學生日常表現總表", School.DefaultSchoolYear, School.DefaultSemester, SmartSchool.ePaper.ViewerType.Student); #region 設定檔 cd = Campus.Configuration.Config.User[ConfigName]; XmlElement config = cd.GetXml("XmlData", null); if (config == null) { e.Cancel = true; return; } absenceList = new List <string>(); int absenceindex = 1; //集會,一般... foreach (XmlElement xml in config.SelectNodes("Type")) { //曠課,病假... foreach (XmlElement node in xml.SelectNodes("Absence")) { string s1 = xml.GetAttribute("Text"); string s2 = node.GetAttribute("Text"); absenceList.Add(s2 + s1); //記錄Index DicSummaryIndex.Add(s2 + s1, absenceindex); absenceindex++; } } #endregion #region 開頭處理 BehaviorList = GetBehaviorConfig(); BehaviorList1 = new List <string>(); BehaviorList2 = new List <string>(); BehaviorList3 = new List <string>(); //製作日常生活表現,標題的Index int BeIndex = 0; foreach (string each in BehaviorList) { BeIndex++; if (BeIndex > SuperBehaviorIndex1 && BeIndex <= SuperBehaviorIndex2) { BehaviorList2.Add(each); DicSummaryIndex.Add(each, BeIndex - SuperBehaviorIndex1); } else if (BeIndex > SuperBehaviorIndex2) { BehaviorList3.Add(each); DicSummaryIndex.Add(each, BeIndex - SuperBehaviorIndex2); } else if (BeIndex <= SuperBehaviorIndex1) { BehaviorList1.Add(each); DicSummaryIndex.Add(each, BeIndex); } } //依據日常生活表現欄位,讀取範本 _template = new Document(new MemoryStream(Properties.Resources.日常生活記錄表_範本_1)); if (BehaviorList.Count > SuperBehaviorIndex1) { _template = new Document(new MemoryStream(Properties.Resources.日常生活記錄表_範本_2)); } if (BehaviorList.Count > SuperBehaviorIndex2) { _template = new Document(new MemoryStream(Properties.Resources.日常生活記錄表_範本_3)); } //建立資料模型 Data = new StudentInfo(BehaviorList); #endregion if (SingeFile) //如果是單檔儲存 { #region 單一學生 Dictionary <string, Document> DocDic = new Dictionary <string, Document>(); foreach (string student in Data.DicStudent.Keys) { Document PageOne = SetDocument(student); //電子報表 MemoryStream stream = new MemoryStream(); PageOne.Save(stream, SaveFormat.Docx); paperForStudent.Append(new PaperItem(PaperFormat.Office2003Doc, stream, student)); if (!DocDic.ContainsKey(student)) { DocDic.Add(student, PageOne); } } e.Result = DocDic; #endregion } else { #region 多名學生存單一檔案 _doc = new Document(); _doc.Sections.Clear(); //清空此Document foreach (string student in Data.DicStudent.Keys) { Document PageOne = SetDocument(student); //電子報表 MemoryStream stream = new MemoryStream(); PageOne.Save(stream, SaveFormat.Docx); paperForStudent.Append(new PaperItem(PaperFormat.Office2003Doc, stream, student)); _doc.Sections.Add(_doc.ImportNode(PageOne.FirstSection, true)); } e.Result = _doc; #endregion } //如果有打勾則上傳電子報表 if (PrintUpdateStudentFile) { SmartSchool.ePaper.DispatcherProvider.Dispatch(paperForStudent); } }
private void buttonX1_Click(object sender, EventArgs e) { #region 儲存 Preference Campus.Configuration.ConfigData cd = Campus.Configuration.Config.User[ConfigName一般設定]; XmlElement config = cd.GetXml("XmlData", null); //XmlElement config = CurrentUser.Instance.Preference["獎懲通知單"]; if (config == null) { config = new XmlDocument().CreateElement("XmlData"); } config.SetAttribute("Default", _defaultTemplate.ToString()); XmlElement customize = config.OwnerDocument.CreateElement("CustomizeTemplate"); XmlElement mode = config.OwnerDocument.CreateElement("DateRangeMode"); XmlElement receive = config.OwnerDocument.CreateElement("Receive"); XmlElement conditions = config.OwnerDocument.CreateElement("Conditions"); XmlElement PrintStudentList = config.OwnerDocument.CreateElement("PrintStudentList"); PrintStudentList.SetAttribute("Checked", _printStudentList.ToString()); config.ReplaceChild(PrintStudentList, config.SelectSingleNode("PrintStudentList")); if (_isUpload) { customize.InnerText = base64; config.ReplaceChild(customize, config.SelectSingleNode("CustomizeTemplate")); } mode.InnerText = ((int)_mode).ToString(); config.ReplaceChild(mode, config.SelectSingleNode("DateRangeMode")); receive.SetAttribute("Name", ((DevComponents.Editors.ComboItem)comboBoxEx1.SelectedItem).Text); receive.SetAttribute("Address", ((DevComponents.Editors.ComboItem)comboBoxEx2.SelectedItem).Text); if (config.SelectSingleNode("Receive") == null) { config.AppendChild(receive); } else { config.ReplaceChild(receive, config.SelectSingleNode("Receive")); } conditions.SetAttribute("ConditionName", ((DevComponents.Editors.ComboItem)comboBoxEx3.SelectedItem).Text); conditions.SetAttribute("ConditionNumber", numericUpDown1.Value.ToString()); if (config.SelectSingleNode("Conditions") == null) { config.AppendChild(conditions); } else { config.ReplaceChild(conditions, config.SelectSingleNode("Conditions")); } cd.SetXml("XmlData", config); cd.Save(); //CurrentUser.Instance.Preference["獎懲通知單"] = config; #endregion this.DialogResult = DialogResult.OK; this.Close(); }