-
Notifications
You must be signed in to change notification settings - Fork 2
/
LoancatUnit.pas
executable file
·239 lines (193 loc) · 6 KB
/
LoancatUnit.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
unit LoancatUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, TntGrids, DBGrids, TntDBGrids, StdCtrls, Buttons,
TntButtons, ExtCtrls, TntExtCtrls, TntStdCtrls;
type
TLoancatForm = class(TForm)
TntDBGrid1: TTntDBGrid;
TntBitBtn1: TTntBitBtn;
TntBitBtn2: TTntBitBtn;
TntBitBtn3: TTntBitBtn;
TntGroupBox1: TTntGroupBox;
TntStringGrid1: TTntStringGrid;
procedure TntBitBtn2Click(Sender: TObject);
procedure TntBitBtn4Click(Sender: TObject);
procedure TntBitBtn3Click(Sender: TObject);
procedure TntDBGrid1DblClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure TntStringGrid1Click(Sender: TObject);
procedure TntDBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
LoancatForm: TLoancatForm;
implementation
uses DataUnit, common, DB, DBAccess, MyAccess, GlobalProcedures;
{$R *.dfm}
Procedure GetLoancat;
var
g,i,maxl,l : integer;
name : WideString;
found:boolean;
begin
Data.loancat.Filtered := false;
for i := 0 to loancatform.TntStringGrid1.RowCount do
loancatform.TntStringGrid1.Cells[1,i] := '';
loancatform.TntStringGrid1.RowCount := 0;
maxl:= data.loancat.recordcount;
i:=0;
data.loancat.First;
for l:= 1 to maxl do
begin
found := false;
name := data.loancat.fieldbyname('description').AsVariant;
for g:=0 to loancatform.TntStringGrid1.RowCount-1 do
if loancatform.TntStringGrid1.Cells[1,g]=name then
found:=true;
if Not found then
begin
loancatform.TntStringGrid1.RowCount := i+1;
loancatform.TntStringGrid1.Cells[1,i]:= name;
i:=i+1;
end;
data.loancat.next;
end;
data.loancat.Filtered := true;
end;
procedure FiltrLoancat(s: widestring);
begin
with Data.loancat do
begin
Filtered := false;
Filter := 'description='+QuotedStr(s);
Filtered := true;
end;
end;
procedure adjust_loan_categories(f: WideString);
var
didi,l,i:integer;
begin
if data.loancat.RecordCount = 0 Then exit;
didi:=data.patroncat.recordcount;
data.patroncat.First;
for l:=1 to didi do
begin
i:=data.patroncat.fieldbyname('id').asinteger;
if not(data.loancat.locate('patroncatid',i,[])) then
begin
data.loancat.Append;
data.loancat['description']:=f;
data.loancat['patroncatid']:=i;
data.loancat.Post;
end;
data.patroncat.next;
end;
end;
procedure TLoancatForm.TntBitBtn2Click(Sender: TObject);
var
temp : WideString;
begin
temp := InputEditBoxW('Add New Category','Loan Category Description' + #13,'');
if trim(temp) <> '' Then
begin
Data.loancat.append;
Data.loancat.FieldByName('patroncatid').AsInteger := 0;
Data.loancat.FieldByName('description').AsVariant := temp;
PostTable (data.loancat);
FiltrLoancat(temp);
adjust_loan_categories(temp);
data.loancat.Refresh;
GetLoancat;
FiltrLoancat(TntStringGrid1.Cells[TntStringGrid1.col,TntStringGrid1.row]);
end;
end;
procedure TLoancatForm.TntBitBtn4Click(Sender: TObject);
begin
PostTable(Data.loancat)
end;
procedure TLoancatForm.TntBitBtn3Click(Sender: TObject);
begin
if MessageBox(0,PAnsiChar('Are you sure you want to delete the selected category?'),PAnsiChar('Delete Loan Category'), MB_YESNO + MB_ICONQUESTION + MB_TASKMODAL)=mrYes then
begin
while Data.loancat.RecordCount <> 0 do
Data.loancat.Delete;
Data.loancat.Refresh;
GetLoancat;
FiltrLoancat(TntStringGrid1.Cells[TntStringGrid1.col,TntStringGrid1.row]);
end;
end;
procedure TLoancatForm.TntDBGrid1DblClick(Sender: TObject);
var
tex : WideString;
reccount : integer;
begin
reccount := data.loancat.RecordCount;
if reccount <> 0 Then
begin
tex := InputEditBoxW('Edit Loan Category','Loan Category Description' + #13, Data.loancat.FieldByName('description').AsVariant);
if trim(tex) <> '' Then
with data.loancat do
begin
First;
while not eof do
begin
EditTable(data.loancat);
FieldByName('description').Value := tex;
PostTable(data.loancat);
Refresh;
if RecordCount = reccount Then Next;
end;
Refresh;
GetLoancat;
FiltrLoancat(TntStringGrid1.Cells[TntStringGrid1.col,TntStringGrid1.row]);
end;
end;
end;
procedure TLoancatForm.FormActivate(Sender: TObject);
begin
GetLoancat;
TntStringGrid1Click(Sender);
end;
procedure TLoancatForm.TntStringGrid1Click(Sender: TObject);
begin
FiltrLoancat(TntStringGrid1.Cells[TntStringGrid1.col,TntStringGrid1.row]);
adjust_loan_categories(TntStringGrid1.Cells[TntStringGrid1.col,TntStringGrid1.row]);
end;
procedure TLoancatForm.TntDBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
var
nr : integer;
s : WideString;
TempRect : TRect;
begin
if Column.FieldName = 'patroncatid' then
begin
nr := Column.Field.AsInteger;
TDBGrid(Sender).Canvas.FillRect(Rect);
TempRect := Rect;
if Data.patroncat.Locate('id',nr,[]) then
begin
s := Data.patroncat.FieldByName('description').Value;
TempRect.Left := TempRect.Left + 2;
TempRect.Top := TempRect.Top + 2;
DrawTextW(TTntDBGrid(Sender).Canvas.Handle, PWideChar(s), -1, TempRect, DT_LEFT);
end
else
TTntDBGrid(Sender).Canvas.TextOut(Rect.Left+2,Rect.Top+2,'None');
end;
end;
procedure TLoancatForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
data.loancat.Filter := 'patroncatid = 0';
data.loancat.Filtered := True;
end;
end.