在一张报表中,如何实现报表的左半部分是来自数据库的字段值,而右半部分不来自数据库。

hailin10 2004-03-14 09:03:06
在细节带中,表中的左边有六列八行都来自数据库中的值,其中地七列没有来自数据库,只有一行,它的高度和左边的八行之和相等,打印是要一起打印出来,如何实现???
...全文
85 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rurama 2004-03-31
  • 打赏
  • 举报
回复
//-----Begin print EndTable
DMdAutoPrint->ADOQueryPrint->Close();
DMdAutoPrint->ADOQueryPrint->SQL->Clear();
DMdAutoPrint->ADOQueryPrint->SQL->Add("Select * from t_report_end where n_listid='"+strTableID.Trim()+"'");
DMdAutoPrint->ADOQueryPrint->Open();
DMdAutoPrint->ADOQueryPrint->First();
while ( !DMdAutoPrint->ADOQueryPrint->Eof )
{
AnsiString strControlName,strCCaption,strCLeft,strCTop,strCBackColor,strCColor,strCFont,strCFontSize,strCImageFile,strCLabelBind;
int intILength,intIHeight;

strControlName = DMdAutoPrint->ADOQueryPrint->FieldByName("c_control_name")->AsString;
strCCaption = DMdAutoPrint->ADOQueryPrint->FieldByName("c_caption")->AsString;
strCLeft = DMdAutoPrint->ADOQueryPrint->FieldByName("c_left")->AsString;
strCTop = DMdAutoPrint->ADOQueryPrint->FieldByName("c_top")->AsString;
strCColor = DMdAutoPrint->ADOQueryPrint->FieldByName("c_color")->AsString;
strCFont = DMdAutoPrint->ADOQueryPrint->FieldByName("c_font")->AsString;
strCFontSize = DMdAutoPrint->ADOQueryPrint->FieldByName("c_fontsize")->AsString;
strCImageFile = DMdAutoPrint->ADOQueryPrint->FieldByName("c_imagefile")->AsString;
strCLabelBind = DMdAutoPrint->ADOQueryPrint->FieldByName("c_labelbind")->AsString;
intILength = DMdAutoPrint->ADOQueryPrint->FieldByName("i_length")->AsInteger;
intIHeight = DMdAutoPrint->ADOQueryPrint->FieldByName("i_height")->AsInteger;
if ( strControlName.Trim() == "Label" )
{
int xLine,yLine;
xLine = StrToInt(strCLeft.Trim())*3.8;
yLine = StrToInt(strCTop.Trim())*3.8;
if ( strCCaption != "数据绑定" )
{
print->Canvas->Font->Color = StringToColor(strCColor);
print->Canvas->Font->Size = StrToInt(strCFontSize);
print->Canvas->Font->Name = strCFont;
print->Canvas->MoveTo(xLine,yLine);
print->Canvas->TextOutA(xLine,yLine,strCCaption);
}
else
{
if ( strCLabelBind != NULL )
{
}
}
}
if ( strControlName.Trim() == "Shape" )
{
int xLine,yLine,xMove,yMove;
xLine = StrToInt(strCLeft.Trim())*3.8;
yLine = StrToInt(strCTop.Trim())*3.8;
if ( intILength > intIHeight )
{
xMove = intILength*3.8+StrToInt(strCLeft.Trim());
yMove = yLine;
}
if ( intILength < intIHeight )
{
xMove = xLine;
yLine = intIHeight*3.8+StrToInt(strCTop.Trim());
}
print->Canvas->MoveTo(xMove,yMove);
print->Canvas->LineTo(xLine,yLine);
}
if ( strControlName.Trim() == "Image")
{

}
DMdAutoPrint->ADOQueryPrint->Next();
}
//---------- End print EndTable
Rurama 2004-03-31
  • 打赏
  • 举报
回复
//------Begin print ContentTable
DMdAutoPrint->ADOQueryPrint->Close();
DMdAutoPrint->ADOQueryPrint->SQL->Clear();
DMdAutoPrint->ADOQueryPrint->SQL->Add("Select * from t_report_content where n_listid='"+strTableID.Trim()+"'");
DMdAutoPrint->ADOQueryPrint->Open();
DMdAutoPrint->ADOQueryPrint->First();

