Example #1
0
        private void OpenTaskXML(bool needDialog)
        {
            if (needDialog)
            {
                OpenFileDialog OPF = new OpenFileDialog();
                OPF.InitialDirectory = Directory.GetCurrentDirectory();
                OPF.Filter           = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
                //OPF.FilterIndex = 1;
                //OPF.RestoreDirectory = true;


                if (OPF.ShowDialog() == DialogResult.OK)
                {
                    gTaskConfig_path = OPF.FileName;
                }
            }

            if (File.Exists(gTaskConfig_path))
            {
                try
                {
                    metroGrid10.Rows.Clear();
                    metroTextBox1.Lines = File.ReadAllLines(gTaskConfig_path);
                    metroTextBox5.Text  = gTaskConfig_path;

                    TaskConf conf = new TaskConf();
                    conf.Name    = Path.GetFileName(gTaskConfig_path);
                    conf.Comment = TaskConf.XMLConfiguration;
                    AddConfig(conf, gTaskConfig_path);

                    for (int i = 0; i < conf.GetItems().Count; i++)
                    {
                        metroGrid10.Rows.Add(conf.GetItems()[i].Name, conf.GetItems()[i].Value);
                    }
                }
                catch
                {
                    MetroFramework.MetroMessageBox.Show(this, "Некорректный XML файл.", "Оповещение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MetroFramework.MetroMessageBox.Show(this, "XML файл не найден.", "Оповещение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (metroTextBox5.Text != "")
            {
                metroButton8.Enabled = true;
                metroButton9.Enabled = true;
            }
        }
Example #2
0
        private static void AddConfig(TaskConf config, string name)
        {
            Stream         myStream       = null;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.FileName = name;
            myStream = openFileDialog.OpenFile();

            StreamReader read = new StreamReader(myStream);
            string       xml  = read.ReadToEnd();

            read.Close();

            XDocument doc = XDocument.Parse(xml);

            XElement[] mxe = doc.Root.Elements().ToArray();
            for (int i = 0; i < mxe.Length; i++)
            {
                config.Add(mxe[i]);
            }
        }