Skip to content

Commit fb5b3ad

Browse files
author
aafent
committed
Fix the WordTemplate1.bas example
1 parent a1a6a8e commit fb5b3ad

8 files changed

Lines changed: 65 additions & 18 deletions

File tree

FAST.FBasic.InteractiveConsole/FBasicSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Settings": {
3-
"ProgramsFolder": "~\\..\\..\\..\\..\\..\\FAST.FBasic.InteractiveConsole\\Tests", // ~ stands for current directory
3+
"ProgramsFolder": "~\\..\\..\\..\\..\\FAST.FBasic.InteractiveConsole\\Tests", // ~ stands for current directory
44
"Startup": "helloWorld.bas"
55
},
66
"ConnectionStrings": {

FAST.FBasic.InteractiveConsole/TestCode/DemoDatabase.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ CREATE TABLE IF NOT EXISTS Orders (
4444
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
4545
)";
4646
command.ExecuteNonQuery();
47+
48+
49+
// Create Customers table
50+
command.CommandText = @"
51+
CREATE TABLE IF NOT EXISTS Applications (
52+
ApplicationID INTEGER PRIMARY KEY AUTOINCREMENT,
53+
CustomerID INTEGER not null,
54+
RequestedAmount REAL not null,
55+
LoanTerms INTEGER not null,
56+
Purpose TEXT NOT NULL,
57+
ApplicationDate TEXT NOT NUll
58+
)";
59+
command.ExecuteNonQuery();
60+
4761
}
4862

4963
private void InsertSampleData(string connectionString)
@@ -96,7 +110,7 @@ INSERT INTO Orders (CustomerID, OrderDate, Amount)
96110
new { CustomerId = 3, Date = "2024-01-30", Amount = 175.50 },
97111
new { CustomerId = 4, Date = "2024-03-05", Amount = 220.00 },
98112
new { CustomerId = 1, Date = "2024-03-22", Amount = 350.25 }
99-
};
113+
};
100114

101115
foreach (var order in orders)
102116
{
@@ -107,6 +121,34 @@ INSERT INTO Orders (CustomerID, OrderDate, Amount)
107121
cmd.ExecuteNonQuery();
108122
}
109123

124+
125+
cmd.CommandText = @"
126+
INSERT INTO Applications (ApplicationID, CustomerID, RequestedAmount, LoanTerms, Purpose, ApplicationDate)
127+
VALUES (@applicationId, @customerId, @requestedAmount, @loanTerms, @purpose, @applicationDate)";
128+
129+
var applications = new[] {
130+
new { ApplicationId = 1010, CustomerId = 1, Date = "2025-01-15", Amount = 1152.50 },
131+
new { ApplicationId = 1011, CustomerId = 1, Date = "2025-02-20", Amount = 2000.00 },
132+
new { ApplicationId = 1012, CustomerId = 2, Date = "2025-01-18", Amount = 975.25 },
133+
new { ApplicationId = 1013, CustomerId = 3, Date = "2025-02-18", Amount = 3975.00},
134+
};
135+
136+
Random random = new Random();
137+
foreach (var appl in applications)
138+
{
139+
cmd.Parameters.Clear();
140+
cmd.Parameters.AddWithValue("@applicationId", appl.ApplicationId);
141+
cmd.Parameters.AddWithValue("@customerId", appl.CustomerId);
142+
cmd.Parameters.AddWithValue("@requestedAmount", appl.Amount);
143+
cmd.Parameters.AddWithValue("@loanTerms", random.Next(1,4)*12);
144+
cmd.Parameters.AddWithValue("@purpose", "To buy consumer goods.");
145+
cmd.Parameters.AddWithValue("@applicationDate", appl.Date);
146+
147+
cmd.ExecuteNonQuery();
148+
}
149+
150+
151+
110152
transaction.Commit();
111153
Console.WriteLine("Sample data inserted successfully!");
112154
}
854 Bytes
Binary file not shown.
4 KB
Binary file not shown.
4.93 KB
Binary file not shown.
1 Byte
Binary file not shown.

FAST.FBasic.InteractiveConsole/Tests/sqlsdata.bas

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ REM ---------------------------------------------------
77
REM Category: Collections
88
REM
99

10-
11-
rem uncomment the folloing line to perform a database test
10+
rem uncomment the following line to perform a database test
1211
'rinput DB, DEMO, ok
1312

1413

FAST.FBasic.InteractiveConsole/Tests/wordTest1.bas

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ REM attaching a second document at the end of the first. The example demonstrati
44
REM how to retrieve only the necessary for the template data from the database.
55
REM
66

7-
FILESTREAM template, in, "", "other", "LoanTemplate.docx" ' Streams Library
7+
rem Prepare template documents
8+
FILESTREAM template, inmemory, "", "other", "LoanTemplate.docx" ' Streams Library
89
FILESTREAM final, out, "", "Output", "example1.docx"
9-
loginfo "Reading the file"
1010
WORDEXTRACTBODY template, text ' Templating Library
1111

12-
rem Orchestrate the needed data
13-
rem extract metadata
14-
print "Load data on demand..."
12+
rem Extract metadata
1513
PHVSDATA allNames text ' TextReplacer Library
1614
PHSdata cnames text ' TextReplacer Library
1715

18-
let LoanAmount=25000
16+
rem Orchestrate the needed data
17+
print "Load data on demand..."
18+
let AppID=1010 ' Input from the caller application
1919

2020
foreach cnames
2121
loginfo "Setting up...."+[cnames.ph]
@@ -25,14 +25,14 @@ endforeach cnames
2525

2626
rem (v) Do the replacement and save the document
2727
loginfo "Creating the new document"
28-
WORDREPALCEBODY template, newdoc, allNames ' Templating Library
28+
WORDREPALCEBODY template, ALL, allNames ' Templating Library
29+
2930

3031
rem (v) Append Consent
3132
FILESTREAM Consent, in, "", "other", "Consent.docx"
32-
'WORDPAGEBREAK newdoc
33-
WORDAPPEND Consent, newdoc
33+
WORDAPPEND Consent, template
3434

35-
SCOPY newdoc,final ' Streams Library
35+
SCOPY template,final ' Streams Library
3636

3737
halt
3838

@@ -46,9 +46,17 @@ reset Days
4646
fetch Days
4747
return
4848

49+
Appl:
50+
loginfo "Loading Application: "+AppID
51+
CURSOR Appl, "select CustomerID,RequestedAmount,LoanTerms,Purpose,ApplicationDate from Applications where ApplicationID="+sql(AppID) ' SQLData Adapter
52+
reset Appl
53+
fetch Appl
54+
55+
return
56+
4957
Cust:
50-
loginfo "Loading Customers"
51-
CURSOR Cust, "select CustomerID,Name,VatNumber,Email,Address,City from Customers" ' SQLData Adapter
58+
loginfo "Loading Customer:"+[Appl.CustomerID]
59+
CURSOR Cust, "select Name,VatNumber,Email,Address,City from Customers where CustomerID="+sql([Appl.CustomerID])
5260
reset Cust
5361
fetch Cust
5462

@@ -58,6 +66,4 @@ notfound:
5866
print "***NOT FOUND***"
5967
return
6068

61-
6269
End
63-

0 commit comments

Comments
 (0)