Ejemplo n.º 1
0
        private void SaveFile(object sender, ExecutedRoutedEventArgs e)
        {
            SpecialPaths.VerifyDirectory(SpecialPaths.DataBases);

            //Начало сохранения данных
            this.BusyIndicator.BusyContent = "Сохранение данных...";
            this.BusyIndicator.IsBusy      = true;

            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += delegate
            {
                this.dataStorage.Save();
            };

            worker.RunWorkerCompleted += delegate
            {
                //Сохранение завершено
                this.BusyIndicator.IsBusy = false;

                MessageBox.Show("Данные сохранены", "Успех", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            };

            worker.RunWorkerAsync();
        }
Ejemplo n.º 2
0
        private void SaveFileAs(object sender, ExecutedRoutedEventArgs e)
        {
            SpecialPaths.VerifyDirectory(SpecialPaths.DataBases);
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "SQLite file|*.sqlite";
            saveFileDialog.InitialDirectory = SpecialPaths.DataBases;

            if (saveFileDialog.ShowDialog(this) == true)
            {
                //Начало сохранения данных
                this.BusyIndicator.BusyContent = "Сохранение данных...";
                this.BusyIndicator.IsBusy      = true;

                BackgroundWorker worker = new BackgroundWorker();

                worker.DoWork += delegate
                {
                    this.dataStorage.SaveAs(saveFileDialog.FileName);
                };

                worker.RunWorkerCompleted += delegate
                {
                    //Сохранение завершено
                    this.BusyIndicator.IsBusy = false;

                    MessageBox.Show("Данные сохранены", "Успех", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                };

                worker.RunWorkerAsync();
            }
        }
Ejemplo n.º 3
0
        private void OpenFile(object sender, ExecutedRoutedEventArgs e)
        {
            SpecialPaths.VerifyDirectory(SpecialPaths.DataBases);

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "sqlite files|*.sqlite|all files|*.*";
            openFileDialog.InitialDirectory = SpecialPaths.DataBases;

            if (openFileDialog.ShowDialog() == true)
            {
                //Начало загрузки данных
                this.BusyIndicator.IsBusy      = true;
                this.BusyIndicator.BusyContent = "Загрузка данных...";

                BackgroundWorker worker = new BackgroundWorker();

                worker.DoWork += delegate
                {
                    try
                    {
                        Dispatcher.Invoke((Action)(() =>
                        {
                            this.dataStorage = new DataStorage(openFileDialog.FileName, true);
                            this.ShowEntities();
                        }));
                    }
                    catch (Exception ex)
                    {
                        this.dataStorage = null;
                        MessageBox.Show("Не удалось считать данные!\n\nException:\n" + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                };

                worker.RunWorkerCompleted += delegate
                {
                    //Загрузка завершена
                    this.BusyIndicator.IsBusy = false;
                };

                worker.RunWorkerAsync();
            }
        }