while ( !DMdAutoPrint->ADOQueryPrint->Eof )
{
AnsiString strControlName,strCCaption,strCLeft,strCTop,strCBackColor,strCColor,strCFont,strCFontSize,strCImageFile,strCLabelBind,strELabelBind,strCETable;
int intILength,intIHeight;

strControlName = DMdAutoPrint->ADOQueryPrint->FieldByName("c_control_name")->AsString;
strCCaption = DMdAutoPrint->ADOQueryPrint->FieldByName("c_caption")->AsString;
strCLeft = DMdAutoPrint->ADOQueryPrint->FieldByName("c_left")->AsString;
strCTop = DMdAutoPrint->ADOQueryPrint->FieldByName("c_top")->AsString;
strCColor = DMdAutoPrint->ADOQueryPrint->FieldByName("c_color")->AsString;
strCFont = DMdAutoPrint->ADOQueryPrint->FieldByName("c_font")->AsString;
strCFontSize = DMdAutoPrint->ADOQueryPrint->FieldByName("c_fontsize")->AsString;
strCImageFile = DMdAutoPrint->ADOQueryPrint->FieldByName("c_imagefile")->AsString;
strCLabelBind = DMdAutoPrint->ADOQueryPrint->FieldByName("c_labelbind")->AsString;
intILength = DMdAutoPrint->ADOQueryPrint->FieldByName("i_length")->AsInteger;
intIHeight = DMdAutoPrint->ADOQueryPrint->FieldByName("i_height")->AsInteger;
strELabelBind = DMdAutoPrint->ADOQueryPrint->FieldByName("c_e_labelbind")->AsString;
strCETable = DMdAutoPrint->ADOQueryPrint->FieldByName("c_e_table")->AsString;
if ( strControlName.Trim() == "Label" )
{
int xLine,yLine;
xLine = StrToInt(strCLeft.Trim())*3.8;
yLine = StrToInt(strCTop.Trim())*3.8;
if ( strCCaption != "数据绑定" )
{
print->Canvas->Font->Color = StringToColor(strCColor);
print->Canvas->Font->Size = StrToInt(strCFontSize);
print->Canvas->Font->Name = strCFont;
print->Canvas->MoveTo(xLine,yLine);
print->Canvas->TextOutA(xLine,yLine,strCCaption);
}
DMdAutoPrint->ADOQueryTempSearch->Next();
}
if ( strControlName.Trim() == "Shape" )
{
int xLine,yLine,xMove,yMove;
xLine = StrToInt(strCLeft.Trim())*3.8;
yLine = StrToInt(strCTop.Trim())*3.8;
if ( intILength > intIHeight )
{
xMove = intILength*3.8+StrToInt(strCLeft.Trim())*3.8;
yMove = yLine;
}
if ( intILength < intIHeight )
{
xMove = xLine;
yMove = intIHeight*3.8+StrToInt(strCTop.Trim())*3.8;
}
print->Canvas->MoveTo(xMove,yMove);
print->Canvas->LineTo(xLine,yLine);
}
if ( strControlName.Trim() == "Image")
{
//Print Image to Page
}
DMdAutoPrint->ADOQueryPrint->Next();
}
//-------End print ContentTable

