⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 query.pas

📁 一个用Delphi做的不错的学生宿舍管理系统!界面比前一个好看!
💻 PAS
字号:
unit query;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ComCtrls, StdCtrls, Grids, jpeg, XPMenu;

type
  TQueryForm = class(TForm)
    GroupBox1: TGroupBox;
    Query: TPageControl;
    XNQuery: TTabSheet;
    XHQuery: TTabSheet;
    JZQuery: TTabSheet;
    PJQuery: TTabSheet;
    GroupBox2: TGroupBox;
    Image1: TImage;
    GroupBox3: TGroupBox;
    GroupBox4: TGroupBox;
    GroupBox5: TGroupBox;
    GroupBox6: TGroupBox;
    Panel1: TPanel;
    Label1: TLabel;
    XHQEdit: TEdit;
    Button1: TButton;
    StringGrid1: TStringGrid;
    Panel2: TPanel;
    StringGrid2: TStringGrid;
    Panel3: TPanel;
    StringGrid3: TStringGrid;
    Panel4: TPanel;
    StringGrid4: TStringGrid;
    Label2: TLabel;
    Button2: TButton;
    Label3: TLabel;
    JTGZEdit: TEdit;
    Button3: TButton;
    Label4: TLabel;
    PJEdit: TEdit;
    Button4: TButton;
    FHQuery: TTabSheet;
    GroupBox7: TGroupBox;
    StringGrid5: TStringGrid;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label10: TLabel;
    XHEdit: TEdit;
    XNEdit: TEdit;
    XPEdit: TComboBox;
    YXEdit: TDateTimePicker;
    Panel5: TPanel;
    Button5: TButton;
    Button6: TButton;
    JYEdit: TComboBox;
    NameEdit: TEdit;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    ComboBox3: TComboBox;
    ComboBox4: TComboBox;
    FMLEdit: TEdit;
    ComboBox5: TComboBox;
    XPMenu1: TXPMenu;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  QueryForm: TQueryForm;

implementation
Uses MD;
{$R *.dfm}
var
Qstr1:string;
// 以下判断是否为空相应的对话框
function isempty(Sender:TObject):boolean;
begin
if trim((sender as Tedit).Text)='' then
result:=true
else
result:=false;
end;
//以下是查询相应的记录
procedure QueryPD(Sender:TObject;Qstr:string);
var
I:integer;
begin
with DataMd.ADOOrder do
begin
  close;
  sql.Clear;
  sql.Add('select * from TBorder '+Qstr);
  open;
   for i:=0 to fieldcount-1 do
    begin
    (sender as TstringGrid).Cells[i,0]:=fields[i].FieldName;
    end;
 if recordcount>0 then
    begin
    first;
      while not Eof do
        begin
           for i:=0 to fieldcount-1 do
             begin
             (sender as TstringGrid).Cells[i,1]:=fields[i].AsString;
              end;
           next;
        end;
    end
    else
    showmessage('没有该姓名的学生,请重新输入再查询');
 end;
end;

procedure TQueryForm.Button1Click(Sender: TObject);
begin
//查询学号
Qstr1:='';
if trim(xhqedit.Text)<>'' then
Qstr1:='where 学号 like ''%'+Trim(xhqedit.Text)+'%'''
else
Qstr1:='where false';
QueryPd(StringGrid1,Qstr1);
end;

procedure TQueryForm.Button2Click(Sender: TObject);
begin
//可以实现模糊查询与精确查询
Qstr1:='';
if trim(NameEdit.Text)<>''
then
Qstr1:='where 姓名 like ''%'+Trim(nameedit.Text)+'%'''
else
Qstr1:=' where false';
QueryPd(StringGrid2,Qstr1);
end;

procedure TQueryForm.Button3Click(Sender: TObject);
begin
//查询家庭地址
Qstr1:='';
if Trim(jtgzedit.Text)<>'' then
Qstr1:=' where 家庭地址 like ''%'+Trim(JTGZEdit.Text)+'%'''
else
Qstr1:='where false';
QueryPd(StringGrid3,Qstr1);
end;

procedure TQueryForm.Button4Click(Sender: TObject);
begin
//查询班级
Qstr1:='';
if trim(pjedit.Text)<>'' then
Qstr1:=' where 班级 like ''%'+Trim(PJedit.Text)+'%'''
else
Qstr1:=' where false';
QueryPd(StringGrid4,Qstr1);
end;

procedure TQueryForm.Button5Click(Sender: TObject);
begin
//混合学号
Qstr1:='';
if isempty(xhedit) then
combobox1.Text:='';
if isempty(xnedit) then
combobox2.Text:='';
if isempty(fmledit) then
combobox5.Text:='';
if  Trim(XHEdit.Text)<>'' then  //选择学号
   Qstr1:=' where 学号='''+trim(XHedit.Text)+''' '
   else
   Qstr1:='';
if (trim(XNEdit.Text)<>'') and (Qstr1<>'') then  //选择姓名
   Qstr1:=Qstr1+combobox1.Text+' 姓名='''+trim(Xnedit.Text)+''' '
   else
   begin
   if Trim(Qstr1)='' then
   Qstr1:='where 姓名='''+trim(Xnedit.Text)+''' ';
   if Trim(xpedit.Text)='' then
   Qstr1:=Qstr1;
   end;
if (trim(xpedit.Text)<>'') and (Qstr1<>'') then //选择
   Qstr1:=Qstr1+combobox2.text+' 性别='''+trim(Xpedit.Text)+''' '
   else
   begin
   if Trim(Qstr1)='' then
   Qstr1:='where 性别='''+trim(XPedit.Text)+''' ';
   if Trim(JYedit.Text)='' then
   Qstr1:=Qstr1;
   end;
if (trim(Jyedit.Text)<>'') and (Qstr1<>'') then    //选择性别
   Qstr1:=Qstr1+combobox3.text+' 专业='''+trim(jyedit.Text)+''' '
   else
   begin
   if Trim(Qstr1)='' then
   Qstr1:='where 专业='''+trim(JYedit.Text)+''' ';
   if Trim(FMLEdit.Text)='' then
   Qstr1:=Qstr1;
   end;
if (trim(FMLedit.Text)<>'') and (Qstr1<>'') then    //选择性别
   Qstr1:=Qstr1+combobox4.text+' 家庭地址='''+trim(FMLEdit.Text)+''' '
   else
   begin
   if Trim(Qstr1)='' then
   Qstr1:='where 家庭地址='''+trim(FMLEdit.Text)+''' ';
   if Trim(datetimetostr(YXedit.DateTime))='' then
   Qstr1:=Qstr1;
   end;
if (Qstr1<>'') and (combobox5.text='') then                                  //选择日期
   Qstr1:=Qstr1+combobox4.text+' 入学日期='+datetostr(yxedit.DateTime)
   else
   begin
   if Qstr1='' then
   Qstr1:=' where  入学日期='+datetostr(yxedit.DateTime)
   else
   Qstr1:=Qstr1+combobox5.text+' 入学日期='+datetostr(yxedit.DateTime);
   end;
   QueryPd(StringGrid5,Qstr1);
end;

procedure TQueryForm.Button6Click(Sender: TObject);
begin
close;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -