Unit1.pas
上传用户:autowell
上传日期:2022-06-21
资源大小:16754k
文件大小:3k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit Unit1;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB;
  6. type
  7.   TForm1 = class(TForm)
  8.     DataSource1: TDataSource;
  9.     ADOQuery1: TADOQuery;
  10.     DBGrid1: TDBGrid;
  11.     GroupBox1: TGroupBox;
  12.     RadioButton1: TRadioButton;
  13.     RadioButton2: TRadioButton;
  14.     RadioButton3: TRadioButton;
  15.     Label1: TLabel;
  16.     Button1: TButton;
  17.     Button2: TButton;
  18.     Label2: TLabel;
  19.     Edit1: TEdit;
  20.     Button3: TButton;
  21.     Button4: TButton;
  22.     procedure Button1Click(Sender: TObject);
  23.     procedure Button2Click(Sender: TObject);
  24.     procedure Button3Click(Sender: TObject);
  25.     procedure Button4Click(Sender: TObject);
  26.   private
  27.     { Private declarations }
  28.   public
  29.     { Public declarations }
  30.   end;
  31. var
  32.   Form1: TForm1;
  33. implementation
  34. uses Unit2;
  35. {$R *.dfm}
  36. procedure TForm1.Button1Click(Sender: TObject);
  37. begin
  38.     adoquery1.connection:=DataModule2.adoconnection1;//adoconnection1连接到库上,而 adoquery1连接到表上,把 adoconnection1单列出来,多个表单可以共享,不用每个表单都用一个
  39.     adoquery1.Active:=true;
  40. end;
  41. procedure TForm1.Button2Click(Sender: TObject);
  42. begin
  43.     Form1.close;
  44. end;
  45. procedure TForm1.Button3Click(Sender: TObject);
  46. begin
  47.     //adoquery1.connection:=DataModule2.adoconnection1;
  48.     //adoquery1.active:=true;
  49.     with adoquery1 do
  50.          begin
  51.            close;
  52.              with sql do
  53.                begin
  54.                  clear;
  55.                  add('select * from students where');
  56.                  if radiobutton1.Checked then
  57.                  add('学号=' + quotedstr(edit1.Text));
  58.                  if radiobutton2.Checked then
  59.                  add('姓名=' + quotedstr(edit1.Text));
  60.                  if radiobutton3.Checked then
  61.                  add('班级=' + quotedstr(edit1.Text));
  62.                end;
  63.                open;
  64.                adoquery1.Active:=true;
  65.          end;
  66.      if adoquery1.Eof then showmessage('呜呜,什么都没找到。');
  67.     
  68. end;
  69. procedure TForm1.Button4Click(Sender: TObject);
  70. var
  71.   strcustmerid:string;
  72.   strcommend1,strcommend2,strcommend3:string;
  73. begin
  74.     begin
  75.       strcustmerid:=trim(edit1.Text);
  76.       strcommend1:='学号 like ''%'+strcustmerid+'%''';
  77.       strcommend2:='姓名 like ''%'+strcustmerid+'%''';
  78.       strcommend3:='班级 like ''%'+strcustmerid+'%''';
  79.       with adoquery1 do
  80.          begin
  81.            close;
  82.              with sql do
  83.                begin
  84.                  clear;
  85.       add('select * from students where');
  86.                  if radiobutton1.Checked then
  87.                  add(strcommend1);
  88.                  if radiobutton2.Checked then
  89.                  add(strcommend2);
  90.                  if radiobutton3.Checked then
  91.                  add(strcommend3);
  92.                end;
  93.                open;
  94.                adoquery1.Active:=true;
  95.          end;
  96.        if adoquery1.Eof then showmessage('呜呜,什么都没找到。');
  97.    end;
  98. end;
  99. end.