-
Notifications
You must be signed in to change notification settings - Fork 2
/
uwebCustListWebBroker.pas
173 lines (153 loc) · 5.92 KB
/
uwebCustListWebBroker.pas
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
unit uwebCustListWebBroker;
interface
uses
System.SysUtils, System.Classes, Web.HTTPApp, Web.HTTPProd, Web.DBWeb, Web.DBXpressWeb, Web.DSProd;
type
TwebCustListWebBroker = class(TWebModule)
ppIndex: TPageProducer;
ppCustList: TPageProducer;
ppLoginFailed: TPageProducer;
ppPageFooter: TPageProducer;
ppPageHeader: TPageProducer;
pptblCustomers: TDataSetTableProducer;
ppAccessDenied: TPageProducer;
ppCustEdit: TPageProducer;
ppStyles: TPageProducer;
procedure webCustListWebBrokerwaLoginVerifyAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse;
var Handled: Boolean);
procedure ppAllHTMLTags(Sender: TObject; Tag: TTag; const TagString: string; TagParams: TStrings;
var ReplaceText: string);
procedure pptblCustomersCreateContent(Sender: TObject; var Continue: Boolean);
procedure WebModuleCreate(Sender: TObject);
procedure webCustListWebBrokerwaListCustomersAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse;
var Handled: Boolean);
procedure pptblCustomersFormatCell(Sender: TObject; CellRow, CellColumn: Integer; var BgColor: THTMLBgColor;
var Align: THTMLAlign; var VAlign: THTMLVAlign; var CustomAttrs, CellData: string);
procedure webCustListWebBrokerwaEditCustomerAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse;
var Handled: Boolean);
procedure ppCustEditHTMLTag(Sender: TObject; Tag: TTag; const TagString: string; TagParams: TStrings;
var ReplaceText: string);
private
const
APP_NAME = 'Customer List for WebBroker';
APP_VERSION = '0.4';
var
FIsLoggedIn: Boolean;
property IsLoggedIn: Boolean read FIsLoggedIn write FIsLoggedIn;
end;
var
WebModuleClass: TComponentClass = TwebCustListWebBroker;
implementation
{%CLASSGROUP 'Vcl.Controls.TControl'}
{$R *.dfm}
uses
udmCust;
procedure TwebCustListWebBroker.ppAllHTMLTags(Sender: TObject; Tag: TTag; const TagString: string; TagParams: TStrings;
var ReplaceText: string);
begin
if SameText(TagString, 'AppName') then
ReplaceText := APP_NAME
else if SameText(TagString, 'AppVersion') then
ReplaceText := APP_VERSION
else if SameText(TagString, 'Header') then
ReplaceText := ppPageHeader.Content
else if SameText(TagString, 'IncludeCSS') then
ReplaceText := ppStyles.Content
else if SameText(TagString, 'Footer') then
ReplaceText := ppPageFooter.Content
else if SameText(TagString, 'Customers') then
ReplaceText := pptblCustomers.Content;
end;
procedure TwebCustListWebBroker.ppCustEditHTMLTag(Sender: TObject; Tag: TTag; const TagString: string;
TagParams: TStrings; var ReplaceText: string);
begin
if SameText(TagString, 'Company') then
ReplaceText := dmCust.qryCustDetailsCompany.AsString
else if SameText(TagString, 'FirstName') then
ReplaceText := dmcust.qryCustDetailsFirstName.AsString
else if SameText(TagString, 'LastName') then
ReplaceText := dmCust.qryCustDetailsLastName.AsString
else if SameText(TagString, 'Address') then
ReplaceText := dmCust.qryCustDetailsAddress.AsString
else if SameText(TagString, 'City') then
ReplaceText := dmCust.qryCustDetailsCity.AsString
else if SameText(TagString, 'State') then
ReplaceText := dmCust.qryCustDetailsState.AsString
else if SameText(TagString, 'Country') then
ReplaceText := dmCust.qryCustDetailsCountry.AsString
else if SameText(TagString, 'Zip') then
ReplaceText := dmCust.qryCustDetailsPostalCode.AsString
else if SameText(TagString, 'Email') then
ReplaceText := dmCust.qryCustDetailsEmail.AsString
else if SameText(TagString, 'Phone') then
ReplaceText := dmCust.qryCustDetailsPhone.AsString
else
ppAllHTMLTags(Sender, Tag, TagString, TagParams, ReplaceText);
end;
procedure TwebCustListWebBroker.pptblCustomersCreateContent(Sender: TObject; var Continue: Boolean);
begin
pptblCustomers.MaxRows := dmCust.CustCount;
Continue := True;
end;
procedure TwebCustListWebBroker.pptblCustomersFormatCell(Sender: TObject; CellRow, CellColumn: Integer;
var BgColor: THTMLBgColor; var Align: THTMLAlign; var VAlign: THTMLVAlign; var CustomAttrs, CellData: string);
begin
if CellRow > 0 then begin
if CellColumn = 0 then // CustomerID
CellData := Format('<a href="\custedit?cust_no=%s">%s</a>', [CellData, CellData])
else if pptblCustomers.DataSet.FieldByName('IsBusiness').AsBoolean then
CustomAttrs := 'class="company_row"';
end;
end;
procedure TwebCustListWebBroker.webCustListWebBrokerwaEditCustomerAction(Sender: TObject; Request: TWebRequest;
Response: TWebResponse; var Handled: Boolean);
var
CustNo: string;
CustNum: Integer;
begin
if not IsLoggedIn then
Response.Content := ppAccessDenied.Content
else
begin
if Request.QueryFields.Count > 0 then
begin
CustNo := Request.QueryFields.Values['cust_no'];
if TryStrToInt(CustNo, CustNum) then
begin
dmCust.OpenCustDetails(CustNum);
Response.Content := ppCustEdit.Content;
dmCust.CloseCustDetails;
end;
end;
end;
Handled := True;
end;
procedure TwebCustListWebBroker.webCustListWebBrokerwaListCustomersAction(Sender: TObject; Request: TWebRequest;
Response: TWebResponse; var Handled: Boolean);
begin
if not IsLoggedIn then
Response.Content := ppAccessDenied.Content
else
Response.Content := ppCustList.Content;
Handled := True;
end;
procedure TwebCustListWebBroker.webCustListWebBrokerwaLoginVerifyAction(Sender: TObject; Request: TWebRequest;
Response: TWebResponse; var Handled: Boolean);
var
Username, Password: string;
begin
Username := Request.ContentFields.Values['uname'];
Password := Request.ContentFields.Values['psw'];
if dmCust.LoginCheck(Username, Password) then
begin
FIsLoggedIn := True;
Response.SendRedirect('/custlist');
end else
Response.Content := ppLoginFailed.Content;
Handled := True;
end;
procedure TwebCustListWebBroker.WebModuleCreate(Sender: TObject);
begin
FIsLoggedIn := False;
end;
end.