//------Begin print LinesNumber
DMdAutoPrint->ADOQueryPrint->Close();
DMdAutoPrint->ADOQueryPrint->SQL->Clear();
DMdAutoPrint->ADOQueryPrint->SQL->Add("Select * from t_report_content where n_listid='"+strTableID.Trim()+"'and (c_control_name = 'Shape') and (c_top =(SELECT MAX(c_top)FROM t_report_content WHERE n_listid = '"+strTableID.Trim()+"' AND c_control_name = 'Shape'))");
DMdAutoPrint->ADOQueryPrint->Open();
DMdAutoPrint->ADOQueryPrint->First();
if ( DMdAutoPrint->ADOQueryPrint->RecordCount > 0 )
{
if ( intPrintLineNum > 0 )
{
for( int i = 0;i<intPrintLineNum+1;i++ )
{
int intILength = DMdAutoPrint->ADOQueryPrint->FieldByName("i_length")->AsInteger;
AnsiString strCLeft = DMdAutoPrint->ADOQueryPrint->FieldByName("c_left")->AsString;
AnsiString strCTop = DMdAutoPrint->ADOQueryPrint->FieldByName("c_top")->AsString;
int xLine,yLine,xMove,yMove;
xLine = StrToInt(strCLeft.Trim())*3.8;
yLine = StrToInt(strCTop.Trim())*3.8;
xMove = intILength*3.8+StrToInt(strCLeft.Trim())*3.8;
yMove = yLine;
print->Canvas->MoveTo(xMove,yMove+i*100);
print->Canvas->LineTo(xLine,yLine+i*100);

}
}
}
//-----End print LinesNumber

Rurama 2004-03-31
  • 打赏
  • 举报
回复
用控件的话就要在打印前动态的生成,同时给控件付值,这个值当然是你说的非数据库的内容。
还有就是用TPRINT打印了。
下面是打印头/*-----------------------------------------------------*/
/* 用以打印设计好的或已选定的报表 */
/* iControlLeft[]用以存贮按升序排列的Left值 */
/* iControlTop[]用以存贮按升序排列的Top值 */
/* iTopSubtration用以记录TOP与300的差值 */
/* iLeftSubtration用以记录LEFT与300的差值 */
/* iArraryCountTemp用以记录向数组中添加值时最 */
/* 后的记录号,以便添加其它控件的同类型值时得 */
/* 以继续添加 */
/* intPrintLineNum打印中每页行数 */
/*-----------------------------------------------------*/
int iChangePage,iDataBindCount;

iChangePage = 0;
//iDataBindCount = 0;

if ( strTableID != "" )
{
int intPrintLineNum;
DMdAutoPrint->ADOQueryTempSearch->Close();
DMdAutoPrint->ADOQueryTempSearch->SQL->Clear();
DMdAutoPrint->ADOQueryTempSearch->SQL->Add("Select * from t_reportList where n_listid='"+strTableID.Trim()+"'");
DMdAutoPrint->ADOQueryTempSearch->Open();
DMdAutoPrint->ADOQueryTempSearch->First();
intPrintLineNum = StrToInt(DMdAutoPrint->ADOQueryTempSearch->FieldByName("c_conditon")->AsString);

DMdAutoPrint->ADOQueryPrint->Close();
DMdAutoPrint->ADOQueryPrint->SQL->Clear();
DMdAutoPrint->ADOQueryPrint->SQL->Add("Select * from t_report_content where n_listid='"+strTableID.Trim()+"'");
DMdAutoPrint->ADOQueryPrint->Open();
TPrinter *print = Printer();
if(Printer()->Printers->Count==0)
{
Application->MessageBoxA(" 在系统中没有找到打印机 ","信息提示",MB_ICONINFORMATION+MB_OK);
return;
}
else
{
//------Begin Brows printer
print->Orientation = poLandscape;
//print->Orientation = poPortrait;
char ADevice[256],ADriver[256],APort[256];
THandle DeviceMode;
PDeviceMode DevMode;

print->GetPrinterA(ADevice,ADriver,APort,DeviceMode);
DevMode = (_devicemodeA*)GlobalLock((void*)DeviceMode);
DevMode->dmFields = DevMode->dmFields|DM_PAPERSIZE;
DevMode->dmPaperSize = DMPAPER_A4;
GlobalUnlock((void*)DeviceMode);
print->SetPrinterA(ADevice,ADriver,APort,DeviceMode);
//------End Brows printer
print->BeginDoc();
//-----Begin print HeadTable
DMdAutoPrint->ADOQueryPrint->Close();
DMdAutoPrint->ADOQueryPrint->SQL->Clear();
DMdAutoPrint->ADOQueryPrint->SQL->Add("Select * from t_report_head where n_listid='"+strTableID.Trim()+"'");
DMdAutoPrint->ADOQueryPrint->Open();
DMdAutoPrint->ADOQueryPrint->First();
while ( !DMdAutoPrint->ADOQueryPrint->Eof )
{
AnsiString strControlName,strCCaption,strCLeft,strCTop,strCBackColor,strCColor,strCFont,strCFontSize,strCImageFile,strCLabelBind;
int intILength,intIHeight;

strControlName = DMdAutoPrint->ADOQueryPrint->FieldByName("c_control_name")->AsString;
strCCaption = DMdAutoPrint->ADOQueryPrint->FieldByName("c_caption")->AsString;
strCLeft = DMdAutoPrint->ADOQueryPrint->FieldByName("c_left")->AsString;
strCTop = DMdAutoPrint->ADOQueryPrint->FieldByName("c_top")->AsString;
strCColor = DMdAutoPrint->ADOQueryPrint->FieldByName("c_color")->AsString;
strCFont = DMdAutoPrint->ADOQueryPrint->FieldByName("c_font")->AsString;
strCFontSize = DMdAutoPrint->ADOQueryPrint->FieldByName("c_fontsize")->AsString;
strCImageFile = DMdAutoPrint->ADOQueryPrint->FieldByName("c_imagefile")->AsString;
strCLabelBind = DMdAutoPrint->ADOQueryPrint->FieldByName("c_labelbind")->AsString;
intILength = DMdAutoPrint->ADOQueryPrint->FieldByName("i_length")->AsInteger;
intIHeight = DMdAutoPrint->ADOQueryPrint->FieldByName("i_height")->AsInteger;
if ( strControlName.Trim() == "Label" )
{
int xLine,yLine;
xLine = StrToInt(strCLeft.Trim())*3.8;
yLine = StrToInt(strCTop.Trim())*3.8;
if ( strCCaption != "数据绑定" )
{
print->Canvas->Font->Color = StringToColor(strCColor);
print->Canvas->Font->Size = StrToInt(strCFontSize);
print->Canvas->Font->Name = strCFont;
print->Canvas->MoveTo(xLine,yLine);
print->Canvas->TextOutA(xLine,yLine,strCCaption);
}
else
{
if ( strCLabelBind != NULL )
{
}
}
}
if ( strControlName.Trim() == "Shape" )
{
int xLine,yLine,xMove,yMove;
xLine = StrToInt(strCLeft.Trim())*3.8;
yLine = StrToInt(strCTop.Trim())*3.8;
if ( intILength > intIHeight )
{
xMove = intILength*3.8+StrToInt(strCLeft.Trim());
yMove = yLine;
}
if ( intILength < intIHeight )
{
xMove = xLine;
yLine = intIHeight*3.8+StrToInt(strCTop.Trim())*3.8;
}
print->Canvas->MoveTo(xMove,yMove);
print->Canvas->LineTo(xLine,yLine);
}
if ( strControlName.Trim() == "Image")
{

}
DMdAutoPrint->ADOQueryPrint->Next();
}
//------End print HeadTable



梦回童年001 2004-03-31
  • 打赏
  • 举报
回复
頂,其實我也不懂
hailin10 2004-03-29
  • 打赏
  • 举报
回复
假设数据库中有10行,显示是detail带中和数据库中的行数应该是相等的,也为10行,所用的表达式后,是显示10行呢还是显示1行???????
这个表达式该怎么写????????望赐教,
WbtServer 2004-03-29
  • 打赏
  • 举报
回复
可以用表达式呀.
hailin10 2004-03-29
  • 打赏
  • 举报
回复
在detail带中,本来可以显示多行数据,但是,我要在detail带中增加一个额外的列,在报表显示时这一列只显示一行,他的高度要和另外几行的高度和相等,增加的列中只有静态信息
ch_builder 2004-03-24
  • 打赏
  • 举报
回复
没听明白,但QR中的数据的确可以不来自数据库,这应该知道呀:)
hailin10 2004-03-16
  • 打赏
  • 举报
回复
c++ builder 中的报表组件作的
chenguangw 2004-03-14
  • 打赏
  • 举报
回复
没明白到底什么样的报表

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