Advertisement
Matixs

Untitled

May 31st, 2023
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 7.37 KB | None | 0 0
  1. unit SearchByParty;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  7.   Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids,
  8.   Vcl.ComCtrls;
  9.  
  10. const
  11.     HEADER_IDCANDIDATE = '№';
  12.     HEADER_FULLNAME = 'ФИО';
  13.     HEADER_PARTY = 'Партия';
  14.     HEADER_AGE = 'Возраст';
  15.     HEADER_COUNTYNUMBER = 'Номер округа';
  16.     HEADER_PROFESSION = 'Профессия';
  17.  
  18. type
  19.   TSearchByPartyFrame = class(TFrame)
  20.     GroupBox1: TGroupBox;
  21.     GroupBox2: TGroupBox;
  22.     ComboBoxParty: TComboBox;
  23.     GroupBox3: TGroupBox;
  24.     GroupBox4: TGroupBox;
  25.     EditSearchByFullname: TEdit;
  26.     SGCandidate: TStringGrid;
  27.     GroupBox5: TGroupBox;
  28.     GroupBox6: TGroupBox;
  29.     Edit1: TEdit;
  30.     ComboBox1: TComboBox;
  31.     UpDown1: TUpDown;
  32.     RadioButtonFullname: TRadioButton;
  33.     RadioButtonCountyNumber: TRadioButton;
  34.     RadioButtonAge: TRadioButton;
  35.     RadioButtonFree: TRadioButton;
  36.     Label1: TLabel;
  37.     procedure FrameEnter(Sender: TObject);
  38.     procedure ComboBoxPartyChange(Sender: TObject);
  39.     procedure RadioButtonFullnameClick(Sender: TObject);
  40.     procedure RadioButtonCountyNumberClick(Sender: TObject);
  41.     procedure RadioButtonAgeClick(Sender: TObject);
  42.     procedure RadioButtonFreeClick(Sender: TObject);
  43.     procedure EditSearchByFullnameChange(Sender: TObject);
  44.     procedure ComboBox1Change(Sender: TObject);
  45.     procedure Edit1Change(Sender: TObject);
  46.   private
  47.     { Private declarations }
  48.   public
  49.     { Public declarations }
  50.     Constructor Create(aOwner : TComponent); override;
  51.     Procedure FilterSG(Str : String; J : Integer);
  52.   end;
  53.  
  54. implementation
  55.  
  56. {$R *.dfm}
  57.  
  58. uses BidirectionalCandidate, Candidate, BidirectionalParty, Party, Main,
  59.   BidirectionalCountyNumber;
  60.  
  61. Constructor TSearchByPartyFrame.Create(aOwner: TComponent);
  62. begin
  63.     inherited Create(aOwner);
  64.     UpDown1.Associate := Edit1;
  65. end;
  66.  
  67. procedure TSearchByPartyFrame.Edit1Change(Sender: TObject);
  68. begin
  69.     if RadioButtonAge.Checked then
  70.         FilterSG(Edit1.Text, 4);
  71. end;
  72.  
  73. procedure TSearchByPartyFrame.EditSearchByFullnameChange(Sender: TObject);
  74. begin
  75.     if RadioButtonFullname.Checked then
  76.     begin
  77.         if Length(EditSearchByFullname.Text) = 0 then
  78.             FrameEnter(NIL)
  79.         else
  80.             FilterSG(EditSearchByFullname.Text, 1);
  81.     end;
  82. end;
  83.  
  84. procedure ClearStringGrid(SG : TStringGrid);
  85. var
  86.     I, J : Integer;
  87. begin
  88.     for I := 0 to SG.RowCount - 1 do
  89.     begin
  90.         SG.Rows[I].Clear;
  91.     end;
  92. end;
  93.  
  94. Procedure TSearchByPartyFrame.FilterSG(Str: string; J : Integer);
  95. var
  96.     I : Integer;
  97. begin
  98.     Str := LowerCase(Str);
  99.  
  100.     for I := 1 to SGCandidate.RowCount - 1 do
  101.     begin
  102.  
  103.         SGCandidate.RowHeights[I] := SGCandidate.DefaultRowHeight;
  104.  
  105.         if Str.Length = 0 then
  106.             Continue;
  107.  
  108.         //for J := 0 to SGCandidate.ColCount - 1 do
  109.         //begin
  110.             if Pos(Str, LowerCase(SGCandidate.Cells[J, I])) > 0 then
  111.             begin
  112.                 SGCandidate.RowHeights[I] := SGCandidate.DefaultRowHeight;
  113.             end
  114.             else
  115.             begin
  116.                 SGCandidate.RowHeights[I] := 0;
  117.             end;
  118.         //end;
  119.     end;
  120. end;
  121.  
  122. procedure FillHeadersSG(SGCandidate : TStringGrid);
  123. begin
  124.  
  125.     SGCandidate.Cells[0,0] := HEADER_IDCANDIDATE;
  126.     SGCandidate.Cells[1,0] := HEADER_FULLNAME;
  127.     SGCandidate.Cells[2,0] := HEADER_PARTY;
  128.     SGCandidate.Cells[3,0] := HEADER_COUNTYNUMBER;
  129.     SGCandidate.Cells[4,0] := HEADER_AGE;
  130.     SGCandidate.Cells[5,0] := HEADER_PROFESSION;
  131.     SGCandidate.ColWidths[0] := 50;
  132.     SGCandidate.ColWidths[1] := 250;
  133.     SGCandidate.ColWidths[2] := 250;
  134.     SGCandidate.ColWidths[3] := 250;
  135.     SGCandidate.ColWidths[4] := 250;
  136.     SGCandidate.ColWidths[5] := 250;
  137. end;
  138.  
  139. Procedure FillCBCountyNumber(CB : TComboBox);
  140. var
  141.     TempHeadCNumber : PCountyNumberList;
  142. begin
  143.     CB.Clear;
  144.     TempHeadCNumber := Main.CountyNumberList.Head;
  145.  
  146.     while TempHeadCNumber <> NIL do
  147.     begin
  148.         CB.Items.Add(TempHeadCNumber.CountyNumber.Number.ToString);
  149.         TempHeadCNumber := TempHeadCNumber^.Next;
  150.     end;
  151. end;
  152.  
  153. Procedure FillCBParty(CB : TComboBox);
  154. var
  155.     TempHeadPartyList : PPartyList;
  156. begin
  157.     CB.Clear;
  158.     TempHeadPartyList := Main.PartyList.Head;
  159.  
  160.     while TempHeadPartyList <> NIL do
  161.     begin
  162.         CB.Items.Add(TempHeadPartyList.Party.Name);
  163.         TempHeadPartyList := TempHeadPartyList^.Next;
  164.     end;
  165. end;
  166.  
  167. Procedure FillStringGrid(SG : TStringGrid; PartyId : Integer);
  168. var
  169.     I, J : Integer;
  170.     TempHead : PCandidateList;
  171.     PartyName : String;
  172.     CountyNum : Integer;
  173. begin
  174.     ClearStringGrid(SG);
  175.     FillHeadersSG(SG);
  176.     TempHead := Main.CandidateList.Head;
  177.  
  178.     I := 1;
  179.     J := 0;
  180.  
  181.     // Цикл для прохода по списку
  182.     while TempHead <> NIL do
  183.     begin
  184.         if TempHead.Candidate.PartyId = PartyId then
  185.         begin
  186.             PartyName := '';
  187.             with SG do
  188.             begin
  189.                 Cells[J, I] := (TempHead^.Candidate.IdCandidate + 1).ToString;
  190.                 Cells[J + 1, I] := TempHead^.Candidate.Fullname;
  191.                 PartyName := TPartyList.GetPartyNameByPK(Main.PartyList, TempHead^.Candidate.PartyId);
  192.                 Cells[J + 2, I] := PartyName;
  193.                 CountyNum := TCountyNumberList.GetCountyNumberByPK(Main.CountyNumberList, TempHead^.Candidate.CountyNumberId);
  194.                 Cells[J + 3, I] := CountyNum.ToString;
  195.                 Cells[J + 4, I] := TempHead^.Candidate.Age.ToString;
  196.                 Cells[J + 5, I] := TempHead^.Candidate.Profession;
  197.             end;
  198.             Inc(I);
  199.             SG.RowCount := I;
  200.         end;
  201.  
  202.         TempHead := TempHead^.Next; // Переход к следующей записи
  203.     end;
  204.  
  205.     Dispose(TempHead);
  206. end;
  207.  
  208.  
  209. procedure TSearchByPartyFrame.ComboBox1Change(Sender: TObject);
  210. begin
  211.     if RadioButtonCountyNumber.Checked then
  212.         FilterSG(ComboBox1.Text, 3);
  213. end;
  214.  
  215. procedure TSearchByPartyFrame.ComboBoxPartyChange(Sender: TObject);
  216. begin
  217.     FillStringGrid(SGCandidate, ComboBoxParty.ItemIndex);
  218. end;
  219.  
  220. procedure TSearchByPartyFrame.FrameEnter(Sender: TObject);
  221. begin
  222.     FillCBParty(ComboBoxParty);
  223.     FillCBCountyNumber(ComboBox1);
  224.     ComboBoxParty.ItemIndex := 0;
  225.     FillStringGrid(SGCandidate, ComboBoxParty.ItemIndex);
  226.  
  227. end;
  228.  
  229. procedure TSearchByPartyFrame.RadioButtonAgeClick(Sender: TObject);
  230. var
  231.     I, J : Integer;
  232. begin
  233.     RadioButtonCountyNumber.Checked := False;
  234.     RadioButtonFullname.Checked := False;
  235.     RadioButtonFree.Checked := False;
  236. end;
  237.  
  238. procedure TSearchByPartyFrame.RadioButtonCountyNumberClick(Sender: TObject);
  239. begin
  240.     RadioButtonFullname.Checked := False;
  241.     RadioButtonAge.Checked := False;
  242.     RadioButtonFree.Checked := False;
  243. end;
  244.  
  245. procedure TSearchByPartyFrame.RadioButtonFreeClick(Sender: TObject);
  246. var
  247.     I : Integer;
  248. begin
  249.     RadioButtonCountyNumber.Checked := False;
  250.     RadioButtonAge.Checked := False;
  251.     RadioButtonFullname.Checked := False;
  252.  
  253.     FrameEnter(NIL);
  254.  
  255.     for I := 1 to SGCandidate.RowCount - 1 do
  256.         SGCandidate.RowHeights[I] := SGCandidate.DefaultRowHeight;
  257. end;
  258.  
  259. procedure TSearchByPartyFrame.RadioButtonFullnameClick(Sender: TObject);
  260. begin
  261.     RadioButtonCountyNumber.Checked := False;
  262.     RadioButtonAge.Checked := False;
  263.     RadioButtonFree.Checked := False;
  264. end;
  265.  
  266. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement