Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit CountyNumberDelete;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
- Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
- type
- TCountyNumberDeleteFrame = class(TFrame)
- LBPK: TLabel;
- GroupBox1: TGroupBox;
- Label1: TLabel;
- Label2: TLabel;
- Label5: TLabel;
- EditNumberCounty: TEdit;
- EditNameCounty: TEdit;
- EditRegion: TEdit;
- BtnPrev: TButton;
- BtnNext: TButton;
- BtnDelete: TButton;
- procedure FrameEnter(Sender: TObject);
- procedure BtnDeleteClick(Sender: TObject);
- procedure BtnPrevClick(Sender: TObject);
- procedure BtnNextClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- procedure FillComponents();
- end;
- implementation
- {$R *.dfm}
- uses BidirectionalCountyNumber, CountyNumber, Main, MainView,
- BidirectionalCandidate;
- var
- CurrentCountyNumber : Integer;
- Function GetCountyNumber() : TCountyNumber;
- var
- TempHead : PCountyNumberList;
- CurrentCountyNumberNode : TCountyNumber;
- Counter : Integer;
- begin
- TempHead := Main.CountyNumberList.Head;
- CurrentCountyNumberNode := NIL;
- Counter := 0;
- While TempHead <> NIL Do
- Begin
- if Counter = CurrentCountyNumber then
- begin
- CurrentCountyNumberNode := TempHead.CountyNumber;
- break
- end
- else
- Inc(Counter);
- TempHead := TempHead^.Next;
- End;
- GetCountyNumber := CurrentCountyNumberNode;
- end;
- Function CheckOnExistCandidateWithSelfCountyNumber(CountyNumberID : Integer) : Boolean;
- var
- TempHeadCandidateList : PCandidateList;
- begin
- CheckOnExistCandidateWithSelfCountyNumber := false;
- TempHeadCandidateList := Main.CandidateList.Head;
- while TempHeadCandidateList <> NIL do
- begin
- if TempHeadCandidateList.Candidate.CountyNumberId = CountyNumberID then
- begin
- CheckOnExistCandidateWithSelfCountyNumber := True;
- break;
- end;
- TempHeadCandidateList := TempHeadCandidateList^.Next;
- end;
- end;
- procedure TCountyNumberDeleteFrame.BtnDeleteClick(Sender: TObject);
- begin
- try
- if NOT CheckOnExistCandidateWithSelfCountyNumber(StrToInt(LBPK.Caption)) then
- begin
- Main.CountyNumberList.DeleteCountyNumberByID(StrToInt(LBPK.Caption));
- Application.MessageBox(PChar('Успешное удаление округа - ' + EditNumberCounty.Text),
- 'Удаление округа',MB_OK+MB_ICONINFORMATION);
- Self.FrameEnter(NIL);
- end
- else
- begin
- Application.MessageBox('Невозможно удалить округ, так как он используется кандидатом(-ами). Сначала удалите кандидата(-ов) или измените параметры округа на актуальные.','Удаление округа',MB_OK+MB_ICONINFORMATION);
- end;
- except
- On E : Exception do
- Application.MessageBox(PChar('Ошибка' + E.Message),'Удаление округа', MB_OK + MB_ICONSTOP);
- end;
- end;
- procedure TCountyNumberDeleteFrame.BtnNextClick(Sender: TObject);
- begin
- if CurrentCountyNumber <> Main.CountyNumberList.Count - 1 then
- begin
- Inc(CurrentCountyNumber);
- FillComponents;
- end;
- end;
- procedure TCountyNumberDeleteFrame.BtnPrevClick(Sender: TObject);
- begin
- if CurrentCountyNumber <> 0 then
- begin
- Dec(CurrentCountyNumber);
- FillComponents;
- end;
- end;
- Procedure TCountyNumberDeleteFrame.FillComponents();
- var
- CountyNumber : TCountyNumber;
- begin
- CountyNumber := GetCountyNumber;
- if CountyNumber <> NIL then
- begin
- LBPK.Caption := CountyNumber.IdCountyNumber.ToString;
- EditNumberCounty.Text := CountyNumber.Number.ToString;
- EditNameCounty.Text := CountyNumber.Name;
- EditRegion.Text := CountyNumber.Region;
- BtnDelete.Enabled := True;
- BtnPrev.Enabled := True;
- BtnNext.Enabled := True;
- end
- else
- begin
- LBPK.Caption := '';
- EditNumberCounty.Text := '';
- EditNameCounty.Text := '';
- EditRegion.Text := '';
- BtnDelete.Enabled := False;
- BtnPrev.Enabled := False;
- BtnNext.Enabled := False;
- end;
- end;
- procedure TCountyNumberDeleteFrame.FrameEnter(Sender: TObject);
- begin
- CurrentCountyNumber := 0;
- FillComponents;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement