Exemplo n.º 1
0
        public async void ExportData(object sender, RoutedEventArgs args)
        {
            SaveExportData sed    = new SaveExportData();
            var            picker = new FileSavePicker
            {
                SuggestedFileName      = "exported.json",
                SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
                CommitButtonText       = UIManager.Rl.GetString("ExportDataFileSelectionCommit")
            };

            picker.FileTypeChoices.Add("Database File", new List <string>()
            {
                ".json"
            });
            StorageFile file = await picker.PickSaveFileAsync();

            if (file != null)
            {
                try
                {
                    await sed.ExportData(file);

                    SaveLoadResult.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                    SaveLoadResult.Text       = UIManager.Rl.GetString("SettingsSaveSucess");
                }
                catch
                {
                    SaveLoadResult.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
                    SaveLoadResult.Text       = UIManager.Rl.GetString("SettingsSaveFailure");
                }
            }
        }
Exemplo n.º 2
0
        public async void LoadSettings(object sender, RoutedEventArgs args)
        {
            SaveExportData sed    = new SaveExportData();
            var            picker = new FileOpenPicker()
            {
                SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
                CommitButtonText       = UIManager.Rl.GetString("LoadDataFileSelectionCommit"),
            };

            picker.FileTypeFilter.Add(".json");
            StorageFile file = await picker.PickSingleFileAsync();

            if (file == null)
            {
                return;
            }

            MessageDialog dialog = new MessageDialog(UIManager.Rl.GetString("SettingDataLoadOverwriteWarning"));

            dialog.Commands.Add(new UICommand(UIManager.Rl.GetString("SettingDataLoadOverwriteWarningConfirm"), new UICommandInvokedHandler(async(IUICommand cmd) =>
            {
                try
                {
                    await sed.LoadData(file);
                    SaveLoadResult.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                    SaveLoadResult.Text       = UIManager.Rl.GetString("SettingsLoadSucess");
                }
                catch
                {
                    SaveLoadResult.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
                    SaveLoadResult.Text       = UIManager.Rl.GetString("SettingsLoadFailure");
                }
            })));
            dialog.Commands.Add(new UICommand(UIManager.Rl.GetString("SettingDataLoadOverwriteWarningCancel")));
            await dialog.ShowAsync();
        }