ywry.pas

来自「完整的delphi书籍源代码,大家有空的时候自己慢慢看看」· PAS 代码 · 共 226 行

PAS
226
字号
unit YWRY;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ADODB, DB, Grids,RVClass,RVProj,RVCsStd, StdCtrls, DBGrids, DBCtrls, Mask, ExtCtrls,
  ComCtrls, RpCon, RpConDS, RpDefine, RpRave;

type
  TYWRYFrm = class(TForm)
    DataSource1: TDataSource;
    ADOTable1: TADOTable;
    ADOTable2: TADOTable;
    ADOTable3: TADOTable;
    ADOQuery1: TADOQuery;
    DataSource2: TDataSource;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    DBNavigator1: TDBNavigator;
    DBEdit1: TDBEdit;
    Button1: TButton;
    DBComboBox1: TDBComboBox;
    DBComboBox2: TDBComboBox;
    GroupBox3: TGroupBox;
    DBGrid1: TDBGrid;
    Button3: TButton;
    DBEdit2: TDBEdit;
    DBComboBox3: TDBComboBox;
    TabSheet2: TTabSheet;
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    Button2: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Button4: TButton;
    RadioButton3: TRadioButton;
    RadioButton4: TRadioButton;
    Edit3: TEdit;
    Edit4: TEdit;
    GroupBox2: TGroupBox;
    DBGrid2: TDBGrid;
    DBNavigator2: TDBNavigator;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TabSheet1Show(Sender: TObject);
    procedure TabSheet2Show(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  YWRYFrm: TYWRYFrm;

implementation

uses YPXX, Main;

{$R *.dfm}

procedure TYWRYFrm.Button1Click(Sender: TObject);
begin
    YWRYFrm.hide;
end;

procedure TYWRYFrm.FormCreate(Sender: TObject);
begin
   dbcombobox1.items.insert(-1,'男');
   dbcombobox1.items.insert(-1,'女');

   ADOtable2.first;
   while not ADOtable2.eof do
      begin
       dbcombobox2.items.insert(-1,ADOtable2.fieldbyname('BMMC').asstring);
       ADOtable2.Next;
      end;

   ADOtable3.first;
   while not ADOtable3.eof do
      begin
       dbcombobox3.items.insert(-1,ADOtable3.fieldbyname('ZWMC').asstring);
       ADOtable3.Next;
      end;

end;


procedure TYWRYFrm.TabSheet1Show(Sender: TObject);
var i:integer;
begin
  DBgrid1.Columns.Clear;
  for i:=1 to 6 do
    begin
      DBgrid1.Columns.add;
    end;
  DBgrid1.Columns[0].Width:=60;
  DBgrid1.Columns[1].Width:=60;
  DBgrid1.Columns[2].Width:=60;
  DBgrid1.Columns[3].Width:=60;
  DBgrid1.Columns[4].Width:=60;
  DBgrid1.Columns[5].Width:=100;
  DBgrid1.Columns[0].Title.caption:='人员编号';
  DBgrid1.Columns[1].Title.caption:='姓名';
  DBgrid1.Columns[2].Title.caption:='性别';
  DBgrid1.Columns[3].Title.caption:='所属部门';
  DBgrid1.Columns[4].Title.caption:='职务';
  DBgrid1.Columns[5].Title.caption:='联系电话';
  DBgrid1.Columns[0].FieldName:='RYBH';
  DBgrid1.Columns[1].FieldName:='RYXM';
  DBgrid1.Columns[2].FieldName:='RYXB';
  DBgrid1.Columns[3].FieldName:='RYBM';
  DBgrid1.Columns[4].FieldName:='RYZW';
  DBgrid1.Columns[5].FieldName:='LXDH';

end;

procedure TYWRYFrm.TabSheet2Show(Sender: TObject);
begin
  Radiobutton1.checked:=true;
  edit1.text:='';
  edit2.text:='';
  edit3.text:='';
  edit4.text:='';
  edit1.setfocus;

end;

procedure TYWRYFrm.Button4Click(Sender: TObject);
begin
   YWRYFrm.hide;
end;

procedure TYWRYFrm.Button2Click(Sender: TObject);
var query:string;
    i:integer;
begin
    query:='';   
    if Radiobutton1.checked=true then
       if edit1.text='' then
          showmessage('请输入相应查询条件')
       else
          query:='select * from YWRY where RYBH='+''''+edit1.text+'''';
    if Radiobutton2.checked=true then
       if edit2.text='' then
          showmessage('请输入相应查询条件')
       else
          query:='select * from YWRY where RYXM like'+''''+'%'+edit2.text+'%'+''''+'order by RYBH';
    if Radiobutton3.checked=true then
       if edit3.text='' then
          showmessage('请输入相应查询条件')
       else
          query:='select * from YWRY where RYBM like'+''''+'%'+edit3.text+'%'+''''+'order by RYBH';
    if Radiobutton4.checked=true then
       if edit4.text='' then
          showmessage('请输入相应查询条件')
       else
          query:='select * from YWRY where RYZW like'+''''+'%'+edit4.text+'%'+''''+'order by RYBH';
    
   if query<>'' then
    begin
    with ADOQuery1 do
     begin
       close;
       sql.clear;
       sql.add(query);
       open;
       first;
       if recordcount=0 then
          begin
          showmessage('对不起,没有符合条件的查询结果!请重新查询!');
          edit1.setfocus;
          end
       else
          begin
          DBgrid2.Columns.Clear;
          for i:=1 to 6 do
           begin
             DBgrid1.Columns.add;
           end;

         DBgrid2.Columns[0].Width:=60;
         DBgrid2.Columns[1].Width:=60;
         DBgrid2.Columns[2].Width:=60;
         DBgrid2.Columns[3].Width:=60;
         DBgrid2.Columns[4].Width:=60;
         DBgrid2.Columns[5].Width:=100;
         DBgrid2.Columns[0].Title.caption:='人员编号';
         DBgrid2.Columns[1].Title.caption:='姓名';
         DBgrid2.Columns[2].Title.caption:='性别';
         DBgrid2.Columns[3].Title.caption:='所属部门';
         DBgrid2.Columns[4].Title.caption:='职务';
         DBgrid2.Columns[5].Title.caption:='联系电话';

         DBgrid2.Columns[0].FieldName:='RYBH';
         DBgrid2.Columns[1].FieldName:='RYXM';
         DBgrid2.Columns[2].FieldName:='RYXB';
         DBgrid2.Columns[3].FieldName:='RYBM';
         DBgrid2.Columns[4].FieldName:='RYZW';
         DBgrid2.Columns[5].FieldName:='LXDH';

         end;
     end;
    end;     
end;

procedure TYWRYFrm.Button3Click(Sender: TObject);
begin
    MainFrm.RvProject1.Open;
    MainFrm.RvProject1.ExecuteReport('YWRYReport');
    MainFrm.RvProject1.Close;
end;

end.

⌨️ 快捷键说明

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