SHARE
TWEET

Untitled

a guest Apr 8th, 2018 135 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unit SearchUnit;
  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.StdCtrls, Vcl.Buttons;
  8.  
  9. type
  10.   TSearch = class(TForm)
  11.     SearchingBox: TComboBox;
  12.     ToSearch: TEdit;
  13.     OkeyButton: TButton;
  14.     HelpButton: TBitBtn;
  15.     procedure ToSearchKeyPress(Sender: TObject; var Key: Char);
  16.     procedure OkeyButtonClick(Sender: TObject);
  17.     procedure SearchingBoxChange(Sender: TObject);
  18.     procedure ToSearchChange(Sender: TObject);
  19.     procedure FormKeyPress(Sender: TObject; var Key: Char);
  20.     procedure HelpButtonClick(Sender: TObject);
  21.     procedure ToSearchKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  22.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  23.   private
  24.     { Private declarations }
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29. var
  30.   Search: TSearch;
  31.   IndexArray: array of integer;
  32.  
  33. implementation
  34. uses
  35.    MainUnit, ShowUnit, EditUnit;
  36. {$R *.dfm}
  37.  
  38. procedure TSearch.FormClose(Sender: TObject; var Action: TCloseAction);
  39. begin
  40.    Anya.Enabled := true;
  41. end;
  42.  
  43. procedure TSearch.FormKeyPress(Sender: TObject; var Key: Char);
  44. begin
  45.    if Key = #27 then
  46.    begin
  47.       SearchingBox.ItemIndex := -1;
  48.       ToSearch.Clear;
  49.       Close;
  50.    end;
  51. end;
  52.  
  53. procedure TSearch.HelpButtonClick(Sender: TObject);
  54. const
  55.    Help = 'Для осуществления поиска записи выберите критерий поиска и введите запрос.';
  56. begin
  57.    MessageDlg(Help, mtInformation, [mbOk], 0);
  58. end;
  59.  
  60. procedure TSearch.OkeyButtonClick(Sender: TObject);
  61. var
  62.    s: string[1];
  63.    str: string[30];
  64.    i, j, k, index, indexArrLen: integer;
  65. begin
  66.    if SearchingBox.ItemIndex = 2 then
  67.    begin
  68.       str := ToSearch.Text;
  69.       s := str[1];
  70.       s := AnsiUpperCase(s);
  71.       str[1] := s[1];
  72.       for i := 2 to Length(str) do
  73.          if str[i] = ' ' then
  74.          begin
  75.             s := str[i + 1];
  76.             s := AnsiUpperCase(s);
  77.             str[i + 1] := s[1];
  78.          end;
  79.       ToSearch.Text := str;
  80.    end;
  81.    str := ToSearch.Text;
  82.    i := 1;
  83.    index := 1;
  84.    indexArrLen := 0;
  85.    with Anya.Table do
  86.       if ToEdit then
  87.       begin
  88.          for i := 1 to Anya.Table.RowCount do
  89.             if (Anya.Table.Cells[SearchingBox.ItemIndex, i] = str) then
  90.             begin
  91.                WhatEdit.ResultTable.Height := WhatEdit.ResultTable.Height + 41;
  92.                WhatEdit.ResultTable.RowCount := WhatEdit.ResultTable.RowCount + 1;
  93.                WhatEdit.ResultTable.FixedRows := 1;
  94.                for k := 0 to 4 do
  95.                   WhatEdit.ResultTable.Cells[k, index] := Anya.Table.Cells[k, i];
  96.                inc(indexArrLen);
  97.                SetLength(IndexArray,indexArrLen);
  98.                IndexArray[indexArrLen - 1] := i;
  99.                inc(index);
  100.             end;
  101.          WhatEdit.ResultTable.RowCount := WhatEdit.ResultTable.RowCount - 1;
  102.       end
  103.       else
  104.       begin
  105.          for i := 1 to Anya.Table.RowCount do
  106.             if (Anya.Table.Cells[SearchingBox.ItemIndex, i] = str) then
  107.             begin
  108.                WhatFound.ResultTable.Height := WhatFound.ResultTable.Height + 41;
  109.                WhatFound.ResultTable.RowCount := WhatFound.ResultTable.RowCount + 1;
  110.                WhatFound.ResultTable.FixedRows := 1;
  111.                for k := 0 to 4 do
  112.                   WhatFound.ResultTable.Cells[k, index] := Anya.Table.Cells[k, i];
  113.                inc(index);
  114.             end;
  115.       end;
  116.    SearchingBox.ItemIndex := -1;
  117.    ToSearch.Clear;
  118.    Close;
  119.    if index = 1 then
  120.       MessageDlg('Запись не найдена', mtError, [mbOk], 0)
  121.    else
  122.       if ToEdit then
  123.          EditUnit.WhatEdit.Show
  124.       else
  125.          ShowUnit.WhatFound.Show;
  126. end;
  127.  
  128. procedure TSearch.SearchingBoxChange(Sender: TObject);
  129. begin
  130.    if SearchingBox.Text = '' then
  131.    begin
  132.       ToSearch.Enabled := false;
  133.       OkeyButton.Enabled := false;
  134.    end
  135.    else
  136.       ToSearch.Enabled := true;
  137.    ToSearch.Clear;
  138. end;
  139.  
  140. procedure TSearch.ToSearchChange(Sender: TObject);
  141. begin
  142.    if Length(ToSearch.Text) > 0 then
  143.       OkeyButton.Enabled := true
  144.    else
  145.       OkeyButton.Enabled := false;
  146. end;
  147.  
  148. procedure TSearch.ToSearchKeyPress(Sender: TObject; var Key: Char);
  149. const
  150.    Numbers = ['0'..'9', #8];
  151.    Date = Numbers + ['.'];
  152. begin
  153.    if Key = #13 then
  154.       OkeyButtonClick(Sender);
  155.    if SearchingBox.ItemIndex = 0 then
  156.    begin
  157.       if (Length(ToSearch.Text) > 5) and (Key <> #8) then
  158.          Key := #0;
  159.       if not (Key in Numbers) then
  160.          Key := #0;
  161.    end;
  162.    if SearchingBox.ItemIndex = 1 then
  163.    begin
  164.       if (Length(ToSearch.Text) > 1) and (Key <> #8) then
  165.          Key := #0;
  166.       if not (Key in Numbers) then
  167.          Key := #0;
  168.    end;
  169.    if SearchingBox.ItemIndex = 2 then
  170.    begin
  171.       if not (((Key >= 'а') and (Key <= 'я')) or ((Key >= 'А') and (Key <= 'Я')) or (Key = ' ') or (Key = '.') or (Key = #8)) then
  172.          Key := #0;
  173.       if (Key = '.') and (Length(ToSearch.Text) = 0) then
  174.          Key := #0;
  175.       if (Length(ToSearch.Text) > 29) and (Key <> #8) then
  176.          Key := #0;
  177.    end;
  178.    if SearchingBox.ItemIndex = 3 then
  179.    begin
  180.       if (Key = '.') and (Length(ToSearch.Text) = 0) then
  181.          Key := #0;
  182.       if (Length(ToSearch.Text) = 2) and (Key <> #8) then
  183.       begin
  184.          ToSearch.Text := ToSearch.Text + '.';
  185.       end
  186.       else
  187.          if (Length(ToSearch.Text) = 5) and (Key <> #8) then
  188.          begin
  189.             ToSearch.Text := ToSearch.Text + '.';
  190.          end;
  191.       if ((not (Key in Date)) or ((Length(ToSearch.Text) > 9) and (Key <> #8))) then
  192.          Key := #0;
  193.    end;
  194.    if SearchingBox.ItemIndex = 4 then
  195.    begin
  196.       if ((Key <> 'м') and (Key <> 'ж') and (Key <> #8)) then
  197.             Key := #0;
  198.       if (Length(ToSearch.Text) > 0) and (Key <> #8) then
  199.          Key := #0;
  200.    end;
  201. end;
  202.  
  203. procedure TSearch.ToSearchKeyUp(Sender: TObject; var Key: Word;
  204.   Shift: TShiftState);
  205. begin
  206.    if SearchingBox.ItemIndex = 3 then
  207.       if (Length(ToSearch.Text) = 2) then
  208.       begin
  209.          ToSearch.Text := ToSearch.Text + '.';
  210.          ToSearch.SelStart := 4;
  211.       end
  212.       else
  213.          if (Length(ToSearch.Text) = 5) then
  214.          begin
  215.             ToSearch.Text := ToSearch.Text + '.';
  216.             ToSearch.SelStart := 7;
  217.          end;
  218. end;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top