上传用户:zhpu1995
上传日期:2013-09-06
资源大小:61151k
文件大小:52k
源码类别:

企业管理

开发平台:

Visual Basic

  1. Attribute VB_Name = "DyjbModule"
  2. '**********************************************
  3. '*    模 块 名 称 :打印基本模块
  4. '*    功 能 描 述 :
  5. '*    程序员姓名  : 张建忠
  6. '*    最后修改人  : 张建忠
  7. '*    最后修改时间:2001/07/25
  8. '*    备        注:
  9. '**********************************************
  10. Public XtReportCode As String                                  '传递打印报表编码
  11. Public Sub Scdybb(Dyymctbl As Form, Bbzbt$, Bbxbt() As String, bbxbtzzxs() As Integer, Bbxbtgs As Integer, Bbbwh() As String, Bbbwhzzxs() As Integer, Bbbwhgs As Integer, bbylte As Boolean, Optional PrintMessageNotShow As Boolean)  '生 成 打 印 报 表
  12.     
  13.     '函数参数为:打印页面设置窗体变量,报表主标题,报表小标题数组,报表小标题组织形式,报表小标题个数,报表表尾行数组,报表表尾行组织形式,报表表尾行行数,是预览还是直接打印(选择项),打印时打印选择项窗体是否显示(主要为了支持连续打印)
  14.     
  15.     '程 序 运 行 临 时 变 量
  16.     Dim Bbbtkd$, Bbbody$, Bbydx#, Bbydy#, Bbqsx#                '报表标题宽度,表体,移动X,移动Y,报表左边界(报表起始X坐标)
  17.     Dim Rowjsq%, Coljsq%, Byhjsq%                               '网格行列计数器,本页行计数器
  18.     Dim Bbzkd#, Btzgd#, Bwzgd#, Btkdte#, Btsjhgd#, MaxColwidth# '报表总宽度,标题总高度,报表表尾行高度,标题宽度,表头+n行数据行高度,报表最大列宽
  19.     Dim Bbhsjsq&, Bbhsjsqte&, Byzzh&, Bybbhs&                   '报表数据行数计数器,报表数据行数计数保存,报表终止行,本页报表行数
  20.     Dim Ztkd1#, Ztkd2#, Ztgd1#, Ztgd2#                          '不同字体高与宽
  21.     Dim Bbsjhgd#, Bbgdhgd#, Kdfdbl#, Gdfdbl#                    '报表数据行高度,固定行高度,表宽放大比例,表高放大比例
  22.     Dim Lszbj#, Bbpage$, Bbynfyh&                               '临时左边界,报表页号,报表页内分页号
  23.     Dim jsqte%                                                  '临时计数器
  24.     Dim bbQslz&, bbzzlz&                                        '本页报表输出起始列值,本页报表输出终止列值
  25.     Dim Yxbbkd#                                                 '本页有效报表宽度
  26.     Dim Tsxx As String                                          '系统提示信息
  27.     Dim Papername(1 To 70) As String                            '纸张大小对应描述
  28.     Dim Bbzys As Integer
  29.     Dim Sfdyfyh As Boolean                                      '是否打印分页号
  30.     Dim Xbtmaxlen As Double                                     '小标题最大长度
  31.     Dim Bwhmaxlen As Double                                     '表尾行最大长度
  32.     
  33.     '设计人员自定义变量(不让用户定义是为了保持系统打印一致性)
  34.     
  35.     Dim Sckd#, Xhsjg#, Xbthjg#, zdxgd#                          '标题下划线缩进,下划线间隔,小标题表尾行间隔,装订线高度
  36.     Dim Zdxsjg#, Zdxzjg#                                        '装订线上间隔,装订线左间隔
  37.     Dim Xbths%, Bwhs%                                           '小标题行数,表尾行数
  38.     Dim Bbfzbl As String                                        '报表分组输出条件
  39.     Dim Bwzb$, Bwbzdw$                                          '表尾制表人,报表编制单位
  40.     
  41.     '用 户 自 定 义 变 量
  42.     Dim Bbgdscqsl&, Bbgdsczzl&, bbscQslz&, bbsczzlz&            '报表固定输出起始列,报表固定输出终止列,报表输出起始列,报表输出终止列(报表起始列>报表固定输出终止列)
  43.     Dim Btfontsize&, Sjfontsize&, Btfontname$, Sjfontname$      '报表标题字体大小,数据区字体大小
  44.     Dim Pagecount%, Mybbhs&, Zdbbhs&                            '报表页数计数器,每页满页报表行数,用户指定报表行数
  45.     Dim Dyxsbz As Boolean, Sfmy As Boolean, Zdhs As Boolean     '是否输出单元标志,表格满页控制,指定每页报表行数
  46.     Dim Bwdyrq$, Bwrjmc$                                        '打印日期,软件制作版本
  47.     Dim Bbalign$                                                '报表组织形式(1-居左,2-居中)
  48.     Dim zdxwz%                                                  '报表装订线位置
  49.     Dim sfsckb  As Boolean                                      '是否输出空表
  50.     Dim sfscgdl As Boolean                                      '页内分页时是否输出固定列
  51.     Dim Sflxdy  As Boolean                                      '报表是否连续打印
  52.     Dim Sftdfssc As Boolean                                     '是否套打方式输出
  53.     Dim Bjjghs  As Integer                                      '报表之间间隔
  54.     Dim Bbmcte  As String                                       '报 表 名 称
  55.     Dim Bbbxjg  As Long                                         '报表表线打印间隔
  56.     
  57.     Papername(1) = "Letter, 8 1/2 x 11 英寸"
  58.     Papername(2) = "Letter Small, 8?x 11 英寸"
  59.     Papername(3) = "Tabloid, 11 x 17 英寸"
  60.     Papername(4) = "Ledger, 17 x 11 英寸"
  61.     Papername(5) = "Legal, 8 x 14 英寸"
  62.     Papername(6) = "Statement, 5 1/2 x 8 1/2 英寸"
  63.     Papername(7) = "Executive, 7 1/2 x 10 1/2 英寸"
  64.     Papername(8) = "A3 297 x 420 毫米"
  65.     Papername(9) = "A4 210 x 297 毫米"
  66.     Papername(10) = "A4 Small, 210 x 297 毫米"
  67.     Papername(11) = "A5, 148 x 210 毫米"
  68.     Papername(12) = "B4, 250 x 354 毫米"
  69.     Papername(13) = "B5, 182 x 257 毫米"
  70.     Papername(14) = "Folio, 8 x 13 英寸"
  71.     Papername(15) = "Quarto, 215 x 275 毫米"
  72.     Papername(16) = "10 x 14 英寸"
  73.     Papername(17) = "11x17 英寸"
  74.     Papername(18) = "Note 8 1/2 x 11 英寸"
  75.     Papername(19) = "Envelope #9 3 7/8 x 8 7/8"
  76.     Papername(20) = "Envelope #10 4 1/8 x 9 1/2"
  77.     Papername(21) = "Envelope #11 4 1/2 x 10 3/8"
  78.     Papername(22) = "Envelope #12 4 276 x 11"
  79.     Papername(23) = "Envelope #14 5 x 11 1/2"
  80.     Papername(24) = "C size sheet"
  81.     Papername(25) = "D size sheet"
  82.     Papername(26) = "E size sheet"
  83.     Papername(27) = "Envelope DL 110 x 220毫米"
  84.     Papername(28) = "Envelope C5 162 x 229 毫米"
  85.     Papername(29) = "Envelope C3  324 x 458 毫米"
  86.     Papername(30) = "Envelope C4  229 x 324 毫米"
  87.     Papername(31) = "Envelope C6  114 x 162 毫米"
  88.     Papername(32) = "Envelope C65 114 x 229 毫米"
  89.     Papername(33) = "Envelope B4  250 x 353 毫米"
  90.     Papername(34) = "Envelope B5  176 x 250 毫米"
  91.     Papername(35) = "Envelope B6  176 x 125 毫米"
  92.     Papername(36) = "Envelope 110 x 230 毫米"
  93.     Papername(37) = "Envelope Monarch 3.875 x 7.5 英寸"
  94.     Papername(38) = "6 3/4 Envelope 3 5/8 x 6 1/2 英寸"
  95.     Papername(39) = "US Std Fanfold 14 7/8 x 11 英寸"
  96.     Papername(40) = "German Std Fanfold 8 1/2 x 12 英寸"
  97.     Papername(41) = "German Legal Fanfold 8 1/2 x 13 英寸"
  98.     Papername(42) = "B4 (ISO) 250 x 353 毫米"
  99.     Papername(43) = "Japanese Postcard 100 x 148 毫米"
  100.     Papername(44) = "9 x 11 英寸"
  101.     Papername(45) = "10 x 11 英寸"
  102.     Papername(46) = "15 x 11 英寸"
  103.     Papername(47) = "Envelope Invite 220 x 220 毫米"
  104.     Papername(48) = "" ' RESERVED--DO NOT USE
  105.     Papername(49) = "" ' RESERVED--DO NOT USE
  106.     Papername(50) = "Letter Extra 9 275 x 12 英寸"
  107.     Papername(51) = "Legal Extra 9 275 x 15 英寸"
  108.     Papername(52) = "Tabloid Extra 11.69 x 18 英寸"
  109.     Papername(53) = "A4 Extra 9.27 x 12.69 英寸"
  110.     Papername(54) = "Letter Transverse 8 275 x 11 英寸"
  111.     Papername(55) = "A4 Transverse 210 x 297 毫米"
  112.     Papername(56) = "Letter Extra Transverse 9275 x 12 英寸"
  113.     Papername(57) = "SuperA/SuperA/A4 227 x 356 毫米"
  114.     Papername(58) = "SuperB/SuperB/A3 305 x 487 毫米"
  115.     Papername(59) = "Letter Plus 8.5 x 12.69 英寸"
  116.     Papername(60) = "A4 Plus 210 x 330 毫米"
  117.     Papername(61) = "A5 Transverse 148 x 210 毫米"
  118.     Papername(62) = "B5 (JIS) Transverse 182 x 257 毫米"
  119.     Papername(63) = "A3 Extra 322 x 445 毫米"
  120.     Papername(64) = "A5 Extra 174 x 235 毫米"
  121.     Papername(65) = "B5 (ISO) Extra 201 x 276 毫米"
  122.     Papername(66) = "A2 420 x 594 毫米"
  123.     Papername(67) = "A3 Transverse 297 x 420 毫米"
  124.     Papername(68) = "A3 Extra Transverse 322 x 445 毫米"
  125.     
  126.     '设计人员依系统情况而定数据(单位:像素点)
  127.     
  128.     zdxgd = 700                                                 '装订线高度
  129.     Sckd = 300                                                  '标题下划线缩进宽度
  130.     Xhsjg = 50                                                  '下划线间隔
  131.     Xbthjg = 150                                                '小标题及表尾与报表之间行间隔
  132.     Xbths = Bbxbtgs                                             '小标题行数
  133.     Bwhs = Bbbwhgs + 3                                          '表尾行数
  134.     Bwzb = "制表:" + Xtczy
  135.     Bwbzdw = "【" + Xtdwm + "】"
  136.     
  137.     '读入用户定义页面特殊设置
  138.     
  139.     With Dyymctbl
  140.         
  141.         '0-报表名称
  142.         Bbmcte = .BbmcLabel
  143.         
  144.         '1-装订位置
  145.         For jsqte = 0 To 2
  146.             If .Zdoption(jsqte).Value Then
  147.                 zdxwz = jsqte
  148.                 Exit For
  149.             End If
  150.         Next jsqte
  151.         
  152.         '2-是否满页打印
  153.         If .MydyCheck.Value = 1 Then
  154.             Sfmy = True
  155.         Else
  156.             Sfmy = False
  157.         End If
  158.         
  159.         '3-对称页边距
  160.         If .BjdcCheck.Value = 1 Then
  161.             Bbalign = "2"
  162.         Else
  163.             Bbalign = "1"
  164.         End If
  165.         
  166.         '4-用户指定报表行数
  167.         If .ZdhsCheck.Value = 1 Then
  168.             Zdhs = True
  169.             Zdbbhs = Val(.BbhsText)
  170.         Else
  171.             Zdhs = False
  172.             Zdbbhs = 0
  173.         End If
  174.         
  175.         '5-无数据记录是否显示空表
  176.         If .KbscCheck = 1 Then
  177.             sfsckb = True
  178.         Else
  179.             sfsckb = False
  180.         End If
  181.         
  182.         '6-报表起始页编号
  183.         Pagecount = 1
  184.         
  185.         '7-页内换页是否输出固定列
  186.         
  187.         If .GdscCheck = 1 Then
  188.             sfscgdl = True
  189.         Else
  190.             sfscgdl = False
  191.         End If
  192.         
  193.         '8-读 入 报 表 标 题 及 表 体 字 体,字 号
  194.         Btfontname = .Btztlabel
  195.         Btfontsize = .Btzhlabel
  196.         Sjfontname = .SjztLabel
  197.         Sjfontsize = .Sjzhlabel
  198.         
  199.         '9-读 入 报 表 输 出 列 情 况
  200.         Bbgdscqsl = 0
  201.         Bbgdsczzl = Dyymctbl.BbsclText
  202.         If sfscgdl Then
  203.             bbscQslz = Dyymctbl.BbsclText + 1
  204.         Else
  205.             bbscQslz = 0
  206.         End If
  207.         bbsczzlz = DY_Tybbyldy.DyylGrid.Cols - 1
  208.         
  209.         '10-读入报表未满页是否连续打印
  210.         If Dyymctbl.LxscCheck = 1 Then
  211.             Sflxdy = True
  212.         Else
  213.             Sflxdy = False
  214.         End If
  215.         
  216.         '11-报表是否套打方式输出
  217.         If Dyymctbl.TdfsCheck = 1 Then
  218.             Sftdfssc = True
  219.         Else
  220.             Sftdfssc = False
  221.         End If
  222.         
  223.         '11-读入报表之间间隔(同时可以考虑表间可以加一下划线--页内折线)
  224.         Bjjghs = Val(Dyymctbl.Bjjglabel)
  225.         
  226.         '12-读入报表表线打印间隔
  227.         Bbbxjg = Val(Dyymctbl.BxjgLabel)
  228.         
  229.     End With
  230.     
  231.     DY_Tybbyldy.Caption = "报表预览_" + Bbmcte   '显示报表名称
  232.     
  233.     With DY_Tybbyldy.Tydy
  234.         If DY_Tybbyldy.Tydy.NDevices <= 0 Then
  235.             Tsxx = "本机未安装任何打印机!"
  236.             Call Xtxxts(Tsxx, 0, 1)
  237.             Unload DY_Tybbyldy
  238.             Exit Sub
  239.         End If
  240.         '10-读入[页面设置]中VSprinter的信息
  241.         '包括打印机 , 输出方向, 来源, 左边界
  242.         '右边界,上边界,下边界,自定义纸张大小
  243.         .Device = Dyymctbl.YmszPrinter.Device
  244.         .Orientation = Dyymctbl.YmszPrinter.Orientation
  245.         .PaperBin = Dyymctbl.YmszPrinter.PaperBin
  246.         .MarginLeft = Dyymctbl.YmszPrinter.MarginLeft
  247.         .MarginRight = Dyymctbl.YmszPrinter.MarginRight
  248.         .MarginTop = Dyymctbl.YmszPrinter.MarginTop
  249.         .MarginBottom = Dyymctbl.YmszPrinter.MarginBottom
  250.         If Dyymctbl.YmszPrinter.PaperSize = pprUser Then
  251.             .PaperSize = pprUser
  252.             .PaperWidth = Dyymctbl.YmszPrinter.PageWidth
  253.             .PageHeight = Dyymctbl.YmszPrinter.PaperHeight
  254.         Else
  255.             .PaperSize = Dyymctbl.YmszPrinter.PaperSize
  256.         End If
  257.         
  258.         '显示简单打印信息
  259.         DY_Tybbyldy.DYStatus.Panels(1).Text = "打印机:" + .Device
  260.         If .PaperSize >= 1 And .PaperSize <= 68 Then
  261.             DY_Tybbyldy.DYStatus.Panels(2).Text = "纸张大小:" + Papername(.PaperSize)
  262.         Else
  263.             DY_Tybbyldy.DYStatus.Panels(2).Text = "纸张大小:" + str(.PaperHeight) + " x " + str(.PaperWidth)
  264.         End If
  265.         If .Orientation = orLandscape Then
  266.             DY_Tybbyldy.DYStatus.Panels(3).Text = "输出方向:" + "横向"
  267.         Else
  268.             DY_Tybbyldy.DYStatus.Panels(3).Text = "输出方向:" + "纵向"
  269.         End If
  270.         
  271.         Bbhsjsq = DY_Tybbyldy.DyylGrid.FixedRows
  272.         Bwdyrq = "打印日期:" + Format(Date, "yyyy.mm.dd")
  273.         Bwrjmc = "【百利/ERP】"
  274.         Sfdyfyh = False
  275.         
  276.         .BrushStyle = bsTransparent
  277.         
  278.         .StartDoc
  279.         
  280.         '测 试 报 表 放 大 比 例
  281.         .FontName = DY_Tybbyldy.DyylGrid.FontName
  282.         .FontSize = DY_Tybbyldy.DyylGrid.FontSize
  283.         .CalcText = "测试"
  284.         Ztkd1 = .TextWid
  285.         Ztgd1 = .TextHei
  286.         .FontName = Sjfontname
  287.         .FontSize = Sjfontsize
  288.         .CalcText = "测试"
  289.         Ztkd2 = .TextWid
  290.         Ztgd2 = .TextHei
  291.         Kdfdbl = Ztkd2 / Ztkd1 / 1.001
  292.         Gdfdbl = Ztgd2 / Ztgd1
  293.         Bbgdhgd = DY_Tybbyldy.DyylGrid.RowHeight(0) * Gdfdbl
  294.         If DY_Tybbyldy.DyylGrid.Rows > DY_Tybbyldy.DyylGrid.FixedRows Then
  295.             Bbsjhgd = DY_Tybbyldy.DyylGrid.RowHeight(DY_Tybbyldy.DyylGrid.FixedRows) * Gdfdbl
  296.         Else
  297.             Bbsjhgd = DY_Tybbyldy.DyylGrid.RowHeight(DY_Tybbyldy.DyylGrid.Rows - 1) * Gdfdbl
  298.         End If
  299.         
  300.         '计算高度(含主标题+下划线+小标题,表头+n行数据行,表尾总高度(保持报表完整性)
  301.         '计算主标题+下划线+小标题高度
  302.         Btzgd = 0
  303.         .FontBold = True
  304.         .FontName = Btfontname
  305.         .FontSize = Btfontsize
  306.         .CalcText = Bbzbt
  307.         Btzgd = Btzgd + .TextHei + 2 * Xhsjg
  308.         .FontBold = False
  309.         .FontName = Sjfontname
  310.         .FontSize = Sjfontsize
  311.         .CalcText = "测试"
  312.         Btzgd = Btzgd + Xbths * .TextHei + (Xbths + 1) * Xbthjg + Zdxsjg
  313.         
  314.         '计算表头+n行数据行高度(如果指定每页报表行数则n=zdbbhs 否则 n=1)
  315.         Btsjhgd = 0
  316.         Btsjhgd = Btsjhgd + DY_Tybbyldy.DyylGrid.FixedRows * Bbgdhgd
  317.         If Zdbbhs <> 0 Then
  318.             Btsjhgd = Btsjhgd + Zdbbhs * Bbsjhgd
  319.         Else
  320.             Btsjhgd = Btsjhgd + Bbsjhgd
  321.         End If
  322.         
  323.         '计算表尾高度(表尾行之间无间隔)
  324.         Bwzgd = Xbthjg + Bwhs * .TextHei + Bjjghs * .TextHei
  325.         
  326.         '计算每页报表满页打印行数及报表总页数
  327.         If zdxwz = 1 Then
  328.             Zdxsjg = zdxgd
  329.         End If
  330.         Mybbhs = Int((.PageHeight - .MarginTop - Zdxsjg - Btzgd - .MarginBottom - Bwzgd - DY_Tybbyldy.DyylGrid.FixedRows * Bbgdhgd) / Bbsjhgd)
  331.         
  332.         '解决由于纸张高度太小出现死循环
  333.         If Mybbhs < 1 Then
  334.             Tsxx = "纸张高度不足以输出一行有效数据行,请重新设置!"
  335.             Call Xtxxts(Tsxx, 0, 4)
  336.             Unload DY_Tybbyldy
  337.             Exit Sub
  338.         End If
  339.         
  340.         If Zdhs Then
  341.             If Zdbbhs < Mybbhs Then
  342.                 Mybbhs = Zdbbhs
  343.             End If
  344.         End If
  345.         
  346.         '循环前初始化值
  347.         
  348.         bbQslz = bbscQslz
  349.         Bbynfyh = 1
  350.         bbynbz = "1"
  351.         Bbhsjsqte = Bbhsjsq
  352.         
  353.         Do While sfsckb Or Bbhsjsq <= DY_Tybbyldy.DyylGrid.Rows - 1
  354.             
  355.             '打印公司标志
  356.             
  357.             '.DrawPicture DY_Tybbyldy.Image1.Picture, .MarginLeft, .MarginTop
  358.             
  359.             '显示打印状态
  360.             Call Sub_SetOperStatus("正在输出打印信息...第" & Trim(str(Pagecount)) & "页")
  361.             
  362.             '输 出 报 表 装 订 线
  363.             Zdxsjg = 0
  364.             Zdxzjg = 0
  365.             Call Scbbzdx(zdxwz, zdxgd, Zdxsjg, Zdxzjg)
  366.             
  367.             '计 算 报 表 总 宽 度 及 报 表 起 始 X
  368.             Bbzkd = 0
  369.             
  370.             '1.计 算 报 表 有 效 区 宽 度(即报表不能超出.marginleft .marginright)
  371.             Yxbbkd = .PageWidth - .MarginLeft - .MarginRight - Zdxzjg
  372.             
  373.             '2.计算报表真正宽度及本页报表起始终止列值(*固定输出列宽<报表有效宽度)
  374.             If sfscgdl Then
  375.                 For Coljsq = Bbgdscqsl To Bbgdsczzl
  376.                     Bbzkd = Bbzkd + DY_Tybbyldy.DyylGrid.ColWidth(Coljsq) * Kdfdbl
  377.                 Next Coljsq
  378.             End If
  379.             For Coljsq = bbQslz To bbsczzlz
  380.                 Bbzkd = Bbzkd + DY_Tybbyldy.DyylGrid.ColWidth(Coljsq) * Kdfdbl
  381.                 If Bbzkd <= Yxbbkd Then
  382.                     bbzkdte = Bbzkd
  383.                     bbzzlz = Coljsq
  384.                 Else
  385.                     Sfdyfyh = True
  386.                     Exit For
  387.                 End If
  388.             Next Coljsq
  389.             Bbzkd = bbzkdte
  390.             
  391.             '计 算 报 表 起 始 X 坐 标
  392.             Select Case Bbalign
  393.             Case "1"
  394.                 Bbqsx = .MarginLeft + Zdxzjg
  395.             Case "2"
  396.                 If Zdxzjg = 0 Then
  397.                     If .PageWidth > Bbzkd Then
  398.                         Bbqsx = (.PageWidth - Bbzkd) / 2
  399.                     Else
  400.                         Bbqsx = .MarginLeft
  401.                     End If
  402.                 Else
  403.                     If .PageWidth - Zdxzjg - .MarginLeft > Bbzkd Then
  404.                         Bbqsx = (.PageWidth - Bbzkd - Zdxzjg - .MarginLeft) / 2 + Zdxzjg + .MarginLeft
  405.                     Else
  406.                         Bbqsx = .MarginLeft + Zdxzjg
  407.                     End If
  408.                 End If
  409.             End Select
  410.             
  411.             '本页报表初始动态X,Y坐标(原则:内容输出完毕紧接着移动坐标为下一次输出作准备)
  412.             Bbydx = Bbqsx
  413.             Bbydy = .MarginTop + Zdxsjg
  414.             
  415.             Do While (Bbydy <= .PageHeight - .MarginBottom - Bwzgd - Bbsjhgd And Bbhsjsq <= DY_Tybbyldy.DyylGrid.Rows - 1) Or sfsckb  '直至整个网格输出完毕
  416.                 
  417.                 '生 成 报 表 标 题
  418.                 .FontBold = True
  419.                 .FontName = Btfontname
  420.                 .FontSize = Btfontsize
  421.                 .CalcText = Bbzbt
  422.                 bbzbty = Bbydy
  423.                 bbzbtx = Bbzkd / 2 - .TextWid / 2 + Bbydx
  424.                 .TextBox Bbzbt, bbzbtx, bbzbty, .TextWid, .TextHei, False
  425.                 
  426.                 '非套打方式输出
  427.                 If Not Sftdfssc Then
  428.                     .DrawLine bbzbtx - Sckd, bbzbty + .TextHei + Xhsjg, bbzbtx + .TextWid + Sckd, bbzbty + .TextHei + Xhsjg
  429.                     .DrawLine bbzbtx - Sckd, bbzbty + .TextHei + 2 * Xhsjg, bbzbtx + .TextWid + Sckd, bbzbty + .TextHei + 2 * Xhsjg
  430.                 End If
  431.                 Bbydy = Bbydy + .TextHei + 2 * Xhsjg + Xbthjg
  432.                 .FontBold = False
  433.                 .FontName = Sjfontname
  434.                 .FontSize = Sjfontsize
  435.                 Xbtmaxlen = 0
  436.                 For jsqte = 1 To Bbxbtgs
  437.                     .CalcText = Bbxbt(jsqte)
  438.                     If .TextWid > Xbtmaxlen Then
  439.                         Xbtmaxlen = .TextWid
  440.                     End If
  441.                 Next jsqte
  442.                 
  443.                 '生成报表小标题同时在最后小标题行加页号
  444.                 For jsqte = 1 To Bbxbtgs
  445.                     
  446.                     .CalcText = Bbxbt(jsqte)
  447.                     Select Case bbxbtzzxs(jsqte)
  448.                     Case 0   '居左
  449.                         .TextBox Bbxbt(jsqte), Bbydx, Bbydy, .TextWid, .TextHei, False
  450.                     Case 1   '居中
  451.                         .TextBox Bbxbt(jsqte), Bbzkd / 2 - Xbtmaxlen / 2 + Bbydx, Bbydy, .TextWid, .TextHei, False
  452.                     Case 2   '居右
  453.                         .TextBox Bbxbt(jsqte), Bbydx + Bbzkd - .TextWid, Bbydy, .TextWid, .TextHei, False
  454.                     End Select
  455.                     
  456.                     '输出页号且居右
  457.                     If jsqte = Bbxbtgs Then
  458.                         If Sfdyfyh Then
  459.                             Bbpage = "第" + Trim(str(Pagecount)) + "-" + Trim(str(Bbynfyh)) + "页  "
  460.                         Else
  461.                             Bbpage = "第" + Trim(str(Pagecount)) + "页  "
  462.                         End If
  463.                         .CalcText = Bbpage
  464.                         .TextBox Bbpage, Bbydx + Bbzkd - .TextWid, Bbydy, .TextWid, .TextHei, False
  465.                     End If
  466.                     
  467.                     Bbydy = Bbydy + .TextHei + Xbthjg
  468.                 Next jsqte
  469.                 
  470.                 '生 成 报 表 表 头
  471.                 Btkdte = 0
  472.                 If sfscgdl <> 0 Then
  473.                     Call scbbbt(DY_Tybbyldy.DyylGrid, Bbgdscqsl, Bbgdsczzl, Kdfdbl, Bbgdhgd, Bbydy, Bbydx, Bbqsx, Sftdfssc)
  474.                     For Coljsq = Bbgdscqsl To Bbgdsczzl
  475.                         Btkdte = Btkdte + DY_Tybbyldy.DyylGrid.ColWidth(Coljsq) * Kdfdbl
  476.                     Next Coljsq
  477.                 End If
  478.                 Call scbbbt(DY_Tybbyldy.DyylGrid, bbQslz, bbzzlz, Kdfdbl, Bbgdhgd, Bbydy, Bbydx + Btkdte, Bbqsx + Btkdte, Sftdfssc)
  479.                 Bbydy = Bbydy + DY_Tybbyldy.DyylGrid.FixedRows * Bbgdhgd
  480.                 
  481.                 '生 成 报 表 表 体(包括各列列宽,数据内容)
  482.                 .CurrentY = Bbydy
  483.                 
  484.                 '报表是否套打方式输出
  485.                 
  486.                 If Sftdfssc Then
  487.                     .TableBorder = tbNone
  488.                 Else
  489.                     If Bbbxjg > 1 Then
  490.                         .TableBorder = tbBoxColumns
  491.                     End If
  492.                 End If
  493.                 
  494.                 .StartTable
  495.                 Bbbtkd = ""
  496.                 Bbbody = ""
  497.                 
  498.                 '填 充 列 宽
  499.                 If sfscgdl Then
  500.                     For Coljsq = Bbgdscqsl To Bbgdsczzl
  501.                         If DY_Tybbyldy.DyylGrid.ColAlignment(Coljsq) = flexAlignRightTop Then
  502.                             Zzf = "+>"
  503.                         Else
  504.                             Zzf = "+"
  505.                         End If
  506.                         Bbbtkd = Bbbtkd + Zzf + Trim(str(DY_Tybbyldy.DyylGrid.ColWidth(Coljsq) * Kdfdbl)) + "|"
  507.                     Next Coljsq
  508.                 End If
  509.                 For Coljsq = bbQslz To bbzzlz
  510.                     If DY_Tybbyldy.DyylGrid.ColAlignment(Coljsq) = flexAlignRightTop Then
  511.                         Zzf = "+>"
  512.                     Else
  513.                         Zzf = "+"
  514.                     End If
  515.                     If Coljsq = bbzzlz Then
  516.                         Bbbtkd = Bbbtkd + Zzf + Trim(str(DY_Tybbyldy.DyylGrid.ColWidth(Coljsq) * Kdfdbl)) + ";"
  517.                     Else
  518.                         Bbbtkd = Bbbtkd + Zzf + Trim(str(DY_Tybbyldy.DyylGrid.ColWidth(Coljsq) * Kdfdbl)) + "|"
  519.                     End If
  520.                 Next Coljsq
  521.                 
  522.                 '填 充 数 据 内 容
  523.                 Bybbhs = 0
  524.                 Do While Bybbhs <= Mybbhs And Bbhsjsq <= DY_Tybbyldy.DyylGrid.Rows - 1
  525.                     If Zdhs Then
  526.                         If Bybbhs >= Zdbbhs Then
  527.                             Exit Do
  528.                         End If
  529.                     End If
  530.                     Rowjsq = Bbhsjsq
  531.                     If sfscgdl Then
  532.                         For Coljsq = Bbgdscqsl To Bbgdsczzl
  533.                             If DY_Tybbyldy.DyylGrid.ColWidth(Coljsq) >= Ztkd2 / 2 Then
  534.                                 DY_Tybbyldy.DyylGrid.TextMatrix(Rowjsq, Coljsq) = Thwxzf(DY_Tybbyldy.DyylGrid.TextMatrix(Rowjsq, Coljsq))
  535.                                 If Len(DY_Tybbyldy.DyylGrid.ColFormat(Coljsq)) <> 0 Then
  536.                                     Bbbody = Bbbody + Format(DY_Tybbyldy.DyylGrid.TextMatrix(Rowjsq, Coljsq), DY_Tybbyldy.DyylGrid.ColFormat(Coljsq)) + "|"
  537.                                 Else
  538.                                     Bbbody = Bbbody + DY_Tybbyldy.DyylGrid.TextMatrix(Rowjsq, Coljsq) + "|"
  539.                                 End If
  540.                             Else
  541.                                 Bbbody = Bbbody + "|"
  542.                             End If
  543.                         Next Coljsq
  544.                     End If
  545.                     For Coljsq = bbQslz To bbzzlz
  546.                         If DY_Tybbyldy.DyylGrid.ColWidth(Coljsq) >= Ztkd2 / 2 Then
  547.                             If Coljsq = bbzzlz Then
  548.                                 DY_Tybbyldy.DyylGrid.TextMatrix(Rowjsq, Coljsq) = Thwxzf(DY_Tybbyldy.DyylGrid.TextMatrix(Rowjsq, Coljsq))
  549.                                 If Len(DY_Tybbyldy.DyylGrid.ColFormat(Coljsq)) <> 0 Then
  550.                                     Bbbody = Bbbody + Format(DY_Tybbyldy.DyylGrid.TextMatrix(Rowjsq, Coljsq), DY_Tybbyldy.DyylGrid.ColFormat(Coljsq)) + ";"
  551.                                 Else
  552.                                     Bbbody = Bbbody + DY_Tybbyldy.DyylGrid.TextMatrix(Rowjsq, Coljsq) + ";"
  553.                                 End If
  554.                             Else
  555.                                 DY_Tybbyldy.DyylGrid.TextMatrix(Rowjsq, Coljsq) = Thwxzf(DY_Tybbyldy.DyylGrid.TextMatrix(Rowjsq, Coljsq))
  556.                                 If Len(DY_Tybbyldy.DyylGrid.ColFormat(Coljsq)) <> 0 Then
  557.                                     Bbbody = Bbbody + Format(DY_Tybbyldy.DyylGrid.TextMatrix(Rowjsq, Coljsq), DY_Tybbyldy.DyylGrid.ColFormat(Coljsq)) + "|"
  558.                                 Else
  559.                                     Bbbody = Bbbody + DY_Tybbyldy.DyylGrid.TextMatrix(Rowjsq, Coljsq) + "|"
  560.                                 End If
  561.                             End If
  562.                         Else
  563.                             If Coljsq = bbzzlz Then
  564.                                 Bbbody = Bbbody + ";"
  565.                             Else
  566.                                 Bbbody = Bbbody + "|"
  567.                             End If
  568.                         End If
  569.                     Next Coljsq
  570.                     Bybbhs = Bybbhs + 1
  571.                     Bbhsjsq = Bbhsjsq + 1
  572.                 Loop
  573.                 .AddTable Bbbtkd, "", Bbbody
  574.                 
  575.                 '如果指定报表行数,则不进行满页打印
  576.                 If Sfmy And Bybbhs < Mybbhs Then
  577.                     Bbbody = ""
  578.                     For Rowjsq = 1 To Mybbhs - Bybbhs
  579.                         If Bbgdsczzl <> 0 Then
  580.                             For Coljsq = Bbgdscqsl To Bbgdsczzl
  581.                                 Bbbody = Bbbody + "|"
  582.                             Next Coljsq
  583.                         End If
  584.                         For Coljsq = bbQslz To bbzzlz
  585.                             If Coljsq = bbzzlz Then
  586.                                 Bbbody = Bbbody + ";"
  587.                             Else
  588.                                 Bbbody = Bbbody + "|"
  589.                             End If
  590.                         Next Coljsq
  591.                         .AddTable Bbbtkd, "", Bbbody
  592.                         Bbbody = ""
  593.                         Bybbhs = Bybbhs + 1
  594.                     Next Rowjsq
  595.                 End If
  596.                 
  597.                 '设置报表行高度
  598.                 For Rowjsq = 1 To Bybbhs
  599.                     .TableCell(tcRowHeight, Rowjsq) = Bbsjhgd
  600.                     Bbydy = Bbydy + Bbsjhgd
  601.                     If Bbbxjg > 1 Then
  602.                         If Rowjsq Mod Bbbxjg = 0 And Rowjsq <> Bybbhs Then
  603.                             If Not Sftdfssc Then
  604.                                 .DrawLine Bbqsx, Bbydy, Bbqsx + Bbzkd, Bbydy
  605.                             End If
  606.                         End If
  607.                     End If
  608.                 Next Rowjsq
  609.                 
  610.                 Lszbj = .MarginLeft
  611.                 .MarginLeft = Bbqsx
  612.                 
  613.                 .EndTable
  614.                 .MarginLeft = Lszbj
  615.                 
  616.                 '生 成 报 表 表 尾
  617.                 Bbydy = Bbydy + Xbthjg
  618.                 If Bbbwhgs <> 0 Then
  619.                     Bwhmaxlen = 0
  620.                     For jsqte = 1 To Bbbwhgs
  621.                         .CalcText = Bbbwh(jsqte)
  622.                         If .TextWid > Bwhmaxlen Then
  623.                             Bwhmaxlen = .TextWid
  624.                         End If
  625.                     Next jsqte
  626.                     For jsqte = 1 To Bbbwhgs
  627.                         .CalcText = Bbbwh(jsqte)
  628.                         Select Case Bbbwhzzxs(jsqte)
  629.                         Case 0
  630.                             .TextBox Bbbwh(jsqte), Bbydx, Bbydy, .TextWid, .TextHei, False
  631.                         Case 1
  632.                             .TextBox Bbbwh(jsqte), Bbzkd / 2 - Bwhmaxlen / 2 + Bbydx, Bbydy, .TextWid, .TextHei, False
  633.                         Case 2
  634.                             .TextBox Bbbwh(jsqte), Bbydx + Bbzkd - .TextWid, Bbydy, .TextWid, .TextHei, False
  635.                         End Select
  636.                         Bbydy = Bbydy + .TextHei
  637.                     Next jsqte
  638.                 End If
  639.                 .CalcText = Bwzb
  640.                 .TextBox Bwzb, Bbqsx, Bbydy, .TextWid, .TextHei
  641.                 .CalcText = Bwdyrq
  642.                 .TextBox Bwdyrq, Bbqsx + Bbzkd - .TextWid, Bbydy, .TextWid, .TextHei
  643.                 Bbydy = Bbydy + .TextHei
  644.                 .CalcText = Bwbzdw
  645.                 .TextBox Bwbzdw, Bbqsx, Bbydy, .TextWid, .TextHei
  646.                 .CalcText = Bwrjmc
  647.                 .TextBox Bwrjmc, Bbqsx + Bbzkd - .TextWid, Bbydy, .TextWid, .TextHei
  648.                 
  649.                 Bbydy = Bbydy + .TextHei + Bjjghs * .TextHei
  650.                 
  651.                 If Not (Sflxdy And .PageHeight - Bbydy >= Btzgd + Btsjhgd + Bwzgd) Then
  652.                     Exit Do
  653.                 End If
  654.             Loop
  655.             
  656.             '判 断 是 页 内 分 页 还 是 开 始 新 的 一 页
  657.             If bbzzlz = bbsczzlz Then
  658.                 
  659.                 '如果为空表仅输出一页
  660.                 sfsckb = False
  661.                 
  662.                 bbynbz = "0"
  663.                 Bbynfyh = 1
  664.                 bbQslz = bbscQslz
  665.                 bbzzlz = bbscQslz
  666.                 If Bbhsjsq <= DY_Tybbyldy.DyylGrid.Rows - 1 Then
  667.                     Bbhsjsqte = Bbhsjsq
  668.                     .NewPage
  669.                     Pagecount = Pagecount + 1
  670.                 End If
  671.             Else
  672.                 bbynbz = "1"
  673.                 Bbhsjsq = Bbhsjsqte
  674.                 Bbynfyh = Bbynfyh + 1
  675.                 bbQslz = bbzzlz + 1
  676.                 .NewPage
  677.             End If
  678.             
  679.             
  680.             '解决由于纸张宽度太小出现死循环
  681.             If Bbynfyh > DY_Tybbyldy.DyylGrid.Cols - 1 Then
  682.                 Tsxx = "纸张宽度太小不能输出报表,请重新设置!"
  683.                 Call Xtxxts(Tsxx, 0, 4)
  684.                 Unload DY_Tybbyldy
  685.                 Exit Sub
  686.             End If
  687.         Loop
  688.         .EndDoc
  689.         
  690.         '还原操作状态
  691.         Call Sub_SetOperStatus("")
  692.         
  693.         '输出打印页号填充滚动条
  694.         
  695.         DY_Tybbyldy.PageHScroll.Max = .Pagecount
  696.         DY_Tybbyldy.PageHScroll.Min = 1
  697.         DY_Tybbyldy.YlToolbar.Buttons("sy").Enabled = False
  698.         If .Pagecount = 1 Then
  699.             DY_Tybbyldy.YlToolbar.Buttons("xy").Enabled = False
  700.         End If
  701.     End With
  702.     
  703.     '预 览 打 印
  704.     If bbylte Then
  705.         DY_Tybbyldy.Show 1
  706.     Else
  707.         Call dyscbb(PrintMessageNotShow)
  708.     End If
  709.     
  710. End Sub
  711. Private Sub Scbbzdx(zdxwzte As Integer, zdxgdte As Double, zdxsjgte As Double, zdxzjgte As Double)      '输 出 报 表 装 订 线
  712.     
  713.     With DY_Tybbyldy.Tydy
  714.         If zdxwzte <> 0 Then
  715.             .PenColor = QBColor(12)
  716.             .PenStyle = psDashDot
  717.             Select Case zdxwzte
  718.             Case 1
  719.                 .DrawLine 0, zdxgdte, .PageWidth, zdxgdte
  720.                 zdxsjgte = zdxgdte
  721.             Case 2
  722.                 .DrawLine zdxgdte, 0, zdxgdte, .PageHeight
  723.                 zdxzjgte = zdxgdte
  724.             End Select
  725.             .PenColor = QBColor(0)
  726.             .PenStyle = psSolid
  727.         End If
  728.     End With
  729.     
  730. End Sub
  731. Private Sub scbbbt(Cxsjwg, bbQslz&, bbzzlz&, Kdfdbl#, Bbgdhgd#, Bbydy#, Bbydx#, Bbqsx#, Sftdfssc As Boolean)                 '输出网格任意多列表头
  732.     
  733.     '参数说明:当前网格,起始列值,终止列值,行宽放大比例,表头行高度,当前Y坐标,当前X坐标,起始X坐标
  734.     Dim Hbrow1&, Hbcol1&, Hbrow2&, Hbcol2&               '合 并 单 元 范 围
  735.     Dim Mgzkd&, Zyhs%                                    '每个字宽度,占用行数
  736.     bbydyte = Bbydy
  737.     bbydxte = Bbydx
  738.     With DY_Tybbyldy.Tydy
  739.         For Rowjsq = 0 To Cxsjwg.FixedRows - 1
  740.             For Coljsq = bbQslz To bbzzlz
  741.                 Dyxsbz = True
  742.                 If Rowjsq <> 0 Or Coljsq <> bbQslz Then
  743.                     If Rowjsq <> 0 Then
  744.                         If Cxsjwg.TextMatrix(Rowjsq, Coljsq) = Cxsjwg.TextMatrix(Rowjsq - 1, Coljsq) Then
  745.                             Dyxsbz = False
  746.                         End If
  747.                     End If
  748.                     If Coljsq <> bbQslz And Dyxsbz Then
  749.                         If Cxsjwg.TextMatrix(Rowjsq, Coljsq) = Cxsjwg.TextMatrix(Rowjsq, Coljsq - 1) Then
  750.                             Dyxsbz = False
  751.                         End If
  752.                     End If
  753.                 End If
  754.                 If Dyxsbz Then
  755.                     Cxsjwg.GetMergedRange Rowjsq, Coljsq, Hbrow1, Hbcol1, Hbrow2, Hbcol2
  756.                     jxkd = 0
  757.                     jxgd = 0
  758.                     For hbrowjsq = Hbrow1 To Hbrow2
  759.                         jxgd = jxgd + Bbgdhgd
  760.                     Next hbrowjsq
  761.                     If Hbcol1 < bbQslz Then
  762.                         Hbcol1 = bbQslz
  763.                     End If
  764.                     If Hbcol2 > bbzzlz Then
  765.                         Hbcol2 = bbzzlz
  766.                     End If
  767.                     For hbcoljsq = Hbcol1 To Hbcol2
  768.                         jxkd = jxkd + Cxsjwg.ColWidth(hbcoljsq) * Kdfdbl
  769.                     Next hbcoljsq
  770.                     .CalcText = Cxsjwg.TextMatrix(Rowjsq, Coljsq)
  771.                     If jxkd - .TextWid > 0 Then
  772.                         textx1 = bbydxte + (jxkd - .TextWid) / 2
  773.                         textkd = .TextWid
  774.                         texty1 = bbydyte + (jxgd - .TextHei) / 2
  775.                         textgd = .TextHei
  776.                     Else
  777.                         
  778.                         '当网格列宽不足以容下标题时,计算文本框大小及坐标
  779.                         If Len(Cxsjwg.TextMatrix(Rowjsq, Coljsq)) = 0 Then
  780.                             Mgzkd = 1
  781.                         Else
  782.                             Mgzkd = .TextWid / Len(Cxsjwg.TextMatrix(Rowjsq, Coljsq))
  783.                         End If
  784.                         If jxkd > Mgzkd Then
  785.                             If Len(Cxsjwg.TextMatrix(Rowjsq, Coljsq)) Mod Int(jxkd / Mgzkd) <> 0 Then
  786.                                 Zyhs = Int(Len(Cxsjwg.TextMatrix(Rowjsq, Coljsq)) / Int(jxkd / Mgzkd)) + 1
  787.                             Else
  788.                                 Zyhs = Len(Cxsjwg.TextMatrix(Rowjsq, Coljsq)) / Int(jxkd / Mgzkd)
  789.                             End If
  790.                             If Int(jxgd / .TextHei) < Zyhs Then
  791.                                 Zyhs = Int(jxgd / .TextHei)
  792.                             End If
  793.                             textkd = Int(jxkd / Mgzkd) * Mgzkd
  794.                             textx1 = bbydxte + (jxkd - textkd) / 2
  795.                             textgd = Zyhs * .TextHei
  796.                             texty1 = bbydyte + (jxgd - textgd) / 2
  797.                         Else
  798.                             Zyhs = -1
  799.                             textx1 = bbydxte
  800.                             texty1 = bbydyte
  801.                             textkd = 0
  802.                             textgd = 0
  803.                         End If
  804.                     End If
  805.                     
  806.                     If textkd <> 0 Then
  807.                         .TextBox Cxsjwg.TextMatrix(Rowjsq, Coljsq), textx1, texty1, textkd, textgd, True
  808.                     End If
  809.                     If Not Sftdfssc Then
  810.                         .DrawLine bbydxte, bbydyte, bbydxte + jxkd, bbydyte
  811.                         .DrawLine bbydxte, bbydyte, bbydxte, bbydyte + jxgd
  812.                         .DrawLine bbydxte + jxkd, bbydyte, bbydxte + jxkd, bbydyte + jxgd
  813.                         .DrawLine bbydxte, bbydyte + jxgd, bbydxte + jxkd, bbydyte + jxgd
  814.                     End If
  815.                 End If
  816.                 bbydxte = bbydxte + Cxsjwg.ColWidth(Coljsq) * Kdfdbl
  817.             Next Coljsq
  818.             bbydxte = Bbqsx
  819.             bbydyte = bbydyte + Bbgdhgd
  820.         Next Rowjsq
  821.     End With
  822.     
  823. End Sub
  824. Public Sub Scyxsjb(Cxsjwg As VSFlexGrid)                       '生成有效数据表(针对网格隐含和数据行为空行情况的解决方案)
  825.     
  826.     '过程参数:输出数据网格
  827.     
  828.     Dim Yxhzjsq%, Yxlzjsq%
  829.     Dim Rowjsq As Long
  830.     With DY_Tybbyldy.DyylGrid
  831.         .Redraw = False             '为了加快传送速度
  832.         .FontName = Cxsjwg.FontName
  833.         .FontSize = Cxsjwg.FontSize
  834.         .FixedRows = Cxsjwg.FixedRows
  835.         .MergeCells = flexMergeFixedOnly
  836.         For jsqte = 0 To .FixedRows - 1
  837.             .MergeRow(jsqte) = True
  838.         Next jsqte
  839.         .WordWrap = True
  840.         Yxlzjsq = 0
  841.         For Coljsq = 0 To Cxsjwg.Cols - 1
  842.             If Not Cxsjwg.ColHidden(Coljsq) Then
  843.                 Yxlzjsq = Yxlzjsq + 1
  844.             End If
  845.         Next Coljsq
  846.         .Cols = Yxlzjsq
  847.         Yxlzjsq = 0
  848.         For Coljsq = 0 To Cxsjwg.Cols - 1
  849.             If Not Cxsjwg.ColHidden(Coljsq) Then
  850.                 .ColAlignment(Yxlzjsq) = Cxsjwg.ColAlignment(Coljsq)
  851.                 .ColWidth(Yxlzjsq) = Cxsjwg.ColWidth(Coljsq)
  852.                 .ColFormat(Yxlzjsq) = Cxsjwg.ColFormat(Coljsq)
  853.                 .MergeCol(Yxlzjsq) = True
  854.                 Yxlzjsq = Yxlzjsq + 1
  855.             End If
  856.         Next Coljsq
  857.         Yxhzjsq = 0
  858.         For Rowjsq = 0 To Cxsjwg.Rows - 1
  859.             If (Not Cxsjwg.RowHidden(Rowjsq)) And (Not GridRowEmpty(Cxsjwg, Rowjsq)) Then
  860.                 Yxhzjsq = Yxhzjsq + 1
  861.             End If
  862.         Next Rowjsq
  863.         .Rows = Yxhzjsq
  864.         Yxhzjsq = 0
  865.         Yxlzjsq = 0
  866.         For Rowjsq = 0 To Cxsjwg.Rows - 1
  867.             If (Not Cxsjwg.RowHidden(Rowjsq)) And (Not GridRowEmpty(Cxsjwg, Rowjsq)) Then
  868.                 For Coljsq = 0 To Cxsjwg.Cols - 1
  869.                     If Not Cxsjwg.ColHidden(Coljsq) Then
  870.                         If Cxsjwg.ColDataType(Coljsq) = flexDTBoolean And Rowjsq >= .FixedRows Then           '布尔型列单独处理
  871.                             If Cxsjwg.TextMatrix(Rowjsq, Coljsq) Then
  872.                                 .TextMatrix(Yxhzjsq, Yxlzjsq) = "√"
  873.                             Else
  874.                                 .TextMatrix(Yxhzjsq, Yxlzjsq) = ""
  875.                             End If
  876.                         Else
  877.                             .TextMatrix(Yxhzjsq, Yxlzjsq) = Cxsjwg.TextMatrix(Rowjsq, Coljsq)
  878.                         End If
  879.                         Yxlzjsq = Yxlzjsq + 1
  880.                     End If
  881.                 Next Coljsq
  882.                 .RowHeight(Yxhzjsq) = Cxsjwg.RowHeight(Rowjsq)
  883.                 Yxlzjsq = 0
  884.                 Yxhzjsq = Yxhzjsq + 1
  885.             End If
  886.         Next Rowjsq
  887.         
  888.         .Redraw = True
  889.     End With
  890.     
  891. End Sub
  892. Public Function GridRowEmpty(Cxsjwg As VSFlexGrid, Rowte As Long) As Boolean           '判断网格行是否为空行
  893.     
  894.     GridRowEmpty = True
  895.     With Cxsjwg
  896.         For jsqte = 0 To .Cols - 1
  897.             If Len(Trim(.TextMatrix(Rowte, jsqte))) <> 0 Then
  898.                 GridRowEmpty = False
  899.                 Exit Function
  900.             End If
  901.         Next jsqte
  902.     End With
  903.     
  904. End Function
  905. Public Sub dyscbb(Optional PrintMessageNotShow As Boolean)                             '打 印 输 出 报 表(调用打印提示选择项窗体)
  906.     
  907.     If Not PrintMessageNotShow Then
  908.         DY_DytsFrm.Show 1
  909.     Else
  910.         DY_DytsFrm.Output_Printer
  911.     End If
  912.     
  913. End Sub
  914. Private Function Thwxzf(Thzfc As String) As String                                     '替换打印中妨碍字符 ";"和"|" 为全角有效字符
  915.     
  916.     Dim lswz As Integer
  917.     Do While InStr(1, Thzfc, ";") <> 0
  918.         lswz = InStr(1, Thzfc, ";")
  919.         Thzfc = Mid(Thzfc, 1, lswz - 1) + ";" + Mid(Thzfc, lswz + 1, Len(Thzfc))
  920.     Loop
  921.     Do While InStr(1, Thzfc, "|") <> 0
  922.         lswz = InStr(1, Thzfc, "|")
  923.         Thzfc = Mid(Thzfc, 1, lswz - 1) + Mid(Thzfc, lswz + 1, Len(Thzfc))
  924.     Loop
  925.     Thwxzf = Thzfc
  926.     
  927. End Function
  928. '单据打印输出
  929. Public Sub BillGridPrint(WglrGrid As Object, LrText As Object, GridStr() As String, Szzls As Integer, Grid_code As String, Text_code As String, XtReportCode As String, Optional PrintDirect As Boolean = False, Optional PrintType As String = "default")
  930.     On Error Resume Next
  931.     Dim I As Integer, GridTop As Double, GridLeft As Double, BodyTop As Integer, FixRowHeight As Double
  932.     Dim TableFormat As String, TableBody As String, DataRows As Integer, TableData() As String
  933.     Dim DataRowHeight As Integer, Rowjsq As Integer, GridDataRows As Integer, BillTitlePrint As String
  934.     Dim aDo_Rec As New Recordset, ColSum(), MarginLeft As Integer, MarginTop As Integer, BillTitleLeft As Integer, BillTitleTop As Integer
  935.     Dim Bbsjqfont As String, Bbsjqsize As String
  936.     With DY_Tybbyldy
  937.         '=====================
  938.         Set aDo_Rec = Cw_DataEnvi.DataConnect.Execute("select * from Xt_dybbcs where bbbm='" & XtReportCode & "'")
  939.         .Tydy.PaperSize = aDo_Rec!PaperSize
  940.         .Tydy.Orientation = aDo_Rec!PaperScfx
  941.         .Tydy.MarginLeft = aDo_Rec!bbzbj
  942.         .Tydy.MarginTop = aDo_Rec!bbsbj
  943.         .Tydy.FontName = Trim(aDo_Rec!Bbbtfont)
  944.         .Tydy.FontSize = aDo_Rec!Bbbtsize
  945.         Bbsjqfont = aDo_Rec!Bbsjqfont
  946.         Bbsjqsize = aDo_Rec!Bbsjqsize
  947.         MarginLeft = .Tydy.MarginLeft
  948.         MarginTop = .Tydy.MarginTop
  949.         aDo_Rec.Close
  950.         '=====================
  951.         For Rowjsq = WglrGrid.FixedRows To WglrGrid.Rows - 1
  952.             If WglrGrid.TextMatrix(Rowjsq, 0) <> "*" Then
  953.                 Exit For
  954.             End If
  955.             GridDataRows = GridDataRows + 1
  956.         Next
  957.         
  958.         '=====================
  959.         Set aDo_Rec = Cw_DataEnvi.DataConnect.Execute("select * from xt_v_billgridPrint where grid_code='" & Grid_code & "' and printgridcode='" & Trim(PrintType) & "' order by colid")
  960.         '================
  961.         If aDo_Rec.RecordCount > 0 Then
  962.             '-----------
  963.             .DyylGrid.FixedRows = aDo_Rec!FixRows: .DyylGrid.Cols = 0
  964.             GridTop = aDo_Rec!PrintGridTop: GridLeft = aDo_Rec!PrintGridLeft
  965.             FixRowHeight = aDo_Rec!FixRowHeight: DataRows = aDo_Rec!PrintDataRows
  966.             DataRowHeight = aDo_Rec!DataRowHeight
  967.             BillTitleLeft = aDo_Rec!BillTitleLeft
  968.             BillTitleTop = aDo_Rec!BillTitleTop
  969.             BillTitlePrint = Trim("" & aDo_Rec!BillTitlePrint)
  970.             '----------
  971.             If aDo_Rec!FixRows = 1 Then BodyTop = aDo_Rec!FixRowHeight + GridTop
  972.             If aDo_Rec!FixRows = 2 Then BodyTop = aDo_Rec!FixRowHeight * 2 + GridTop
  973.             If aDo_Rec!FixRows = 3 Then BodyTop = aDo_Rec!FixRowHeight * 3 + GridTop
  974.             '----------
  975.             aDo_Rec.MoveNext
  976.             '================
  977.             .DyylGrid.MergeCells = flexMergeFixedOnly
  978.             For I = 0 To .DyylGrid.FixedRows - 1
  979.                 .DyylGrid.MergeRow(I) = True
  980.             Next I
  981.             I = 0
  982.             '======================
  983.             ReDim TableData(aDo_Rec.RecordCount - 1)
  984.             ReDim ColSum(2, aDo_Rec.RecordCount - 1)
  985.             
  986.             Do While Not aDo_Rec.EOF           '网格头
  987.                 If aDo_Rec!YnPrint = False Then
  988.                     .DyylGrid.Cols = .DyylGrid.Cols + 1
  989.                     .DyylGrid.TextMatrix(0, I) = Trim(aDo_Rec!ColTitle1)
  990.                     .DyylGrid.TextMatrix(1, I) = Trim(aDo_Rec!ColTitle2)
  991.                     .DyylGrid.TextMatrix(2, I) = Trim(aDo_Rec!ColTitle3)
  992.                     .DyylGrid.ColWidth(I) = aDo_Rec!PrintColWidth
  993.                     .DyylGrid.MergeCol(I) = True
  994.                     '-----------
  995.                     If aDo_Rec!ColAlignment = 6 Then
  996.                         TableFormat = TableFormat & "+>" & aDo_Rec!PrintColWidth & "|"
  997.                     Else
  998.                         TableFormat = TableFormat & "+<" & aDo_Rec!PrintColWidth & "|"
  999.                     End If
  1000.                     TableData(I) = Trim(aDo_Rec!ColIndex)
  1001.                     ColSum(0, I) = aDo_Rec!ColSum_flag
  1002.                     '-----------
  1003.                     I = I + 1
  1004.                 End If
  1005.                 aDo_Rec.MoveNext
  1006.             Loop
  1007.             aDo_Rec.Close
  1008.             TableFormat = Mid(TableFormat, 1, Len(TableFormat) - 1)
  1009.             '---------------
  1010.         End If
  1011.         '======================
  1012.         Dim h As Integer, PrintDataRows As Integer
  1013.         Dim PrintRow As Integer: Dim TTF As Boolean
  1014.         PrintRow = WglrGrid.FixedRows
  1015.         Set aDo_Rec = Cw_DataEnvi.DataConnect.Execute("select * from Xt_v_billtextPrint where text_group_code='" & Text_code & "' and printtextcode='" & Trim(PrintType) & "' order by text_index")
  1016.         '<<<<<<<<
  1017.         .Tydy.StartDoc
  1018.         '------------
  1019.         PrintDataRows = GridDataRows  (DataRows - 1)
  1020.         If GridDataRows Mod (DataRows - 1) > 0 Then PrintDataRows = PrintDataRows + 1
  1021.         If PrintDataRows = 0 Then PrintDataRows = 1
  1022.         
  1023.         .Tydy.CurrentX = BillTitleLeft + MarginLeft: .Tydy.CurrentY = BillTitleTop + MarginTop
  1024.         .Tydy = BillTitlePrint
  1025.         .Tydy.FontName = Trim(Bbsjqfont)
  1026.         .Tydy.FontSize = Bbsjqsize
  1027.         
  1028.         For h = 1 To PrintDataRows
  1029.             '==============
  1030.             aDo_Rec.MoveFirst
  1031.             TableBody = ""
  1032.             '----------
  1033.             Do While Not aDo_Rec.EOF '表头数据
  1034.                 If aDo_Rec!YnPrint = True Then
  1035.                     .Tydy.CurrentX = Val("" & aDo_Rec!printLabelLeft) + MarginLeft: .Tydy.CurrentY = aDo_Rec!PrintTop + MarginTop
  1036.                     .Tydy = Trim(aDo_Rec!Text_Name) & ":"
  1037.                     .Tydy.CurrentX = aDo_Rec!PrintLeft + MarginLeft: .Tydy.CurrentY = aDo_Rec!PrintTop + MarginTop
  1038.                     .Tydy = LrText(aDo_Rec!text_Index)
  1039.                 End If
  1040.                 aDo_Rec.MoveNext
  1041.             Loop
  1042.             '==========
  1043.             If DataRows <> 0 Then
  1044.                 '===================== 表体数据
  1045.                 
  1046.                 TableBody = ""
  1047.                 TTF = False
  1048.                 For Rowjsq = PrintRow To WglrGrid.Rows - 1
  1049.                     If WglrGrid.TextMatrix(Rowjsq, 0) <> "*" Then
  1050.                         TTF = True
  1051.                         Exit For
  1052.                     End If
  1053.                     '----------------表体数据行
  1054.                     For I = 0 To UBound(TableData) - 1
  1055.                         If Trim(WglrGrid.ColFormat(Sydz(TableData(I), GridStr(), Szzls))) = "" Then
  1056.                             TableBody = TableBody & Trim(WglrGrid.TextMatrix(Rowjsq, Sydz(TableData(I), GridStr(), Szzls))) & "|"
  1057.                         Else
  1058.                             TableBody = TableBody & Format(Trim(WglrGrid.TextMatrix(Rowjsq, Sydz(TableData(I), GridStr(), Szzls))), WglrGrid.ColFormat(Sydz(TableData(I), GridStr(), Szzls))) & "|"
  1059.                         End If
  1060.                         If ColSum(0, I) = True Then
  1061.                             ColSum(1, I) = ColSum(1, I) + Val(WglrGrid.TextMatrix(Rowjsq, Sydz(TableData(I), GridStr(), Szzls)))
  1062.                         End If
  1063.                     Next I
  1064.                     TableBody = Mid(TableBody, 1, Len(TableBody) - 1)
  1065.                     TableBody = TableBody & ";"
  1066.                     PrintRow = PrintRow + 1
  1067.                     
  1068.                     If (Rowjsq - WglrGrid.FixedRows + 1) - ((DataRows - 1) * h) = 0 Then
  1069.                         Exit For
  1070.                     End If
  1071.                     
  1072.                 Next Rowjsq
  1073.                 
  1074.                 For DataRow = (Rowjsq - WglrGrid.FixedRows + 1) - ((DataRows - 1) * (h - 1)) To DataRows
  1075.                     
  1076.                     If DataRow = IIf(TTF, DataRows, DataRows - 1) Then
  1077.                         TableBody = TableBody & "小计:" & "|"
  1078.                         '--------
  1079.                         For I = 1 To UBound(TableData) - 1
  1080.                             If ColSum(0, I) = True Then
  1081.                                 TableBody = TableBody & Format(Trim(ColSum(1, I)), WglrGrid.ColFormat(Sydz(TableData(I), GridStr(), Szzls))) & "|"
  1082.                                 ColSum(1, I) = 0
  1083.                             Else
  1084.                                 TableBody = TableBody & " |"
  1085.                             End If
  1086.                         Next I
  1087.                         '--------
  1088.                         TableBody = Mid(TableBody, 1, Len(TableBody) - 1) & ";"
  1089.                         Exit For
  1090.                     End If
  1091.                     '=============================
  1092.                     For I = 0 To UBound(TableData) - 1
  1093.                         TableBody = TableBody & " |"
  1094.                     Next I
  1095.                     TableBody = Mid(TableBody, 1, Len(TableBody) - 1) & ";"
  1096.                 Next DataRow
  1097.                 
  1098.                 
  1099.                 '=====================
  1100.                 
  1101.                 Call scbbbt(.DyylGrid, 0, .DyylGrid.Cols - 1, 1, FixRowHeight, GridTop + MarginTop, GridLeft + MarginLeft, GridLeft + MarginLeft, False)
  1102.                 '====================
  1103.                 .Tydy.MarginLeft = GridLeft + MarginLeft: .Tydy.CurrentY = BodyTop + MarginTop
  1104.                 .Tydy.StartTable
  1105.                 '--------
  1106.                 .Tydy.AddTable TableFormat, "", TableBody, , , True
  1107.                 .Tydy.TableCell(tcRows) = DataRows
  1108.                 For I = 1 To DataRows
  1109.                     .Tydy.TableCell(tcRowHeight, I) = DataRowHeight
  1110.                 Next
  1111.                 '--------
  1112.                 .Tydy.EndTable
  1113.                 '===================
  1114.                 If h < PrintDataRows Then
  1115.                     .Tydy.NewPage
  1116.                 End If
  1117.                 '=================
  1118.                 
  1119.             End If
  1120.             
  1121.         Next h
  1122.         '================
  1123.         
  1124.         .Tydy.EndDoc
  1125.         
  1126.         '判断是直接打印还是预览
  1127.         If Not PrintDirect Then
  1128.             .Show 1                                     '预览
  1129.         Else
  1130.             Call DY_DytsFrm.Output_Printer              '直接打印输出
  1131.             Unload DY_Tybbyldy                          '卸载打印预览窗体
  1132.             Unload DY_DytsFrm                           '卸载打印选择提示选项
  1133.         End If
  1134.         
  1135.     End With
  1136.     
  1137. End Sub
  1138. '单据打印输出
  1139. Public Sub BillTextPrint(Lab_Title As Object, LrText As Object, Text_code As String, XtReportCode As String, Optional PrintDirect As Boolean = False, Optional PrintType As String = "default")
  1140.     On Error Resume Next
  1141.     Dim aDo_Rec As New Recordset, MarginLeft As Integer, MarginTop As Integer, Bbmc As String
  1142.     With DY_Tybbyldy
  1143.         '=====================
  1144.         Set aDo_Rec = Cw_DataEnvi.DataConnect.Execute("select * from Xt_dybbcs where bbbm='" & XtReportCode & "'")
  1145.         .Tydy.PaperSize = aDo_Rec!PaperSize
  1146.         .Tydy.Orientation = aDo_Rec!PaperScfx
  1147.         .Tydy.MarginLeft = aDo_Rec!bbzbj
  1148.         .Tydy.MarginTop = aDo_Rec!bbsbj
  1149.         MarginLeft = aDo_Rec!bbzbj
  1150.         MarginTop = aDo_Rec!bbsbj
  1151.         .Tydy.FontName = Trim(aDo_Rec!Bbbtfont)
  1152.         .Tydy.FontSize = aDo_Rec!Bbbtsize
  1153.         Bbsjqfont = aDo_Rec!Bbsjqfont
  1154.         Bbsjqsize = aDo_Rec!Bbsjqsize
  1155.         aDo_Rec.Close
  1156.         '=====================
  1157.         
  1158.         
  1159.         Set aDo_Rec = Cw_DataEnvi.DataConnect.Execute("select * from Xt_v_billtextPrint where text_group_code='" & Text_code & "' and printtextcode='" & Trim(PrintType) & "' order by text_index")
  1160.         '<<<<<<<<
  1161.         .Tydy.StartDoc
  1162.         If .Tydy.Orientation = 0 Then
  1163.             .Tydy.CurrentX = .Tydy.PaperWidth / 2 - Lab_Title.Width / 2
  1164.         Else
  1165.             .Tydy.CurrentX = .Tydy.PaperHeight / 2 - Lab_Title.Width / 2
  1166.         End If
  1167.         .Tydy.CurrentY = MarginTop
  1168.         .Tydy = Lab_Title
  1169.         .Tydy.FontName = Trim(Bbsjqfont)
  1170.         .Tydy.FontSize = Bbsjqsize
  1171.         
  1172.         '=========
  1173.         Do While Not aDo_Rec.EOF '表头数据
  1174.             If aDo_Rec!YnPrint = True Then
  1175.                 .Tydy.CurrentX = Val("" & aDo_Rec!printLabelLeft) + MarginLeft: .Tydy.CurrentY = aDo_Rec!PrintTop + MarginTop
  1176.                 .Tydy = Trim(aDo_Rec!Text_Name) & ":"
  1177.                 .Tydy.CurrentX = aDo_Rec!PrintLeft + MarginLeft: .Tydy.CurrentY = aDo_Rec!PrintTop + MarginTop
  1178.                 .Tydy = LrText(aDo_Rec!text_Index)
  1179.             End If
  1180.             aDo_Rec.MoveNext
  1181.         Loop
  1182.         '==========
  1183.         
  1184.         .Tydy.EndDoc
  1185.         
  1186.         '判断是直接打印还是预览
  1187.         If Not PrintDirect Then
  1188.             .Show 1                                     '预览
  1189.         Else
  1190.             Call DY_DytsFrm.Output_Printer              '直接打印输出
  1191.             Unload DY_Tybbyldy                          '卸载打印预览窗体
  1192.             Unload DY_DytsFrm                           '卸载打印选择提示选项
  1193.         End If
  1194.         
  1195.     End With
  1196.     
  1197. End Sub