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;
        }
コード例 #2
0
        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();
        }