コード例 #1
0
        private void BrowseButton_Click(object sender, RoutedEventArgs e)
        {
            TextBlock1.Text = "";
            TextBlock2.Text = "";

            NaarDBLabel.Visibility  = Visibility.Hidden;
            NaarDBButton.Visibility = Visibility.Hidden;
            stripsFromJson          = null;

            if (Hoofdlabel.Content.Equals("Laad uw Json in en wij updaten uw databank."))
            {
                // Create OpenFileDialog
                Microsoft.Win32.OpenFileDialog openFileDlg = new Microsoft.Win32.OpenFileDialog();
                openFileDlg.DefaultExt = ".json";// Set filter for file extension and default file extension
                openFileDlg.Filter     = "Json files (*.json)|*.json";

                openFileDlg.Multiselect = false; // Multiple selection with all file types
                                                 // Launch OpenFileDialog by calling ShowDialog method
                Nullable <bool> result = openFileDlg.ShowDialog();
                // Get the selected file name and display in a TextBox.
                // Load content of file in a TextBlock
                if (result == true)
                {
                    FileNameTextBox.Text = openFileDlg.FileName;


                    //Leest de Json bestand in en maakt er objecten van
                    JsonFileReader_ToObjects jfr = new JsonFileReader_ToObjects();
                    //     jfr.locatieJson = openFileDlg.FileName;
                    try
                    {
                        stripsFromJson = jfr.leesJson_GeefAlleStripsTerug(FileNameTextBox.Text);
                    }
                    catch
                    {
                        stripsFromJson = null;
                    }
                    if (stripsFromJson != null && stripsFromJson.Count != 0)
                    {
                        TextBlock1.Text = "Gevonden strips in bestand: " + stripsFromJson.Count.ToString() + " strips.";

                        NaarDBLabel.Visibility  = Visibility.Visible;
                        NaarDBButton.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        TextBlock1.Text = "Ongeldige bestand, geen strips in gevonden.";
                    }
                }
                else
                {
                    TextBlock1.Text = "Ongeldige bestand, geen strips in gevonden.";
                }
            }
            else if (Hoofdlabel.Content.Equals("Kies een locatie waar je het wil schrijven."))
            {
                TextBlock1.Text = "Kies hierboven de locatie om de databank strips in op te slaan. het duurt even, maar u krijgt een seintje als het klaar is.";

                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter = "Json files (*.json)|*.json";

                if (saveFileDialog.ShowDialog() == true)
                {
                    SchrijfwegnaarJSON swj = new SchrijfwegnaarJSON();
                    swj.allesWegSchrijvenNaarJSONFile(saveFileDialog.FileName);
                    TextBlock1.Text = "Het is gelukt!";
                }
                // File.WriteAllText(saveFileDialog.FileName, txtEditor.Text)
            }
        }