Advertisement
MadCortez

Untitled

Mar 23rd, 2021
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 5.20 KB | None | 0 0
  1. unit Base;
  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, Vcl.Grids, Vcl.Menus, Vcl.StdCtrls;
  8.  
  9. type
  10.   TBaseForm = class(TForm)
  11.     Data: TStringGrid;
  12.     MainMenu1: TMainMenu;
  13.     About: TMenuItem;
  14.     Update: TMenuItem;
  15.     Find: TButton;
  16.     Ans: TMemo;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  19.     procedure UpdateClick(Sender: TObject);
  20.     procedure FormShow(Sender: TObject);
  21.     procedure AboutClick(Sender: TObject);
  22.     procedure FindClick(Sender: TObject);
  23.   private
  24.     { Private declarations }
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29. var
  30.   BaseForm: TBaseForm;
  31.  
  32. implementation
  33.  
  34. Uses
  35.    Menu, ChangeMenu, Add, DeleteRef, Change;
  36.  
  37. {$R *.dfm}
  38.  
  39. procedure TBaseForm.FindClick(Sender: TObject);
  40. var
  41.    a, b: array of TRef;
  42.    i, k, j, l, r: Integer;
  43.    s, sDay, sMonth: String;
  44.    Day, Month: array of Byte;
  45.    TempDay, TempMonth: Byte;
  46.    Temp: TRef;
  47. begin
  48.    for i := 0 to n - 1 do
  49.    begin
  50.       s := Ref[i].Date;
  51.       k := 2;
  52.       while k > 0 do
  53.       begin
  54.          if s[1] = '.' then
  55.             Dec(k);
  56.          delete(s, 1, 1);
  57.       end;
  58.       if s = '2021' then
  59.       begin
  60.          SetLength(a, Length(a) + 1);
  61.          a[High(a)] := Ref[i];
  62.       end;
  63.    end;
  64.  
  65.    for i := 0 to High(a) do
  66.       if a[i].Str <= 20 then
  67.       begin
  68.          SetLength(b, Length(b) + 1);
  69.          SetLength(Day, Length(Day) + 1);
  70.          SetLength(Month, Length(Month) + 1);
  71.          b[High(b)] := a[i];
  72.          s := a[i].Date;
  73.          k := 2;
  74.          sDay := '';
  75.          sMonth := '';
  76.          while k > 0 do
  77.          begin
  78.             if s[1] = '.' then
  79.                Dec(k)
  80.             else
  81.                if k = 2 then
  82.                   sDay := sDay + s[1]
  83.                else
  84.                   SMonth := sMonth + s[1];
  85.             delete(s, 1, 1);
  86.          end;
  87.          Day[High(Day)] := StrToInt(sDay);
  88.          Month[High(Month)] := StrToInt(sMonth);
  89.       end;
  90.  
  91.    for i := 0 to High(b) - 1 do
  92.       for j := i to High(b) - i do
  93.          if Month[i] > Month[j] then
  94.          begin
  95.             Temp := b[i];
  96.             b[i] := b[j];
  97.             b[j] := Temp;
  98.             TempDay := Day[i];
  99.             Day[i] := Day[j];
  100.             Day[j] := TempDay;
  101.             TempMonth := Month[i];
  102.             Month[i] := Month[j];
  103.             Month[j] := TempMonth;
  104.          end;
  105.  
  106.    l := 0;
  107.    r := 0;
  108.    while l <= High(b) do
  109.    begin
  110.       while (Month[l] = Month[r]) and (r < Length(b)) do
  111.          Inc(r);
  112.       Dec(r);
  113.       for i := l to r - 1 do
  114.          for j := i to r - i do
  115.             if Day[i] > Day[j] then
  116.             begin
  117.                Temp := b[i];
  118.                b[i] := b[j];
  119.                b[j] := Temp;
  120.                TempDay := Day[i];
  121.                Day[i] := Day[j];
  122.                Day[j] := TempDay;
  123.                TempMonth := Month[i];
  124.                Month[i] := Month[j];
  125.                Month[j] := TempMonth;
  126.             end;
  127.       Inc(r);
  128.       l := r;
  129.    end;
  130.  
  131.    Ans.Lines.Clear;
  132.    for i := 0 to High(b) do
  133.    begin
  134.       s := b[i].Topic;
  135.       s := s + ' ' + b[i].Author;
  136.       s := s + ' ' + IntToStr(b[i].Str);
  137.       s := s + ' ' + b[i].Date;
  138.       Ans.Lines.Add(s);
  139.    end;
  140.    ShowMessage(Ans.Text);
  141. end;
  142.  
  143. procedure TBaseForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  144. begin
  145.    CanClose := MessageDlg('Вы уверены, что хотите выйти из программы?' +
  146.       #10#13 + 'Все несохраненные данные будут утеряны.',
  147.       mtConfirmation, [mbYes, mbNo], 0) = mrYes;
  148.    MenuForm.Close;
  149.    ChangeMenuForm.Close;
  150.    AddForm.Close;
  151.    DeleteForm.Close;
  152.    ChangeForm.Close;
  153. end;
  154.  
  155. procedure TBaseForm.FormCreate(Sender: TObject);
  156. begin
  157.    Data.Cells[0, 0] := 'Тема';
  158.    Data.Cells[1, 0] := 'Фамилия';
  159.    Data.Cells[2, 0] := 'Кол-во страниц';
  160.    Data.Cells[3, 0] := 'Дата страниц';
  161. end;
  162.  
  163. procedure TBaseForm.FormShow(Sender: TObject);
  164. var
  165.    i: Integer;
  166. begin
  167.    Data.RowCount := n + 1;
  168.    for i := 0 to n - 1 do
  169.    begin
  170.       Data.Cells[0, i + 1] := Ref[i].Topic;
  171.       Data.Cells[1, i + 1] := Ref[i].Author;
  172.       Data.Cells[2, i + 1] := IntToStr(Ref[i].Str);
  173.       Data.Cells[3, i + 1] := Ref[i].Date;
  174.    end;
  175.    if n <> 0 then
  176.       Data.Rows[n + 1].Clear
  177.    else
  178.       Data.Rows[1].Clear;
  179. end;
  180.  
  181. procedure TBaseForm.AboutClick(Sender: TObject);
  182. var
  183.    Info: String;
  184. begin
  185.    Info := 'База данных о рефератах с возможностью редактирования' + #10#13 +
  186.    'Кнопка "Найти" показывает ведения о рефератах, написанных в текущем году с количеством страниц не более 20 в порядке дат написания '
  187.    + #10#13 + 'Автор - Пестунов Илья, гр. 051007';
  188.    MessageDlg(Info, mtInformation, [mbOK], 0);
  189. end;
  190.  
  191. procedure TBaseForm.UpdateClick(Sender: TObject);
  192. var
  193.    i: Integer;
  194. begin
  195.    BaseForm.Hide;
  196.    ChangeMenuForm.Show;
  197. end;
  198.  
  199. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement