-
Notifications
You must be signed in to change notification settings - Fork 2
/
uwebCustListWebStencil.pas
129 lines (113 loc) · 4 KB
/
uwebCustListWebStencil.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
unit uwebCustListWebStencil;
interface
uses
System.SysUtils, System.Classes, Web.HTTPApp, Web.HTTPProd, Web.Stencils;
type
TwebCustListWebStencil = class(TWebModule)
wspIndex: TWebStencilsProcessor;
wsEngineCustList: TWebStencilsEngine;
wspLoginFailed: TWebStencilsProcessor;
wspCustList: TWebStencilsProcessor;
wspAccessDenied: TWebStencilsProcessor;
wspCustEdit: TWebStencilsProcessor;
procedure WebModuleCreate(Sender: TObject);
procedure webCustListWebStencilDefaultHandlerAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse;
var Handled: Boolean);
procedure webCustListWebStencilwaLoginVerifyAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse;
var Handled: Boolean);
procedure webCustListWebStencilwaListCustomersAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse;
var Handled: Boolean);
procedure webCustListWebStencilwaEditCustomerAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse;
var Handled: Boolean);
procedure wsEngineCustListError(Sender: TObject; const AMessage: string);
private
// these are NOT accessible by the WebStencilsEngine
FVersion: string;
FTitle: string;
public
// these will be available by the WebStencilsEngine parser
property Title: string read FTitle write FTitle;
property Version: string read FVersion write FVersion;
end;
var
WebModuleClass: TComponentClass = TwebCustListWebStencil;
implementation
{%CLASSGROUP 'Vcl.Controls.TControl'}
{$R *.dfm}
uses
Dialogs, System.bindings.EvalProtocol, System.Bindings.Methods,
udmCust;
procedure TwebCustListWebStencil.webCustListWebStencilDefaultHandlerAction(Sender: TObject; Request: TWebRequest;
Response: TWebResponse; var Handled: Boolean);
begin
Response.Content := wspIndex.Content;
Handled := True;
end;
procedure TwebCustListWebStencil.webCustListWebStencilwaEditCustomerAction(Sender: TObject; Request: TWebRequest;
Response: TWebResponse; var Handled: Boolean);
var
CustNo: string;
CustNum: Integer;
begin
if Request.QueryFields.Count > 0 then
begin
CustNo := Request.QueryFields.Values['cust_no'];
if TryStrToInt(CustNo, CustNum) then
begin
dmCust.OpenCustDetails(CustNum);
if not wsEngineCustList.HasVar('CustDetails') then
wsEngineCustList.AddVar('CustDetails', dmCust.qryCustDetails, False);
try
Response.Content := wspCustEdit.Content;
except
on E:EWebStencilsLoginRequired do
Response.Content := wspAccessDenied.Content;
end;
dmCust.CloseCustDetails;
end;
end;
end;
procedure TwebCustListWebStencil.webCustListWebStencilwaListCustomersAction(Sender: TObject; Request: TWebRequest;
Response: TWebResponse; var Handled: Boolean);
begin
dmCust.qryCustomers.Open;
try
if not wsEngineCustList.HasVar('CustList') then
wsEngineCustList.AddVar('CustList', dmCust.qryCustomers, False);
try
Response.Content := wspCustList.Content;
except
on E:EWebStencilsLoginRequired do
Response.Content := wspAccessDenied.Content;
end;
finally
dmCust.qryCustomers.Close;
end;
end;
procedure TwebCustListWebStencil.webCustListWebStencilwaLoginVerifyAction(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
wspCustList.UserLoggedIn := True;
wspCustEdit.UserLoggedIn := True;
Response.SendRedirect('/custlist');
end else
Response.Content := wspLoginFailed.Content;
Handled := True;
end;
procedure TwebCustListWebStencil.WebModuleCreate(Sender: TObject);
begin
FTitle := 'Customer List for WebStencils';
FVersion := '0.3';
wsEngineCustList.AddVar('App', Self, False);
end;
procedure TwebCustListWebStencil.wsEngineCustListError(Sender: TObject; const AMessage: string);
begin
ShowMessage(AMessage);
end;
end.