-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataResultPage.xaml.cs
More file actions
133 lines (121 loc) · 6.06 KB
/
DataResultPage.xaml.cs
File metadata and controls
133 lines (121 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using Docutain.SDK.MAUI;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Docutain_SDK_Example_.NET_MAUI
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class DataResultPage : ContentPage
{
public DataResultPage(FileResult fileResult)
{
InitializeComponent();
LoadData(fileResult);
}
private void LoadData(FileResult fileResult)
{
Task.Run(() =>
{
// If a FileResult is available, it means we have imported a file. If so, we need to load it into the SDK first.
if (fileResult != null)
{
// If a uri is available, it means we have imported a file. If so, we need to load it into the SDK first
if (!DocumentDataReader.LoadFile(fileResult.FullPath))
{
// An error occurred, get the latest error message
Debug.WriteLine($"DocumentDataReader.LoadFile failed, last error: {DocutainSDK.LastError}");
return;
}
}
// Analyze the currently loaded document and get the detected data
string json = DocumentDataReader.Analyze();
if (string.IsNullOrEmpty(json))
{
// No data detected
return;
}
MainThread.BeginInvokeOnMainThread(() =>
{
FillEntries(json);
});
});
}
private void FillEntries(string json)
{
try
{
JObject result = (JObject)JsonConvert.DeserializeObject(json);
DateEntry.Text = result.GetValue("Date")?.ToString();
DateEntry.IsVisible = !string.IsNullOrWhiteSpace(DateEntry.Text);
DateLabel.IsVisible = DateEntry.IsVisible;
AmountEntry.Text = result.GetValue("Amount")?.ToString();
AmountEntry.IsVisible = !string.IsNullOrWhiteSpace(AmountEntry.Text) && AmountEntry.Text != "0.00";
AmountLabel.IsVisible = AmountEntry.IsVisible;
InvoiceIdEntry.Text = result.GetValue("InvoiceId")?.ToString();
InvoiceIdEntry.IsVisible = !string.IsNullOrWhiteSpace(InvoiceIdEntry.Text);
InvoiceIdLabel.IsVisible = InvoiceIdEntry.IsVisible;
ReferenceEntry.Text = result.GetValue("Reference")?.ToString();
ReferenceEntry.IsVisible = !string.IsNullOrWhiteSpace(ReferenceEntry.Text);
ReferenceLabel.IsVisible = ReferenceEntry.IsVisible;
PaymentStateEntry.Text = result.GetValue("PaymentState")?.ToString();
PaymentStateEntry.IsVisible = !string.IsNullOrWhiteSpace(PaymentStateEntry.Text);
PaymentStateLabel.IsVisible = PaymentStateEntry.IsVisible;
JObject address = (JObject)JsonConvert.DeserializeObject(result.GetValue("Address").ToString());
Name1Entry.Text = address.GetValue("Name1")?.ToString();
Name1Entry.IsVisible = !string.IsNullOrWhiteSpace(Name1Entry.Text);
Name1Label.IsVisible = Name1Entry.IsVisible;
Name2Entry.Text = address.GetValue("Name2")?.ToString();
Name2Entry.IsVisible = !string.IsNullOrWhiteSpace(Name2Entry.Text);
Name2Label.IsVisible = Name2Entry.IsVisible;
Name3Entry.Text = address.GetValue("Name3")?.ToString();
Name3Entry.IsVisible = !string.IsNullOrWhiteSpace(Name3Entry.Text);
Name3Label.IsVisible = Name3Entry.IsVisible;
ZipCodeEntry.Text = address.GetValue("Zipcode")?.ToString();
ZipCodeEntry.IsVisible = !string.IsNullOrWhiteSpace(ZipCodeEntry.Text);
ZipCodeLabel.IsVisible = ZipCodeEntry.IsVisible;
CityEntry.Text = address.GetValue("City")?.ToString();
CityEntry.IsVisible = !string.IsNullOrWhiteSpace(CityEntry.Text);
CityLabel.IsVisible = CityEntry.IsVisible;
StreetEntry.Text = address.GetValue("Street")?.ToString();
StreetEntry.IsVisible = !string.IsNullOrWhiteSpace(StreetEntry.Text);
StreetLabel.IsVisible = StreetEntry.IsVisible;
PhoneEntry.Text = address.GetValue("Phone")?.ToString();
PhoneEntry.IsVisible = !string.IsNullOrWhiteSpace(PhoneEntry.Text);
PhoneLabel.IsVisible = PhoneEntry.IsVisible;
CustomerIdEntry.Text = address.GetValue("CustomerId")?.ToString();
CustomerIdEntry.IsVisible = !string.IsNullOrWhiteSpace(CustomerIdEntry.Text);
CustomerIDLabel.IsVisible = CustomerIdEntry.IsVisible;
var bank = (JArray)address.GetValue("Bank");
var IBAN = "";
var BIC = "";
// TODO: handle multiple bank accounts
if (bank.Count > 0)
{
var object1 = (JObject)bank.First;
IBAN = object1.GetValue("IBAN")?.ToString();
BIC = object1.GetValue("BIC")?.ToString();
}
var regex = new Regex(".{4}");
IbanEntry.Text = regex.Replace(IBAN, "$0 ");
IbanEntry.IsVisible = !string.IsNullOrWhiteSpace(IbanEntry.Text);
IbanLabel.IsVisible = IbanEntry.IsVisible;
BicEntry.Text = BIC;
BicEntry.IsVisible = !string.IsNullOrWhiteSpace(BicEntry.Text);
BicLabel.IsVisible = BicEntry.IsVisible;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
activityIndicator.IsRunning = false;
activityIndicator.IsVisible = false;
ScrollView.IsVisible = true;
}
}
}