-
Notifications
You must be signed in to change notification settings - Fork 1
/
Index.razor
140 lines (124 loc) · 4.79 KB
/
Index.razor
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
134
135
136
137
138
139
140
@page "/"
@inject DocumentService DocumentService
@inject IJSRuntime JS
<div class="container">
<DxFormLayout>
<DxFormLayoutGroup Caption="Loan Amortization Schedule" ColSpanMd="11">
<DxFormLayoutItem ColSpanMd="12">
<Template>
<p>
This example uses the
<a href="https://www.devexpress.com/products/net/office-file-api/spreadsheet/">Spreadsheet Document API</a>
to create a loan amortization schedule. Specify the loan amount, loan period in years,
annual interest rate, and start date to calculate your loan payments. Click <b>Export to XLSX</b>
or <b>Export to PDF</b> to save the result as XLSX or PDF.
</p>
</Template>
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Loan Amount:" ColSpanMd="5">
<Template>
<DxSpinEdit @bind-Value="LoanAmount"
DisplayFormat="c"
Increment="100"
MinValue="100"
MaxValue="1000000" />
</Template>
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Period in Years:" ColSpanMd="5">
<Template>
<DxSpinEdit @bind-Value="PeriodInYears"
Increment="1"
MinValue="1"
MaxValue="100" />
</Template>
</DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="2">
<Template>
<DxButton Click="ExportToXlsx" CssClass="btn-block" Text="Export to XLSX" />
</Template>
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Interest Rate:" ColSpanMd="5">
<Template>
<DxSpinEdit @bind-Value="InterestRate"
DisplayFormat="p"
Increment="0.01"
MinValue="0.001"
MaxValue="100" />
</Template>
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Start Date of Loan:" ColSpanMd="5">
<Template>
<DxDateEdit @bind-Date="StartDate"></DxDateEdit>
</Template>
</DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="2">
<Template>
<DxButton Click="ExportToPdf" CssClass="btn-block" Text="Export to PDF" />
</Template>
</DxFormLayoutItem>
<DxFormLayoutItem ColSpanMd="12">
<Template>
<iframe class="col p-0 preview" height="500" src="@content"/>
</Template>
</DxFormLayoutItem>
</DxFormLayoutGroup>
</DxFormLayout>
</div>
@code{
string content = String.Empty;
double loanAmount = 19000;
int periodInYears = 2;
double interestRate = 0.055d;
DateTime startDate = DateTime.Now;
double LoanAmount
{
get => loanAmount;
set { loanAmount = value; UpdateValue(); }
}
int PeriodInYears
{
get => periodInYears;
set { periodInYears = value; UpdateValue(); }
}
double InterestRate
{
get => interestRate;
set { interestRate = value; UpdateValue(); }
}
DateTime StartDate
{
get => startDate;
set { startDate = value; UpdateValue(); }
}
protected override async Task OnInitializedAsync()
{
await UpdatePreview();
await base.OnInitializedAsync();
}
void UpdateValue() =>
InvokeAsync(async () =>
{
await UpdatePreview();
StateHasChanged();
});
async Task UpdatePreview()
{
var document = await DocumentService.GetHtmlDocumentAsync(loanAmount,
periodInYears, interestRate, startDate);
content = "data:text/html;base64," + Convert.ToBase64String(document);
}
void ExportToXlsx(MouseEventArgs args) => JS.InvokeAsync<object>("open",
GetQueryString("api/Export/Xlsx"), "_self");
void ExportToPdf(MouseEventArgs args) => JS.InvokeAsync<object>("open",
GetQueryString("api/Export/Pdf"), "_self");
string GetQueryString(string uri)
{
var queryParams = new Dictionary<string, string?>() {
{ "loanAmount", loanAmount.ToString() },
{ "periodInYears", periodInYears.ToString() },
{ "interestRate", interestRate.ToString(CultureInfo.InvariantCulture) },
{ "loanStartDate", startDate.ToString("O") },
};
return QueryHelpers.AddQueryString(uri, queryParams);
}
}