怎样预览、打印工资条?(100分)

  • 主题发起人 主题发起人 jbas
  • 开始时间 开始时间
J

jbas

Unregistered / Unconfirmed
GUEST, unregistred user!
我用的是devexpress的控件(dxdbgrid和dxComponentPrinter),请问怎样打印,预览工资条
每条工资条上都有各个字段和本人的各个信息。
 
DevExpress Printing System
ftp://ftp.xxtax.gov.cn/delphi/eps22.rar
它的原理是建立一个ReportLink,把Dev的屏幕控件发往打印机,Cool极了,就是中文支持
不是很好。
 
老兄,我有那个控件,用的是devexpress的控件(dxdbgrid和dxComponentPrinter),请问怎样打印,预览工资条
每条工资条上都有各个字段和本人的各个信息??
quickreport能实现(看到过),但这个我不会。
 
好像不行吧,工资条每张都要有科目明细。
还是用QR实现吧。
 
procedure MyRectangle(DC: HDC;
Rect: TRect);
procedure SgDrawCenterText(Canvas: TCanvas;
Rect: TRect;
Text: PChar);
overload;
procedure SgDrawCenterText(DC: HDC;
Rect: TRect;
Text: PChar);
overload;
procedure SGDrawCenterText(DC: HDC;
Rect: TRect;
Text: String);
overload;
procedure SgSetPrinter;
procedure SgPrintDJ(CzDj: TCzDJ;
SfPage: TSfPage);
procedure SgPrintDjSf(CzDj: TCzDj;
Canvas: TCanvas;
SfPage: TSfPage);
procedure SgPrintSf(DC: HDC;
aSf: TSF;
T, L: Real;
PPIX, PPIY: Integer);
function IsSfValidate(SF: TSF): Boolean;
function CmToPixelX(cm: Real;
PPIX: Integer):Integer;
function CmToPixelY(Cm: Real;
PPIY: Integer):Integer;
function CmRect(L, T, W, H: Real;
PPIX, PPIY: Integer): TRect;
procedure SgSetPrinter;
var
ADevice : PChar;
ADriver : PChar;
APort : PChar;
DeviceMode : THandle;
DevMode : PDeviceMode;
PPIX, PPIY: Integer;
DC: HDC;
ARect: TRect;
function Supported(Setting : integer) : boolean;
begin
Supported := (DevMode^.dmFields and Setting) = Setting
end;

procedure SetField(aField : integer);
begin
DevMode^.dmFields := DevMode^.dmFields or aField;
end;
begin
GetMem(ADevice, 128);
GetMem(ADriver, 128);
GetMem(APort, 128);
DC := Printer.Handle;
PPIX := GetDeviceCaps(DC,LogPixelsX);
PPIY := GetDeviceCaps(DC,LogPixelsY);
Printer.GetPrinter(ADevice, ADriver, APort, DeviceMode);
DevMode := GlobalLock(DeviceMode);
// if PaperSize = Custom then
// begin
// SetField(dm_PaperSize);
// DevMode^.dmPaperSize := DMPAPER_A3;
SetField(dm_paperlength);
DevMode^.dmPaperLength := Round(PageHeight * 100);
SetField(dm_paperwidth);
DevMode^.dmPaperWidth := Round(PageWidth * 100);
// end;

// if FDuplex then
// begin
// SetField(dm_duplex);
// DevMode^.dmDuplex := dmdup_horizontal;
// end;

// if Supported(dm_PaperSize) and (PaperSize <> Default) then
// begin
// SetField(dm_papersize);
// DevMode^.dmPaperSize := cQRPaperTranslate[PaperSize];
// end;

SetField(dm_copies);
DevMode^.dmCopies := 1;
//FCopies;
SetField(dm_defaultsource);
DevMode^.dmDefaultSource := (DevMode^.dmDefaultSource and 256);// or cQRBinTranslate[OutputBin];
SetField(dm_orientation);
// if Orientation=poPortrait then
DevMode^.dmOrientation := dmorient_portrait;
// else
// DevMode^.dmOrientation := dmorient_landscape;
Printer.SetPrinter(ADevice, ADriver, APort, DeviceMode);
GlobalUnlock(DeviceMode);
with Printer.Canvasdo
begin
Font.Name := '宋体';
Font.Size := 10;
end;
end;

procedure SgPrintDJ(CzDj: TCzDJ;
SfPage: TSfPage);
begin
Printer.begin
Doc;
Printer.Title := format('收费 单据 %d 号',[CzDJ.Djh]);
SgPrintDjsf(CzDj,Printer.Canvas, SfPage);
Printer.EndDoc;
end;

