コード例 #1
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();
        }
        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;
        }
コード例 #3
0
        //儲存
        private void buttonX1_Click(object sender, EventArgs e)
        {
            _RequestSignTitleList.Clear();
            foreach (var textBox in new DevComponents.DotNetBar.Controls.TextBoxX[] { textBoxX1, textBoxX2, textBoxX3, textBoxX4, textBoxX5, textBoxX6 })
            {
                _RequestSignTitleList.Add(textBox.Text);
            }


            _AnnualSignTitleList.Clear();
            foreach (var textBox in new DevComponents.DotNetBar.Controls.TextBoxX[] { textBoxX7, textBoxX8, textBoxX9, textBoxX10, textBoxX11 })
            {
                _AnnualSignTitleList.Add(textBox.Text);
            }


            XmlDocument doc  = new XmlDocument();
            XmlElement  root = doc.CreateElement("Config");

            doc.AppendChild(root);

            foreach (ListViewItem item in listViewEx1.Items)
            {
                if (item.Checked)
                {
                    XmlElement AllowAbsence = doc.CreateElement("AllowAbsence");

                    AllowAbsence.InnerText = item.Text;

                    root.AppendChild(AllowAbsence);
                }
            }

            if (comboBoxEx1.Text != "")
            {
                XmlElement AnnualAbsence = doc.CreateElement("AnnualAbsence");
                AnnualAbsence.InnerText = comboBoxEx1.Text;
                root.AppendChild(AnnualAbsence);
            }

            foreach (string title in _RequestSignTitleList)
            {
                XmlElement RequestSignTitle = doc.CreateElement("RequestSignTitle");
                RequestSignTitle.InnerText = title;
                root.AppendChild(RequestSignTitle);
            }

            foreach (string title in _AnnualSignTitleList)
            {
                XmlElement AnnualSignTitle = doc.CreateElement("AnnualSignTitle");

                AnnualSignTitle.InnerText = title;

                root.AppendChild(AnnualSignTitle);
            }


            Campus.Configuration.ConfigData absence1 = Campus.Configuration.Config.App["ischool.leave.config"];
            if (absence1.PreviousData == null)
            {
                absence1.Save();
            }

            DSXmlHelper helper = new DSXmlHelper("Lists");

            helper.AddElement("List");
            helper.AddElement("List", "Content", root.OuterXml, true);
            helper.AddElement("List", "Condition");
            helper.AddElement("List/Condition", "Name", "ischool.leave.config");

            //儲存
            try
            {
                Framework.Feature.Config.Update(new DSRequest(helper));
            }
            catch (Exception exception)
            {
                FISCA.Presentation.Controls.MsgBox.Show("更新失敗 :" + exception.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            FISCA.Presentation.Controls.MsgBox.Show("儲存成功!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //更新
            try
            {
                Campus.Configuration.Config.App.Sync("ischool.leave.config");
            }
            catch
            {
                FISCA.Presentation.Controls.MsgBox.Show("資料重設失敗,新設定值將於下次啟動系統後生效!", "失敗", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.Close();
        }