Ejemplo n.º 1
0
        public void Execute(object parameter)
        {
            var vm = new ConfirmViewModel()
            {
                Caption = "Clear Entries?",
                Message = "Are you sure you want to clear all" +
                          " the listed entries?\n" +
                          "\nThis action cannot be undone."
            };

            var window = new ConfirmWindow
            {
                DataContext = vm,
            };
            window.ShowDialog();
            var result = vm.Result;

            if (result == ConfirmResult.Affirmative)
            {
                LocalDataService.Backup(_viewModel.Entries);
                _viewModel.Entries = new ObservableCollection<EntryViewModel>();
                LocalDataService.Save(_viewModel.Entries);
                _viewModel.Refresh();
            }
        }
Ejemplo n.º 2
0
        public void Execute(object parameter)
        {
            var dlg = new SaveFileDialog()
            {
                DefaultExt = "manvan",
                Filter = "ManVan Entry Files|*.manvan",
                RestoreDirectory = true,
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                FileName = "manvan_" + DateTime.Now.ToString("yyyy-MM-dd"),
            };
            var result = dlg.ShowDialog();
            if (result.HasValue && !result.Value)
            {
                return;
            }
            try
            {
                var entries = _viewModel.Entries;

                var xs = new XmlSerializer(entries.GetType());

                var path = dlg.FileName;

                using (TextWriter writer = new StreamWriter(path))
                {
                    xs.Serialize(writer, entries);
                }
            }
            catch (Exception exception)
            {
                var vm = new ConfirmViewModel()
                {
                    Caption = "Unexpected Error",
                    Message = exception.Message,
                    NegativeVisibility = Visibility.Hidden,
                    AffirmativeLabel = "Okay",
                };

                var window = new ConfirmWindow
                {
                    DataContext = vm,
                };
                window.ShowDialog();
            }
        }
Ejemplo n.º 3
0
        private void Cancel_OnClick(object sender, RoutedEventArgs e)
        {
            var vm = new ConfirmViewModel()
            {
                NegativeLabel = "No",
                AffirmativeLabel = "Yes",
                Caption = "Cancel New Entry?",
                Message = "Are you sure you want to cancel this new entry?"
            };

            var window = new ConfirmWindow
            {
                DataContext = vm,
            };

            window.ShowDialog();
            if (vm.Result == ConfirmResult.Negative) return;
            DialogResult = false;
            Close();
        }
Ejemplo n.º 4
0
        private void Delete_OnClick(object sender, RoutedEventArgs e)
        {
            var vm = new ConfirmViewModel()
            {
                NegativeLabel = "No",
                AffirmativeLabel = "Yes",
                Caption = "Delete Entry?",
                Message = "Are you sure you want to delete this entry?\n" +
                          "This action cannot be undone."
            };

            var window = new ConfirmWindow
            {
                DataContext = vm,
            };

            window.ShowDialog();

            if (vm.Result == ConfirmResult.Negative) return;
            DialogResult = false;
            Close();
        }
Ejemplo n.º 5
0
        public void Execute(object parameter)
        {
            var dlg = new OpenFileDialog()
            {
                Multiselect = false,
                Filter = "ManVan Entry Files|*.manvan",
                InitialDirectory = Environment.GetFolderPath(
                    Environment.SpecialFolder.Desktop),
            };
            var result = dlg.ShowDialog();
            if (result.HasValue && !result.Value)
            {
                return;
            }
            try
            {
                var path = dlg.FileName;
                var file = new FileInfo(path);
                if (!file.Exists)
                    throw new FileNotFoundException("The file does not exist.");
                var str = File.ReadAllText(file.FullName);
                var entries = _viewModel.Entries;
                var xs = new XmlSerializer(entries.GetType());
                var list = (ObservableCollection<EntryViewModel>)xs.Deserialize(new StringReader(str));
                list.ToList().ForEach(x =>
                {
                    if(!_viewModel.EntriesContainsId(x.Id))
                        entries.Add(x);
                });
                _viewModel.Refresh();
            }
            catch (Exception exception)
            {
                var vm = new ConfirmViewModel()
                {
                    Caption = "Unexpected Error",
                    Message = exception.Message,
                    NegativeVisibility = Visibility.Hidden,
                    AffirmativeLabel = "Okay",
                };

                var window = new ConfirmWindow
                {
                    DataContext = vm,
                };
                window.ShowDialog();
            }
        }