Advertisement
Guest User

Untitled

a guest
Jun 15th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.76 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, Menus, StdCtrls, ComCtrls, uMySqlVio, uMysqlCT, uMysqlClient, uMysqlHelpers ;
  8.  
  9. type
  10.   TReachedit = class(TForm)
  11.     Label1: TLabel;
  12.     Label2: TLabel;
  13.     RichEdit1: TRichEdit;
  14.     ListBox1: TListBox;
  15.     ListBox2: TListBox;
  16.     Edit1: TEdit;
  17.     Edit2: TEdit;
  18.     Button1: TButton;
  19.     Button2: TButton;
  20.     procedure FormCreate(Sender: TObject);
  21.     procedure FormDestroy(Sender: TObject);
  22.     procedure ListBox1Click(Sender: TObject);
  23.     procedure ListBox2Click(Sender: TObject);
  24.     procedure Button1Click(Sender: TObject);
  25.     procedure Button2Click(Sender: TObject);
  26.   private
  27.     { Private declarations }
  28.   public
  29.     { Public declarations }
  30.   end;
  31.  
  32. var
  33.   Reachedit: TReachedit;
  34.   MySQLClient: TMySQLClient;
  35.   MySQLResult: TMysqlResult;
  36.  
  37. implementation
  38.  
  39. {$R *.dfm}
  40.  
  41. procedure TReachedit.FormCreate(Sender: TObject);
  42. var
  43.  ok :boolean;
  44.  i: integer;
  45.  query1: string;
  46. begin
  47.   MySQLClient := TMySQLClient.Create;
  48.   RichEdit1.Enabled := false;
  49.   Edit1.Enabled := false;
  50.   Edit2.Enabled := false;
  51.   RichEdit1.Clear;
  52.   MySQLClient.Host := '127.0.0.1';
  53.   MySQLClient.port := 3306;
  54.   MySQLClient.user := 'root';
  55.   MySQLClient.password := '';
  56.   MySQLClient.UnixSocket := '';
  57.   MySQLClient.Db := 'referats';
  58.   MySQLClient.UseNamedPipe := false;
  59.   MySQLClient.UseSSL := false;
  60.   MySQLClient.Compress := false;
  61.   MySQLClient.TrySockets := false;
  62.  
  63.   if MySQLClient.Connect then ShowMessage('База данных успешно подключена');
  64.   i:=1;
  65.   repeat
  66.      begin
  67.        query1 := Format('SELECT * FROM predmet WHERE id = %d', [i]);
  68.        MySQLResult := MySQLClient.Query(query1, True,ok);
  69.        ListBox1.Items.Add(MySQLResult.FieldValueByName('name'));
  70.        i:=i+1;
  71.      end;
  72.   until MySQLResult.FieldValueByName('id') = nil;
  73.   ListBox1.Items.Delete(i-2);
  74. end;
  75.  
  76. procedure TReachedit.FormDestroy(Sender: TObject);
  77. begin
  78.  
  79.   MySQLClient.Free;
  80.   if MySQLResult <> nil then
  81.   MySQLResult.Free;
  82. end;
  83.  
  84. procedure TReachedit.ListBox1Click(Sender: TObject);
  85. var
  86.  ok :boolean;
  87.  i,j: integer;
  88.  query1 : string;
  89. begin
  90.  
  91.   ListBox2.Clear;
  92.   i:=1;
  93.  
  94.   repeat
  95.     begin
  96.  
  97.        query1 := Format('SELECT * FROM documents WHERE id_p = %d and id_n = %d', [ListBox1.Itemindex+1,i]);
  98.  
  99.        MySQLResult := MySQLClient.Query(query1, True,ok);
  100.        if MySQLResult.FieldValueByName('name') <> nil then
  101.        ListBox2.Items.Add(MySQLResult.FieldValueByName('name'));
  102.        i:=i+1;
  103.      end;
  104.   until (i>10) ;
  105.   ListBox2.Items.Delete(i-1);
  106. end;
  107.  
  108. procedure TReachedit.ListBox2Click(Sender: TObject);
  109. var
  110.  ok :boolean;
  111.  i,j: integer;
  112.  query1, location : string;
  113. begin
  114.   RichEdit1.Clear;
  115.   query1 := Format('SELECT * FROM documents WHERE id_p = %d and id_n = %d', [ListBox1.Itemindex+1,ListBox2.Itemindex+1]);
  116.   MySQLResult := MySQLClient.Query(query1, True,ok);
  117.   location := 'C:/wamp/www/'+MySQLResult.FieldValueByName('link');
  118.   RichEdit1.Lines.LoadFromFile(location);
  119.   Edit2.Text := MySQLResult.FieldValueByName('name');
  120.   query1 := Format('SELECT * FROM predmet WHERE id = %d', [ListBox1.Itemindex+1]);
  121.   MySQLResult := MySQLClient.Query(query1, True,ok);
  122.   Edit1.Text := MySQLResult.FieldValueByName('name');
  123.   Button1.Enabled := true;
  124. end;
  125.  
  126. procedure TReachedit.Button1Click(Sender: TObject);
  127. begin
  128.   RichEdit1.Enabled := true;
  129.   Edit1.Enabled := true;
  130.   Edit2.Enabled := true;
  131.   ListBox1.Enabled:=false;
  132.   ListBox2.Enabled:=false;
  133.   Button2.Enabled:=true;
  134. end;
  135.  
  136. procedure TReachedit.Button2Click(Sender: TObject);
  137. begin
  138.   RichEdit1.Enabled := false;
  139.   Edit1.Enabled := false;
  140.   Edit2.Enabled := false;
  141.   ListBox1.Enabled:=true;
  142.   ListBox2.Enabled:=true;
  143.   Button2.Enabled:=false;
  144. end;
  145.  
  146. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement