📄 rpttable.pas
字号:
//-->控制表格标题
QRLB_Title.Caption:=Para.Title;
QRLB_Title.Top:=Para.Top-trunc(QRLB_Title.Height*2);
QRLB_Title.Left:=(Self.QuickRep1.Width-QRLB_Title.Width) div 2; //使标题居中
QRS_Title.Top:=QRLB_Title.Top+QRLB_Title.Height+5;
QRS_Title.Width:=QRLB_Title.Width+40;
QRS_Title.Left:=QRLB_Title.Left-20;
//-->对标题的四个角进行处理,用QRshape把四个角挡住
for i :=1 to 4 do
begin
QRS:=TQRShape.Create(self);
QRS.Parent:=Para.Parent;
QRS.Pen.Color:=clWhite;
case i of
1:
begin
QRS.Shape:=qrsHorLine;
QRS.Height:=1;
QRS.Width:=QRLB_Title.Width;
QRS.Left:=QRLB_Title.Left;
QRS.Top:=QRLB_Title.Top;
end;
2:
begin
QRS.Shape:=qrsHorLine;
QRS.Height:=1;
QRS.Width:=QRLB_Title.Width;
QRS.Left:=QRLB_Title.Left;
QRS.Top:=QRLB_Title.Top+QRLB_Title.Height-1;
end;
3:
begin
QRS.Height:=QRLB_Title.Height;
QRS.Shape:=qrsVertLine;
QRS.Width:=1;
QRS.Left:=QRLB_Title.Left;
QRS.Top:=QRLB_Title.Top;
end;
4:
begin
QRS.Height:=QRLB_Title.Height;
QRS.Shape:=qrsVertLine;
QRS.Width:=1;
QRS.Left:=QRLB_Title.Left+QRLB_Title.Width-1;
QRS.Top:=QRLB_Title.Top;
end;
end;
end;
SetLength(ED_Cell,FootC);//设置表格行数
for i :=0 to High(ED_Cell) do
begin
if i<HeadC then
SetLength(ED_Cell[i],strtoint(Para.Head[1]))
else if i<BandC then
SetLength(ED_Cell[i],strtoint(Para.Band[1]))
else if i<BodyC then
SetLength(ED_Cell[i],strtoint(Para.Body[1]))
else if i<SummaryC then
SetLength(ED_Cell[i],strtoint(Para.Summary[1]))
else if i<FootC then
SetLength(ED_Cell[i],strtoint(Para.Foot[1]));
end;
for i :=0 to High(ED_Cell) do
begin
for j:=0 to High(ED_Cell[i]) do
begin
ED_Cell[i][j]:=TQRRichTExt.Create(self);
ED_Cell[i][j].Parent:=Para.Parent;
ED_Cell[i][j].Height:=Para.LinesH;
ED_Cell[i][j].Font:=Para.FontStyle;
//ED_Cell[i][j].SendToBack;
if i<HeadC then
ED_Cell[i][j].Width:=strtoint(Para.Head[j+2])+1
else if i<BandC then
ED_Cell[i][j].Width:=strtoint(Para.Band[j+2])+1
else if i<BodyC then
ED_Cell[i][j].Width:=strtoint(Para.Body[j+2])+1
else if i<SummaryC then
ED_Cell[i][j].Width:=strtoint(Para.Summary[j+2])+1
else if i<FootC then
ED_Cell[i][j].Width:=strtoint(Para.Foot[j+2])+1;
if i=0 then
ED_Cell[i][j].Top:=Para.Top
else
ED_Cell[i][j].Top:=ED_Cell[i-1][0].Top+ED_Cell[i-1][0].Height-1;
if j=0 then
begin
ED_Cell[i][j].Left:=Para.Left;
ED_Cell[i][j].Alignment:=taCenter;//第一列文本居中显示
end
else
ED_Cell[i][j].Left:=ED_Cell[i][j-1].Left+ED_Cell[i][j-1].Width-1;
//<--Width+1和Left-1错位消除处理
//头几行及最后几行增高,字体加大
if (i<BandC) or(i>=BodyC) then
begin
ED_Cell[i][j].Height:=ED_Cell[i][j].Height+4;
ED_Cell[i][j].Font.Size:=ED_Cell[i][j].Font.Size+2;
end;
//-->划表框
//划单元格上边的线
QRS:=TQRShape.Create(self);
QRS.Parent:=Para.Parent;
QRS.Shape:=qrsHorLine;
if i=Low(ED_Cell) then
begin
QRS.Pen.Width:=10; //最上边行
QRS.Height:=2;
end
else
begin
QRS.Pen.Width:=5;
QRS.Height:=1;
end;
QRS.Width:=ED_Cell[i][j].Width;
QRS.Left:=ED_Cell[i][j].Left;
QRS.Top:=ED_Cell[i][j].Top;
//划单元格左边的线
QRS:=TQRShape.Create(self);
QRS.Parent:=Para.Parent;
QRS.Height:=ED_Cell[i][j].Height;
QRS.Shape:=qrsVertLine;
if j=low(ED_Cell[i]) then
begin
QRS.Pen.Width:=10; //最左边列
QRS.Width:=2;
end
else
begin
QRS.Pen.Width:=5;
QRS.Width:=1;
end;
QRS.Left:=ED_Cell[i][j].Left;
QRS.Top:=ED_Cell[i][j].Top;
//如果单元格是最下边的,则划下边线
if i=High(ED_Cell) then
begin
QRS:=TQRShape.Create(self);
QRS.Parent:=Para.Parent;
QRS.Shape:=qrsHorLine;
QRS.Pen.Width:=10;
QRS.Height:=2;
QRS.Width:=ED_Cell[i][j].Width;
QRS.Left:=ED_Cell[i][j].Left+1;
QRS.Top:=ED_Cell[i][j].Top+ED_Cell[i][j].Height-1;
end;
//如果单元格是最右边的,则划右边线
if j=High(ED_Cell[i]) then
begin
QRS:=TQRShape.Create(self);
QRS.Parent:=Para.Parent;
QRS.Height:=ED_Cell[i][j].Height;
QRS.Shape:=qrsVertLine;
QRS.Pen.Width:=10;
QRS.Width:=2;
QRS.Left:=ED_Cell[i][j].Left+ED_Cell[i][j].Width-1;
QRS.Top:=ED_Cell[i][j].Top+1;
end;
Application.ProcessMessages;
end; //end j
end; // end i
//调整控件位置,使文字居中
for i:=low(ED_Cell) to High(ED_Cell) do
begin
for j:=low(ED_Cell[i]) to High(ED_Cell[i]) do
begin
ED_Cell[i][j].Top:=ED_Cell[i][j].Top+4;
ED_Cell[i][j].Visible:=False;
end;
end;
AddEdit;
end;
function TFrm_Table.ReadIni(TableName:string):TTBPara;// 读取表格布局信息
var
FileName:string;
IniFile:TIniFile;
TBPara:TTBPara;
str,ColCount,RowCount:string;
i:integer;
begin
FileName:=ExtractFilepath(Application.ExeName)+'Config\TB'+TableName;
if FileExists(FileName) then
begin
IniFile:=TIniFile.Create(FileName);
try
//读取表格整体信息
TBPara.Left:=IniFile.ReadInteger('Table','Left',80);
TBPara.Top:=IniFile.ReadInteger('Table','Top',150);
TBPara.LinesH:=IniFile.ReadInteger('Table','LinesH',28);
TBPara.Title:=IniFile.ReadString('Table','Title','调 度 综 合 令 票');
//-->读取各部分列宽信息
//Head
TBPara.Head:=TStringList.Create;
RowCount:=IniFile.ReadString('Head','RowCount','1');
ColCount:=IniFile.ReadString('Head','ColCount','4');
TBPara.Head.Add(RowCount);
TBPara.Head.Add(ColCount);
for i:=1 to strtoint(ColCount) do
begin
str:=IniFile.ReadString('Head','Col'+inttostr(i),'100');
TBPara.Head.Add(str);
end;
//Band
TBPara.Band:=TStringList.Create;
RowCount:=IniFile.ReadString('Band','RowCount','1');
ColCount:=IniFile.ReadString('Band','ColCount','4');
TBPara.Band.Add(RowCount);
TBPara.Band.Add(ColCount);
for i:=1 to strtoint(ColCount) do
begin
str:=IniFile.ReadString('Band','Col'+inttostr(i),'100');
TBPara.Band.Add(str);
end;
//Body
TBPara.Body:=TStringList.Create;
Rowcount:=IniFile.ReadString('Body','RowCount','17');
ColCount:=IniFile.ReadString('Body','ColCount','4');
TBPara.Body.Add(RowCount);
TBPara.Body.Add(ColCount);
for i:=1 to strtoint(ColCount) do
begin
str:=IniFile.ReadString('Body','Col'+inttostr(i),'100');
TBPara.Body.Add(str);
end;
//Summary
TBPara.Summary:=TStringList.Create;
Rowcount:=IniFile.ReadString('Summary','RowCount','2');
ColCount:=IniFile.ReadString('Summary','ColCount','4');
TBPara.Summary.Add(RowCount);
TBPara.Summary.Add(ColCount);
for i:=1 to strtoint(ColCount) do
begin
str:=IniFile.ReadString('Summary','Col'+inttostr(i),'100');
TBPara.Summary.Add(str);
end;
//Foot
TBPara.Foot:=TStringList.Create;
RowCount:=IniFile.ReadString('Foot','RowCount','2');
ColCount:=IniFile.ReadString('Foot','ColCount','4');
TBPara.Foot.Add(RowCount);
TBPara.Foot.Add(ColCount);
for i:=1 to strtoint(ColCount) do
begin
str:=IniFile.ReadString('Foot','Col'+inttostr(i),'100');
TBPara.Foot.Add(str);
end;
finally
IniFile.Free;
end;
end
else
begin
TBPara.Top:=-1;
end;
Result:=TBPara;
end;
procedure TFrm_Table.FormCreate(Sender: TObject);
var
Para:TTBPara;
begin
CurrentLine:=-1;
self.QuickRep1.DoubleBuffered:=true;// 双缓冲,解决可视化对象在屏幕上重画时效率的
//初始化
ADOTable.Connection:=Frm_Com.ADOConnection;
TableName:=ReadTableName;
if TableName <>'' then
begin
if TableName='XLDZ.ini' then
begin
self.DBGrid.Visible:=True;
Self.Panel4.Visible:=True;
Self.LB_CZ.Visible:=True;
end
else
begin
self.DBGrid.Visible:=False;
Self.Panel4.Visible:=False;
Self.LB_CZ.Visible:=False;
end;
Self.QuickRep1.Top:=0;
Self.QuickRep1.Left:=0;
Self.DetailBand1.Width:=0;
Self.DetailBand1.Height:=0;
// Self.Parent:=Frm_Main.PL_Body;
Para:=ReadIni(TableName); //// 读取表格布局信息
if(Para.Top>0) then
begin
Para.Parent:=Self.QuickRep1;
Para.FontStyle:=Self.Font;
DrawTable(Para);
SetData;
end
else
begin
showmessage('读取表格配置信息出错,配置文件丢失或损坏!');
exit;
end;
end
else
begin
showmessage('读取票据类型出错,配置文件丢失或损坏!');
exit;
end;
BT_Select.Top:=Text_Cell[BandC][0].Top-(BT_Select.Height-Text_Cell[BandC][0].Height) div 2;
BT_Select.Left:=Text_Cell[BandC][0].Left-BT_Select.Width;
end;
procedure TFrm_Table.HeaderControl1SectionClick(
HeaderControl: THeaderControl; Section: THeaderSection);
var
FileName:String;
begin
SaveData;//把在表格上的修改保存到Content中
case Section.Index of
0://第一页
begin
PageIndex:=0;
BindData(PageIndex);
end;
1://上一页
begin
if PageIndex>0 then
begin
PageIndex:=PageIndex-1;
BindData(PageIndex);
end;
end;
2://下一页
begin
if PageIndex<PageC-1 then
begin
PageIndex:=PageIndex+1;
BindData(PageIndex);
end;
end;
3://最后一页
begin
PageIndex:=PageC-1;
BindData(PageIndex);
end;
4://打印设置
begin
Self.QuickRep1.PrinterSetup;
end;
5://打印
begin
Application.CreateForm(TFrm_Print,Frm_Print);
Frm_Print.ShowModal;
end;
6://预览
begin
Self.QuickRep1.Preview;
end;
7://保存
begin
if Self.SaveDialog1.Execute then
begin
FileName:=SaveDialog1.FileName+'.DRT';
if FileExists(FileName) then
begin
if Application.MessageBox('文件已存在,是否覆盖?','警告!', MB_YESNO)=IDYES then
SaveReport(content,FileName);
end
else
SaveReport(content,FileName);
end;
end;
8://退出
begin
Close;
end;
else ;
end;
end;
procedure TFrm_Table.FormResize(Sender: TObject);
begin
Self.QuickRep1.Top:=0;
//Self.QuickRep1.Left:=(Self.Width-Self.QuickRep1.Width) div 2;
Self.QuickRep1.Left:=0;
end;
procedure TFrm_Table.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;
procedure TFrm_Table.PM_CellPopup(Sender: TObject);
var
i,j:integer;
begin
CurrentLine:=-1;
for i:=low(Text_Cell) to High(Text_Cell) do
begin
for j := low(Text_Cell[i]) to High(Text_Cell[i]) do
begin
if Text_Cell[i][j].Focused then
begin
BT_Select.Top:=Text_Cell[i][0].Top-(BT_Select.Height-Text_Cell[i][0].Height) div 2;
BT_Select.Left:=Text_Cell[i][0].Left-BT_Select.Width;
if (i>BandC) and (i<BodyC) then
begin
PM_Cell.Items[8].Enabled:=true;
PM_Cell.Items[9].Enabled:=true;
CurrentLine:=(i-BandC-1)+(BodyC-BandC-1)*PageIndex;
if CurrentLine>Content.Body.Count-1 then
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -