📄 uviewrecord.pas
字号:
unit UViewRecord;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGridEh, Buttons, dbgridehimpexp, StdCtrls;
type
TForm_ViewRecord = class(TForm)
DBGridViewRecord: TDBGridEh;
ADOQViewRecord: TADOQuery;
SBOutput: TSpeedButton;
SBAllDelete: TSpeedButton;
SBDelete: TSpeedButton;
SBClose: TSpeedButton;
DS9: TDataSource;
SpeedButton1: TSpeedButton;
procedure SBCloseClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure SBOutputClick(Sender: TObject);
procedure SBDeleteClick(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SBAllDeleteClick(Sender: TObject);
private
{ Private declarations }
selectTabel:string;
public
{ Public declarations }
end;
var
Form_ViewRecord: TForm_ViewRecord;
implementation
uses Umain;
{$R *.dfm}
procedure TForm_ViewRecord.SBCloseClick(Sender: TObject);
begin
close;
end;
procedure TForm_ViewRecord.FormShow(Sender: TObject);
begin
selectTabel:='';
//查看家庭成员记录
if Form_ViewRecord.Caption = '家庭成员' then
begin
try
with ADOQViewRecord do
begin
close;
sql.Clear;
sql.Text := 'select Family_EmployeeID as 职工编号, Family_Name as 成员姓名,Family_Birthday as 出生日期,Family_Work as 工作单位,Family_Role as 担任职务,Family_polity as 政治面貌,Family_Connection as 关系,Family_Tel as 电话 From Family';
open;
end;
except
beep;
showmessage('打开家庭成员表失败,请检查数据库是否存在');
end;
selectTabel:='From family';
exit;
end;
//查看培训记录
if Form_ViewRecord.Caption = '培训记录' then
begin
try
with ADOQViewRecord do
begin
close;
sql.Clear;
sql.Text := 'select Cultivate_EmployeeID as 职工编号,Cultivate_Speciality as 培训专业,';
sql.Text := sql.text + 'Cultivate_Mode as 培训方式,Cultivate_StartDate as 开始日期,Cultivate_StopDate as 结束日期,Cultivate_Corp as 培训单位,Cultivate_Outlay as 培训经费,Cultivate_Result as 培训结果 From Cultivate';
open;
end;
except
beep;
showmessage('打开培训记录表失败,请检查数据库是否存在');
end;
selectTabel:='From Cultivate';
exit;
end;
//查看奖惩记录
if Form_ViewRecord.Caption = '奖惩记录' then
begin
try
with ADOQViewRecord do
begin
close;
sql.Clear;
sql.Text := 'select AP_EmployeeID as 职工编号, AP_Type as 奖惩类型,AP_FirstDept as 一级部门,';
sql.text := sql.text + 'AP_SecondDept as 二级部门,AP_StartDate as 奖惩日期, AP_StartExplain as 奖惩原因,AP_StopDate as 解除日期,AP_StopExplain as 解除原因 From AwardAndPenalize';
open;
end;
except
beep;
showmessage('打开奖惩记录表失败,请检查数据库是否存在');
end;
selectTabel:='From AwardAndPenalize';
exit;
end;
//查看请假记录
if Form_ViewRecord.Caption = '请假记录' then
begin
try
with ADOQViewRecord do
begin
close;
sql.Clear;
sql.Text := 'select Leave_EmployeeID as 职工编号,Leave_Type as 请假类型,Leave_Explain as 请假原因,Leave_StartDate as 开始日期,Leave_StopDate as 结束日期 From Leave';
open;
end;
except
beep;
showmessage('打开请假表失败,请检查数据库是否存在');
end;
selectTabel:='From Leave';
exit;
end;
//查看调动记录
if Form_ViewRecord.Caption = '调动记录' then
begin
try
with ADOQViewRecord do
begin
close;
sql.Clear;
sql.Text := 'select MT_EmployeeID as 职工编号,MT_OldFirstDept as 调动前一级部门,MT_OldSecondDept as 调动前二级部门,';
sql.Text := sql.Text + 'MT_NewFirstDept as 调动后一级部门,MT_NewSecondDept as 调动后二级部门,MT_Explain as 调动理由,MT_Date as 调动日期,MT_OlePay as 调动前薪资,MT_NewPay as 调动后薪资 From MoveTo';
open;
end;
except
beep;
showmessage('打开调动表失败,请检查数据库是否存在');
end;
selectTabel:='From MoveTo';
exit;
end;
//查看工作单位
if Form_ViewRecord.Caption = '工作单位' then
begin
try
with ADOQViewRecord do
begin
close;
sql.Clear;
sql.Text := 'select WS_EmployeeID as 职工编号,WS_StartDate as 开始日期,WS_StopDate as 结束日期,';
sql.text := sql.text + 'WS_Corp as 工作单位,WS_Dept as 工作部门,WS_Role as 担任职务 From WorkStoy';
open;
end;
except
beep;
showmessage('打开工作单位表失败,请检查数据库是否存在');
end;
selectTabel:='From WorkStoy';
exit;
end;
end;
procedure TForm_ViewRecord.SBOutputClick(Sender: TObject);
var ExpClass: TDBGridEhExportClass;
Ext: string;
begin
if ADOQViewRecord.RecordCount = 0 then
begin
beep;
showmessage('当前没有任何记录!');
exit;
end;
Form_main.SaveDialog1.FileName := 'file1';
if Form_main.SaveDialog1.Execute then
begin
case Form_main.SaveDialog1.FilterIndex of
1: begin ExpClass := TDBGridEhExportAsText; Ext := 'txt'; end;
2: begin ExpClass := TDBGridEhExportAsCSV; Ext := 'csv'; end;
3: begin ExpClass := TDBGridEhExportAsHTML; Ext := 'htm'; end;
4: begin ExpClass := TDBGridEhExportAsRTF; Ext := 'rtf'; end;
5: begin ExpClass := TDBGridEhExportAsXLS; Ext := 'xls'; end;
else
ExpClass := nil; Ext := '';
end;
if ExpClass <> nil then
begin
if UpperCase(Copy(Form_main.SaveDialog1.FileName, Length(Form_main.SaveDialog1.FileName) - 2, 3)) <>
UpperCase(Ext) then
Form_main.SaveDialog1.FileName := Form_main.SaveDialog1.FileName + '.' + Ext;
SaveDBGridEhToExportFile(ExpClass, DBGridViewRecord,
Form_main.SaveDialog1.FileName, true);
end;
end;
exit;
end;
procedure TForm_ViewRecord.SBDeleteClick(Sender: TObject);
begin
if ADOQViewRecord.RecordCount = 0 then
begin
beep;
showmessage('当前没有记录');
exit;
end;
try
if ((MessageDlg('您确定要删除此记录吗?', mtConfirmation,
[mbYes, mbNo], 0)) = mrYes) then
begin
ADOQViewRecord.Delete;
end;
except
beep;
showmessage('删除失败');
end;
end;
procedure TForm_ViewRecord.SpeedButton1Click(Sender: TObject);
var cc, i: integer;
begin
//设置表格列的宽度
cc := DBGridViewRecord.Columns.Count - 1;
//职工编号宽50;
DBGridViewRecord.Columns[0].Width := 65;
//其它的字段宽85;
for i := 1 to cc do
DBGridViewRecord.Columns[i].Width := 100;
end;
procedure TForm_ViewRecord.SBAllDeleteClick(Sender: TObject);
begin
if ADOQViewRecord.RecordCount = 0 then
begin
beep;
showmessage('当前没有记录');
exit;
end;
try
if ((MessageDlg('您确定要删除全部记录吗?', mtConfirmation,
[mbYes, mbNo], 0)) = mrYes) then
begin
with ADOQViewRecord do
begin
close;
sql.Clear;
sql.Text:='delete '+selectTabel;
// showmessage(sql.Text);
execsql;
end;
end;
except
beep;
showmessage('删除失败');
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -