Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit SearchByParty;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
- Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids,
- Vcl.ComCtrls;
- const
- HEADER_IDCANDIDATE = '№';
- HEADER_FULLNAME = 'ФИО';
- HEADER_PARTY = 'Партия';
- HEADER_AGE = 'Возраст';
- HEADER_COUNTYNUMBER = 'Номер округа';
- HEADER_PROFESSION = 'Профессия';
- type
- TSearchByPartyFrame = class(TFrame)
- GroupBox1: TGroupBox;
- GroupBox2: TGroupBox;
- ComboBoxParty: TComboBox;
- GroupBox3: TGroupBox;
- GroupBox4: TGroupBox;
- EditSearchByFullname: TEdit;
- SGCandidate: TStringGrid;
- GroupBox5: TGroupBox;
- GroupBox6: TGroupBox;
- Edit1: TEdit;
- ComboBox1: TComboBox;
- UpDown1: TUpDown;
- RadioButtonFullname: TRadioButton;
- RadioButtonCountyNumber: TRadioButton;
- RadioButtonAge: TRadioButton;
- RadioButtonFree: TRadioButton;
- Label1: TLabel;
- procedure FrameEnter(Sender: TObject);
- procedure ComboBoxPartyChange(Sender: TObject);
- procedure RadioButtonFullnameClick(Sender: TObject);
- procedure RadioButtonCountyNumberClick(Sender: TObject);
- procedure RadioButtonAgeClick(Sender: TObject);
- procedure RadioButtonFreeClick(Sender: TObject);
- procedure EditSearchByFullnameChange(Sender: TObject);
- procedure ComboBox1Change(Sender: TObject);
- procedure Edit1Change(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- Constructor Create(aOwner : TComponent); override;
- Procedure FilterSG(Str : String; J : Integer);
- end;
- implementation
- {$R *.dfm}
- uses BidirectionalCandidate, Candidate, BidirectionalParty, Party, Main,
- BidirectionalCountyNumber;
- Constructor TSearchByPartyFrame.Create(aOwner: TComponent);
- begin
- inherited Create(aOwner);
- UpDown1.Associate := Edit1;
- end;
- procedure TSearchByPartyFrame.Edit1Change(Sender: TObject);
- begin
- if RadioButtonAge.Checked then
- FilterSG(Edit1.Text, 4);
- end;
- procedure TSearchByPartyFrame.EditSearchByFullnameChange(Sender: TObject);
- begin
- if RadioButtonFullname.Checked then
- begin
- if Length(EditSearchByFullname.Text) = 0 then
- FrameEnter(NIL)
- else
- FilterSG(EditSearchByFullname.Text, 1);
- end;
- end;
- procedure ClearStringGrid(SG : TStringGrid);
- var
- I, J : Integer;
- begin
- for I := 0 to SG.RowCount - 1 do
- begin
- SG.Rows[I].Clear;
- end;
- end;
- Procedure TSearchByPartyFrame.FilterSG(Str: string; J : Integer);
- var
- I : Integer;
- begin
- Str := LowerCase(Str);
- for I := 1 to SGCandidate.RowCount - 1 do
- begin
- SGCandidate.RowHeights[I] := SGCandidate.DefaultRowHeight;
- if Str.Length = 0 then
- Continue;
- //for J := 0 to SGCandidate.ColCount - 1 do
- //begin
- if Pos(Str, LowerCase(SGCandidate.Cells[J, I])) > 0 then
- begin
- SGCandidate.RowHeights[I] := SGCandidate.DefaultRowHeight;
- end
- else
- begin
- SGCandidate.RowHeights[I] := 0;
- end;
- //end;
- end;
- end;
- procedure FillHeadersSG(SGCandidate : TStringGrid);
- begin
- SGCandidate.Cells[0,0] := HEADER_IDCANDIDATE;
- SGCandidate.Cells[1,0] := HEADER_FULLNAME;
- SGCandidate.Cells[2,0] := HEADER_PARTY;
- SGCandidate.Cells[3,0] := HEADER_COUNTYNUMBER;
- SGCandidate.Cells[4,0] := HEADER_AGE;
- SGCandidate.Cells[5,0] := HEADER_PROFESSION;
- SGCandidate.ColWidths[0] := 50;
- SGCandidate.ColWidths[1] := 250;
- SGCandidate.ColWidths[2] := 250;
- SGCandidate.ColWidths[3] := 250;
- SGCandidate.ColWidths[4] := 250;
- SGCandidate.ColWidths[5] := 250;
- end;
- Procedure FillCBCountyNumber(CB : TComboBox);
- var
- TempHeadCNumber : PCountyNumberList;
- begin
- CB.Clear;
- TempHeadCNumber := Main.CountyNumberList.Head;
- while TempHeadCNumber <> NIL do
- begin
- CB.Items.Add(TempHeadCNumber.CountyNumber.Number.ToString);
- TempHeadCNumber := TempHeadCNumber^.Next;
- end;
- end;
- Procedure FillCBParty(CB : TComboBox);
- var
- TempHeadPartyList : PPartyList;
- begin
- CB.Clear;
- TempHeadPartyList := Main.PartyList.Head;
- while TempHeadPartyList <> NIL do
- begin
- CB.Items.Add(TempHeadPartyList.Party.Name);
- TempHeadPartyList := TempHeadPartyList^.Next;
- end;
- end;
- Procedure FillStringGrid(SG : TStringGrid; PartyId : Integer);
- var
- I, J : Integer;
- TempHead : PCandidateList;
- PartyName : String;
- CountyNum : Integer;
- begin
- ClearStringGrid(SG);
- FillHeadersSG(SG);
- TempHead := Main.CandidateList.Head;
- I := 1;
- J := 0;
- // Цикл для прохода по списку
- while TempHead <> NIL do
- begin
- if TempHead.Candidate.PartyId = PartyId then
- begin
- PartyName := '';
- with SG do
- begin
- Cells[J, I] := (TempHead^.Candidate.IdCandidate + 1).ToString;
- Cells[J + 1, I] := TempHead^.Candidate.Fullname;
- PartyName := TPartyList.GetPartyNameByPK(Main.PartyList, TempHead^.Candidate.PartyId);
- Cells[J + 2, I] := PartyName;
- CountyNum := TCountyNumberList.GetCountyNumberByPK(Main.CountyNumberList, TempHead^.Candidate.CountyNumberId);
- Cells[J + 3, I] := CountyNum.ToString;
- Cells[J + 4, I] := TempHead^.Candidate.Age.ToString;
- Cells[J + 5, I] := TempHead^.Candidate.Profession;
- end;
- Inc(I);
- SG.RowCount := I;
- end;
- TempHead := TempHead^.Next; // Переход к следующей записи
- end;
- Dispose(TempHead);
- end;
- procedure TSearchByPartyFrame.ComboBox1Change(Sender: TObject);
- begin
- if RadioButtonCountyNumber.Checked then
- FilterSG(ComboBox1.Text, 3);
- end;
- procedure TSearchByPartyFrame.ComboBoxPartyChange(Sender: TObject);
- begin
- FillStringGrid(SGCandidate, ComboBoxParty.ItemIndex);
- end;
- procedure TSearchByPartyFrame.FrameEnter(Sender: TObject);
- begin
- FillCBParty(ComboBoxParty);
- FillCBCountyNumber(ComboBox1);
- ComboBoxParty.ItemIndex := 0;
- FillStringGrid(SGCandidate, ComboBoxParty.ItemIndex);
- end;
- procedure TSearchByPartyFrame.RadioButtonAgeClick(Sender: TObject);
- var
- I, J : Integer;
- begin
- RadioButtonCountyNumber.Checked := False;
- RadioButtonFullname.Checked := False;
- RadioButtonFree.Checked := False;
- end;
- procedure TSearchByPartyFrame.RadioButtonCountyNumberClick(Sender: TObject);
- begin
- RadioButtonFullname.Checked := False;
- RadioButtonAge.Checked := False;
- RadioButtonFree.Checked := False;
- end;
- procedure TSearchByPartyFrame.RadioButtonFreeClick(Sender: TObject);
- var
- I : Integer;
- begin
- RadioButtonCountyNumber.Checked := False;
- RadioButtonAge.Checked := False;
- RadioButtonFullname.Checked := False;
- FrameEnter(NIL);
- for I := 1 to SGCandidate.RowCount - 1 do
- SGCandidate.RowHeights[I] := SGCandidate.DefaultRowHeight;
- end;
- procedure TSearchByPartyFrame.RadioButtonFullnameClick(Sender: TObject);
- begin
- RadioButtonCountyNumber.Checked := False;
- RadioButtonAge.Checked := False;
- RadioButtonFree.Checked := False;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement