コード例 #1
0
        private void NewAreaBtn_Click(object sender, EventArgs e)
        {
            try
            {
                string strText = string.Empty;
                InputDialog.Show(out strText);
                if (Char.IsDigit(strText, 0))
                {
                    throw new Exception("开头不能是数字");
                }
                if (strText == "")
                {
                    throw new Exception("名称不能为空");
                }
                if (strText.StartsWith("-"))
                {
                    throw new Exception("非法字符");
                }

                foreach (XmlNode childNode in CoordXML.SelectSingleNode("Root").ChildNodes)
                {
                    if (childNode.Name == strText)
                    {
                        throw new Exception("区域已存在");
                    }
                }

                XmlElement   xmlElement   = CoordXML.CreateElement(strText);
                XmlAttribute xmlAttribute = CoordXML.CreateAttribute("Class");
                xmlElement.SetAttribute("Class", "Area");
                CoordXML.SelectSingleNode("Root").AppendChild(xmlElement);
                treeView1.Nodes.Clear();
                RecursionTreeControl(CoordXML.DocumentElement, treeView1.Nodes);
                loader.OutputXML(CoordXML, CoordDataPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "严重错误:上溢", MessageBoxButtons.OK);
            }
        }