用print.canvas 自己画啦。
procedure TfrmSale.btnPrnClick(Sender: TObject);
var
y,r : integer;
fpe : Boolean;
//发票额是否已记入明细中
begin
fpe := False;
if not InitPrinter then
begin
Application.MessageBox('未安装打印机或打印机驱动程序丢失,请与系统管理员联系!', '出错', mb_IconError + mb_OK);
Exit;
end;
SetPaperSize(1200,1400);
//打印文本
try
Printer.begin
Doc;
with Printer.Canvas do
begin
DM.ADSlsd.First;
Font.Name := '宋体';
Font.Size := 16;
TextOut(TX(100),TY(1),' . ');
TextOut(TX(350),TY(20),lsdname);
Font.Size := 10;
TextOut(TX(140),TY(130),'票号:' + edtxpbh.Text );
TextOut(TX(450),TY(130),formatdatetime('yyyy/mm/dd hh:mm',Now));
TextOut(TX(780),TY(130),'操作员:' + czy);
TextOut(TX(100),TY(170),'━━━━━━━━━━━━━━━━━━━━━━━━━━');
TextOut(TX(120),TY(220),'商品编号 商品名称 尺码 颜色 数量 金额');
TextOut(TX(100),TY(260),'--------------------------------------------------');
r := 1;
y := 60;
while sgsp.Cells[0,r] <> ''do
begin
TextOut(TX(100),TY(250 + y),sgsp.Cells[0,r]);
TextOut(TX(340),TY(250 + y),sgsp.Cells[1,r]);
TextOut(TX(620),TY(250 + y),sgsp.Cells[3,r]);
TextOut(TX(710),TY(250 + y),sgsp.Cells[2,r]);
TextOut(TX(830),TY(250 + y),sgsp.Cells[10,r]);
TextOut(TX(910),TY(250 + y),sgsp.Cells[12,r]);
inc(r);
inc(y,60);
end;
// TextOut(TX(140),TY(220),'');
// TextOut(TX(140),TY(220),'');
// TextOut(TX(140),TY(220),'');
// TextOut(TX(140),TY(220),'');
// TextOut(TX(140),TY(220),'');
TextOut(TX(100),TY(760),'━━━━━━━━━━━━━━━━━━━━━━━━━━');
TextOut(TX(100),TY(800),'应收:' + FormatCurr('0.00',ysk));
TextOut(TX(350),TY(800),'实收:' + FormatCurr('0.00',edtss.Value));
TextOut(TX(580),TY(800),'现金:' + FormatCurr('0.00',edtxj.Value));
TextOut(TX(820),TY(800),'回找:' + FormatCurr('0.00',edtZl.Value));
TextOut(TX(120),TY(900),DM.ADSlsd.Fieldbyname('Fend1').AsString);
TextOut(TX(120),TY(950),DM.ADSlsd.Fieldbyname('Fend2').AsString);
TextOut(TX(100),TY(1000),'━━━━━━━━━━━━━━━━━━━━━━━━━━');
TextOut(TX(120),TY(1030),'让您满意是我们最大的心愿');
end;
Printer.EndDoc;
DM.ADOConnection1.begin
Trans ;
if edtbh.Text <> '' then
begin
with DM.ADShydo
begin
if Locate('Fbh',edtbh.Text,[]) then
begin
Edit;
FieldValues['Fjf'] := FieldValues['Fjf'] + fz;
FieldValues['Fxfje'] := FieldValues['Fxfje'] + edtss.Value;
FieldValues['Flastxfd'] := DM.ADSlsd.Fieldbyname('Fname').AsString;
FieldValues['Flastxfr'] := date;
FieldValues['Flastxfe'] := edtss.Value;
Post;
end;
end;
end;
r := 1;
try
while sgsp.Cells[0,r] <> ''do
begin
with DM.ADSsaledo
begin
Append;
FieldByName('Frq').AsDateTime := Date;
FieldByName('Fsj').AsDateTime := Time;
FieldByName('Ffph').AsString := edtxpbh.Text;
FieldByName('Fgroup').AsString := cbgz.Text;
FieldByName('Flsj').AsCurrency := strtocurr(sgsp.Cells[13,r]);
if stxm.Caption <> '' then
FieldByName('Fhybh').AsString := edtbh.Text;
FieldByName('Fspbh').AsString := sgsp.Cells[0,r];
FieldByName('Fsl').AsInteger := strtoint(sgsp.Cells[10,r]);
FieldByName('Fdj').AsCurrency := strtocurr(sgsp.Cells[8,r]);
FieldByName('Fkh').AsString := sgsp.Cells[5,r];
if sgsp.Cells[11,r] <> '' then
FieldByName('Fzk').AsInteger := strtoint(sgsp.Cells[11,r]);
FieldByName('Fje').AsCurrency := strtocurr(sgsp.Cells[12,r]);
if Not fpe then
begin
FieldByName('Ffpe').AsCurrency := edtss.Value;
fpe := True;
end
else
begin
FieldByName('Ffpe').AsCurrency := 0;
end;
FieldByName('Fczy').AsString := '';
Post;
end;
inc(r);
end;
DM.ADOConnection1.CommitTrans;
clrall;
except
DM.ADOConnection1.RollbackTrans;
Application.MessageBox('入库错误,请清除后重新打印本销售单。','警告',MB_OK);
raise;
end;
except
Application.MessageBox('打印出错,请清除后重新打印本销售单。','警告',MB_OK);
end;
end;