📄 queryemployee.pas
字号:
unit QueryEmployee;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, QueryModul, DB, ADODB, Grids, DBGrids, ExtCtrls, ComCtrls,
ToolWin, StdCtrls, DBCtrls, RpDefine, RpRave, RpCon, RpConDS;
type
TfrmQueryEmployee = class(TfrmQueryModul)
aqryQueryEMPLOYEENO: TWideStringField;
aqryQueryEMPLOYEENAME: TWideStringField;
aqryQueryDEPARTMENTNAME: TWideStringField;
aqryQuerySEX: TWideStringField;
aqryQueryPOSTNAME: TWideStringField;
aqryQueryEMPLOYEEDATE: TDateTimeField;
aqryQueryWORKDATE: TDateTimeField;
lblDisp1: TLabel;
lblStart: TLabel;
lblEnd: TLabel;
lblDisp: TLabel;
dtpBegin: TDateTimePicker;
dtpEnd: TDateTimePicker;
cboxSelect: TComboBox;
edtCondition: TEdit;
dbcboxDepartment: TDBLookupComboBox;
dbcboxPost: TDBLookupComboBox;
aqryDepartment: TADOQuery;
aqryPost: TADOQuery;
dsDepartment: TDataSource;
dsPost: TDataSource;
rvpEmployee: TRvProject;
RvDataSetConnection1: TRvDataSetConnection;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure cboxSelectChange(Sender: TObject);
private
{ Private declarations }
protected
//以下定义的是虚函数,该虚函数在父类定义了,但是
//没有实现过程,它们即将在本单元实现
function funQuery() :integer; override;
function funSelect() :integer; override;
function funView() :integer; override;
function funExit() :integer; override;
public
{ Public declarations }
end;
var
frmQueryEmployee: TfrmQueryEmployee;
function gfunOpenQueryEmployee(var sEmployeeNo,sEmployeeName :string;
nState :integer) :integer;
implementation
uses DataModual, EmployeePrint;
var
usEmployeeNo,usEmployeeName :string;
{$R *.dfm}
//------------------------------------------------------------------
// sEmployeeNo 返回查询到的员工编号
// sEmployeeName 返回查询到的员工名称
// nState :表示打开表单是否允许选择一个员工,并且返回编号和名称;
// 当从主菜单进入查询界面时nState=0表示选择按钮变灰
// 当从员工维护界面进入查询界面时nState=1表示选择按钮可用
//------------------------------------------------------------------
function gfunOpenQueryEmployee(var sEmployeeNo,sEmployeeName :string;
nState :integer) :integer;
begin
frmQueryEmployee :=TfrmQueryEmployee.Create(nil);
if nState = 0 then
frmQueryEmployee.tbtnSelect.Enabled := False;
frmQueryEmployee.ShowModal ;
sEmployeeNo := usEmployeeNo;
sEmployeeName := usEmployeeName;
result :=0;
frmQueryEmployee.Free ;
end;
//查询函数
function TfrmQueryEmployee.funQuery() :integer;
var sqlString :string;
dtStart,dtEnd :TDateTime;
begin
if aqryQuery.Active then aqryQuery.Close;
aqryQuery.SQL.Clear ;
aqryQuery.SQL.Add('select EmployeeNo,EmployeeName,DepartmentName,Sex,');
aqryQuery.SQL.Add(' PostName,EmployeeDate,WorkDate ') ;
aqryQuery.SQL.Add('from Employee a, Department b, DCPost c');
aqryQuery.SQL.Add('where a.DepartmentNo=b.DepartmentNo and a.PostNo=c.PostNo (+)');
case cboxSelect.ItemIndex of
0 :begin //按编号查询
sqlString := ' and EmployeeNo like '+ ''''+ trim(edtCondition.Text)+'%'+'''';
end;
1 :begin //按姓名查询
sqlString := ' and EmployeeName like '+ ''''+ trim(edtCondition.Text)+'%'+'''';
end;
2 :begin //按岗位查询
if trim(dbcboxPost.Text) ='' then
begin
application.MessageBox('没有选择岗位','提示',mb_ok);
dbcboxPost.SetFocus ;
Result := -1;
exit;
end;
sqlString := ' and a.PostNo = '+ '''' + dbcboxPost.KeyValue +'''';
end;
3 :begin //按部门查询
if trim(dbcboxDepartment.Text) ='' then
begin
application.MessageBox('没有选择部门','提示',mb_ok);
dbcboxDepartment.SetFocus ;
Result := -1;
exit;
end;
sqlString := ' and a.DepartmentNo = '+ '''' + dbcboxDepartment.KeyValue +'''';
end;
4 :begin //按工作日期查询
sqlString := ' and WorkDate >= :dtStart and WorkDate <= :dtEnd' ;
end;
end;
aqryQuery.SQL.Add(sqlString);
if cboxSelect.ItemIndex = 4 then
begin
aqryQuery.Parameters.ParamByName('dtStart').Value := dtpBegin.DateTime ;
aqryQuery.Parameters.ParamByName('dtEnd').Value := dtpEnd.DateTime ;
end;
try
aqryQuery.Open;
except
application.MessageBox('检索员工出错','提示',MB_ok);
Result := -1;
exit;
end;
Result :=0;
end;
//选择函数
function TfrmQueryEmployee.funSelect() :integer;
begin
if not aqryQuery.Active then
begin
Result := 0;
exit;
end;
usEmployeeNo := aqryQuery.FieldByName('EmployeeNo').AsString ;
usEmployeeName := aqryQuery.FieldByName('EmployeeName').AsString ;
if usEmployeeNo='' then
begin
application.MessageBox('没有选择员工','提示',MB_ok);
Result := -1;
exit;
end;
Result :=0;
close;
end;
//预览函数
function TfrmQueryEmployee.funView() :integer;
begin
rvpEmployee.Execute ;
Result :=0;
end;
//退出函数
function TfrmQueryEmployee.funExit() :integer;
begin
close;
Result :=0;
end;
//表单初始化
procedure TfrmQueryEmployee.FormShow(Sender: TObject);
begin
inherited;
//将员工信息检索出来
if aqryQuery.Active then aqryQuery.Close ;
try
aqryQuery.Open;
except
application.MessageBox('检索员工出错','提示',MB_ok);
close;
end;
//打开其他数据集
if aqryDepartment.Active then aqryDepartment.Close ;
try
aqryDepartment.Open;
except
application.MessageBox('检索员工出错','提示',MB_ok);
close;
end;
if aqryPost.Active then aqryPost.Close ;
try
aqryPost.Open;
except
application.MessageBox('检索员工出错','提示',MB_ok);
close;
end;
//初始化界面
dtpBegin.DateTime := now();
dtpEnd.DateTime :=now();
dtpBegin.Visible :=False;
dtpEnd.Visible := False;
dbcboxDepartment.Visible :=False;
dbcboxPost.Visible := False;
lblEnd.Visible :=False;
lblStart.Visible := False;
cboxSelect.ItemIndex :=0; //设置按编号查询
end;
//表单关闭释放资源
procedure TfrmQueryEmployee.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
if aqryQuery.Active then aqryQuery.Close ;
if aqryDepartment.Active then aqryDepartment.Close ;
if aqryPost.Active then aqryPost.Close ;
end;
//当查询方式改变时界面动态变化
procedure TfrmQueryEmployee.cboxSelectChange(Sender: TObject);
begin
inherited;
case cboxSelect.ItemIndex of
0 :begin //按编号查询
dtpBegin.Visible :=False;
dtpEnd.Visible := False;
dbcboxDepartment.Visible := False;
dbcboxPost.Visible := False;
lblEnd.Visible := False;
lblStart.Visible := False;
lblDisp.Visible := True;
lblDisp.Caption := '请输入编号:';
edtCondition.Visible := True;
edtCondition.Text :='';
end;
1 :begin //按姓名查询
dtpBegin.Visible :=False;
dtpEnd.Visible := False;
dbcboxDepartment.Visible := False;
dbcboxPost.Visible := False;
lblEnd.Visible := False;
lblStart.Visible := False;
lblDisp.Visible := True;
lblDisp.Caption := '请输入姓名:';
edtCondition.Visible := True;
edtCondition.Text :='';
end;
2 :begin //按岗位查询
dtpBegin.Visible :=False;
dtpEnd.Visible := False;
dbcboxDepartment.Visible :=False;
dbcboxPost.Visible := True;
lblEnd.Visible :=False;
lblStart.Visible := False;
lblDisp.Visible := True;
lblDisp.Caption := '请选择岗位:';
edtCondition.Visible := False;
end;
3 :begin //按部门查询
dtpBegin.Visible :=False;
dtpEnd.Visible := False;
dbcboxDepartment.Visible := True;
dbcboxPost.Visible := False;
lblEnd.Visible :=False;
lblStart.Visible := False;
lblDisp.Visible := True;
lblDisp.Caption := '请选择部门:';
edtCondition.Visible := False;
end;
4 :begin //按工作日期查询
dtpBegin.Visible := True;
dtpEnd.Visible := True;
dbcboxDepartment.Visible :=False;
dbcboxPost.Visible := False;
lblEnd.Visible := True;
lblStart.Visible := True;
lblDisp.Visible := False;
edtCondition.Visible := False;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -