-
Notifications
You must be signed in to change notification settings - Fork 1
/
Unit11.pas
258 lines (214 loc) · 6.58 KB
/
Unit11.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
unit Unit11;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls, Grids, DBGrids, dbConn_u, pngimage,
DB, ADODB, UserAcc;
type
TForm11 = class(TForm)
Label3: TLabel;
DBGrid1: TDBGrid;
ComboBox1: TComboBox;
DateTimePicker1: TDateTimePicker;
Panel1: TPanel;
ComboBox2: TComboBox;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Panel2: TPanel;
DBGrid2: TDBGrid;
Label1: TLabel;
Image2: TImage;
Label4: TLabel;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
DataSource1: TDataSource;
DataSource2: TDataSource;
ComboBox3: TComboBox;
Panel3: TPanel;
procedure FormCreate(Sender: TObject);
procedure DateTimePicker1Change(Sender: TObject);
procedure Image2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer;
var Resize: Boolean);
procedure ComboBox1Change(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Account : TAccount;
procedure displayTable1( x : String);
procedure displayTable2;
end;
var
Form11: TForm11;
implementation
uses unit17;
{$R *.dfm}
procedure TForm11.BitBtn1Click(Sender: TObject);
begin
//this is to clear all input components
ComboBox1.Text :='';
ComboBox2.Text :='';
ComboBox1.ItemIndex:=-1;
ComboBox2.ItemIndex:=-1;
ComboBox3.ItemIndex := -1;
ComboBox3.Text := '';
displayTable1('');
displayTable2;
DateTimePicker1.DateTime := Now;
end;
procedure TForm11.BitBtn2Click(Sender: TObject);
var queryV , queryD, fin: String;
begin
//
queryV:='';
queryD:='';
/// The user firstly chooses what they want to search for
/// If they pick All, then they will be searching for 2 kinds of data - TransactionDate and one of the different Type of IDs
/// Either EmployeeID, customerID or receriptID.
/// However, if the user picks anything else except for All, then they will be performing a search based on a single field
if (ComboBox1.ItemIndex = 0) and (ComboBox3.ItemIndex>=0) then
begin
if (ComboBox2.ItemIndex >= 0) and (ComboBox2.ItemIndex<=2) then
queryD := ComboBox2.Text +'(TransactionDate) = ' + ComboBox2.Text + '(#'+ DateToStr(DateTimePicker1.Date)+'#)'
else
if (ComboBox2.ItemIndex = 3) then
queryD := 'TransactionDate = #'+ DateToStr(DateTimePicker1.Date)+'#'
else
begin
ShowMessage('You need to pick Either Month, Day, Year or Both!');
Exit;
end; //end else
queryV := ComboBox3.Text+ ' Like ' +QuotedStr('%'+InputBox('','Enter '+ ComboBox3.Text,'')+'%');
end//end if
else
if ComboBox1.ItemIndex in [1..4] then
begin
//However, if the user picks the last option, TransactionDate, then we extract the following
//If user choses either Day, Month or Year , the program will fetch records that match that criteria.
if ComboBox1.ItemIndex = 4 then
begin
if (ComboBox2.ItemIndex >= 0) and (ComboBox2.ItemIndex<=2) then
queryD := ComboBox2.Text +'(TransactionDate) = ' + ComboBox2.Text + '(#'+ DateToStr(DateTimePicker1.Date)+'#)'
else
//However if they choose the last option, BOTH, then we simply fetch records which match the chosen date in the datetimepicker
if (ComboBox2.ItemIndex = 3) then
queryD := 'TransactionDate = #'+ DateToStr(DateTimePicker1.Date)+'#'
else
begin
ShowMessage('You need to pick Either Month, Day, Year or Both!');
exit;
end;
end //end
else queryV := ComboBox1.Text+ ' Like ' +QuotedStr('%'+InputBox('','Enter '+ ComboBox1.Text,'')+'%');
end
else
ShowMessage('You need to select / Enter the appropriate Data in order to search');
fin := '';
if (queryV<>'') and (queryD<>'') then
fin := 'Where '+queryV+' AND '+queryD
else
if (queryD<>'') then
fin := 'Where '+queryD
else
if (queryV<>'') then
fin := 'Where '+queryV;
displayTable1(' '+fin);
end;
procedure TForm11.Button3Click(Sender: TObject);
begin
//
end;
procedure TForm11.ComboBox1Change(Sender: TObject);
begin
//
if ComboBox1.ItemIndex in [0,4] then
begin
ComboBox2.Show;
DateTimePicker1.Show;
if ComboBox1.ItemIndex = 0 then
ComboBox3.Show;
end
else
begin
ComboBox2.Hide;
DateTimePicker1.Hide;
ComboBox3.Hide;
end;
end;
procedure TForm11.DateTimePicker1Change(Sender: TObject);
begin
if DateTimePicker1.Date>Date then
DateTimePicker1.DateTime := Now;
end;
procedure TForm11.displayTable1(x: String);
begin
ADOQuery1.Close;
ADOQuery1.SQL.Text:='Select * from tblSales ' + x;
ADOQuery1.Open;
DBGrid1.Columns[0].Width := 60;
DBGrid1.Columns[1].Width := 100;
DBGrid1.Columns[2].Width := 150;
DBGrid1.Columns[3].Width := 150;
DBGrid1.Columns[4].Width := 100;
DBGrid1.Columns[5].Width := 100;
end;
procedure TForm11.displayTable2;
var x : integer;
begin
//this code is to display all the daily sales.
ADOQuery2.Close;
ADOQuery2.SQL.Text:='Select * from tblSales where TransactionDate = #'+DateToStr(now)+'#';
ADOQuery2.Open;
//CALCULATE SUM
ADOQuery2.First;
x := 0;
while not ADOQuery2.Eof do
begin
x := x + ADOQuery2['totalAmount'];
ADOQuery2.Next;
end;
ADOQuery1.First;
DBGrid2.Columns[0].Width := 60;
DBGrid2.Columns[1].Width := 100;
DBGrid2.Columns[2].Width := 150;
DBGrid2.Columns[3].Width := 150;
DBGrid2.Columns[4].Width := 100;
DBGrid2.Columns[5].Width := 100;
Panel3.Caption := 'Total Amount made from sales today is '+FloatToStrF(x, ffCurrency, 7,2);
end;
procedure TForm11.FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
begin
Resize := False;
end;
procedure TForm11.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := False;
Image2Click(Self);
end;
procedure TForm11.FormCreate(Sender: TObject);
begin
(Sender as TForm).Position:=poScreenCenter;
(Sender as TForm).DefaultMonitor := dmMainForm;
ComboBox1Change(Self);
CurrencyString := 'R';
end;
procedure TForm11.FormShow(Sender: TObject);
begin
displayTable1('');
displayTable2;
BitBtn1Click(Self);
ComboBox1Change(Self);
end;
procedure TForm11.Image2Click(Sender: TObject);
begin
form15.show;
form11.hide;
end;
end.