function CmRect(L, T, W, H: Real;
PPIX, PPIY: Integer): TRect;
var
mL, mT, mW, mH: Integer;
begin
mL := CmToPixelX(L,PPIX);
mT := CmToPixelY(T,PPIY);
mW := mL + CmToPixelX(W,PPIX);
mH := mT + CmToPixelY(H,PPIY);
Result := Rect(mL, mT, mW, mH);
end;

function CmToPixelX(cm: Real;
PPIX: Integer):Integer;
begin
Result := Trunc((cm * PPIX) / 2.54);
end;

function CmToPixelY(Cm: Real;
PPIY: Integer):Integer;
begin
Result := Trunc((cm * PPIY) / 2.54);
end;

procedure SgPrintSf(DC: HDC;
aSf: TSF;
T, L: Real;
PPIX, PPIY: Integer);
var
ARect: TRect;
myText, NText: String;
I, Len, mL: Integer;
begin
T := T + 1;
ARect := CmRect(L, T, 5.7, 0.8, PPIX, PPIY);
myText := aSF.xmmc;
SgDrawCenterText(DC,ARect,myText);
L := L + 5.7;
ARect := CmRect(L, T, 2, 0.8, PPIX, PPIY);
myText := aSF.jsdw;
SgDrawCenterText(DC,ARect,PChar(myText));
L := L + 2;
ARect := CmRect(L, T, 2, 0.8, PPIX, PPIY);
myText := format('%.2f',[aSF.sfbz]);
SgDrawCenterText(DC,ARect,PChar(myText));
L := L + 2;
ARect := CmRect(L, T, 2, 0.8, PPIX, PPIY);
myText := format('%.2f',[aSf.sl]);
SgDrawCenterText(DC,ARect,PChar(myText));
L := L + 2;
ARect := CmRect(L, T, 2.8, 0.8, PPIX, PPIY);
myText := format('%.0f',[aSF.je*100]);
Len := Length(myText);
mL := CmToPixelX(L + 2.8, PPIX);
for I := Lendo
wnto 1do
begin
NText := format('%s',[myText]);
ARect.Right := mL;
mL := mL - CmToPixelX(0.4, PPIY);
ARect.Left := mL;
SgDrawCenterText(Dc,ARect,PChar(NText));
end;
end;

procedure SgPrintDjSf(CzDj: TCzDj;
Canvas: TCanvas;
SfPage: TSfPage);
var
DC: HDC;
myText: PChar;
sText: String;
PPIX, PPIY, I, mL, mW: Integer;
T, L, W, H: Real;
ARect: TRect;
y, m, d: Word;
begin
DC := Canvas.Handle;
PPIX := GetDeviceCaps(DC,LogPixelsX);
PPIY := GetDeviceCaps(DC,LogPixelsY);
//
ARect := CmRect(0.1, 0.1, 18.1, 9.2, PPIX, PPIY);
Canvas.Pen.Color := clBlack;
// MyRectangle(Dc,ARect);
//以上打印出一个矩形,用来确定收据的位置
//
//单据号
T := 1.4-SfPage.TopMargin;
L := 12.0;
W := 2.5;
H := 0.4;
myText := PChar(format('编号: %d',[CzDj.djh]));
ARect := CmRect(L,T,W,H,PPIX,PPIY);
SgDrawCenterText(DC,ARect,MyText);
//时间
DecodeDate(CzDj.sj,y,m,d);
T := 1.9-SfPage.TopMargin;
L := 12.8;
W := 0.8;
H := 0.4;
myText := PChar(format('%d',[y]));
ARect := CmRect(L,T,W,H,PPIX,PPIY);
SgDrawCenterText(DC,ARect,MyText);
L := L + 0.8 + 0.4;
myText := PChar(format('%d',[m]));
ARect := CmRect(L,T,W,H,PPIX,PPIY);
SgDrawCenterText(DC,ARect,MyText);
L := L + 0.8 + 0.4;
myText := PChar(format('%d',[d]));
ARect := CmRect(L,T,W,H,PPIX,PPIY);
SgDrawCenterText(DC,ARect,MyText);
//单位
T := 1.9-SfPage.TopMargin;
L := 4.0;
W := 3.4;
H := 0.4;
myText := PChar(String(CzDj.jkr));
ARect := CmRect(L,T,W,H,PPIX,PPIY);
SgDrawCenterText(DC,AREct,MyText);
//地址
T := 1.9-SfPage.TopMargin;
L := 8.3;
W := 4.0;
H := 0.4;
myText := PChar(String(CzDj.dz));
ARect := CmRect(L,T,W,H,PPIX,PPIY);
SgDrawCenterText(DC,AREct,MyText);
//项目
T := 2.4-SfPage.TopMargin;
L := 1.7;
for I := 1 to 3do
begin
if IsSfValidate(CzDj.SfDj) then
begin
SgPrintSf(DC,CzDj.SfDj,T,L,PPIX,PPIY);
T := 2.4 + 0.8-SfPage.TopMargin;
end;
end;
//大写金额
sText := format('%7.0f',[CzDj.je * 100]);
for I := 1 to 7do
begin
if sText = ' ' then
begin
sText := '0';
end;
end;
mW := Canvas.TextWidth('万');
ARect.Left := CmToPixelX(5.3 - 0.8, PPIX);
ARect.Top := CmToPixelY(6.2-SfPage.TopMargin, PPIY);
ARect.Bottom := ARect.Top + Canvas.TextHeight('万');
for I := 1 to 7do
begin
ARect.Right := ARect.Left + CmToPixelX(0.8,PPIX);
SGDrawCenterText(DC,ARect,Copy(Su,(Ord(sText)-Ord('0'))*2+1,2));
ARect.Left := ARect.Left + mW + CmToPixelX(0.8,PPIX);
end;
//小写金额
myText := PChar(format('%.2f',[CzDj.je]));
ARect.Left := CmToPixelX(13.0, PPIX);
ARect.Top := CmToPixelY(6.2-SfPage.TopMargin, PPIY);
ARect.Bottom := ARect.Top + Canvas.TextHeight('万');
ARect.Right := ARect.Left + Canvas.TextWidth(format('%.2f',[CzDj.je]));
SgDrawCenterText(DC,ARect,myText);
L := 13.0;
T := 6.2-SfPage.TopMargin;
//备注
T := 7-SfPage.TopMargin;
L := 4;
W := 12.0;
H := 0.4;
myText := PChar(String(CzDj.pz));
ARect := CmRect(L,T,W,H,PPIX,PPIY);
SgDrawCenterText(DC,AREct,MyText);
//开票
T := 8-SfPage.TopMargin;
L := 9;
W := 2.5;
H := 0.4;
myText := PChar(String(CzDj.kpr));
ARect := CmRect(L,T,W,H,PPIX,PPIY);
SgDrawCenterText(DC,AREct,MyText);
//收款
T := 8-SfPage.TopMargin;
L := 13.0;
W := 2.5;
H := 0.4;
myText := PChar(String(CzDj.skr));
ARect := CmRect(L,T,W,H,PPIX,PPIY);
SgDrawCenterText(DC,AREct,MyText);
end;

function IsSfValidate(SF: TSF): Boolean;
begin
Result := (SF.xmmc <> '') and
(SF.jsdw <> '') and
(SF.sfbz > 0) and
(SF.sl > 0) and
(SF.je > 0);
end;

procedure MyRectangle(DC: HDC;
Rect: TRect);
begin
Rectangle(DC,Rect.Left,Rect.Top,Rect.Right,Rect.Bottom);
end;

procedure SgDrawCenterText(DC: HDC;
Rect: TRect;
Text: PChar);
var
aRect, vRect: TRect;
h, w: Integer;
myRgn: HRgn;
begin
aRect := Rect;
vRect := Rect;
DrawText(DC,Text,StrLen(Text),vRect,DT_CALCRECT);
h := vRect.Bottom - vRect.Top;
w := vRect.Right - vRect.Left;
aRect.Top := aRect.Top + ((Rect.Bottom - Rect.Top) - h) div 2;
aRect.Left := aRect.Left + ((Rect.Right - Rect.Left) - w) div 2;
aRect.Right := aRect.Left + w;
aRect.Bottom := aRect.Top + h;
DrawText(DC,Text,StrLen(Text),aRect,DT_CENTER + DT_VCENTER);
end;

procedure SgDrawCenterText(Canvas: TCanvas;
Rect: TRect;
Text: PChar);
begin
SgDrawCenterText(Canvas.Handle,Rect,Text);
end;

procedure SgDrawCenterText(DC: HDC;
Rect: TRect;
Text: String);
begin
SgDrawCenterText(DC,Rect,PChar(Text));
end;

大同小异,将就^_^
 
试试 Ehlib
 
如果只是打印工资条用QR就完全可以了。
DELPHI 有自带的例子。
 
frreport解决最好了。参考给你发的例子,我想,应该可以有点收获的。
如果你工资条涉及到其他部门,那你做分类就行了。你看下DEMO(组件自带的。),花不了太长时间的。
 
谢谢816顶力相助!
我看用devexpress控件很难实现我的要求,如果真的不行的话,我就换fastreport了。
 
后退
顶部