Example #1
0
        private void RemoveDatabase_OnClick(object sender, RoutedEventArgs e)
        {
            var firstWarningMessageBox = new RemoveDataBaseMessageBox();
            var decision = firstWarningMessageBox.Show();

            if (decision)
            {
                var secondWarningMessageBox = new RemoveDatabaseWithBooksMessageBox();
                var lastDecision            = secondWarningMessageBox.Show();
                if (lastDecision)
                {
                    ResetDatabase();
                    Books.Clear();
                    ImportButton.Visibility = Visibility.Visible;
                }
            }
        }
Example #2
0
        private void ImportData(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.ShowDialog();
            var fileName = openFileDialog.FileName;

            if (fileName == "")
            {
                return;
            }

            MainGrid.Visibility = Visibility.Collapsed;
            BackgroundWorker worker = new BackgroundWorker {
                WorkerReportsProgress = true
            };

            ImportButton.Visibility    = Visibility.Hidden;
            ImportGrid.Visibility      = Visibility.Visible;
            worker.DoWork             += worker_DoWork;
            worker.ProgressChanged    += worker_ProgressChanged;
            worker.RunWorkerCompleted += (o, args) => {
                if (args.Result != null)
                {
                    if (args.Result.GetType() == typeof(ImportException))
                    {
                        var messageBox = new RemoveDataBaseMessageBox();
                        var answer     = messageBox.Show();
                        if (answer)
                        {
                            ResetDatabase();
                        }

                        ImportButton.Visibility = Visibility.Visible;
                    }
                }

                ImportGrid.Visibility = Visibility.Hidden;
                MainGrid.Visibility   = Visibility.Visible;
                ResizeGridViewColumns(BooksGridView);
            };
            worker.RunWorkerAsync(argument: fileName);
        }