Advertisement
Matixs

Untitled

May 31st, 2023
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.56 KB | None | 0 0
  1. unit CandidateAdd;
  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,
  8.   Vcl.ComCtrls, Vcl.NumberBox,  BidirectionalParty,
  9.   BidirectionalCountyNumber, Candidate, BidirectionalCandidate;
  10.  
  11. type
  12.   TCandidateAddFrame = class(TFrame)
  13.     GroupBox1: TGroupBox;
  14.     Edit1: TEdit;
  15.     Label1: TLabel;
  16.     ComboBox1: TComboBox;
  17.     Label2: TLabel;
  18.     Label3: TLabel;
  19.     NumberBox1: TNumberBox;
  20.     UpDown1: TUpDown;
  21.     Label4: TLabel;
  22.     Edit2: TEdit;
  23.     ComboBox2: TComboBox;
  24.     Label5: TLabel;
  25.     BtnSave: TButton;
  26.     procedure FrameEnter(Sender: TObject);
  27.     procedure BtnSaveClick(Sender: TObject);
  28.   private
  29.     { Private declarations }
  30.   public
  31.     { Public declarations }
  32.     Constructor Create (aOwner : TComponent); override;
  33.   end;
  34.  
  35. implementation
  36.  
  37. {$R *.dfm}
  38.  
  39. uses Main;
  40.  
  41. procedure TCandidateAddFrame.BtnSaveClick(Sender: TObject);
  42. var
  43.     NewCandidate : TCandidate;
  44.     Key, PKParty, PKCountyNumber : Integer;
  45. begin
  46.     if (Edit1.Text <> '') AND (Edit2.Text <> '') then
  47.     begin
  48.         try
  49.             Key := TCandidateList.GetLastPrimaryKey(CandidateList) + 1;
  50.             PKParty := TPartyList.GetPartyPrimaryKeyByName(Main.PartyList, ComboBox1.Text);
  51.             PKCountyNumber := TCountyNumberList.GetGetCountyNumberPrimaryKeyByNumber(Main.CountyNumberList, StrToInt(ComboBox2.Text));
  52.             NewCandidate := TCandidate.Create(Key, Edit1.Text, PKParty,
  53.                                                 PKCountyNumber, StrToInt(NumberBox1.Text), Edit2.Text);
  54.             Main.CandidateList.AddNewCandidate(NewCandidate);
  55.             Application.MessageBox('Кандидат успешно добавлен!','Добавление кандидата',MB_OK+MB_ICONINFORMATION);
  56.         except
  57.             On E : Exception do
  58.                 Application.MessageBox(PChar(E.Message),'Ошибка добавления кандидата', MB_OK + MB_ICONWARNING);
  59.         end;
  60.     end
  61.     else
  62.         Application.MessageBox('Заполните все поля!','Добавление кандидата',MB_OK+MB_ICONWARNING);
  63. end;
  64.  
  65. Constructor TCandidateAddFrame.Create(aOwner: TComponent);
  66. begin
  67.     inherited Create(aOwner);
  68.     UpDown1.Associate := NumberBox1;
  69. end;
  70.  
  71. Procedure FillComboboxs(CBParty, CBCountyNumber : TComboBox; const PartyList : TPartyList; const CNumberList : TCountyNumberList);
  72. var
  73.     TempHeadPartyList : PPartyList;
  74.     TempHeadCNumberList : PCountyNumberList;
  75. begin
  76.  
  77.     TempHeadPartyList := PartyList.Head;
  78.     TempHeadCNumberList := CNumberList.Head;
  79.  
  80.     CBParty.Clear;
  81.     CBCountyNumber.Clear;
  82.  
  83.     while TempHeadPartyList <> NIL do
  84.     begin
  85.         CBParty.Items.Add(TempHeadPartyList^.Party.Name);
  86.         TempHeadPartyList := TempHeadPartyList^.Next;
  87.     end;
  88.  
  89.     while TempHeadCNumberList <> NIL do
  90.     begin
  91.         CBCountyNumber.Items.Add(TempHeadCNumberList^.CountyNumber.Number.ToString);
  92.         TempHeadCNumberList := TempHeadCNumberList^.Next;
  93.     end;
  94.  
  95.     Dispose(TempHeadPartyList);
  96.     Dispose(TempHeadCNumberList);
  97. end;
  98.  
  99. procedure TCandidateAddFrame.FrameEnter(Sender: TObject);
  100. var
  101.     CParty : TPartyList;
  102.     CCountyNumber : TCountyNumberList;
  103. begin
  104.     // TODO: передать данные из основого фрейма.
  105.  
  106.     CParty := Main.PartyList;
  107.     CCountyNumber := Main.CountyNumberList;
  108.  
  109.     FillComboboxs(ComboBox1, ComboBox2, CParty, CCountyNumber);
  110.     ComboBox1.ItemIndex := 0;
  111.     ComboBox2.ItemIndex := 0;
  112. end;
  113.  
  114. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement