打印本文 打印本文 关闭窗口 关闭窗口
Delphi程序执行时实时生成报表
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3048  更新时间:2009/4/23 18:42:10  文章录入:mintao  责任编辑:mintao
,QuickRep.Page.BottomMargin);
  PageLeft.Text:=FormatFloat(''''0.00'''',QuickRep.Page.LeftMargin);
  PageRight.Text:=FormatFloat(''''0.00'''',QuickRep.Page.RightMargin);
  PageSpace.Text:=FormatFloat(''''0.00'''',QuickRep.page.ColumnSpace);
  R1.Checked:=QuickRep.Page.Orientation=poPortrait;
  Image1.Visible:=R1.Checked;
  R2.Checked:=QuickRep.Page.Orientation=poLandscape;
  Image2.Visible:=R2.Checked;
  PageDlux.Checked:=QuickRep.PrinterSettings.Duplex;
  Pages.Text:=IntToStr(QuickRep.PrinterSettings.Copies);
  PaperH.Text:=FormatFloat(''''0.00'''',QuickRep.Page.Length);
  PaperW.Text:=FormatFloat(''''0.00'''',QuickRep.Page.Width);
  For I:=0 to 26 do     //PS列表框显示纸张类型
    if QuickRep.Page.PaperSize=PaperSize[I] then begin
       PS.ItemIndex:=I;
       Break;
end;
//判断纸张宽度是否可以更改,只有纸张类型为自定义(Ps.ItemIndex=26)才能更改
  PaperH.Enabled:=Ps.ItemIndex=26;
  PaperW.Enabled:=Ps.ItemIndex=26;
end;

procedure TPrintForm.RadioButtonClick(Sender: TObject);
//纸张方向改变事件处理
var
  S:String;
begin
  Image1.Visible:=R1.Checked;
  Image2.Visible:=R2.Checked;
  if R1.Checked then
    QuickRep.Page.Orientation:=poPortrait
  else
    QuickRep.Page.Orientation:=poLandscape;
  //交换纸张宽度和长度的值
  S:=PaperH.Text;
  PaperH.Text:=PaperW.Text;
  PaperW.Text:=S;
  if (Ps.ItemIndex=26) or (Ps.ItemIndex=0) then begin
    QuickRep.Page.Width:=StrToFloat(PaperW.Text);
    QuickRep.Page.Length:=StrToFloat(PaperH.Text);
  end;
end;

procedure TPrintForm.PageDluxClick(Sender: TObject);
begin
  QuickRep.PrinterSettings.Duplex:=PageDlux.Checked;
end;

procedure TPrintForm.PageColChange(Sender: TObject);
begin
  if StrToInt(PageCol.Text)<1 then PageCol.Text:=''''1'''';
  QuickRep.Page.Columns:=StrToInt(PageCol.Text);
end;

procedure TPrintForm.PageSpaceExit(Sender: TObject);
begin
  QuickRep.Page.ColumnSpace:=StrToFloat(PageSpace.Text);
end;

procedure TPrintForm.PagesChange(Sender: TObject);
begin
  if StrToInt(Pages.Text)<1 then Pages.Text:=''''1'''';
  QuickRep.PrinterSettings.Copies:=StrToInt(Pages.Text);
end;

procedure TPrintForm.PageTopExit(Sender: TObject);
begin
  QuickRep.Page.TopMargin:=StrToFloat(PageTop.Text);
end;

procedure TPrintForm.PageBottomExit(Sender: TObject);
begin
  QuickRep.Page.BottomMargin:=StrToFloat(PageBottom.Text);
end;

procedure TPrintForm.PageLeftExit(Sender: TObject);
begin
  QuickRep.Page.LeftMargin:=StrToFloat(PageLeft.Text);
end;

procedure TPrintForm.PageRightExit(Sender: TObject);
begin
  QuickRep.Page.RightMargin:=StrToFloat(PageRight.Text);
end;

procedure TPrintForm.TTExit(Sender: TObject);//标题更改事件处理
begin
  QuickRep.ReportTitle:=TT.Text;
  Title.Caption:=TT.Text;
  Bt:=TT.Text;
end;

procedure TPrintForm.DTClick(Sender: TObject);//打印查询条件复选框事件
begin
  QRSQL.Enabled:=SR.Checked;
end;

procedure TPrintForm.BtnPrviewClick(Sender: TObject);//预览按钮单击事件
begin
  QuickRep.Preview;
end;

procedure TPrintForm.BtnSetClick(Sender: TObject); //设置按钮单击事件
begin
  QuickRep.PrinterSetup;
end;

procedure TPrintForm.PsChange(Sender: TObject);//纸张类型改变事件
begin
  QuickREp.Page.PaperSize:=PaperSize[Ps.ItemIndex];
  PaperH.Text:=FormatFloat(''''0.00'''',QuickRep.Page.Length);
  PaperW.Text:=FormatFloat(''''0.00'''',QuickRep.Page.Width);
  PaperH.Enabled:=Ps.ItemIndex=26;
  PaperW.Enabled:=Ps.ItemIndex=26;
  CrtRep.Enabled:=True;
  BtnPrint.Enabled:=not CrtRep.Enabled;
  BtnPrview.Enabled:=BtnPrint.Enabled;
end;

procedure TPrintForm.PaperChange(Sender: TObject);//纸张宽度和长度改变事件
begin
  QuickRep.Page.Width:=StrToFloat(PaperW.Text);
  QuickRep.Page.Length:=StrToFloat(PaperH.Text);
end;

procedure TPrintForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:=caFree;
end;

procedure TPrintForm.FormDestroy(Sender: TObject);
begin
  ClearRep;
  PrintForm:=nil;
end;

procedure TPrintForm.CreateReport(Sender: TObject);//生成按钮单击事件
Var
  I,L:Byte;
  CHBtp,CHBlf,Cd,ObWidth:Word;
begin
  Screen.Cursor:=crHourGlass;
  Title.Caption:=Bt;//设置标题
  ClearRep(); //清除已经建立的对象;
  if Sr.Checked then QrSQL.Caption:=CXTJ else QRSQL.Caption:='''''''';//是否打印查询条件?
  CHBtp:=HB.Height-17;//建立的控件在带区中的顶部位置
  CHBlf:=0; //建立的控件在带区中的左边位置
  ObWidth:=0; //建立的控件的宽度
  for I := 0 to Query.FieldCount-1 do    //根据Query返回字段数建立控件
  begin
if (Query.Fields[I].DataType<>ftBlob) And (Query.Fields[I].DataType<>ftMemo) then    
begin    //忽略备注字段和相片字段
      L:=Query.Fields[I].DataSize-1;//L=字段宽度(字节)-1
      case Rd1 of   //根据选择的对齐方式设置控件的对齐方式
        0: if L<=10 then Dj:=taCenter else DJ:=taLeftJustify;
        //自动对齐:字段小于等于10居中对齐,否则左边对齐
        1: Dj:=taCenter;//居中对齐
        2: DJ:=taLeftJustify;//左边对齐
      end;
      case Rd2 of    //根据选择的列表宽度设置报表列宽度
        0: begin    
       //自动宽度:如果L>14则宽度ObWidth=14+(L-14)/2;如果ObWidth
       //的宽度不能显示列标题,则ObWidth=列标题宽度;如果字段类型
       //为日期型、货币型和浮点数型,则ObWidth=65
             if L>14 then L:=14+(L-14) div 2;
             ObWidth:=L*6;
             L:=Length(Query.Fields[I].DisplayName);
             if ObWidth<L*6 then ObWidth:=L*6;
             ObWidth:=ObWidth+2;
             if (Query.Fields[I].DataType=ftDateTime) or
                (Query.Fields[I].DataType=ftFloat) or
                (Query.Fields[I].DataType=ftCurrency) then ObWidth:=65;
           end;
        1: if ColWd.Text<>'''''''' then ObWidth:=StrToInt(ColWd.Text)
              else ObWidth:=100;//相同宽度:ObWidth=输入宽度值
        2: begin  //限制最大宽度:首先按自动宽度计算再判断宽度是否超最大值,
                  //如果超过则ObWidth=最大宽度输入值
             if ColWd.Text<>'''''''' then Cd:=StrToInt(ColWd.Text)
                else Cd:=200;
             ObWidth:=L*6;
             if ObWidth>Cd then ObWidth:=Cd;
             ObWidth:=ObWidth+2;
             if (Query.Fields[I].DataType=ftDateTime) or
                (Query.Fields[I].DataType=ftFloat) or
                (Query.Fields[I].DataType=ftCurrency) then ObWidth:=65;
           end;
      end;

      if CHBlf+ObWidth>=HB.Width then begin  //建立控件>纸宽?
        DlgMes:=''''纸张宽度不够,请更改纸张尺寸。'''';
        MessageBox(Handle,DlgMes,Cap_Inf,Ico_Inf);
        break;
      end
      else begin
        CHBShape[I]:=TQRShape.Create(HB);//建立列标头带区线条控件
        CHBShape[I].Parent:=HB;
        CHBShape[I].Top:=CHBtp;
        CHBShape[I].Left:=CHBlf;
        CHBShape[I].Width:=ObWidth+1;
        CHBShape[I].Height:=17;

        CHBNAME[I]:=TQRLabel.Create(HB); //建立列标题控件
        CHBNAME[I].Parent:=HB;
        CHBNAME[I].Top:=CHBtp+2;
        CHBNAME[I].Left:=CHBlf+1;
        CHBNAME[I].AutoSize:=False;
        CHBNAME[I].Width:=ObWidth-1;
 

上一页  [1] [2] [3] [4]  下一页

打印本文 打印本文 关闭窗口 关闭窗口