public SubjectConductSettingForm(ConductSetting setting)
        {
            InitializeComponent();
            _setting = setting;
            _doc     = new XmlDocument();
            _doc.LoadXml(_setting.Conduct);
            _subjects = new List <string>();

            _A = new AccessHelper();

            int index = 0;

            foreach (SubjectRecord s in _A.Select <SubjectRecord>())
            {
                ButtonItem item = new ButtonItem();
                item.OptionGroup = "subject";
                item.Text        = s.Name;
                item.Click      += new EventHandler(item_click);
                if (_doc.SelectNodes("//Conduct[@Subject=" + Tool.XPathLiteral(s.Name) + "]").Count > 0)
                {
                    item.ForeColor = Color.Red;

                    itemPanle1.Items.Insert(index++, item);
                }
                else
                {
                    itemPanle1.Items.Add(item);
                }

                if (!_subjects.Contains(s.Name))
                {
                    _subjects.Add(s.Name);
                }
            }
        }
        private void Save(ConductSetting setting, DataGridView dgv)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(setting.Conduct);

            //刪除帶有Common屬性的node
            foreach (XmlNode node in doc.SelectNodes("//Conduct[@Common]"))
                doc.DocumentElement.RemoveChild(node);

            List<string> check_list = new List<string>();
            foreach (DataGridViewRow row in dgv.Rows)
            {
                if (row.IsNewRow) continue;

                string group = row.Cells[colGroup.Index].Value + "";
                string title = row.Cells[colTitle.Index].Value + "";
                string common = row.Cells[colCommon.Index].Value + "" == "True" ? "True" : "False";
                string key = group + "_" + title;

                //搜尋具有common屬性,且group名稱符合的node
                XmlElement elem = doc.SelectSingleNode("//Conduct[@Group=" + Tool.XPathLiteral(group) + "][@Common]") as XmlElement;

                //node不存在代表需新增並append
                if (elem == null)
                {
                    elem = doc.CreateElement("Conduct");
                    elem.SetAttribute("Group", group);
                    elem.SetAttribute("Common", common);
                    doc.DocumentElement.AppendChild(elem);
                }

                //同group避免重複add相同item
                if (!check_list.Contains(key))
                {
                    XmlElement item = doc.CreateElement("Item");
                    item.SetAttribute("Title", title);

                    elem.AppendChild(item);

                    check_list.Add(key);
                }
            }

            setting.Conduct = doc.OuterXml;
            setting.Save();
        }
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            ConductSetting currentSetting = null;

            if (tabControl1.SelectedTab.Equals(ti1))
                currentSetting = _Grade1;
            if (tabControl1.SelectedTab.Equals(ti2))
                currentSetting = _Grade2;
            if (tabControl1.SelectedTab.Equals(ti3))
                currentSetting = _Grade3;
            if (tabControl1.SelectedTab.Equals(ti4))
                currentSetting = _Grade4;
            if (currentSetting != null)
            {
                SubjectConductSettingForm form = new SubjectConductSettingForm(currentSetting);
                form.ShowDialog();
            }
        }
        private void LoadConduct(ConductSetting setting, DataGridView dgv)
        {
            dgv.Rows.Clear();

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(setting.Conduct);

            //將具有Common屬性的node加入畫面
            foreach (XmlElement parent in doc.SelectNodes("//Conduct[@Common]"))
            {
                string group = parent.GetAttribute("Group");
                bool common = parent.GetAttribute("Common") == "True" ? true : false;

                foreach (XmlElement elem in parent.SelectNodes("Item"))
                {
                    string title = elem.GetAttribute("Title");

                    DataGridViewRow row = new DataGridViewRow();
                    row.CreateCells(dgv, group, title, common);
                    dgv.Rows.Add(row);
                }
            }
        }
        public ConductSettingForm()
        {
            InitializeComponent();
            _A = new AccessHelper();

            List<ConductSetting> allConductList = _A.Select<ConductSetting>();
            foreach (ConductSetting record in allConductList)
            {
                if (record.Grade == 1)
                {
                    _Grade1 = record;
                }
                else if (record.Grade == 2)
                {
                    _Grade2 = record;
                }
                else if (record.Grade == 3)
                {
                    _Grade3 = record;
                }
                else if (record.Grade == 4)
                {
                    _Grade4 = record;
                }
                else if (record.Grade <= 6)
                {
                    _MediumGrade = record;
                }
                else
                {
                    _HighGrade = record;
                }
            }

            if (_Grade1 == null)
            {
                _Grade1 = new ConductSetting(1);
                _Grade1.Save();
            }

            if (_Grade2 == null)
            {
                _Grade2 = new ConductSetting(2);
                _Grade2.Save();
            }

            if (_Grade3 == null)
            {
                _Grade3 = new ConductSetting(3);
                _Grade3.Save();
            }

            if (_Grade4 == null)
            {
                _Grade4 = new ConductSetting(4);
                _Grade4.Save();
            }

            if (_MediumGrade == null)
            {
                _MediumGrade = new ConductSetting(6);
                _MediumGrade.Save();
            }

            if (_HighGrade == null)
            {
                _HighGrade = new ConductSetting(12);
                _HighGrade.Save();
            }
        }