You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.2 KiB

using Syncfusion.XPS;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Syncfusion.Windows.Forms.PdfViewer;
namespace OnDoc_JSONViewer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
DirectoryInfo dir = new DirectoryInfo(textBox1.Text);
foreach (FileInfo file in dir.GetFiles())
{
listBox1.Items.Add(file.Name);
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string ext = System.IO.Path.GetExtension(listBox1.SelectedItem.ToString().ToUpper());
string filename = textBox1.Text + @"\" + listBox1.SelectedItem.ToString();
textBox2.Text = "";
switch (ext)
{
case ".PDF":
pdfViewerControl1.Load(filename);
break;
case ".JSON":
string jsonstring;
using (StreamReader streamReader = new StreamReader(filename, Encoding.UTF8))
{
jsonstring = streamReader.ReadToEnd();
}
// var prettyJson1 = JsonConvert.SerializeObject(jsonstring, Formatting.Indented);
//dynamic parsedJson1 = JsonConvert.DeserializeObject(jsonstring);
//prettyJson1 = JsonConvert.SerializeObject(parsedJson1, Formatting.Indented);
string source2 = jsonstring;
dynamic data2 = JObject.Parse(source2);
string data3 = JObject.Parse(jsonstring)["bpNummer"].ToString();
string data4 = JObject.Parse(jsonstring)["personNummer"].ToString();
textBox2.Text= data3 + Environment.NewLine+data4;
if (toolStripCheckBox1.Checked == true)
{
try
{
string source = jsonstring;
dynamic data = JObject.Parse(source);
string data1 = JObject.Parse(jsonstring)["dokumentDatei"].ToString();
var stream = new MemoryStream(Convert.FromBase64String(data1));
if (stream.Length > 0)
{
this.pdfViewerControl1.Load(stream);
this.pdfViewerControl1.Visible = true;
pdfViewerControl1.ZoomMode = ZoomMode.FitWidth;
stream = null;
}
else
{
}
}
catch { }
}
break;
}
}
}
}