コード例 #1
0
        private void AddData()
        {
            Views.DataValidateView validateView = new Views.DataValidateView();
            DataModel             newData       = new DataModel();
            DataValidateViewModel validateVM    = new DataValidateViewModel(ref newData, ref validateView.passwordBox, new DataGenerator());

            validateView.DataContext = validateVM;
            validateView.ShowDialog();

            if (newData.Password != null)
            {
                CategoryModel currentCategory = OnNeededCurrentCategory?.Invoke();
                if (currentCategory == null)
                {
                    return;
                }

                try
                {
                    storageHandler.AddData(newData, currentCategory);
                }
                catch (FileNotFoundException ex)
                { MessageBox.Show($"File not found {ex.Message}."); }
                catch (InvalidOperationException ex)
                { MessageBox.Show($"Can't write data to file {ex.Message}."); }
                catch (Exception ex)
                { MessageBox.Show($"Something is wrong {ex.Message}."); }

                DataChanged();
            }
        }