📄 emppay.~pas
字号:
unit emppay;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ToolWin, ComCtrls, StdCtrls, Buttons, DB, ADODB,Printers,
Grids, DBGrids;
type
TMyDBGrid=class(TDBGrid);
Temp_payForm = class(TForm)
StatusBar1: TStatusBar;
ToolBar1: TToolBar;
Panel1: TPanel;
Panel2: TPanel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
GroupBox1: TGroupBox;
ComboBox1: TComboBox;
GroupBox2: TGroupBox;
ClientButton1: TRadioButton;
ClientButton2: TRadioButton;
ClientButton3: TRadioButton;
ClientButton4: TRadioButton;
ClientButton5: TRadioButton;
ClientButton6: TRadioButton;
ClientButton7: TRadioButton;
ClientButton8: TRadioButton;
ClientButton9: TRadioButton;
ClientButton10: TRadioButton;
ClientButton11: TRadioButton;
ClientButton12: TRadioButton;
ClientButton13: TRadioButton;
ClientButton14: TRadioButton;
ClientButton15: TRadioButton;
ClientButton16: TRadioButton;
ClientButton17: TRadioButton;
ClientButton18: TRadioButton;
ClientButton19: TRadioButton;
ClientButton20: TRadioButton;
DataSource1: TDataSource;
aminallist: TADOQuery;
emppaylistsp: TADOStoredProc;
DBGrid1: TDBGrid;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ClientButton1Click(Sender: TObject);
procedure ClientButton2Click(Sender: TObject);
procedure ClientButton3Click(Sender: TObject);
procedure ClientButton4Click(Sender: TObject);
procedure ClientButton5Click(Sender: TObject);
procedure ClientButton6Click(Sender: TObject);
procedure ClientButton7Click(Sender: TObject);
procedure ClientButton8Click(Sender: TObject);
procedure ClientButton9Click(Sender: TObject);
procedure ClientButton10Click(Sender: TObject);
procedure ClientButton11Click(Sender: TObject);
procedure ClientButton12Click(Sender: TObject);
procedure ClientButton13Click(Sender: TObject);
procedure ClientButton14Click(Sender: TObject);
procedure ClientButton15Click(Sender: TObject);
procedure ClientButton16Click(Sender: TObject);
procedure ClientButton17Click(Sender: TObject);
procedure ClientButton18Click(Sender: TObject);
procedure ClientButton19Click(Sender: TObject);
procedure ClientButton20Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
private
{ Private declarations }
ClientId:integer;
procedure screport(Sender:Tobject);
Procedure OnMouseWheel(Var Msg :TMsg;var Handled:Boolean);
public
{ Public declarations }
end;
var
emp_payForm: Temp_payForm;
implementation
uses NumberManger;
{$R *.dfm}
Procedure Temp_payForm.OnMouseWheel(Var Msg :TMsg;var Handled:Boolean);
begin
if Msg.message = WM_MouseWheel then
begin
if Msg.wParam > 0 then
begin
if DBGrid1.Focused then
DataSource1.DataSet.Prior;
end
else
begin
if DBGrid1.Focused then
DataSource1.DataSet.Next;
end;
Handled:= True;
end;
end;
procedure Temp_payForm.screport(Sender: TObject);
begin
if combobox1.Text='' then
begin
application.MessageBox('请选择或录入期号!','系统提示',MB_ICONERROR);
combobox1.SetFocus;
end;
emppaylistsp.Close;
emppaylistsp.Parameters[1].value:=combobox1.Text;
emppaylistsp.Parameters[2].Value:=ClientId;
if radiobutton2.Checked then
emppaylistsp.Parameters[3].Value:=0
else
emppaylistsp.Parameters[3].Value:=1;
emppaylistsp.Prepared;
emppaylistsp.Open;
if emppaylistsp.RecordCount<1 then
begin
application.MessageBox('无相应客户操作信息,请重新选择客户!','系统提示',MB_ICONERROR);
end;
end;
procedure Temp_payForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
action:=cafree;
end;
procedure Temp_payForm.BitBtn2Click(Sender: TObject);
begin
close;
end;
procedure Temp_payForm.FormShow(Sender: TObject);
var
ClientBz:boolean;
begin
aminallist.Close;
aminallist.SQL.Clear;
aminallist.SQL.Add('select FClientid,FVisible from T_Client order by FClientid');
aminallist.Open;
if aminallist.RecordCount <1 then
begin
application.MessageBox('无客户信息,请设置客户信息!','系统提示',MB_ICONERROR);
close;
end
else
begin
while not aminallist.Eof do
begin
if aminallist.Fields[1].asboolean=true then
begin
if aminallist.Fields[0].value=1 then ClientButton1.Visible:=true;
if aminallist.Fields[0].value=2 then ClientButton2.Visible:=true;
if aminallist.Fields[0].value=3 then ClientButton3.Visible:=true;
if aminallist.Fields[0].value=4 then ClientButton4.Visible:=true;
if aminallist.Fields[0].value=5 then ClientButton5.Visible:=true;
if aminallist.Fields[0].value=6 then ClientButton6.Visible:=true;
if aminallist.Fields[0].value=7 then ClientButton7.Visible:=true;
if aminallist.Fields[0].value=8 then ClientButton8.Visible:=true;
if aminallist.Fields[0].value=9 then ClientButton9.Visible:=true;
if aminallist.Fields[0].value=10 then ClientButton10.Visible:=true;
if aminallist.Fields[0].value=11 then ClientButton11.Visible:=true;
if aminallist.Fields[0].value=12 then ClientButton12.Visible:=true;
if aminallist.Fields[0].value=13 then ClientButton13.Visible:=true;
if aminallist.Fields[0].value=14 then ClientButton14.Visible:=true;
if aminallist.Fields[0].value=15 then ClientButton15.Visible:=true;
if aminallist.Fields[0].value=16 then ClientButton16.Visible:=true;
if aminallist.Fields[0].value=17 then ClientButton17.Visible:=true;
if aminallist.Fields[0].value=18 then ClientButton18.Visible:=true;
if aminallist.Fields[0].value=19 then ClientButton19.Visible:=true;
if aminallist.Fields[0].value=20 then ClientButton20.Visible:=true;
ClientBz:=true;
end;
aminallist.Next;
end;
end;
if not ClientBz then
begin
application.MessageBox('无可用的客户信息,请设置客户信息!','系统提示',MB_ICONERROR);
//close;
end;
aminallist.Close;
aminallist.SQL.Clear;
aminallist.SQL.Add('select * from T_SalePeriod ');
aminallist.Open;
if aminallist.RecordCount>0 then
begin
combobox1.Items.Clear;
while not aminallist.Eof do
begin
combobox1.Text:=aminallist.Fields[0].value;
combobox1.Items.Add(aminallist.Fields[0].value);
aminallist.Next;
end;
end;
aminallist.Close;
end;
procedure Temp_payForm.ClientButton1Click(Sender: TObject);
begin
ClientId:=1;
{ if radiobutton2.Checked then
begin
dbgrid1.
DBGrid1.Columns[5].Visible:=false;
DBGrid1.Columns[6].Visible:=false;
DBGrid1.Columns[7].Visible:=false;
DBGrid1.Columns[8].Visible:=false;
DBGrid1.Columns[9].Visible:=false;
DBGrid1.Columns[10].Visible:=false;
end
else
begin
DBGrid1.Columns[5].Visible:=true;
DBGrid1.Columns[6].Visible:=true;
DBGrid1.Columns[7].Visible:=true;
DBGrid1.Columns[8].Visible:=true;
DBGrid1.Columns[9].Visible:=true;
DBGrid1.Columns[10].Visible:=true;
end; }
screport(Sender);
end;
procedure Temp_payForm.ClientButton2Click(Sender: TObject);
begin
ClientId:=2;
screport(Sender);
end;
procedure Temp_payForm.ClientButton3Click(Sender: TObject);
begin
ClientId:=3;
screport(Sender);
end;
procedure Temp_payForm.ClientButton4Click(Sender: TObject);
begin
ClientId:=4;
screport(Sender);
end;
procedure Temp_payForm.ClientButton5Click(Sender: TObject);
begin
ClientId:=5;
screport(Sender);
end;
procedure Temp_payForm.ClientButton6Click(Sender: TObject);
begin
ClientId:=6;
screport(Sender);
end;
procedure Temp_payForm.ClientButton7Click(Sender: TObject);
begin
ClientId:=7;
screport(Sender);
end;
procedure Temp_payForm.ClientButton8Click(Sender: TObject);
begin
ClientId:=8;
screport(Sender);
end;
procedure Temp_payForm.ClientButton9Click(Sender: TObject);
begin
ClientId:=9;
screport(Sender);
end;
procedure Temp_payForm.ClientButton10Click(Sender: TObject);
begin
ClientId:=10;
screport(Sender);
end;
procedure Temp_payForm.ClientButton11Click(Sender: TObject);
begin
ClientId:=11;
screport(Sender);
end;
procedure Temp_payForm.ClientButton12Click(Sender: TObject);
begin
ClientId:=12;
screport(Sender);
end;
procedure Temp_payForm.ClientButton13Click(Sender: TObject);
begin
ClientId:=13;
screport(Sender);
end;
procedure Temp_payForm.ClientButton14Click(Sender: TObject);
begin
ClientId:=14;
screport(Sender);
end;
procedure Temp_payForm.ClientButton15Click(Sender: TObject);
begin
ClientId:=15;
screport(Sender);
end;
procedure Temp_payForm.ClientButton16Click(Sender: TObject);
begin
ClientId:=16;
screport(Sender);
end;
procedure Temp_payForm.ClientButton17Click(Sender: TObject);
begin
ClientId:=17;
screport(Sender);
end;
procedure Temp_payForm.ClientButton18Click(Sender: TObject);
begin
ClientId:=18;
screport(Sender);
end;
procedure Temp_payForm.ClientButton19Click(Sender: TObject);
begin
ClientId:=19;
screport(Sender);
end;
procedure Temp_payForm.ClientButton20Click(Sender: TObject);
begin
ClientId:=20;
screport(Sender);
end;
procedure Temp_payForm.BitBtn1Click(Sender: TObject);
const
LeftBlank=1;//定义页边距单位厘米
RightBlank=1;
TopBlank=2;
BottomBlank=3;
var
PointX,PointY,lx,ly:integer;
PointScale,PrintStep:integer;
s:string;
x,y,y1:integer;
i,j:integer;
print_ti:boolean;
comno:string;
begin
print_ti:=false;
comno:='hl00';
//获取当前打印机的分辨率
PointX:=Trunc(GetDeviceCaps(Printer.Handle,LOGPIXELSX)/2.54);
PointY:=Trunc(GetDeviceCaps(Printer.Handle,LOGPIXELSY)/2.54);
//根据打印机和屏幕的分辨率计算出从屏幕转换到打印机的比例
PointScale:=Trunc(GetDeviceCaps(Printer.Handle,LOGPIXELSX)/Screen.PixelsPerInch+0.5);
j:=0;
//横向打印
for i:=0 to DBGrid1.FieldCount-1 do
begin
if DBGrid1.Columns[i].Visible then
begin
j:=j+1;
end;
end;
if j<10 then
printer.Orientation:=poPortrait
else
printer.Orientation:=poLandscape;
//打印的字体和大小
printer.Canvas.Font.Name:='宋体';
printer.canvas.Font.Size:=10;
//根据字体的大小确定每行的高度
s:='有限公司';
PrintStep:=printer.canvas.TextHeight(s)+26;
//打印的起点位置
x:=PointX*LeftBlank;
y:=PointY*TopBlank;
ly:=PointY*TopBlank+100;
//DataSource1是DBGrid1所连接的数据源
if ((DataSource1.DataSet).Active=true) and ((DataSource1.DataSet).RecordCount>0) then
begin
printer.BeginDoc;
(DataSource1.DataSet).First;
while not (DataSource1.DataSet).Eof do
begin //打印DBGrid中的所有列
for i:=0 to DBGrid1.FieldCount-1 do
begin
if DBGrid1.Columns[i].Visible then
begin
//假如所要打印的列超出了打印范围,则忽略该列
if (x+DBGrid1.Columns.Items[i].Width*PointScale)<=(Printer.PageWidth-PointX*RightBlank)then
begin //画表格线
//**打印标题**//
if y=PointY*TopBlank then
begin
if not print_ti then
begin
printer.Canvas.Font.Name:='宋体';
printer.canvas.Font.Size:=18;
comno:=' 员工工资明细表 ' ;
Printer.Canvas.TextOut(x+60,y-160,comno);
printer.Canvas.Font.Name:='宋体';
printer.canvas.Font.Size:=12;
comno:=' 打印时间:'+DateToStr(Date);
Printer.Canvas.TextOut(x,y-20,comno);
print_ti:=true;
y:=y+100;
end;
end;
Printer.Canvas.Rectangle(x,y-8,x+DBGrid1.Columns.Items[i].Width*PointScale,y+PrintStep);
if y=ly then
begin
printer.Canvas.Font.Name:='宋体';
printer.canvas.Font.Size:=14;
Printer.Canvas.TextOut(x+8,y,DBGrid1.Columns[i].Title.Caption);
end
else
begin
printer.Canvas.Font.Color:=DBGrid1.Canvas.Font.Color;
//printer.Canvas.Font.Color:=DBGrid1.Columns.Items[i].Font.Color;
printer.Canvas.Font.Name:='宋体';
printer.canvas.Font.Size:=14;
Printer.Canvas.TextOut(x+8,y,DBGrid1.Fields[i].asString);
end;
end;
//计算下一列的横坐标
x:=x+DBGrid1.Columns.Items[i].Width*PointScale;
end;
end;
//if not (y=PointY*TopBlank) then (DataSource1.DataSet).next;
if not (y=ly) then (DataSource1.DataSet).next;
x:=PointX*LeftBlank;
y:=y+PrintStep; //换页
if (y+PrintStep)>(Printer.PageHeight-PointY*BottomBlank) then
begin
Printer.NewPage;
y:=PointY*TopBlank;
print_ti:=false;
end;
end;
printer.Canvas.Font.Name:='宋体';
printer.canvas.Font.Size:=12;
comno:='共'+IntToStr(emppaylistsp.RecordCount)+'条记录';
Printer.Canvas.TextOut(x+60,y+60,comno);
printer.EndDoc;
Application.MessageBox('打印完成','打印',32);
(DataSource1.DataSet).First;
end ;
end;
procedure Temp_payForm.FormCreate(Sender: TObject);
begin
Application.OnMessage:=OnMouseWheel; // 截获鼠标滚动事件
end;
procedure Temp_payForm.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
with TMyDBGrid(Sender) do
begin
if (emppaylistsp.Fields[3].value='中奖') then
begin
(Sender as TDBGrid).Canvas.Brush.Color := RGB(191, 255, 223); //定义背景颜色
(Sender as TDBGrid).Canvas.Font.Color:=clRed;
end
else
begin
(Sender as TDBGrid).Canvas.Brush.Color := RGB(191, 255, 223); //定义背景颜色
(Sender as TDBGrid).Canvas.Font.Color:=clBlue;
end;
DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -