在QRreport中打印一条主记录及其明细记录的问题(300分)

  • 主题发起人 主题发起人 wuzhongl
  • 开始时间 开始时间
W

wuzhongl

Unregistered / Unconfirmed
GUEST, unregistred user!
在report中只打印当前主表的一条记录,该主记录打印后,在后面打印主表的两个从表中的
相应记录,从表中的记录用表格来打印,该怎样实现?问题较复杂,分多一点:300大洋
 
以下为一个从表的方法,若想说清楚恐怕当面
放入table2,其datasource指向table1,设定mastersource,masterfields
等。
放入subdetail,指定master为quickrep1,dataset为table2
 
这个问题复杂吗?
这是很典型的主细表打印问题。你看看delphi有关QuickReport的demo,专门有一部分介绍
的主细表的打印。
从表中的表格可以用QrShape来画。
 
delphi的示例中就自带有这个。
 
做了一个例子,可惜没法把数据库贴到这里 ,^_^
dpr:
program repquick;
uses
Forms,
repquickUnit in 'repquickUnit.pas' {Form1};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

//////////
dfm:
object Form1: TForm1
Left = 99
Top = 165
Width = 688
Height = 397
Caption = 'Form1'
Color = clBtnFace
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
OldCreateOrder = False
Scaled = False
PixelsPerInch = 96
TextHeight = 12
object QuickRep1: TQuickRep
Left = -28
Top = -24
Width = 794
Height = 1123
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
DataSet = ADOQuery1
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
Functions.Strings = (
'PAGENUMBER'
'COLUMNNUMBER'
'REPORTTITLE')
Functions.DATA = (
'0'
'0'
'''''')
Options = [FirstPageHeader, LastPageFooter]
Page.Columns = 1
Page.Orientation = poPortrait
Page.PaperSize = A4
Page.Values = (
100
2970
100
2100
100
100
0)
PrinterSettings.Copies = 1
PrinterSettings.Duplex = False
PrinterSettings.FirstPage = 0
PrinterSettings.LastPage = 0
PrinterSettings.OutputBin = Auto
PrintIfEmpty = True
SnapToGrid = True
Units = MM
Zoom = 100
object ColumnHeaderBand1: TQRBand
Left = 38
Top = 38
Width = 718
Height = 40
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
AlignToBottom = False
Color = clWhite
ForceNewColumn = False
ForceNewPage = False
Size.Values = (
105.833333333333
1899.70833333333)
BandType = rbColumnHeader
end
object DetailBand1: TQRBand
Left = 38
Top = 78
Width = 718
Height = 29
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
AlignToBottom = False
Color = clWhite
ForceNewColumn = False
ForceNewPage = False
Size.Values = (
76.7291666666667
1899.70833333333)
BandType = rbDetail
object QRDBText1: TQRDBText
Left = 16
Top = 3
Width = 25
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
42.3333333333333
7.9375
66.1458333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Color = clWhite
DataSet = ADOQuery1
DataField = 'DWMC'
Transparent = False
WordWrap = True
FontSize = 9
end
object QRDBText2: TQRDBText
Left = 232
Top = 3
Width = 25
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
613.833333333333
7.9375
66.1458333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Color = clWhite
DataSet = ADOQuery1
DataField = 'JHND'
Transparent = False
WordWrap = True
FontSize = 9
end
object QRDBText3: TQRDBText
Left = 388
Top = -1
Width = 25
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
1026.58333333333
-2.64583333333333
66.1458333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Color = clWhite
DataSet = ADOQuery1
DataField = 'JHLX'
Transparent = False
WordWrap = True
FontSize = 9
end
end
object QRSubDetail1: TQRSubDetail
Left = 38
Top = 107
Width = 718
Height = 21
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
AlignToBottom = False
Color = clWhite
ForceNewColumn = False
ForceNewPage = False
Size.Values = (
55.5625
1899.70833333333)
Master = QuickRep1
DataSet = ADOQuery2
PrintBefore = False
PrintIfEmpty = True
object QRShape1: TQRShape
Left = 4
Top = 0
Width = 469
Height = 21
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
55.5625
10.5833333333333
0
1240.89583333333)
Shape = qrsRectangle
end
object QRDBText4: TQRDBText
Left = 388
Top = 2
Width = 25
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
1026.58333333333
5.29166666666667
66.1458333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Color = clWhite
DataSet = ADOQuery2
DataField = 'SPLB'
Transparent = False
WordWrap = True
FontSize = 9
end
object QRDBText5: TQRDBText
Left = 232
Top = 2
Width = 25
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
613.833333333333
5.29166666666667
66.1458333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Color = clWhite
DataSet = ADOQuery2
DataField = 'SPSL'
Transparent = False
WordWrap = True
FontSize = 9
end
object QRDBText6: TQRDBText
Left = 20
Top = 2
Width = 25
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
52.9166666666667
5.29166666666667
66.1458333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Color = clWhite
DataSet = ADOQuery2
DataField = 'SPMC'
Transparent = False
WordWrap = True
FontSize = 9
end
object QRShape2: TQRShape
Left = 208
Top = 1
Width = 1
Height = 19
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
50.2708333333333
550.333333333333
2.64583333333333
2.64583333333333)
Shape = qrsRectangle
end
object QRShape3: TQRShape
Left = 317
Top = 1
Width = 1
Height = 20
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
52.9166666666667
838.729166666667
2.64583333333333
2.64583333333333)
Shape = qrsRectangle
end
end
end
object ADOConnection1: TADOConnection
Connected = True
ConnectionString =
'Provider=SQLOLEDB.1;Password=admin;Persist Security Info=True;Us' +
'er ID=sa;Initial Catalog=sale;Data Source=zzz'
LoginPrompt = False
Provider = 'SQLOLEDB.1'
Left = 40
Top = 20
end
object ADOQuery1: TADOQuery
Active = false
Connection = ADOConnection1
CursorType = ctStatic
Parameters = <>
SQL.Strings = (
'select * from T_jhqk')
Left = 124
Top = 20
end
object ADOQuery2: TADOQuery
Active = True
Connection = ADOConnection1
CursorType = ctStatic
Parameters = <>
SQL.Strings = (
'select * from T_jhmx')
Left = 204
Top = 20
end
end
///////////////////
pas:
unit repquickUnit;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, QuickRpt, QRCtrls, ExtCtrls;

type
TForm1 = class(TForm)
QuickRep1: TQuickRep;
ColumnHeaderBand1: TQRBand;
DetailBand1: TQRBand;
QRSubDetail1: TQRSubDetail;
QRDBText1: TQRDBText;
QRDBText2: TQRDBText;
QRDBText3: TQRDBText;
QRDBText4: TQRDBText;
QRDBText5: TQRDBText;
QRDBText6: TQRDBText;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
QRShape1: TQRShape;
QRShape2: TQRShape;
QRShape3: TQRShape;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

end.
 
这个问题还有一个关键之处:就是只打印主表中的一条记录!
 
那也很简单啊!你要做的就不再是打印主从表的关系了,而是打印一个表!
其他不变。你将主表中的字段中的字段放在ColumnHeaderBand1中而从表字段放在DetailBand1中,就是打印你要的当前主表的一个记录下的从表记录!
 
carzycat,
如果将主表字段中的字段放在ColumnHeaderBand1中,如果从表中没有记录则
该报表将什么也显示不出来.
 
后退
顶部