Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit CandidateAdd;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
- Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
- Vcl.ComCtrls, Vcl.NumberBox, BidirectionalParty,
- BidirectionalCountyNumber, Candidate, BidirectionalCandidate;
- type
- TCandidateAddFrame = class(TFrame)
- GroupBox1: TGroupBox;
- Edit1: TEdit;
- Label1: TLabel;
- ComboBox1: TComboBox;
- Label2: TLabel;
- Label3: TLabel;
- NumberBox1: TNumberBox;
- UpDown1: TUpDown;
- Label4: TLabel;
- Edit2: TEdit;
- ComboBox2: TComboBox;
- Label5: TLabel;
- BtnSave: TButton;
- procedure FrameEnter(Sender: TObject);
- procedure BtnSaveClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- Constructor Create (aOwner : TComponent); override;
- end;
- implementation
- {$R *.dfm}
- uses Main;
- procedure TCandidateAddFrame.BtnSaveClick(Sender: TObject);
- var
- NewCandidate : TCandidate;
- Key, PKParty, PKCountyNumber : Integer;
- begin
- if (Edit1.Text <> '') AND (Edit2.Text <> '') then
- begin
- try
- Key := TCandidateList.GetLastPrimaryKey(CandidateList) + 1;
- PKParty := TPartyList.GetPartyPrimaryKeyByName(Main.PartyList, ComboBox1.Text);
- PKCountyNumber := TCountyNumberList.GetGetCountyNumberPrimaryKeyByNumber(Main.CountyNumberList, StrToInt(ComboBox2.Text));
- NewCandidate := TCandidate.Create(Key, Edit1.Text, PKParty,
- PKCountyNumber, StrToInt(NumberBox1.Text), Edit2.Text);
- Main.CandidateList.AddNewCandidate(NewCandidate);
- Application.MessageBox('Кандидат успешно добавлен!','Добавление кандидата',MB_OK+MB_ICONINFORMATION);
- except
- On E : Exception do
- Application.MessageBox(PChar(E.Message),'Ошибка добавления кандидата', MB_OK + MB_ICONWARNING);
- end;
- end
- else
- Application.MessageBox('Заполните все поля!','Добавление кандидата',MB_OK+MB_ICONWARNING);
- end;
- Constructor TCandidateAddFrame.Create(aOwner: TComponent);
- begin
- inherited Create(aOwner);
- UpDown1.Associate := NumberBox1;
- end;
- Procedure FillComboboxs(CBParty, CBCountyNumber : TComboBox; const PartyList : TPartyList; const CNumberList : TCountyNumberList);
- var
- TempHeadPartyList : PPartyList;
- TempHeadCNumberList : PCountyNumberList;
- begin
- TempHeadPartyList := PartyList.Head;
- TempHeadCNumberList := CNumberList.Head;
- CBParty.Clear;
- CBCountyNumber.Clear;
- while TempHeadPartyList <> NIL do
- begin
- CBParty.Items.Add(TempHeadPartyList^.Party.Name);
- TempHeadPartyList := TempHeadPartyList^.Next;
- end;
- while TempHeadCNumberList <> NIL do
- begin
- CBCountyNumber.Items.Add(TempHeadCNumberList^.CountyNumber.Number.ToString);
- TempHeadCNumberList := TempHeadCNumberList^.Next;
- end;
- Dispose(TempHeadPartyList);
- Dispose(TempHeadCNumberList);
- end;
- procedure TCandidateAddFrame.FrameEnter(Sender: TObject);
- var
- CParty : TPartyList;
- CCountyNumber : TCountyNumberList;
- begin
- // TODO: передать данные из основого фрейма.
- CParty := Main.PartyList;
- CCountyNumber := Main.CountyNumberList;
- FillComboboxs(ComboBox1, ComboBox2, CParty, CCountyNumber);
- ComboBox1.ItemIndex := 0;
- ComboBox2.ItemIndex := 0;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement