Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
TwilioMsgs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mac Stephens
TwilioMsgs
Commits
6af57824
Commit
6af57824
authored
Feb 14, 2025
by
Mac Stephens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated search, changed dbgrid size
parent
8fba3662
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
430 additions
and
450 deletions
+430
-450
fMain.cpp
fMain.cpp
+227
-235
fMain.dfm
fMain.dfm
+158
-192
fMain.h
fMain.h
+45
-23
No files found.
fMain.cpp
View file @
6af57824
...
@@ -42,13 +42,6 @@ __fastcall TfrmMain::TfrmMain(TComponent* Owner)
...
@@ -42,13 +42,6 @@ __fastcall TfrmMain::TfrmMain(TComponent* Owner)
for
(
int
i
=
0
;
i
<
12
;
i
++
)
for
(
int
i
=
0
;
i
<
12
;
i
++
)
dbcbYear
->
Items
->
Add
(
y
-
i
);
dbcbYear
->
Items
->
Add
(
y
-
i
);
static
String
sMonths
[
12
]
=
{
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
};
for
(
int
i
=
0
;
i
<
12
;
i
++
)
dbcbMonth
->
Items
->
Add
(
sMonths
[
i
]);
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void
__fastcall
TfrmMain
::
btnExitClick
(
TObject
*
Sender
)
void
__fastcall
TfrmMain
::
btnExitClick
(
TObject
*
Sender
)
...
@@ -58,101 +51,90 @@ void __fastcall TfrmMain::btnExitClick(TObject *Sender)
...
@@ -58,101 +51,90 @@ void __fastcall TfrmMain::btnExitClick(TObject *Sender)
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void
__fastcall
TfrmMain
::
btnMessagesClick
(
TObject
*
Sender
)
void
__fastcall
TfrmMain
::
btnMessagesClick
(
TObject
*
Sender
)
{
{
String
res
=
BuildMessageRequestURL
();
bool
saveToDB
=
cbSaveToDB
->
Checked
;
TJSONValue
*
jValue
;
String
nextPageUri
=
BuildMessageRequestURL
();
TJSONObject
*
jObj
;
TJSONArray
*
jaMessages
;
String
jsonPair
;
Memo1
->
Lines
->
Add
(
"---------------------------------------------------------------"
);
// Reset grid, pagination, and total message count
Memo1
->
Lines
->
Add
(
"/Messages.json end point..."
);
grdData
->
ClearAll
();
Memo2
->
Clear
();
grdData
->
RowCount
=
1
;
Memo3
->
Clear
();
pagesLoaded
=
0
;
int
totalMessages
=
0
;
// Reset total message count
// Create REST client
if
(
saveToDB
)
TRESTClient
*
pRESTClient
=
new
TRESTClient
(
NULL
);
Memo2
->
Lines
->
Add
(
"Fetching messages to be saved in the database..."
);
pRESTClient
->
BaseURL
=
"https://api.twilio.com"
;
else
Memo2
->
Lines
->
Add
(
"Fetching messages from Twilio for AdvGrid..."
);
TRESTRequest
*
pRESTRequest
=
new
TRESTRequest
(
NULL
);
do
{
pRESTRequest
->
Client
=
pRESTClient
;
TRESTClient
*
pRESTClient
=
new
TRESTClient
(
NULL
);
pRESTClient
->
BaseURL
=
"https://api.twilio.com"
;
TRESTResponse
*
pRESTResponse
=
new
TRESTResponse
(
NULL
);
TRESTRequest
*
pRESTRequest
=
new
TRESTRequest
(
NULL
);
pRESTRequest
->
Response
=
pRESTResponse
;
pRESTRequest
->
Client
=
pRESTClient
;
pRESTRequest
->
Method
=
rmGET
;
TRESTResponse
*
pRESTResponse
=
new
TRESTResponse
(
NULL
)
;
pRESTRequest
->
Resource
=
res
;
pRESTRequest
->
Response
=
pRESTResponse
;
// Set authorization header
pRESTRequest
->
Method
=
rmGET
;
TRESTRequestParameter
*
param
=
pRESTRequest
->
Params
->
AddItem
();
pRESTRequest
->
Resource
=
nextPageUri
;
param
->
Name
=
"Authorization"
;
param
->
Kind
=
pkHTTPHEADER
;
param
->
Options
=
TRESTRequestParameterOptions
()
<<
poDoNotEncode
;
param
->
Value
=
authHeader
;
Memo1
->
Lines
->
Add
(
"Messages: "
+
pRESTRequest
->
GetFullRequestURL
());
TRESTRequestParameter
*
param
=
pRESTRequest
->
Params
->
AddItem
();
pRESTRequest
->
Execute
();
param
->
Name
=
"Authorization"
;
param
->
Kind
=
pkHTTPHEADER
;
param
->
Options
=
TRESTRequestParameterOptions
()
<<
poDoNotEncode
;
param
->
Value
=
authHeader
;
jValue
=
pRESTResponse
->
JSONValue
;
Memo1
->
Lines
->
Add
(
"Fetching Messages from URI: "
+
pRESTRequest
->
GetFullRequestURL
());
Memo3
->
Lines
->
Add
(
""
);
pRESTRequest
->
Execute
();
Memo3
->
Lines
->
Add
(
"jValue = pRESTResponse->JSONValue;"
);
Memo3
->
Lines
->
Add
(
"---------------------------------------------------------------------"
);
Memo3
->
Lines
->
Add
(
jValue
->
Format
(
2
));
jObj
=
dynamic_cast
<
TJSONObject
*>
(
jValue
);
TJSONObject
*
jObj
=
dynamic_cast
<
TJSONObject
*>
(
pRESTResponse
->
JSONValue
);
if
(
!
jObj
)
{
Memo1
->
Lines
->
Add
(
"No JSON object returned."
);
break
;
}
if
(
jObj
)
TJSONArray
*
jaMessages
=
dynamic_cast
<
TJSONArray
*>
(
jObj
->
GetValue
(
"messages"
));
{
if
(
jaMessages
&&
jaMessages
->
Count
>
0
)
{
for
(
int
e
=
0
;
e
<
jObj
->
Count
;
e
++
)
if
(
pagesLoaded
==
0
)
{
{
GetFieldsFromJsonArray
(
jaMessages
);
if
(
jObj
->
Pairs
[
e
]
->
JsonString
->
Value
()
!=
"messages"
)
LoadJsonArray
(
jaMessages
,
""
);
{
}
else
{
jsonPair
=
jObj
->
Pairs
[
e
]
->
JsonString
->
Value
();
AppendJsonArray
(
jaMessages
);
jsonPair
+=
" : "
+
jObj
->
Pairs
[
e
]
->
JsonValue
->
Value
();
Memo1
->
Lines
->
Add
(
jsonPair
);
}
}
}
if
(
jObj
->
Get
(
"next_page_uri"
))
if
(
saveToDB
)
txtNextPageUri
->
Text
=
jObj
->
Get
(
"next_page_uri"
)
->
JsonValue
->
Value
();
SaveMessagesToDB
(
jaMessages
);
else
txtNextPageUri
->
Text
=
""
;
jaMessages
=
dynamic_cast
<
TJSONArray
*>
(
jObj
->
GetValue
(
"messages"
));
pagesLoaded
++
;
if
(
jaMessages
&&
jaMessages
->
Count
>
0
)
totalMessages
+=
jaMessages
->
Count
;
{
Memo2
->
Lines
->
Add
(
"jaMessages->Count: "
+
IntToStr
(
jaMessages
->
Count
));
GetFieldsFromJsonArray
(
jaMessages
);
Memo2
->
Lines
->
Add
(
"Loaded page #"
+
IntToStr
(
pagesLoaded
));
for
(
int
i
=
0
;
i
<
fieldsList
->
Count
;
i
++
)
Memo2
->
Lines
->
Add
(
"Messages on this page: "
+
IntToStr
(
jaMessages
->
Count
));
{
Memo2
->
Lines
->
Add
(
fieldsList
->
Strings
[
i
]);
}
LoadJsonArray
(
jaMessages
,
""
);
Memo2
->
Lines
->
Add
(
"grdMessages->Count: "
+
IntToStr
(
grdData
->
RowCount
-
1
));
pagesLoaded
=
1
;
if
(
saveToDB
)
Memo2
->
Lines
->
Add
(
"Total messages saved to database: "
+
IntToStr
(
totalMessages
));
else
Memo2
->
Lines
->
Add
(
"Total messages loaded: "
+
IntToStr
(
totalMessages
));
}
else
{
Memo2
->
Lines
->
Add
(
"No messages found on this page."
);
break
;
}
}
if
(
jObj
->
Get
(
"next_page_uri"
))
nextPageUri
=
jObj
->
Get
(
"next_page_uri"
)
->
JsonValue
->
Value
();
else
else
{
nextPageUri
=
""
;
// No more pages
Memo2
->
Lines
->
Add
(
"No messages returned."
);
grdData
->
ClearAll
();
grdData
->
RowCount
=
1
;
}
}
else
{
Memo1
->
Lines
->
Add
(
"No JSON object returned."
);
}
if
(
cbSaveToDB
->
Checked
)
delete
pRESTClient
;
{
delete
pRESTRequest
;
SaveMessagesToDB
(
jaMessages
);
delete
pRESTResponse
;
}
}
while
(
!
nextPageUri
.
IsEmpty
()
&&
nextPageUri
!=
"null"
);
delete
pRESTClient
;
Memo2
->
Lines
->
Add
(
"Get messages complete."
);
delete
pRESTRequest
;
delete
pRESTResponse
;
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void
TfrmMain
::
SaveMessagesToDB
(
TJSONArray
*
jaMessages
)
void
TfrmMain
::
SaveMessagesToDB
(
TJSONArray
*
jaMessages
)
{
{
...
@@ -174,48 +156,47 @@ void TfrmMain::SaveMessagesToDB(TJSONArray* jaMessages)
...
@@ -174,48 +156,47 @@ void TfrmMain::SaveMessagesToDB(TJSONArray* jaMessages)
String
sid
=
jso
->
GetValue
(
"sid"
)
->
Value
();
String
sid
=
jso
->
GetValue
(
"sid"
)
->
Value
();
// Check if the message already exists
// Check if the message already exists
uqMessages
->
Close
();
uqMessages
->
Close
();
uqMessages
->
SQL
->
Text
=
"SELECT * FROM public.messages WHERE sid = :sid"
;
uqMessages
->
SQL
->
Text
=
"SELECT * FROM public.messages WHERE sid = :sid"
;
uqMessages
->
ParamByName
(
"sid"
)
->
AsString
=
sid
;
uqMessages
->
ParamByName
(
"sid"
)
->
AsString
=
sid
;
Memo1
->
Lines
->
Add
(
"Checking available fields in uqMessages:"
);
uqMessages
->
Open
();
uqMessages
->
Open
();
if
(
uqMessages
->
IsEmpty
())
if
(
uqMessages
->
IsEmpty
())
{
{
uqMessages
->
Append
();
uqMessages
->
Append
();
// Insert new record
}
}
else
else
{
{
uqMessages
->
Edit
();
uqMessages
->
Edit
();
// Update existing record
}
}
uqMessages
->
FieldByName
(
"sid"
)
->
AsString
=
sid
;
uqMessages
->
FieldByName
(
"sid"
)
->
AsString
=
sid
;
uqMessages
->
FieldByName
(
"account_sid"
)
->
AsString
=
jso
->
GetValue
(
"account_sid"
)
->
Value
();
uqMessages
->
FieldByName
(
"account_sid"
)
->
AsString
=
jso
->
GetValue
(
"account_sid"
)
->
Value
();
uqMessages
->
FieldByName
(
"api_version"
)
->
AsString
=
jso
->
GetValue
(
"api_version"
)
->
Value
();
uqMessages
->
FieldByName
(
"api_version"
)
->
AsString
=
jso
->
GetValue
(
"api_version"
)
->
Value
();
uqMessages
->
FieldByName
(
"body"
)
->
AsString
=
jso
->
GetValue
(
"body"
)
->
Value
();
uqMessages
->
FieldByName
(
"body"
)
->
AsString
=
jso
->
GetValue
(
"body"
)
->
Value
();
uqMessages
->
FieldByName
(
"date_created"
)
->
AsDateTime
=
ParseTwilioDateTime
(
jso
->
GetValue
(
"date_created"
)
->
Value
());
uqMessages
->
FieldByName
(
"date_created"
)
->
AsDateTime
=
ParseTwilioDateTime
(
jso
->
GetValue
(
"date_created"
)
->
Value
());
uqMessages
->
FieldByName
(
"date_sent"
)
->
AsDateTime
=
ParseTwilioDateTime
(
jso
->
GetValue
(
"date_sent"
)
->
Value
());
uqMessages
->
FieldByName
(
"date_sent"
)
->
AsDateTime
=
ParseTwilioDateTime
(
jso
->
GetValue
(
"date_sent"
)
->
Value
());
uqMessages
->
FieldByName
(
"date_updated"
)
->
AsDateTime
=
ParseTwilioDateTime
(
jso
->
GetValue
(
"date_updated"
)
->
Value
());
uqMessages
->
FieldByName
(
"date_updated"
)
->
AsDateTime
=
ParseTwilioDateTime
(
jso
->
GetValue
(
"date_updated"
)
->
Value
());
uqMessages
->
FieldByName
(
"direction"
)
->
AsString
=
jso
->
GetValue
(
"direction"
)
->
Value
();
uqMessages
->
FieldByName
(
"direction"
)
->
AsString
=
jso
->
GetValue
(
"direction"
)
->
Value
();
uqMessages
->
FieldByName
(
"error_code"
)
->
AsInteger
=
jso
->
GetValue
(
"error_code"
)
->
Value
().
ToIntDef
(
0
);
uqMessages
->
FieldByName
(
"error_code"
)
->
AsInteger
=
jso
->
GetValue
(
"error_code"
)
->
Value
().
ToIntDef
(
0
);
uqMessages
->
FieldByName
(
"error_message"
)
->
AsString
=
jso
->
GetValue
(
"error_message"
)
->
Value
();
uqMessages
->
FieldByName
(
"error_message"
)
->
AsString
=
jso
->
GetValue
(
"error_message"
)
->
Value
();
uqMessages
->
FieldByName
(
"from_number"
)
->
AsString
=
jso
->
GetValue
(
"from"
)
->
Value
();
uqMessages
->
FieldByName
(
"from_number"
)
->
AsString
=
jso
->
GetValue
(
"from"
)
->
Value
();
uqMessages
->
FieldByName
(
"messaging_service_sid"
)
->
AsString
=
jso
->
GetValue
(
"messaging_service_sid"
)
->
Value
();
uqMessages
->
FieldByName
(
"messaging_service_sid"
)
->
AsString
=
jso
->
GetValue
(
"messaging_service_sid"
)
->
Value
();
uqMessages
->
FieldByName
(
"num_media"
)
->
AsInteger
=
jso
->
GetValue
(
"num_media"
)
->
Value
().
ToIntDef
(
0
);
uqMessages
->
FieldByName
(
"num_media"
)
->
AsInteger
=
jso
->
GetValue
(
"num_media"
)
->
Value
().
ToIntDef
(
0
);
uqMessages
->
FieldByName
(
"num_segments"
)
->
AsInteger
=
jso
->
GetValue
(
"num_segments"
)
->
Value
().
ToIntDef
(
0
);
uqMessages
->
FieldByName
(
"num_segments"
)
->
AsInteger
=
jso
->
GetValue
(
"num_segments"
)
->
Value
().
ToIntDef
(
0
);
uqMessages
->
FieldByName
(
"price"
)
->
AsFloat
=
jso
->
GetValue
(
"price"
)
->
Value
().
ToDouble
();
uqMessages
->
FieldByName
(
"price"
)
->
AsFloat
=
jso
->
GetValue
(
"price"
)
->
Value
().
ToDouble
();
uqMessages
->
FieldByName
(
"price_unit"
)
->
AsString
=
jso
->
GetValue
(
"price_unit"
)
->
Value
();
uqMessages
->
FieldByName
(
"price_unit"
)
->
AsString
=
jso
->
GetValue
(
"price_unit"
)
->
Value
();
uqMessages
->
FieldByName
(
"status"
)
->
AsString
=
jso
->
GetValue
(
"status"
)
->
Value
();
uqMessages
->
FieldByName
(
"status"
)
->
AsString
=
jso
->
GetValue
(
"status"
)
->
Value
();
uqMessages
->
FieldByName
(
"to_number"
)
->
AsString
=
jso
->
GetValue
(
"to"
)
->
Value
();
uqMessages
->
FieldByName
(
"to_number"
)
->
AsString
=
jso
->
GetValue
(
"to"
)
->
Value
();
uqMessages
->
FieldByName
(
"uri"
)
->
AsString
=
jso
->
GetValue
(
"uri"
)
->
Value
();
uqMessages
->
FieldByName
(
"uri"
)
->
AsString
=
jso
->
GetValue
(
"uri"
)
->
Value
();
uqMessages
->
Post
();
uqMessages
->
Post
();
}
}
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
TDateTime
TfrmMain
::
ParseTwilioDateTime
(
String
dateStr
)
TDateTime
TfrmMain
::
ParseTwilioDateTime
(
String
dateStr
)
{
{
// Twilio format: "Wed, 12 Feb 2025 18:21:17 +0000"
// Twilio format: "Wed, 12 Feb 2025 18:21:17 +0000"
std
::
map
<
UnicodeString
,
int
>
monthMap
;
std
::
map
<
UnicodeString
,
int
>
monthMap
;
monthMap
[
"Jan"
]
=
1
;
monthMap
[
"Feb"
]
=
2
;
monthMap
[
"Mar"
]
=
3
;
monthMap
[
"Jan"
]
=
1
;
monthMap
[
"Feb"
]
=
2
;
monthMap
[
"Mar"
]
=
3
;
monthMap
[
"Apr"
]
=
4
;
monthMap
[
"May"
]
=
5
;
monthMap
[
"Jun"
]
=
6
;
monthMap
[
"Apr"
]
=
4
;
monthMap
[
"May"
]
=
5
;
monthMap
[
"Jun"
]
=
6
;
monthMap
[
"Jul"
]
=
7
;
monthMap
[
"Aug"
]
=
8
;
monthMap
[
"Sep"
]
=
9
;
monthMap
[
"Jul"
]
=
7
;
monthMap
[
"Aug"
]
=
8
;
monthMap
[
"Sep"
]
=
9
;
monthMap
[
"Oct"
]
=
10
;
monthMap
[
"Nov"
]
=
11
;
monthMap
[
"Dec"
]
=
12
;
monthMap
[
"Oct"
]
=
10
;
monthMap
[
"Nov"
]
=
11
;
monthMap
[
"Dec"
]
=
12
;
...
@@ -270,23 +251,38 @@ String TfrmMain::BuildMessageRequestURL()
...
@@ -270,23 +251,38 @@ String TfrmMain::BuildMessageRequestURL()
if
(
hasStartDate
||
hasEndDate
)
if
(
hasStartDate
||
hasEndDate
)
{
{
TDateTime
now
=
Now
();
TDateTime
d1
,
d2
;
TDateTime
d1
,
d2
;
if
(
hasStartDate
)
d1
=
dtpStartDate
->
Date
;
if
(
hasStartDate
)
d1
=
dtpStartDate
->
Date
;
if
(
hasEndDate
)
d2
=
dtpEndDate
->
Date
;
if
(
hasEndDate
)
d2
=
dtpEndDate
->
Date
;
if
(
hasStartDate
&&
hasEndDate
&&
d1
>
d2
)
{
throw
Exception
(
"Invalid date range: The start date cannot be more recent than the end date."
);
}
if
(
hasStartDate
&&
hasEndDate
)
if
(
hasStartDate
&&
hasEndDate
)
{
{
if
(
d1
>
d2
)
std
::
swap
(
d1
,
d2
);
if
(
d1
==
d2
)
url
+=
"?DateSent>="
+
FormatDateTime
(
"yyyy-mm-dd"
,
d1
)
+
{
"&DateSent<="
+
FormatDateTime
(
"yyyy-mm-dd"
,
d2
);
url
+=
"?DateSent="
+
FormatDateTime
(
"yyyy-mm-dd"
,
d1
);
}
else
{
url
+=
"?DateSent>="
+
FormatDateTime
(
"yyyy-mm-dd"
,
d1
)
+
"&DateSent<="
+
FormatDateTime
(
"yyyy-mm-dd"
,
d2
);
}
}
}
else
if
(
hasStartDate
)
else
if
(
hasStartDate
)
{
{
url
+=
"?DateSent
>
="
+
FormatDateTime
(
"yyyy-mm-dd"
,
d1
);
url
+=
"?DateSent="
+
FormatDateTime
(
"yyyy-mm-dd"
,
d1
);
}
}
else
if
(
hasEndDate
)
else
if
(
hasEndDate
)
{
{
url
+=
"?DateSent<="
+
FormatDateTime
(
"yyyy-mm-dd"
,
d2
);
TDateTime
oldestAvailable
=
now
-
395
;
// Twilio keeps messages for exactly 395 days
url
+=
"?DateSent>="
+
FormatDateTime
(
"yyyy-mm-dd"
,
oldestAvailable
)
+
"&DateSent<="
+
FormatDateTime
(
"yyyy-mm-dd"
,
d2
);
}
}
if
(
!
pageSizeStr
.
IsEmpty
())
if
(
!
pageSizeStr
.
IsEmpty
())
...
@@ -295,26 +291,24 @@ String TfrmMain::BuildMessageRequestURL()
...
@@ -295,26 +291,24 @@ String TfrmMain::BuildMessageRequestURL()
else
else
{
{
if
(
!
pageSizeStr
.
IsEmpty
())
if
(
!
pageSizeStr
.
IsEmpty
())
url
+=
"?PageSize="
+
pageSizeStr
;
url
+=
"?PageSize="
+
pageSizeStr
;
}
}
return
url
;
return
url
;
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void
TfrmMain
::
GetFieldsFromJsonArray
(
TJSONArray
*
jaData
)
void
TfrmMain
::
GetFieldsFromJsonArray
(
TJSONArray
*
jaData
)
{
{
String
fieldname
;
String
fieldname
;
String
str
;
String
str
;
TJSONObject
*
jobj
;
TJSONObject
*
jso
;
TJSONObject
*
jso
;
fieldsList
=
new
TStringList
;
TJSONArray
*
ja
;
int
row
;
if
(
!
jaData
||
jaData
->
Count
==
0
)
return
;
jso
=
dynamic_cast
<
TJSONObject
*>
(
jaData
->
Items
[
0
]);
if
(
!
jso
)
return
;
fieldsList
=
new
TStringList
;
jso
=
(
TJSONObject
*
)
jaData
->
Items
[
0
];
for
(
int
i
=
0
;
i
<
jso
->
Count
;
i
++
){
for
(
int
i
=
0
;
i
<
jso
->
Count
;
i
++
){
fieldname
=
jso
->
Pairs
[
i
]
->
JsonString
->
Value
();
fieldname
=
jso
->
Pairs
[
i
]
->
JsonString
->
Value
();
str
=
fieldname
+
"=0"
;
str
=
fieldname
+
"=0"
;
...
@@ -324,34 +318,23 @@ void TfrmMain::GetFieldsFromJsonArray(TJSONArray* jaData)
...
@@ -324,34 +318,23 @@ void TfrmMain::GetFieldsFromJsonArray(TJSONArray* jaData)
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void
TfrmMain
::
LoadJsonArray
(
TJSONArray
*
jaData
,
String
detail
)
void
TfrmMain
::
LoadJsonArray
(
TJSONArray
*
jaData
,
String
detail
)
{
{
TJSONObject
*
jobj
;
TJSONObject
*
jso
;
TJSONObject
*
jso
;
TJSONArray
*
ja
;
int
row
;
grdData
->
ClearAll
();
grdData
->
ClearAll
();
grdData
->
RowCount
=
1
;
grdData
->
RowCount
=
1
;
grdData
->
StartUpdate
();
grdData
->
StartUpdate
();
jso
=
(
TJSONObject
*
)
jaData
->
Items
[
0
];
if
(
!
jaData
||
jaData
->
Count
==
0
)
{
grdData
->
EndUpdate
();
return
;
}
jso
=
dynamic_cast
<
TJSONObject
*>
(
jaData
->
Items
[
0
]);
if
(
!
jso
)
{
grdData
->
EndUpdate
();
return
;
}
grdData
->
ColCount
=
jso
->
Count
;
grdData
->
ColCount
=
jso
->
Count
;
for
(
int
e
=
0
;
e
<
jso
->
Count
;
e
++
)
for
(
int
e
=
0
;
e
<
jso
->
Count
;
e
++
)
grdData
->
Cells
[
e
+
1
][
0
]
=
jso
->
Pairs
[
e
]
->
JsonString
->
Value
();
grdData
->
Cells
[
e
+
1
][
0
]
=
jso
->
Pairs
[
e
]
->
JsonString
->
Value
();
for
(
int
i
=
0
;
i
<
jaData
->
Count
;
i
++
){
for
(
int
i
=
0
;
i
<
jaData
->
Count
;
i
++
){
jso
=
dynamic_cast
<
TJSONObject
*>
(
jaData
->
Items
[
i
]);
jso
=
(
TJSONObject
*
)
jaData
->
Items
[
i
];
if
(
!
jso
)
continue
;
grdData
->
RowCount
++
;
grdData
->
RowCount
++
;
int
row
=
grdData
->
RowCount
-
1
;
row
=
grdData
->
RowCount
-
1
;
for
(
int
e
=
0
;
e
<
jso
->
Count
;
e
++
)
for
(
int
e
=
0
;
e
<
jso
->
Count
;
e
++
)
grdData
->
Cells
[
e
+
1
][
row
]
=
jso
->
Pairs
[
e
]
->
JsonValue
->
Value
();
grdData
->
Cells
[
e
+
1
][
row
]
=
jso
->
Pairs
[
e
]
->
JsonValue
->
Value
();
}
}
...
@@ -366,7 +349,7 @@ void TfrmMain::AppendJsonArray(TJSONArray* jaData)
...
@@ -366,7 +349,7 @@ void TfrmMain::AppendJsonArray(TJSONArray* jaData)
grdData
->
BeginUpdate
();
grdData
->
BeginUpdate
();
for
(
int
i
=
0
;
i
<
jaData
->
Count
;
i
++
)
for
(
int
i
=
0
;
i
<
jaData
->
Count
;
i
++
)
{
{
TJSONObject
*
jso
=
dynamic_cast
<
TJSONObject
*>
(
jaData
->
Items
[
i
]);
TJSONObject
*
jso
=
dynamic_cast
<
TJSONObject
*>
(
jaData
->
Items
[
i
]);
if
(
!
jso
)
if
(
!
jso
)
continue
;
continue
;
...
@@ -375,7 +358,7 @@ void TfrmMain::AppendJsonArray(TJSONArray* jaData)
...
@@ -375,7 +358,7 @@ void TfrmMain::AppendJsonArray(TJSONArray* jaData)
for
(
int
e
=
0
;
e
<
jso
->
Count
;
e
++
)
for
(
int
e
=
0
;
e
<
jso
->
Count
;
e
++
)
{
{
grdData
->
Cells
[
e
+
1
][
row
]
=
jso
->
Pairs
[
e
]
->
JsonValue
->
Value
();
grdData
->
Cells
[
e
+
1
][
row
]
=
jso
->
Pairs
[
e
]
->
JsonValue
->
Value
();
}
}
}
}
grdData
->
EndUpdate
();
grdData
->
EndUpdate
();
}
}
...
@@ -394,110 +377,119 @@ void TfrmMain::SetDatePickersFromMonthYear()
...
@@ -394,110 +377,119 @@ void TfrmMain::SetDatePickersFromMonthYear()
{
{
int
year
=
0
;
int
year
=
0
;
int
month
=
0
;
int
month
=
0
;
TDateTime
startDate
;
TDateTime
endDate
;
if
(
!
dbcbYear
->
Value
.
IsEmpty
()
)
if
(
!
dbcbYear
->
Value
.
IsEmpty
()
)
year
=
StrToInt
(
dbcbYear
->
Value
);
year
=
StrToInt
(
dbcbYear
->
Value
);
if
(
!
dbcbMonth
->
Value
.
IsEmpty
())
if
(
!
dbcbMonth
->
Value
.
IsEmpty
()
)
{
month
=
StrToInt
(
dbcbMonth
->
Value
);
String
selMonth
=
dbcbMonth
->
Value
;
if
(
selMonth
==
"January"
)
month
=
1
;
else
if
(
selMonth
==
"February"
)
month
=
2
;
else
if
(
selMonth
==
"March"
)
month
=
3
;
else
if
(
selMonth
==
"April"
)
month
=
4
;
else
if
(
selMonth
==
"May"
)
month
=
5
;
else
if
(
selMonth
==
"June"
)
month
=
6
;
else
if
(
selMonth
==
"July"
)
month
=
7
;
else
if
(
selMonth
==
"August"
)
month
=
8
;
else
if
(
selMonth
==
"September"
)
month
=
9
;
else
if
(
selMonth
==
"October"
)
month
=
10
;
else
if
(
selMonth
==
"November"
)
month
=
11
;
else
if
(
selMonth
==
"December"
)
month
=
12
;
}
if
(
month
>
0
&&
year
>
0
)
if
(
month
>
0
&&
year
>
0
){
{
startDate
=
StartOfAMonth
(
year
,
month
);
TDateTime
s
=
StartOfAMonth
(
year
,
month
);
endDate
=
EndOfAMonth
(
year
,
month
);
TDateTime
e
=
EndOfAMonth
(
year
,
month
);
dtpStartDate
->
Date
=
startDate
;
dtpStartDate
->
Date
=
s
;
dtpEndDate
->
Date
=
endDate
;
dtpEndDate
->
Date
=
e
;
}
}
else
if
(
year
>
0
)
else
if
(
year
>
0
){
{
startDate
=
StartOfAMonth
(
year
,
1
);
TDateTime
s
=
StartOfAMonth
(
year
,
1
);
endDate
=
EndOfAMonth
(
year
,
12
);
TDateTime
ee
=
EndOfAMonth
(
year
,
12
);
dtpStartDate
->
Date
=
startDate
;
dtpStartDate
->
Date
=
s
;
dtpEndDate
->
Date
=
endDate
;
dtpEndDate
->
Date
=
ee
;
}
}
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void
__fastcall
TfrmMain
::
btnNextPage
Click
(
TObject
*
Sender
)
void
__fastcall
TfrmMain
::
Button1
Click
(
TObject
*
Sender
)
{
{
// Stop if there's no next page URI
TDateTime
dt
;
if
(
txtNextPageUri
->
Text
.
Trim
().
IsEmpty
()
||
txtNextPageUri
->
Text
==
"null"
)
{
Memo2
->
Lines
->
Add
(
"No more pages left to load."
);
return
;
}
TRESTClient
*
pRESTClient
=
new
TRESTClient
(
NULL
);
dt
=
ParseTwilioDateTime
(
"Wed, 12 Feb 2025 18:21:17 +0000"
);
pRESTClient
->
BaseURL
=
"https://api.twilio.com"
;
Memo1
->
Lines
->
Add
(
dt
.
DateTimeString
()
);
}
//---------------------------------------------------------------------------
void
__fastcall
TfrmMain
::
btnDBMessagesClick
(
TObject
*
Sender
)
{
Memo1
->
Lines
->
Add
(
"Fetching messages from the database..."
);
TRESTRequest
*
pRESTRequest
=
new
TRESTRequest
(
NULL
);
if
(
!
ucTwilioDB
->
Connected
)
pRESTRequest
->
Client
=
pRESTClient
;
ucTwilioDB
->
Connected
=
true
;
TRESTResponse
*
pRESTResponse
=
new
TRESTResponse
(
NULL
);
bool
hasStartDate
=
!
dtpStartDate
->
Text
.
IsEmpty
();
pRESTRequest
->
Response
=
pRESTResponse
;
bool
hasEndDate
=
!
dtpEndDate
->
Text
.
IsEmpty
();
TDateTime
startDate
,
endDate
;
TDateTime
now
=
Now
();
TDateTime
oldestAvailable
=
now
-
395
;
// EXACTLY 395 days for Twilio's retention period
pRESTRequest
->
Method
=
rmGET
;
if
(
hasStartDate
)
startDate
=
dtpStartDate
->
Date
;
pRESTRequest
->
Resource
=
txtNextPageUri
->
Text
;
if
(
hasEndDate
)
endDate
=
dtpEndDate
->
Date
;
TRESTRequestParameter
*
param
=
pRESTRequest
->
Params
->
AddItem
();
// **Validation: Ensure Start Date is not more recent than End Date**
param
->
Name
=
"Authorization"
;
if
(
hasStartDate
&&
hasEndDate
&&
startDate
>
endDate
)
param
->
Kind
=
pkHTTPHEADER
;
{
param
->
Options
=
TRESTRequestParameterOptions
()
<<
poDoNotEncode
;
throw
Exception
(
"Invalid date range: The start date cannot be more recent than the end date."
)
;
param
->
Value
=
authHeader
;
}
pRESTRequest
->
Execut
e
();
uqDBMessages
->
Clos
e
();
TJSONObject
*
jObj
=
dynamic_cast
<
TJSONObject
*>
(
pRESTResponse
->
JSONValue
);
if
(
hasStartDate
&&
hasEndDate
)
if
(
!
jObj
)
{
if
(
startDate
==
endDate
)
// **Fix: Handle same start & end date**
{
uqDBMessages
->
SQL
->
Text
=
"SELECT * FROM public.messages "
"WHERE date_sent::DATE = :selectedDate "
"ORDER BY date_sent ASC"
;
uqDBMessages
->
ParamByName
(
"selectedDate"
)
->
AsDateTime
=
startDate
;
}
else
{
uqDBMessages
->
SQL
->
Text
=
"SELECT * FROM public.messages "
"WHERE date_sent::DATE >= :startDate AND date_sent::DATE <= :endDate "
"ORDER BY date_sent ASC"
;
uqDBMessages
->
ParamByName
(
"startDate"
)
->
AsDateTime
=
startDate
;
uqDBMessages
->
ParamByName
(
"endDate"
)
->
AsDateTime
=
endDate
;
}
}
else
if
(
hasStartDate
)
{
{
Memo2
->
Lines
->
Add
(
"No JSON object returned for next page."
);
uqDBMessages
->
SQL
->
Text
=
"SELECT * FROM public.messages "
"WHERE date_sent::DATE = :startDate "
"ORDER BY date_sent ASC"
;
uqDBMessages
->
ParamByName
(
"startDate"
)
->
AsDateTime
=
startDate
;
}
else
if
(
hasEndDate
)
{
uqDBMessages
->
SQL
->
Text
=
"SELECT * FROM public.messages "
"WHERE date_sent >= :oldestAvailable AND date_sent::DATE <= :endDate "
"ORDER BY date_sent ASC"
;
uqDBMessages
->
ParamByName
(
"oldestAvailable"
)
->
AsDateTime
=
oldestAvailable
;
uqDBMessages
->
ParamByName
(
"endDate"
)
->
AsDateTime
=
endDate
;
}
}
else
else
{
{
TJSONArray
*
jaMessages
=
dynamic_cast
<
TJSONArray
*>
(
jObj
->
GetValue
(
"messages"
));
uqDBMessages
->
SQL
->
Text
=
if
(
jaMessages
&&
jaMessages
->
Count
>
0
)
"SELECT * FROM public.messages "
{
"ORDER BY date_sent ASC"
;
AppendJsonArray
(
jaMessages
);
// Append new messages
pagesLoaded
++
;
Memo2
->
Lines
->
Add
(
"Loaded next page (#"
+
IntToStr
(
pagesLoaded
)
+
")."
);
Memo2
->
Lines
->
Add
(
"Total messages in grid: "
+
IntToStr
(
grdData
->
RowCount
-
1
));
// Update next_page_uri
if
(
jObj
->
Get
(
"next_page_uri"
))
txtNextPageUri
->
Text
=
jObj
->
Get
(
"next_page_uri"
)
->
JsonValue
->
Value
();
else
txtNextPageUri
->
Text
=
""
;
// Stop further pagination
}
else
{
Memo2
->
Lines
->
Add
(
"No messages in next page."
);
}
}
}
delete
pRESTClient
;
Memo1
->
Lines
->
Add
(
"Executing query: "
+
uqDBMessages
->
SQL
->
Text
);
delete
pRESTRequest
;
uqDBMessages
->
Open
();
delete
pRESTResponse
;
}
//---------------------------------------------------------------------------
void
__fastcall
TfrmMain
::
Button1Click
(
TObject
*
Sender
)
{
TDateTime
dt
;
dt
=
ParseTwilioDateTime
(
"Wed, 12 Feb 2025 18:21:17 +0000"
);
if
(
uqDBMessages
->
IsEmpty
())
{
Memo1
->
Lines
->
Add
(
dt
.
DateTimeString
()
);
Memo2
->
Lines
->
Add
(
"No messages found for the selected date range."
);
return
;
}
Memo2
->
Lines
->
Add
(
"Messages retrieved: "
+
IntToStr
(
uqDBMessages
->
RecordCount
));
dsMessages
->
DataSet
=
uqDBMessages
;
dbgrdDatabase
->
Refresh
();
Memo1
->
Lines
->
Add
(
"Database messages loaded into grid."
);
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
fMain.dfm
View file @
6af57824
...
@@ -183,7 +183,7 @@ object frmMain: TfrmMain
...
@@ -183,7 +183,7 @@ object frmMain: TfrmMain
Version = '4.0.6.0'
Version = '4.0.6.0'
end
end
object cbSaveToDB: TCheckBox
object cbSaveToDB: TCheckBox
Left = 1
38
Left = 1
64
Top = 82
Top = 82
Width = 171
Width = 171
Height = 17
Height = 17
...
@@ -191,14 +191,57 @@ object frmMain: TfrmMain
...
@@ -191,14 +191,57 @@ object frmMain: TfrmMain
TabOrder = 6
TabOrder = 6
end
end
object Button1: TButton
object Button1: TButton
Left =
44
0
Left =
82
0
Top =
76
Top =
39
Width = 139
Width = 139
Height = 25
Height = 25
Caption = 'DateTime Conversion'
Caption = 'DateTime Conversion'
TabOrder = 7
TabOrder = 7
OnClick = Button1Click
OnClick = Button1Click
end
end
object btnDBMessages: TButton
Left = 387
Top = 78
Width = 129
Height = 25
Caption = 'Get Database Messages'
TabOrder = 8
OnClick = btnDBMessagesClick
end
object dbcbMonth: TwwDBComboBox
Left = 342
Top = 41
Width = 120
Height = 21
ShowButton = True
Style = csDropDown
MapList = True
AllowClearKey = False
DropDownCount = 12
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
ItemHeight = 0
Items.Strings = (
'January'#9'01'
'February'#9'02'
'March'#9'03'
'April'#9'04'
'May'#9'05'
'June'#9'06'
'July'#9'07'
'August'#9'08'
'September'#9'09'
'October'#9'10'
'November'#9'11'
'December'#9'12')
ParentFont = False
Sorted = False
TabOrder = 9
UnboundDataType = wwDefault
end
end
end
object Panel2: TPanel
object Panel2: TPanel
Left = 0
Left = 0
...
@@ -213,7 +256,7 @@ object frmMain: TfrmMain
...
@@ -213,7 +256,7 @@ object frmMain: TfrmMain
Width = 1182
Width = 1182
Height = 267
Height = 267
Align = alClient
Align = alClient
ActivePage = AdvOfficePage
1
ActivePage = AdvOfficePage
2
ButtonSettings.CloseButtonPicture.Data = {
ButtonSettings.CloseButtonPicture.Data = {
424DA20400000000000036040000280000000900000009000000010008000000
424DA20400000000000036040000280000000900000009000000010008000000
00006C000000C30E0000C30E00000001000000010000427B8400DEEFEF00FFFF
00006C000000C30E0000C30E00000001000000010000427B8400DEEFEF00FFFF
...
@@ -704,6 +747,7 @@ object frmMain: TfrmMain
...
@@ -704,6 +747,7 @@ object frmMain: TfrmMain
SortSettings.HeaderMirrorColor = clWhite
SortSettings.HeaderMirrorColor = clWhite
SortSettings.HeaderMirrorColorTo = clWhite
SortSettings.HeaderMirrorColorTo = clWhite
Version = '9.1.4.1'
Version = '9.1.4.1'
ExplicitLeft = 1
ColWidths = (
ColWidths = (
16
16
64
64
...
@@ -788,153 +832,20 @@ object frmMain: TfrmMain
...
@@ -788,153 +832,20 @@ object frmMain: TfrmMain
TabAppearance.BackGround.Color = clWhite
TabAppearance.BackGround.Color = clWhite
TabAppearance.BackGround.ColorTo = clWhite
TabAppearance.BackGround.ColorTo = clWhite
TabAppearance.BackGround.Direction = gdHorizontal
TabAppearance.BackGround.Direction = gdHorizontal
object
grdFields: TAdvString
Grid
object
dbgrdDatabase: TDB
Grid
Left = 2
Left = 2
Top = 2
Top = 2
Width = 1176
Width = 1176
Height = 235
Height = 235
Align = alClient
Align = alClient
Ctl3D = True
DataSource = dsMessages
DrawingStyle = gdsClassic
Options = [dgEditing, dgTitles, dgIndicator, dgColLines, dgRowLines, dgTabs, dgConfirmDelete, dgCancelOnExit, dgTitleClick, dgTitleHotTrack]
FixedColor = clWhite
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goColSizing, goEditing, goFixedColClick]
ParentCtl3D = False
TabOrder = 0
TabOrder = 0
ActiveCellFont.Charset = DEFAULT_CHARSET
TitleFont.Charset = DEFAULT_CHARSET
ActiveCellFont.Color = 4474440
TitleFont.Color = clWindowText
ActiveCellFont.Height = -11
TitleFont.Height = -12
ActiveCellFont.Name = 'Tahoma'
TitleFont.Name = 'Segoe UI'
ActiveCellFont.Style = [fsBold]
TitleFont.Style = []
ActiveCellColor = 11565130
ActiveCellColorTo = 11565130
BorderColor = 11250603
ControlLook.FixedGradientFrom = clWhite
ControlLook.FixedGradientTo = clWhite
ControlLook.FixedGradientHoverFrom = clGray
ControlLook.FixedGradientHoverTo = clWhite
ControlLook.FixedGradientHoverMirrorFrom = clWhite
ControlLook.FixedGradientHoverMirrorTo = clWhite
ControlLook.FixedGradientHoverBorder = 11645361
ControlLook.FixedGradientDownFrom = clWhite
ControlLook.FixedGradientDownTo = clWhite
ControlLook.FixedGradientDownMirrorFrom = clWhite
ControlLook.FixedGradientDownMirrorTo = clWhite
ControlLook.FixedGradientDownBorder = 11250603
ControlLook.DropDownHeader.Font.Charset = DEFAULT_CHARSET
ControlLook.DropDownHeader.Font.Color = clWindowText
ControlLook.DropDownHeader.Font.Height = -11
ControlLook.DropDownHeader.Font.Name = 'Tahoma'
ControlLook.DropDownHeader.Font.Style = []
ControlLook.DropDownHeader.Visible = True
ControlLook.DropDownHeader.Buttons = <>
ControlLook.DropDownFooter.Font.Charset = DEFAULT_CHARSET
ControlLook.DropDownFooter.Font.Color = clWindowText
ControlLook.DropDownFooter.Font.Height = -11
ControlLook.DropDownFooter.Font.Name = 'Tahoma'
ControlLook.DropDownFooter.Font.Style = []
ControlLook.DropDownFooter.Visible = True
ControlLook.DropDownFooter.Buttons = <>
ControlLook.ToggleSwitch.BackgroundBorderWidth = 1.000000000000000000
ControlLook.ToggleSwitch.ButtonBorderWidth = 1.000000000000000000
ControlLook.ToggleSwitch.CaptionFont.Charset = DEFAULT_CHARSET
ControlLook.ToggleSwitch.CaptionFont.Color = clWindowText
ControlLook.ToggleSwitch.CaptionFont.Height = -12
ControlLook.ToggleSwitch.CaptionFont.Name = 'Segoe UI'
ControlLook.ToggleSwitch.CaptionFont.Style = []
ControlLook.ToggleSwitch.Shadow = False
Filter = <>
FilterDropDown.Font.Charset = DEFAULT_CHARSET
FilterDropDown.Font.Color = clWindowText
FilterDropDown.Font.Height = -11
FilterDropDown.Font.Name = 'Tahoma'
FilterDropDown.Font.Style = []
FilterDropDown.TextChecked = 'Checked'
FilterDropDown.TextUnChecked = 'Unchecked'
FilterDropDownClear = '(All)'
FilterEdit.TypeNames.Strings = (
'Starts with'
'Ends with'
'Contains'
'Not contains'
'Equal'
'Not equal'
'Larger than'
'Smaller than'
'Clear')
FixedColWidth = 16
FixedRowHeight = 22
FixedRowAlways = True
FixedFont.Charset = DEFAULT_CHARSET
FixedFont.Color = clWindowText
FixedFont.Height = -11
FixedFont.Name = 'Tahoma'
FixedFont.Style = [fsBold]
FloatFormat = '%.2f'
HoverButtons.Buttons = <>
HTMLSettings.ImageFolder = 'images'
HTMLSettings.ImageBaseName = 'img'
Look = glCustom
PrintSettings.DateFormat = 'dd/mm/yyyy'
PrintSettings.Font.Charset = DEFAULT_CHARSET
PrintSettings.Font.Color = clWindowText
PrintSettings.Font.Height = -11
PrintSettings.Font.Name = 'Tahoma'
PrintSettings.Font.Style = []
PrintSettings.FixedFont.Charset = DEFAULT_CHARSET
PrintSettings.FixedFont.Color = clWindowText
PrintSettings.FixedFont.Height = -11
PrintSettings.FixedFont.Name = 'Tahoma'
PrintSettings.FixedFont.Style = []
PrintSettings.HeaderFont.Charset = DEFAULT_CHARSET
PrintSettings.HeaderFont.Color = clWindowText
PrintSettings.HeaderFont.Height = -11
PrintSettings.HeaderFont.Name = 'Tahoma'
PrintSettings.HeaderFont.Style = []
PrintSettings.FooterFont.Charset = DEFAULT_CHARSET
PrintSettings.FooterFont.Color = clWindowText
PrintSettings.FooterFont.Height = -11
PrintSettings.FooterFont.Name = 'Tahoma'
PrintSettings.FooterFont.Style = []
PrintSettings.PageNumSep = '/'
SearchFooter.ColorTo = clNone
SearchFooter.FindNextCaption = 'Find &next'
SearchFooter.FindPrevCaption = 'Find &previous'
SearchFooter.Font.Charset = DEFAULT_CHARSET
SearchFooter.Font.Color = clWindowText
SearchFooter.Font.Height = -11
SearchFooter.Font.Name = 'Tahoma'
SearchFooter.Font.Style = []
SearchFooter.HighLightCaption = 'Highlight'
SearchFooter.HintClose = 'Close'
SearchFooter.HintFindNext = 'Find next occurrence'
SearchFooter.HintFindPrev = 'Find previous occurrence'
SearchFooter.HintHighlight = 'Highlight occurrences'
SearchFooter.MatchCaseCaption = 'Match case'
SearchFooter.ResultFormat = '(%d of %d)'
SelectionColor = 13744549
SelectionTextColor = clWindowText
SortSettings.HeaderColor = clWhite
SortSettings.HeaderColorTo = clWhite
SortSettings.HeaderMirrorColor = clWhite
SortSettings.HeaderMirrorColorTo = clWhite
Version = '9.1.4.1'
ColWidths = (
16
64
64
64
64)
RowHeights = (
22
22
22
22
22
22
22
22
22
22)
end
end
end
end
object AdvOfficePage3: TAdvOfficePage
object AdvOfficePage3: TAdvOfficePage
...
@@ -1238,37 +1149,12 @@ object frmMain: TfrmMain
...
@@ -1238,37 +1149,12 @@ object frmMain: TfrmMain
object btnMessages: TButton
object btnMessages: TButton
Left = 32
Left = 32
Top = 78
Top = 78
Width =
83
Width =
121
Height = 25
Height = 25
Caption = 'Get Messages'
Caption = 'Get
Twilio
Messages'
TabOrder = 3
TabOrder = 3
OnClick = btnMessagesClick
OnClick = btnMessagesClick
end
end
object dbcbMonth: TwwDBComboBox
Left = 342
Top = 40
Width = 123
Height = 23
ShowButton = True
Style = csDropDown
MapList = False
AllowClearKey = False
DropDownCount = 8
ItemHeight = 0
Sorted = False
TabOrder = 4
UnboundDataType = wwDefault
OnCloseUp = dbcbYearCloseUp
end
object btnNextPage: TButton
Left = 780
Top = 39
Width = 83
Height = 25
Caption = 'Next Page'
TabOrder = 5
OnClick = btnNextPageClick
end
object RESTClient1: TRESTClient
object RESTClient1: TRESTClient
Accept = 'application/json, text/plain; q=0.9, text/html;q=0.8,'
Accept = 'application/json, text/plain; q=0.9, text/html;q=0.8,'
AcceptCharset = 'utf-8, *;q=0.8'
AcceptCharset = 'utf-8, *;q=0.8'
...
@@ -1306,6 +1192,7 @@ object frmMain: TfrmMain
...
@@ -1306,6 +1192,7 @@ object frmMain: TfrmMain
Database = 'twilio_db'
Database = 'twilio_db'
Username = 'postgres'
Username = 'postgres'
Server = '192.168.102.130'
Server = '192.168.102.130'
Connected = True
LoginPrompt = False
LoginPrompt = False
Left = 562
Left = 562
Top = 169
Top = 169
...
@@ -1317,19 +1204,19 @@ object frmMain: TfrmMain
...
@@ -1317,19 +1204,19 @@ object frmMain: TfrmMain
'select * from public.messages')
'select * from public.messages')
Left = 676
Left = 676
Top = 169
Top = 169
object uqMessagessid: T
Memo
Field
object uqMessagessid: T
String
Field
FieldName = 'sid'
FieldName = 'sid'
Required = True
Required = True
BlobType = ftMemo
Size = 35
end
end
object uqMessagesaccount_sid: T
Memo
Field
object uqMessagesaccount_sid: T
String
Field
FieldName = 'account_sid'
FieldName = 'account_sid'
Required = True
Required = True
BlobType = ftMemo
Size = 35
end
end
object uqMessagesapi_version: T
Memo
Field
object uqMessagesapi_version: T
String
Field
FieldName = 'api_version'
FieldName = 'api_version'
BlobType = ftMemo
Size = 15
end
end
object uqMessagesbody: TMemoField
object uqMessagesbody: TMemoField
FieldName = 'body'
FieldName = 'body'
...
@@ -1344,9 +1231,8 @@ object frmMain: TfrmMain
...
@@ -1344,9 +1231,8 @@ object frmMain: TfrmMain
object uqMessagesdate_updated: TDateTimeField
object uqMessagesdate_updated: TDateTimeField
FieldName = 'date_updated'
FieldName = 'date_updated'
end
end
object uqMessagesdirection: T
Memo
Field
object uqMessagesdirection: T
String
Field
FieldName = 'direction'
FieldName = 'direction'
BlobType = ftMemo
end
end
object uqMessageserror_code: TIntegerField
object uqMessageserror_code: TIntegerField
FieldName = 'error_code'
FieldName = 'error_code'
...
@@ -1355,14 +1241,13 @@ object frmMain: TfrmMain
...
@@ -1355,14 +1241,13 @@ object frmMain: TfrmMain
FieldName = 'error_message'
FieldName = 'error_message'
BlobType = ftMemo
BlobType = ftMemo
end
end
object uqMessagesfrom_number: T
Memo
Field
object uqMessagesfrom_number: T
String
Field
FieldName = 'from_number'
FieldName = 'from_number'
Required = True
Required = True
BlobType = ftMemo
end
end
object uqMessagesmessaging_service_sid: T
Memo
Field
object uqMessagesmessaging_service_sid: T
String
Field
FieldName = 'messaging_service_sid'
FieldName = 'messaging_service_sid'
BlobType = ftMemo
Size = 35
end
end
object uqMessagesnum_media: TIntegerField
object uqMessagesnum_media: TIntegerField
FieldName = 'num_media'
FieldName = 'num_media'
...
@@ -1373,26 +1258,107 @@ object frmMain: TfrmMain
...
@@ -1373,26 +1258,107 @@ object frmMain: TfrmMain
object uqMessagesprice: TFloatField
object uqMessagesprice: TFloatField
FieldName = 'price'
FieldName = 'price'
end
end
object uqMessagesprice_unit: T
Memo
Field
object uqMessagesprice_unit: T
String
Field
FieldName = 'price_unit'
FieldName = 'price_unit'
BlobType = ftMemo
Size = 5
end
end
object uqMessagesstatus: T
Memo
Field
object uqMessagesstatus: T
String
Field
FieldName = 'status'
FieldName = 'status'
BlobType = ftMemo
Size = 25
end
end
object uqMessagesto_number: T
Memo
Field
object uqMessagesto_number: T
String
Field
FieldName = 'to_number'
FieldName = 'to_number'
Required = True
Required = True
BlobType = ftMemo
end
end
object uqMessagesuri: T
Memo
Field
object uqMessagesuri: T
String
Field
FieldName = 'uri'
FieldName = 'uri'
BlobType = ftMemo
Size = 150
end
end
end
end
object PostgreSQLUniProvider1: TPostgreSQLUniProvider
object PostgreSQLUniProvider1: TPostgreSQLUniProvider
Left = 631
Left = 631
Top = 277
Top = 277
end
end
object dsMessages: TDataSource
DataSet = uqMessages
Left = 773
Top = 171
end
object uqDBMessages: TUniQuery
Connection = ucTwilioDB
SQL.Strings = (
'select * from public.messages')
Left = 676
Top = 231
object StringField1: TStringField
FieldName = 'sid'
Required = True
Size = 35
end
object StringField2: TStringField
FieldName = 'account_sid'
Required = True
Size = 35
end
object StringField3: TStringField
FieldName = 'api_version'
Size = 15
end
object MemoField1: TMemoField
FieldName = 'body'
BlobType = ftMemo
end
object DateTimeField1: TDateTimeField
FieldName = 'date_created'
end
object DateTimeField2: TDateTimeField
FieldName = 'date_sent'
end
object DateTimeField3: TDateTimeField
FieldName = 'date_updated'
end
object StringField4: TStringField
FieldName = 'direction'
end
object IntegerField1: TIntegerField
FieldName = 'error_code'
end
object MemoField2: TMemoField
FieldName = 'error_message'
BlobType = ftMemo
end
object StringField5: TStringField
FieldName = 'from_number'
Required = True
end
object StringField6: TStringField
FieldName = 'messaging_service_sid'
Size = 35
end
object IntegerField2: TIntegerField
FieldName = 'num_media'
end
object IntegerField3: TIntegerField
FieldName = 'num_segments'
end
object FloatField1: TFloatField
FieldName = 'price'
end
object StringField7: TStringField
FieldName = 'price_unit'
Size = 5
end
object StringField8: TStringField
FieldName = 'status'
Size = 25
end
object StringField9: TStringField
FieldName = 'to_number'
Required = True
end
object StringField10: TStringField
FieldName = 'uri'
Size = 150
end
end
end
end
fMain.h
View file @
6af57824
...
@@ -44,6 +44,7 @@
...
@@ -44,6 +44,7 @@
#include "vcl.wwdbdatetimepicker.hpp"
#include "vcl.wwdbdatetimepicker.hpp"
#include "PostgreSQLUniProvider.hpp"
#include "PostgreSQLUniProvider.hpp"
#include "UniProvider.hpp"
#include "UniProvider.hpp"
#include <Vcl.DBGrids.hpp>
#include <dinkumware\map>
#include <dinkumware\map>
#include <SysUtils.hpp>
#include <SysUtils.hpp>
#include <DateUtils.hpp>
#include <DateUtils.hpp>
...
@@ -70,7 +71,6 @@ __published: // IDE-managed Components
...
@@ -70,7 +71,6 @@ __published: // IDE-managed Components
TAdvOfficePage
*
AdvOfficePage1
;
TAdvOfficePage
*
AdvOfficePage1
;
TAdvStringGrid
*
grdData
;
TAdvStringGrid
*
grdData
;
TAdvOfficePage
*
AdvOfficePage2
;
TAdvOfficePage
*
AdvOfficePage2
;
TAdvStringGrid
*
grdFields
;
TAdvOfficePage
*
AdvOfficePage3
;
TAdvOfficePage
*
AdvOfficePage3
;
TAdvStringGrid
*
asgData
;
TAdvStringGrid
*
asgData
;
TButton
*
btnMessages
;
TButton
*
btnMessages
;
...
@@ -85,37 +85,59 @@ __published: // IDE-managed Components
...
@@ -85,37 +85,59 @@ __published: // IDE-managed Components
TLabel
*
Label3
;
TLabel
*
Label3
;
TLabel
*
Label4
;
TLabel
*
Label4
;
TLabel
*
Label5
;
TLabel
*
Label5
;
TwwDBComboBox
*
dbcbMonth
;
TLabel
*
Label6
;
TLabel
*
Label6
;
TButton
*
btnNextPage
;
TCheckBox
*
cbSaveToDB
;
TCheckBox
*
cbSaveToDB
;
TPostgreSQLUniProvider
*
PostgreSQLUniProvider1
;
TPostgreSQLUniProvider
*
PostgreSQLUniProvider1
;
TMemoField
*
uqMessagessid
;
TMemoField
*
uqMessagesaccount_sid
;
TMemoField
*
uqMessagesapi_version
;
TMemoField
*
uqMessagesbody
;
TDateTimeField
*
uqMessagesdate_created
;
TDateTimeField
*
uqMessagesdate_sent
;
TDateTimeField
*
uqMessagesdate_updated
;
TMemoField
*
uqMessagesdirection
;
TIntegerField
*
uqMessageserror_code
;
TMemoField
*
uqMessageserror_message
;
TMemoField
*
uqMessagesfrom_number
;
TMemoField
*
uqMessagesmessaging_service_sid
;
TIntegerField
*
uqMessagesnum_media
;
TIntegerField
*
uqMessagesnum_segments
;
TFloatField
*
uqMessagesprice
;
TMemoField
*
uqMessagesprice_unit
;
TMemoField
*
uqMessagesstatus
;
TMemoField
*
uqMessagesto_number
;
TMemoField
*
uqMessagesuri
;
TButton
*
Button1
;
TButton
*
Button1
;
TDBGrid
*
dbgrdDatabase
;
TButton
*
btnDBMessages
;
TDataSource
*
dsMessages
;
TStringField
*
uqMessagessid
;
TStringField
*
uqMessagesaccount_sid
;
TStringField
*
uqMessagesapi_version
;
TMemoField
*
uqMessagesbody
;
TDateTimeField
*
uqMessagesdate_created
;
TDateTimeField
*
uqMessagesdate_sent
;
TDateTimeField
*
uqMessagesdate_updated
;
TStringField
*
uqMessagesdirection
;
TIntegerField
*
uqMessageserror_code
;
TMemoField
*
uqMessageserror_message
;
TStringField
*
uqMessagesfrom_number
;
TStringField
*
uqMessagesmessaging_service_sid
;
TIntegerField
*
uqMessagesnum_media
;
TIntegerField
*
uqMessagesnum_segments
;
TFloatField
*
uqMessagesprice
;
TStringField
*
uqMessagesprice_unit
;
TStringField
*
uqMessagesstatus
;
TStringField
*
uqMessagesto_number
;
TStringField
*
uqMessagesuri
;
TwwDBComboBox
*
dbcbMonth
;
TUniQuery
*
uqDBMessages
;
TStringField
*
StringField1
;
TStringField
*
StringField2
;
TStringField
*
StringField3
;
TMemoField
*
MemoField1
;
TDateTimeField
*
DateTimeField1
;
TDateTimeField
*
DateTimeField2
;
TDateTimeField
*
DateTimeField3
;
TStringField
*
StringField4
;
TIntegerField
*
IntegerField1
;
TMemoField
*
MemoField2
;
TStringField
*
StringField5
;
TStringField
*
StringField6
;
TIntegerField
*
IntegerField2
;
TIntegerField
*
IntegerField3
;
TFloatField
*
FloatField1
;
TStringField
*
StringField7
;
TStringField
*
StringField8
;
TStringField
*
StringField9
;
TStringField
*
StringField10
;
void
__fastcall
btnExitClick
(
TObject
*
Sender
);
void
__fastcall
btnExitClick
(
TObject
*
Sender
);
void
__fastcall
btnMessagesClick
(
TObject
*
Sender
);
void
__fastcall
btnMessagesClick
(
TObject
*
Sender
);
void
__fastcall
dbcbMonthCloseUp
(
TwwDBComboBox
*
Sender
,
bool
Select
);
void
__fastcall
dbcbMonthCloseUp
(
TwwDBComboBox
*
Sender
,
bool
Select
);
void
__fastcall
dbcbYearCloseUp
(
TwwDBComboBox
*
Sender
,
bool
Select
);
void
__fastcall
dbcbYearCloseUp
(
TwwDBComboBox
*
Sender
,
bool
Select
);
void
__fastcall
btnNextPageClick
(
TObject
*
Sender
);
void
__fastcall
Button1Click
(
TObject
*
Sender
);
void
__fastcall
Button1Click
(
TObject
*
Sender
);
void
__fastcall
btnDBMessagesClick
(
TObject
*
Sender
);
private
:
// User declarations
private
:
// User declarations
String
accountSid
;
String
accountSid
;
String
authHeader
;
String
authHeader
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment