Advertisement
believe_me

Untitled

Sep 5th, 2022
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.96 KB | None | 0 0
  1. unit EditUnit;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, MainUnit, Vcl.Samples.Spin, Vcl.StdCtrls,
  8.   Vcl.Menus, AddUnit;
  9.  
  10. type
  11.   TEditForm = class(TForm)
  12.     TelephoneLabel: TLabel;
  13.     SurnameLabel: TLabel;
  14.     YearLabel: TLabel;
  15.     EditButton: TButton;
  16.     TelephoneEdit: TEdit;
  17.     SurnameEdit: TEdit;
  18.     YearSpinEdit: TSpinEdit;
  19.     GoBackButton: TButton;
  20.     ResultLabel: TLabel;
  21.     MainMenu: TMainMenu;
  22.     InstructionMenu: TMenuItem;
  23.     procedure TelephoneEditKeyPress(Sender: TObject; var Key: Char);
  24.     procedure SurnameEditKeyPress(Sender: TObject; var Key: Char);
  25.     procedure FormShow(Sender: TObject);
  26.     procedure FormCreate(Sender: TObject);
  27.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  28.     procedure GoBackButtonClick(Sender: TObject);
  29.     procedure EditButtonClick(Sender: TObject);
  30.     procedure TelephoneEditChange(Sender: TObject);
  31.     procedure SurnameEditChange(Sender: TObject);
  32.     procedure YearSpinEditChange(Sender: TObject);
  33.     procedure InstructionMenuClick(Sender: TObject);
  34.   private
  35.     { Private declarations }
  36.   public
  37.     { Public declarations }
  38.   end;
  39.  
  40. var
  41.   EditForm: TEditForm;
  42.  
  43. implementation
  44.  
  45. {$R *.dfm}
  46.  
  47. procedure TEditForm.EditButtonClick(Sender: TObject);
  48. var
  49.    CurrSub: TSubscriber;
  50. begin
  51.    ResultLabel.Visible := false;
  52.    if AddForm.IsTelCorrect(TelephoneEdit) and AddForm.IsSurnameCorrect(SurnameEdit) then
  53.    begin
  54.       CurrSub.telephoneNumber := StrToInt(TelephoneEdit.Text);
  55.       CurrSub.yearOfReg := YearSpinEdit.value;
  56.       CurrSub.surname := SurnameEdit.text;
  57.       Subscribers[SelectedSub] := CurrSub;
  58.       ResultLabel.Visible := true;
  59.       WriteSubsInFile();
  60.    end
  61.    else
  62.       Application.MessageBox('Введены некорректные данные!', 'Ошибка!', MB_ICONERROR);
  63. end;
  64.  
  65. procedure TEditForm.FormClose(Sender: TObject; var Action: TCloseAction);
  66. begin
  67.    ResultLabel.Visible := false;
  68.    EditForm.hide;
  69.    MainForm.Show;
  70. end;
  71.  
  72. procedure TEditForm.FormCreate(Sender: TObject);
  73. begin
  74.    SurnameEdit.MaxLength := MAX_SURNAME_LENGTH;
  75.    TelephoneEdit.MaxLength := MAX_TELEPHONE_LENGTH;
  76.    YearSpinEdit.MinValue := MIN_YEAR_OF_REGISTRATION;
  77.    YearSpinEdit.MaxValue := MAX_YEAR_OF_REGISTRATION;
  78.    YearSpinEdit.MaxLength := MIN_YEAR_OF_REGISTRATION_LENGTH;
  79. end;
  80.  
  81. procedure TEditForm.FormShow(Sender: TObject);
  82. begin
  83.    SurnameEdit.Text := Subscribers[SelectedSub].surname;
  84.    TelephoneEdit.Text := IntToStr(Subscribers[SelectedSub].telephoneNumber);
  85.    YearSpinEdit.Value := Subscribers[SelectedSub].yearOfReg;
  86. end;
  87.  
  88. procedure TEditForm.GoBackButtonClick(Sender: TObject);
  89. begin
  90.    ResultLabel.Visible := false;
  91.    EditForm.hide;
  92.    MainForm.Show;
  93. end;
  94.  
  95. procedure TEditForm.InstructionMenuClick(Sender: TObject);
  96. begin
  97.    MessageDlg('Окно редактирования.' + #13#10 + #13#10 +
  98.                'Для успешного изменения абонента необходимо заполнить все поля для ввода.'
  99.                + #13#10 + #13#10 + 'Для возвращения к главному окну нажмите "Назад".',
  100.                MtInformation, [mbOk], 0);
  101. end;
  102.  
  103. procedure TEditForm.SurnameEditChange(Sender: TObject);
  104. begin
  105.    ResultLabel.Visible := false;
  106. end;
  107.  
  108. procedure TEditForm.SurnameEditKeyPress(Sender: TObject; var Key: Char);
  109. begin
  110.    if (Key <> #08) then
  111.    begin
  112.       if not(Key in LETTERS) then
  113.          Key := #0;
  114.    end;
  115. end;
  116.  
  117. procedure TEditForm.TelephoneEditChange(Sender: TObject);
  118. begin
  119.    ResultLabel.Visible := false;
  120. end;
  121.  
  122. procedure TEditForm.TelephoneEditKeyPress(Sender: TObject; var Key: Char);
  123. begin
  124.    if (Key <> #08) then
  125.    begin
  126.       if not(Key in DIGITS) then
  127.          Key := #0;
  128.    end;
  129. end;
  130.  
  131. procedure TEditForm.YearSpinEditChange(Sender: TObject);
  132. begin
  133.    ResultLabel.Visible := false;
  134. end;
  135.  
  136. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement