📄 hwprint.pas.svn-base
字号:
TfrMemoView(v).Alignment := frtaCenter + frtaMiddle;
TfrMemoView(v).Font := pnlColumn.Font;
v.Memo.Add(edtReportTitle.Text);
Page.Objects.Add(v);
//标题band
b := TfrBandView(frCreateObject(gtBand, ''));
b.BandType := btMasterHeader;
b.SetBounds(0, 60, 1000, 30);
b.Flags := b.Flags or flStretched;
Page.Objects.Add(b);
//数据band
b := TfrBandView(frCreateObject(gtBand, ''));
b.BandType := btMasterData;
b.Dataset := FReportDataSet.Name;
b.SetBounds(0, 100, 1000, 18);
b.Flags := b.Flags or flStretched;
Page.Objects.Add(b);
FLeft:=0;
for I:=1 to sgFields.RowCount-1 do
begin
if (Page.LeftMargin+Fleft)>=Page.pgWidth then Break;
FWidth:=Round(StrToInt(sgFields.Cells[1,I])*3.6);
v := frCreateObject(gtMemo, '');
v.SetBounds(Page.LeftMargin+FLeft, 60, FWidth, 30);
TfrMemoView(v).Alignment := frtaCenter + frtaMiddle;
TfrMemoView(v).Font := pnlColumn.Font;
v.FrameTyp := 15;
v.Flags := v.Flags or flWordWrap or flStretched;
v.Memo.Add((sgFields.Cells[0,I]));
Page.Objects.Add(v);
v := frCreateObject(gtMemo, '');
v.SetBounds(Page.LeftMargin+FLeft, 100, FWidth, 18);
TfrMemoView(v).Font := pnlData.Font;
v.FrameTyp := 15;
TfrMemoView(v).GapX := 3;
v.Flags := v.Flags or flWordWrap or flStretched;
v.Memo.Add('["'+GetFieldName((sgFields.Cells[0,I]))+'"]');
Page.Objects.Add(v);
FLeft:=FLeft+FWidth;
end;
//页尾
b := TfrBandView(frCreateObject(gtBand, ''));
b.BandType := btPageFooter;
b.SetBounds(0, 260, 1000, 30);
Page.Objects.Add(b);
v := frCreateObject(gtMemo, '');
v.SetBounds(0, 270, 300, 20);
TfrMemoView(v).BandAlign:=baLeft;
TfrMemoView(v).Font := pnlFoot.Font;
// v.Memo.Add(GetDllString(10471)+'[DATE] [TIME]'); //'打印日期:'
v.Memo.Add('打印日期:[DATE] [TIME]');
Page.Objects.Add(v);
v := frCreateObject(gtMemo, '');
v.SetBounds(0, 270, 100, 20);
TfrMemoView(v).BandAlign:=baRight;
TfrMemoView(v).Font := pnlFoot.Font;
// v.Memo.Add(GetDllString(10472)+'[PAGE#] of [TOTALPAGES]'); //'页数:'
v.Memo.Add('页数:[PAGE#] of [TOTALPAGES]');
Page.Objects.Add(v);
frReport1.ShowReport;
FReportDataSet.Free;
FDataSet.EnableControls;
FDataSet.GotoBookmark(SavePlace);
FDataSet.FreeBookmark(SavePlace);
end;
procedure THwPrintForm.bbtnExitClick(Sender: TObject);
begin
//退出
Close;
end;
procedure THwPrintForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=vk_return then perform(WM_NEXTDLGCTL,0,0);
end;
procedure THwPrintForm.cbPaperClick(Sender: TObject);
begin
if Prn.PaperSizes[cbPaper.ItemIndex] = $100 then
begin
lblWidth.Enabled:=True;
lblHeight.Enabled:=True;
edtWidth.Enabled:=True;
edtHeight.Enabled:=True;
edtWidth.Color:=AEnableColor;
edtHeight.Color:=AEnableColor;
end else
begin
lblWidth.Enabled:=False;
lblHeight.Enabled:=False;
edtWidth.Enabled:=False;
edtHeight.Enabled:=False;
edtWidth.Color:=ADisableColor;
edtHeight.Color:=ADisableColor;
end;
end;
procedure THwPrintForm.rbVerticalClick(Sender: TObject);
begin
//纵向
Image1.Visible:=True;
Image2.Visible:=False;
end;
procedure THwPrintForm.rbHorizontalClick(Sender: TObject);
begin
//横向
Image2.Visible:=True;
Image1.Visible:=False;
end;
procedure THwPrintForm.bbtnTitleClick(Sender: TObject);
begin
//报表名称
FontDialog1.Font:=pnlTitle.Font;
if FontDialog1.Execute then pnlTitle.Font:=FontDialog1.Font;
end;
procedure THwPrintForm.bbtnColumnClick(Sender: TObject);
begin
//列标题
FontDialog1.Font:=pnlColumn.Font;
if FontDialog1.Execute then pnlColumn.Font:=FontDialog1.Font;
end;
procedure THwPrintForm.bbtnDataClick(Sender: TObject);
begin
//数据行
FontDialog1.Font:=pnlData.Font;
if FontDialog1.Execute then pnlData.Font:=FontDialog1.Font;
end;
procedure THwPrintForm.bbtnFootClick(Sender: TObject);
begin
//报表页脚
FontDialog1.Font:=pnlFoot.Font;
if FontDialog1.Execute then pnlFoot.Font:=FontDialog1.Font;
end;
function THwPrintForm.GetPrintWidth(AFieldName:string):string;
var
I:Integer;
begin
Result:='0';
for I:=0 to FDataSet.FieldCount-1 do
begin
if AFieldName=FDataSet.Fields[I].DisplayName then
begin
Result:=IntToStr(Round(FDataSet.Fields[I].DisplayWidth*2));
Break;
end;
end;
end;
function THwPrintForm.GetFieldName(AFieldName:string):string;
var
I:Integer;
begin
Result:='';
for I:=0 to FDataSet.FieldCount-1 do
begin
if AFieldName=FDataSet.Fields[I].DisplayName then
begin
Result:=FDataSet.Fields[I].FieldName;
Break;
end;
end;
end;
procedure THwPrintForm.SpeedButton1Click(Sender: TObject);
var
I:Integer;
Flag:string;
begin
//单选
Flag:='N';
for I:=0 to CheckListBox1.Items.Count-1 do
begin
if CheckListBox1.Checked[I] then Flag:='Y';
end;
if Flag='N' then Exit;
if CheckListBox1.ItemEnabled[CheckListBox1.ItemIndex] then
begin
CheckListBox1.Checked[CheckListBox1.ItemIndex]:=True;
if sgFields.Cells[0,1]='' then
begin
sgFields.Cells[0,1]:=CheckListBox1.Items[CheckListBox1.ItemIndex];
sgFields.Cells[1,1]:=GetPrintWidth(sgFields.Cells[0,1]);
end else
begin
sgFields.RowCount:=sgFields.RowCount+1;
sgFields.Cells[0,sgFields.RowCount-1]:=CheckListBox1.Items[CheckListBox1.ItemIndex];
sgFields.Cells[1,sgFields.RowCount-1]:=GetPrintWidth(sgFields.Cells[0,sgFields.RowCount-1]);
end;
CheckListBox1.ItemEnabled[CheckListBox1.ItemIndex]:=False;
end;
CheckListBox1.Refresh;
end;
procedure THwPrintForm.SpeedButton2Click(Sender: TObject);
var
I:Integer;
begin
//多选
for I:=0 to CheckListBox1.Items.Count-1 do
begin
if (CheckListBox1.ItemEnabled[I]) and (CheckListBox1.Checked[I]) then
begin
if sgFields.Cells[0,1]='' then
begin
sgFields.Cells[0,1]:=CheckListBox1.Items[I];
sgFields.Cells[1,1]:=GetPrintWidth(sgFields.Cells[0,1]);
end else
begin
sgFields.RowCount:=sgFields.RowCount+1;
sgFields.Cells[0,sgFields.RowCount-1]:=CheckListBox1.Items[I];
sgFields.Cells[1,sgFields.RowCount-1]:=GetPrintWidth(sgFields.Cells[0,sgFields.RowCount-1]);
end;
CheckListBox1.ItemEnabled[I]:=False;
end;
end;
CheckListBox1.Refresh;
end;
procedure THwPrintForm.SpeedButton3Click(Sender: TObject);
var
I:Integer;
begin
//单删
if not sgFields.Focused then Exit;
for I:=0 to CheckListBox1.Items.Count-1 do
begin
CheckListBox1.ItemEnabled[I]:=True;
if CheckListBox1.Items[I]=sgFields.Cells[0,ARows] then
begin
CheckListBox1.Checked[I]:=False;
sgFields.RowCount:=2;
sgFields.Cells[0,1]:='';
sgFields.Cells[1,1]:='';
end;
end;
SpeedButton2.Click;
CheckListBox1.Refresh;
end;
procedure THwPrintForm.SpeedButton4Click(Sender: TObject);
var
I:Integer;
begin
//多删
for I:=0 to CheckListBox1.Items.Count-1 do
begin
CheckListBox1.ItemEnabled[I]:=True;
CheckListBox1.Checked[I]:=False;
sgFields.RowCount:=2;
sgFields.Cells[0,1]:='';
sgFields.Cells[1,1]:='';
end;
CheckListBox1.Refresh;
end;
procedure THwPrintForm.sgFieldsSelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
ACols:=ACol;
ARows:=ARow;
end;
procedure THwPrintForm.sgFieldsKeyPress(Sender: TObject; var Key: Char);
begin
ValidInteger(Sender, Key);
end;
initialization
RegisterClass(THwPrintForm);
finalization
UnRegisterClass(THwPrintForm);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -