Ejemplo n.º 1
0
        private void save_file_FileOk(object sender, CancelEventArgs e)
        {
            try
            {
                using (FileStream fs = new FileStream(save_file.FileName, FileMode.Create))
                {
                    XmlSerializer settings_xml = null;
                    object        settings     = null;

                    switch (tabControl_lab.SelectedIndex + 1)
                    {
                    case 1:
                        settings_xml = new XmlSerializer(typeof(XML_settings_lab1));
                        settings     = new XML_settings_lab1(this);
                        break;

                    case 2:
                        settings_xml = new XmlSerializer(typeof(XML_settings_lab2));
                        settings     = new XML_settings_lab2(this);
                        break;

                    case 3:
                        settings_xml = new XmlSerializer(typeof(XML_settings_lab3));
                        settings     = new XML_settings_lab3(this);
                        break;

                    case 4:
                        settings_xml = new XmlSerializer(typeof(XML_settings_lab4));
                        settings     = new XML_settings_lab4(this);
                        break;

                    case 5:
                        settings_xml = new XmlSerializer(typeof(XML_settings_lab5));
                        settings     = new XML_settings_lab5(this);
                        break;

                    default:
                        MessageBox.Show("Выберите вкладку для сохранения настроек!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    settings_xml.Serialize(fs, settings);
                    fs.Close();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Невозможно записать в файл!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }
Ejemplo n.º 2
0
        private void save_file_FileOk(object sender, CancelEventArgs e)
        {
            try
            {
                using (FileStream fs = new FileStream(save_file.FileName, FileMode.Create))
                {
                    XmlSerializer settings_xml = null;
                    object settings = null;

                    switch (tabControl_lab.SelectedIndex + 1)
                    {
                        case 1:
                            settings_xml = new XmlSerializer(typeof(XML_settings_lab1));
                            settings = new XML_settings_lab1(this);
                            break;

                        case 2:
                            settings_xml = new XmlSerializer(typeof(XML_settings_lab2));
                            settings = new XML_settings_lab2(this);
                            break;

                        case 3:
                            settings_xml = new XmlSerializer(typeof(XML_settings_lab3));
                            settings = new XML_settings_lab3(this);
                            break;

                        case 4:
                            settings_xml = new XmlSerializer(typeof(XML_settings_lab4));
                            settings = new XML_settings_lab4(this);
                            break;

                        case 5:
                            settings_xml = new XmlSerializer(typeof(XML_settings_lab5));
                            settings = new XML_settings_lab5(this);
                            break;

                        default:
                            MessageBox.Show("Выберите вкладку для сохранения настроек!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                    }

                    settings_xml.Serialize(fs, settings);
                    fs.Close();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Невозможно записать в файл!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }