Пример #1
0
        /// <summary>
        /// Открывает диалоговое окно для чтения из файла
        /// </summary>
        public static ObservableCollection <Department> OpenFileDialog()
        {
            OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();

            openFileDialog.Title            = "Открыть файл";
            openFileDialog.Filter           = "files (*.json)|*.json|files (*.xml)|*.xml";
            openFileDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;

            if (openFileDialog.ShowDialog() == true)
            {
                PathFile = openFileDialog.FileName;

                if (Path.GetExtension(PathFile) == ".json")
                {
                    return(FileIOService.OpenAsJSON(PathFile));
                }

                if (Path.GetExtension(PathFile) == ".xml")
                {
                    return(FileIOService.OpenAsXML(PathFile));
                }
            }

            return(null);
        }
Пример #2
0
        /// <summary>
        /// Открывает диалоговое окно для сохранения в файл
        /// </summary>
        public static void SaveFileDialog(ObservableCollection <Department> listSave)
        {
            SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();

            saveFileDialog.Title            = "Сохранить файл";
            saveFileDialog.Filter           = "files (*.json)|*.json|files (*.xml)|*.xml";
            saveFileDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;

            if (saveFileDialog.ShowDialog() == true)
            {
                PathFile = saveFileDialog.FileName;

                if (Path.GetExtension(PathFile) == ".json")
                {
                    FileIOService.SaveAsJSON(PathFile, listSave);
                }

                if (Path.GetExtension(PathFile) == ".xml")
                {
                    FileIOService.SaveAsXML(PathFile, listSave);
                }
            }
        }