Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit ShowSquareUnit;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Menus, MainUnit;
- type
- TShowForm = class(TForm)
- Image: TImage;
- ShowLowerPartButton: TButton;
- ShowFirstSquareButton: TButton;
- BuildSecondSquareButton: TButton;
- ShowMagicSquareButton: TButton;
- MainMenu: TMainMenu;
- InstructionMenu: TMenuItem;
- SaveMenu: TMenuItem;
- SaveToFile: TSaveDialog;
- SumLabel: TLabel;
- TaskLabel: TLabel;
- procedure ShowMagicSquareButtonClick(Sender: TObject);
- procedure BuildSecondSquareButtonClick(Sender: TObject);
- procedure ShowFirstSquareButtonClick(Sender: TObject);
- procedure ShowLowerPartButtonClick(Sender: TObject);
- procedure InstructionMenuClick(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure SaveMenuClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- ShowForm: TShowForm;
- implementation
- {$R *.dfm}
- uses
- DrawSquareUnit, MagicBoxUnit;
- const
- TextMagicSquare = 'Итоговый магический квадрат:';
- TextSecondSquare = 'Второй латинский квадрат:';
- TextFirstSquare = 'Первый латинский квадрат:';
- TextLowerPartSquare = 'Основа первого латинского квадрата:';
- var
- FirstLatinSquare, SecondLatinSquare, MagicSquare, FirstLowerLatinSquare: TSquare;
- Sum, IndexOfPrinted: integer;
- procedure TShowForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- SquarePrinter.clear(Image);
- Main.Enabled := true;
- end;
- procedure TShowForm.FormShow(Sender: TObject);
- begin
- Main.Enabled := false;
- SumLabel.visible := false;
- TaskLabel.Visible := false;
- SystemParametersInfo(SPI_SETBEEP, 0, nil, SPIF_SENDWININICHANGE);
- SaveMenu.Enabled := false;
- Sum := 0;
- Size := strToInt(Main.SizeSpinEdit.Text);
- TSquareOperations.receiveMagicSquare(MagicSquare,
- FirstLatinSquare, SecondLatinSquare, FirstLowerLatinSquare, Sum, Size);
- end;
- procedure TShowForm.InstructionMenuClick(Sender: TObject);
- Var
- InstructionMenu: TForm;
- Instruction: string;
- begin
- Instruction := 'Отображение разных этапов получения магического квадрата:' + #13#10 + #13#10
- + '1. "Нижняя часть" - отобразить нижнюю часть первого латинского квадрата(Верхняя будет заполнена нулями).' + #13#10
- + '2. "Первый латинский" - отобразить нижний латинский квадрат.' + #13#10 +
- '3. "Второй латинский" - отобразить второй латинский квадрат.' +
- #13#10 + '4. "Магический квадрат" - отобразить магический квадрат с суммой элементов.';
- InstructionMenu := CreateMessageDialog(Instruction, mtInformation, [mbOk], mbOK);
- InstructionMenu.ShowModal;
- InstructionMenu.Free;
- end;
- procedure TShowForm.BuildSecondSquareButtonClick(Sender: TObject);
- begin
- IndexOfPrinted := 3;
- SumLabel.visible := false;
- SaveMenu.Enabled := true;
- TaskLabel.Visible := false;
- SumLabel.Caption := '';
- SquarePrinter.clear(Image);
- SquarePrinter.printText(TextSecondSquare, Image);
- SquarePrinter.drawSquare(SecondLatinSquare, Image);
- end;
- procedure TShowForm.SaveMenuClick(Sender: TObject);
- begin
- if SaveToFile.Execute() then
- Begin
- case IndexOfPrinted of
- 1: TSquareOperations.saveSquare(FirstLowerLatinSquare, SaveToFile.FileName, TextLowerPartSquare);
- 2: TSquareOperations.saveSquare(FirstLatinSquare, SaveToFile.FileName, TextFirstSquare);
- 3: TSquareOperations.saveSquare(SecondLatinSquare, SaveToFile.FileName, TextSecondSquare);
- 4:
- begin
- TSquareOperations.saveSquare(MagicSquare, SaveToFile.FileName, TextMagicSquare, TSquareOperations.findSum(MagicSquare));
- end;
- end;
- Application.MessageBox('Квадрат записан в файл.', 'Запись в файл');
- End;
- end;
- procedure TShowForm.ShowFirstSquareButtonClick(Sender: TObject);
- begin
- IndexOfPrinted := 2;
- SaveMenu.Enabled := true;
- SumLabel.visible := false;
- TaskLabel.Visible := false;
- SumLabel.Caption := '';
- SquarePrinter.clear(Image);
- SquarePrinter.printText(TextFirstSquare, Image);
- SquarePrinter.drawSquare(FirstLatinSquare, Image);
- end;
- procedure TShowForm.ShowLowerPartButtonClick(Sender: TObject);
- begin
- IndexOfPrinted := 1;
- SaveMenu.Enabled := true;
- SumLabel.Caption := '';
- TaskLabel.Visible := false;
- SquarePrinter.clear(Image);
- SquarePrinter.printText(TextLowerPartSquare, Image);
- SquarePrinter.drawSquare(FirstLowerLatinSquare, Image);
- end;
- procedure TShowForm.ShowMagicSquareButtonClick(Sender: TObject);
- begin
- IndexOfPrinted := 4;
- SumLabel.visible := true;
- TaskLabel.Visible := true;
- SumLabel.Caption := '';
- SumLabel.Caption := intToStr(TSquareOperations.findSum(MagicSquare));
- SaveMenu.Enabled := true;
- SquarePrinter.clear(Image);
- SquarePrinter.printText(TextMagicSquare, Image);
- SquarePrinter.drawSquare(MagicSquare, Image);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement