-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainApplication.pas.orig
216 lines (182 loc) · 5.3 KB
/
MainApplication.pas.orig
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
unit MainApplication;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TOperativeUnit, ComCtrls, StdCtrls, DateUtils, FormAdd, FormEdit;
procedure Append(item : TElemType); stdcall
external 'LinkedList.dll' name 'Append';
procedure WriteEach; stdcall
external 'LinkedList.dll' name 'WriteEach';
procedure Seed; stdcall
external 'LinkedList.dll' name 'Seed';
procedure WriteToFile; stdcall
external 'LinkedList.dll' name 'WriteToFile';
procedure ReadFromFile; stdcall
external 'LinkedList.dll' name 'ReadFromFile';
function GetHead : PElem; stdcall
external 'LinkedList.dll' name 'GetHead';
function EqualTOperatives : PElem; stdcall
external 'LinkedList.dll' name 'EqualTOperatives';
procedure Remove(op : TOperative); stdcall
external 'LinkedList.dll' name 'Remove';
procedure UpdateOperative(a, b : TOperative); stdcall;
external 'LinkedList.dll' name 'UpdateOperative';
type
TMainForm = class(TForm)
lvOperatives: TListView;
btnDelete: TButton;
btnAddOperative: TButton;
btnEdit: TButton;
procedure FormCreate(Sender: TObject);
procedure btnAddOperativeClick(Sender: TObject);
procedure btnDeleteClick(Sender: TObject);
procedure lvOperativesColumnClick(Sender: TObject; Column: TListColumn);
procedure lvOperativesCompare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer; var Compare: Integer);
procedure lvOperativesSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure btnEditClick(Sender: TObject);
private
SortDescending : Bool;
SortColumn : Integer;
procedure FillListBox;
function OperativeFromSelected : TOperative;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
procedure TMainForm.FormCreate(Sender: TObject);
begin
ReadFromFile;
FillListBox;
end;
procedure TMainForm.lvOperativesColumnClick(Sender: TObject;
Column: TListColumn);
begin
TListView(sender).SortType := stData;
if Column.Index <> SortColumn then
begin
SortColumn := Column.Index;
SortDescending := False;
end
else
begin
SortDescending := not SortDescending;
TListView(sender).SortType := stData;
end;
lvOperatives.AlphaSort;
end;
procedure TMainForm.lvOperativesCompare(Sender: TObject; Item1,
Item2: TListItem; Data: Integer; var Compare: Integer);
begin
if SortColumn = 0 then
begin
Compare := CompareText(Item1.Caption, Item2.Caption)
end
else if SortColumn = 3 then
begin
Compare := CompareDate(
StrToDate(Item1.SubItems[2]),
StrToDate(Item2.SubItems[2]));
end
else
begin
Compare := CompareText(Item1.SubItems[SortColumn-1],
Item2.SubItems[SortColumn-1]);
end;
if SortDescending then
Compare := -Compare;
end;
procedure TMainForm.lvOperativesSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
begin
btnEdit.Enabled := Selected;
btnDelete.Enabled := Selected;
end;
procedure TMainForm.FillListBox;
var
iter : PElem;
item : TListItem;
begin
lvOperatives.Items.Clear;
iter := GetHead;
while iter <> nil do
begin
item := lvOperatives.Items.Add;
item.Caption := iter^.Val.FirstName;
item.SubItems.Add(iter^.Val.LastName);
item.SubItems.Add(iter^.Val.NickName);
item.SubItems.Add(DateToStr(iter^.Val.DateOfBirth));
item.SubItems.Add(iter^.Val.BirthPlace);
iter := iter^.Next;
end;
end;
procedure TMainForm.btnAddOperativeClick(Sender: TObject);
var
row : TOperative;
begin
FormAdd.Form1.ShowModal;
WriteToFile;
FillListBox;
end;
function TMainForm.OperativeFromSelected : TOperative;
var
op : TOperative;
i : Integer;
begin
for i := 0 to lvOperatives.Items.Count - 1 do
begin
if lvOperatives.Items[i].Selected then //DAFUQ
begin
op.FirstName := lvOperatives.Items[i].Caption;
op.LastName := lvOperatives.Items[i].SubItems[0];
op.NickName := lvOperatives.Items[i].SubItems[1];
op.DateOfBirth := StrToDate(lvOperatives.Items[i].SubItems[2]);
op.BirthPlace := lvOperatives.Items[i].SubItems[3];
Result := op;
Exit;
end;
end;
end;
procedure TMainForm.btnDeleteClick(Sender: TObject);
var
op : TOperative;
dlgResult : Integer;
begin
if lvOperatives.Selected <> nil then
begin
dlgResult := MessageDlg('Na pewno usunąć?', mtConfirmation, mbYesNo, 0);
if dlgResult = mrYes then
begin
op := OperativeFromSelected;
Remove(op);
FillListBox;
end;
end;
end;
procedure TMainForm.btnEditClick(Sender: TObject);
var
row, old : TOperative;
begin
old := OperativeFromSelected;
FormEdit.Form2.OperativeBeingEdited := @row;
FormEdit.Form2.edtFirstName.Text := old.FirstName;
FormEdit.Form2.edtLastName.Text := old.LastName;
FormEdit.Form2.edtNickName.Text := old.NickName;
FormEdit.Form2.dtpBirthDate.Date := old.DateOfBirth;
FormEdit.Form2.edtPlaceOfBirth.Text := old.BirthPlace;
FormEdit.Form2.ShowModal;
if FormEdit.Form2.OperativeBeingEdited <> nil then
begin
UpdateOperative(old, row);
end;
FillListBox;
<<<<<<< HEAD
=======
//TODO: defaultowo wygasić btnDelete
>>>>>>> 055f2407a3c3714965164b1bf824cef666918c72
end;
end.