-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCandidateSearchUnit.pas
170 lines (146 loc) · 4.66 KB
/
CandidateSearchUnit.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
Unit CandidateSearchUnit;
Interface
Uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
Type
TCandidateSearchForm = Class(TForm)
LabelSearch: TLabel;
LabelInfo: TLabel;
EditValue: TEdit;
ButtonSearch: TButton;
ButtonCancel: TButton;
ButtonNext: TButton;
ComboBoxParam: TComboBox;
Procedure ComboBoxParamSelect(Sender: TObject);
Procedure ButtonCancelClick(Sender: TObject);
Procedure EditValueChange(Sender: TObject);
Procedure ButtonSearchClick(Sender: TObject);
Procedure ButtonNextClick(Sender: TObject);
Procedure FormClose(Sender: TObject; Var Action: TCloseAction);
Procedure EditValueKeyPress(Sender: TObject; Var Key: Char);
Procedure FormKeyDown(Sender: TObject; Var Key: Word;
Shift: TShiftState);
Private
{ Private declarations }
Public
{ Public declarations }
End;
Var
CandidateSearchForm: TCandidateSearchForm;
Implementation
{$R *.dfm}
Uses MainUnit, CandidateListUnit;
Type
TSearchParameter = (SpSurname, SpSpeciality, SpTitle);
TSearchFunc = Function(Param: ShortString; Candidate: PCandidate): Boolean;
Function AreSurnamesEqual(Surname: ShortString; Candidate: PCandidate): Boolean;
Begin
AreSurnamesEqual := AnsiUpperCase(String(Candidate.Info.Surname))
= AnsiUpperCase(String(Surname));
End;
Function AreSpecialitiesEqual(Spec: ShortString; Candidate: PCandidate)
: Boolean;
Begin
AreSpecialitiesEqual := AnsiUpperCase(String(Candidate.Info.Speciality))
= AnsiUpperCase(String(Spec));
End;
Function AreTitlesEqual(Title: ShortString; Candidate: PCandidate): Boolean;
Begin
AreTitlesEqual := AnsiUpperCase(String(Candidate.Info.Title))
= AnsiUpperCase(String(Title));
End;
Const
AreParamsEqual: Array [TSearchParameter] Of TSearchFunc = (AreSurnamesEqual,
AreSpecialitiesEqual, AreTitlesEqual);
Var
SearchParam: TSearchParameter;
FoundIndexes: Array Of Integer;
Count: Integer;
Procedure AddToArray(I: Integer);
Begin
SetLength(FoundIndexes, Length(FoundIndexes) + 1);
FoundIndexes[High(FoundIndexes)] := I;
End;
Procedure Search(Param: ShortString);
Var
Temp: PCandidate;
I: Integer;
Begin
I := 0;
Temp := CandidateHead;
While Temp <> Nil Do
Begin
If AreParamsEqual[SearchParam](Param, Temp) Then
AddToArray(I);
Inc(I);
Temp := Temp.Next;
End;
End;
Procedure TCandidateSearchForm.ButtonSearchClick(Sender: TObject);
Begin
FoundIndexes := Nil;
Search(ShortString(EditValue.Text));
Count := Length(FoundIndexes);
If Count = 0 Then
LabelInfo.Caption := 'Êàíäèäàòû íå áûëè íàéäåíû.'
Else
Begin
LabelInfo.Caption := 'Áûëî íàéäåíî ' + IntToStr(Count) + ' êàíäèäàòîâ.';
ButtonNext.Enabled := True;
End;
LabelInfo.Visible := True;
End;
Procedure TCandidateSearchForm.ButtonCancelClick(Sender: TObject);
Begin
Close;
End;
Procedure TCandidateSearchForm.ButtonNextClick(Sender: TObject);
Begin
SelectItemInListView(FoundIndexes[Length(FoundIndexes) - Count],
CandidateListForm.ListView);
If Count > 1 Then
Dec(Count)
Else
Count := Length(FoundIndexes);
End;
Procedure TCandidateSearchForm.ComboBoxParamSelect(Sender: TObject);
Begin
LabelInfo.Visible := False;
ButtonNext.Enabled := False;
SearchParam := TSearchParameter(ComboBoxParam.ItemIndex);
EditValue.Enabled := True;
End;
Procedure TCandidateSearchForm.EditValueChange(Sender: TObject);
Begin
ButtonSearch.Enabled := Not(Length(EditValue.Text) > MAXLEN) And
(EditValue.Text <> '');
End;
Procedure TCandidateSearchForm.EditValueKeyPress(Sender: TObject;
Var Key: Char);
Begin
If Not(Length(EditValue.Text) < MAXLEN) And (Key <> BACKSPACE) Then
Key := NULL;
End;
Procedure TCandidateSearchForm.FormClose(Sender: TObject;
Var Action: TCloseAction);
Begin
EditValue.Text := '';
EditValue.Enabled := False;
ComboBoxParam.ClearSelection;
ComboBoxParam.SetFocus;
LabelInfo.Visible := False;
FoundIndexes := Nil;
End;
Procedure TCandidateSearchForm.FormKeyDown(Sender: TObject; Var Key: Word;
Shift: TShiftState);
Begin
If Key = VK_ESCAPE Then
Close
Else If (Key = 13) And ButtonSearch.Enabled Then
ButtonSearch.Click
Else If (Key In [VK_RIGHT, VK_DOWN]) And ButtonNext.Enabled Then
ButtonNext.Click
End;
End.