Advertisement
Matixs

Untitled

May 31st, 2023
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.58 KB | None | 0 0
  1. unit CountyNumberDelete;
  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.  
  9. type
  10.   TCountyNumberDeleteFrame = class(TFrame)
  11.     LBPK: TLabel;
  12.     GroupBox1: TGroupBox;
  13.     Label1: TLabel;
  14.     Label2: TLabel;
  15.     Label5: TLabel;
  16.     EditNumberCounty: TEdit;
  17.     EditNameCounty: TEdit;
  18.     EditRegion: TEdit;
  19.     BtnPrev: TButton;
  20.     BtnNext: TButton;
  21.     BtnDelete: TButton;
  22.     procedure FrameEnter(Sender: TObject);
  23.     procedure BtnDeleteClick(Sender: TObject);
  24.     procedure BtnPrevClick(Sender: TObject);
  25.     procedure BtnNextClick(Sender: TObject);
  26.   private
  27.     { Private declarations }
  28.   public
  29.     { Public declarations }
  30.     procedure FillComponents();
  31.   end;
  32.  
  33. implementation
  34.  
  35. {$R *.dfm}
  36.  
  37. uses BidirectionalCountyNumber, CountyNumber, Main, MainView,
  38.   BidirectionalCandidate;
  39.  
  40. var
  41.     CurrentCountyNumber : Integer;
  42.  
  43. Function GetCountyNumber() : TCountyNumber;
  44. var
  45.     TempHead : PCountyNumberList;
  46.     CurrentCountyNumberNode : TCountyNumber;
  47.     Counter : Integer;
  48. begin
  49.     TempHead := Main.CountyNumberList.Head;
  50.     CurrentCountyNumberNode := NIL;
  51.     Counter := 0;
  52.  
  53.     While TempHead <> NIL Do
  54.     Begin
  55.         if Counter = CurrentCountyNumber then
  56.         begin
  57.             CurrentCountyNumberNode := TempHead.CountyNumber;
  58.             break
  59.         end
  60.         else
  61.             Inc(Counter);
  62.         TempHead := TempHead^.Next;
  63.     End;
  64.     GetCountyNumber := CurrentCountyNumberNode;
  65. end;
  66.  
  67. Function CheckOnExistCandidateWithSelfCountyNumber(CountyNumberID : Integer) : Boolean;
  68. var
  69.     TempHeadCandidateList : PCandidateList;
  70. begin
  71.     CheckOnExistCandidateWithSelfCountyNumber := false;
  72.     TempHeadCandidateList := Main.CandidateList.Head;
  73.  
  74.     while TempHeadCandidateList <> NIL do
  75.     begin
  76.  
  77.         if TempHeadCandidateList.Candidate.CountyNumberId = CountyNumberID then
  78.         begin
  79.             CheckOnExistCandidateWithSelfCountyNumber := True;
  80.             break;
  81.         end;
  82.  
  83.         TempHeadCandidateList := TempHeadCandidateList^.Next;
  84.     end;
  85. end;
  86.  
  87. procedure TCountyNumberDeleteFrame.BtnDeleteClick(Sender: TObject);
  88. begin
  89.     try
  90.         if NOT CheckOnExistCandidateWithSelfCountyNumber(StrToInt(LBPK.Caption)) then
  91.         begin
  92.             Main.CountyNumberList.DeleteCountyNumberByID(StrToInt(LBPK.Caption));
  93.             Application.MessageBox(PChar('Успешное удаление округа - ' + EditNumberCounty.Text),
  94.                                          'Удаление округа',MB_OK+MB_ICONINFORMATION);
  95.             Self.FrameEnter(NIL);
  96.         end
  97.         else
  98.         begin
  99.             Application.MessageBox('Невозможно удалить округ, так как он используется кандидатом(-ами). Сначала удалите кандидата(-ов) или измените параметры округа на актуальные.','Удаление округа',MB_OK+MB_ICONINFORMATION);
  100.         end;
  101.     except
  102.         On E : Exception do
  103.             Application.MessageBox(PChar('Ошибка' + E.Message),'Удаление округа', MB_OK + MB_ICONSTOP);
  104.     end;
  105. end;
  106.  
  107. procedure TCountyNumberDeleteFrame.BtnNextClick(Sender: TObject);
  108. begin
  109.     if CurrentCountyNumber <> Main.CountyNumberList.Count - 1 then
  110.     begin
  111.         Inc(CurrentCountyNumber);
  112.         FillComponents;
  113.     end;
  114. end;
  115.  
  116. procedure TCountyNumberDeleteFrame.BtnPrevClick(Sender: TObject);
  117. begin
  118.     if CurrentCountyNumber <> 0 then
  119.     begin
  120.         Dec(CurrentCountyNumber);
  121.         FillComponents;
  122.     end;
  123. end;
  124.  
  125. Procedure TCountyNumberDeleteFrame.FillComponents();
  126. var
  127.     CountyNumber : TCountyNumber;
  128. begin
  129.     CountyNumber := GetCountyNumber;
  130.  
  131.     if CountyNumber <> NIL then
  132.     begin
  133.         LBPK.Caption := CountyNumber.IdCountyNumber.ToString;
  134.         EditNumberCounty.Text := CountyNumber.Number.ToString;
  135.         EditNameCounty.Text := CountyNumber.Name;
  136.         EditRegion.Text := CountyNumber.Region;
  137.         BtnDelete.Enabled := True;
  138.         BtnPrev.Enabled := True;
  139.         BtnNext.Enabled := True;
  140.     end
  141.     else
  142.     begin
  143.         LBPK.Caption := '';
  144.         EditNumberCounty.Text := '';
  145.         EditNameCounty.Text := '';
  146.         EditRegion.Text := '';
  147.         BtnDelete.Enabled := False;
  148.         BtnPrev.Enabled := False;
  149.         BtnNext.Enabled := False;
  150.     end;
  151. end;
  152.  
  153. procedure TCountyNumberDeleteFrame.FrameEnter(Sender: TObject);
  154. begin
  155.     CurrentCountyNumber := 0;
  156.     FillComponents;
  157. end;
  158.  
  159. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement