Foxtable(狐表)用户栏目专家坐堂 → 再问自定义函数


  共有2399人关注过本帖树形打印复制链接

主题:再问自定义函数

帅哥哟,离线,有人找我吗?
czy66ds
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1684 积分:16374 威望:0 精华:0 注册:2013/7/31 13:03:00
再问自定义函数  发帖心情 Post By:2020/6/2 11:28:00 [只看该作者]

经过询问和老师回答,对于内部函数args参数写法头脑中清晰一些了,知道了args的强大。但是对于代码段的处理还是蒙圈,例如:

Dim cmd As New SQLCommand '定义一个SQL命令

cmd.C

Dim dt As DataTable '定义一个数据表变量

Dim dt1 As DataTable '定义一个数据表变量

Dim cm As WinForm.ComboBox = e.Form.Controls("ComboBox1")

Dim T2 As Table = e.Form.Controls("Table2").Table

 

' --------服务器时间----------------------------

Dim sj As Date

cmd.CommandText = "Select GetDate()"

sj = cmd.ExecuteScalar()

sj = Format(sj, "yyyy-M-d") '2008-2-28

If cm.value = "差旅费" Then

    For Each r2 As Row In T2.GetCheckedRows

        Dim spbh As String = r2("审批编号")

        Dim doc As New PrintDoc         '定义一个报表

        Dim rt As New prt.RenderTable()

        Dim rx As New prt.RenderText  

        doc.PageSetting.Width = 240

        doc.PageSetting.Height = 140

        Doc.PageSetting.LeftMargin = 20

        Doc.PageSetting.RightMargin = 10

        Doc.PageSetting.TopMargin = 15

        Doc.PageSetting.BottomMargin = 10

       

        '===========标题=======

        rx.text = r2("申请人") & "差旅费报销单"

        rx.Style.FontBold = True

        rx.Style.FontSize = 12

        rx.Width = 178.5

        rx.Style.TextAlignHorz = prt.AlignHorzEnum.Center

        rx.Style.Spacing.Bottom = 2

        doc.Body.Children.Add(rx)

       

        '======= 主表() ======

        rt = New prt.RenderTable

        rt.Style.TextAlignVert = prt.AlignVertEnum.Center

        rt.Style.TextAlignHorz = prt.AlignHorzEnum.Left

        rt.Cols(2).Style.TextAlignHorz =prt.AlignHorzEnum.Right

        rt.Style.Spacing.Bottom = 1

        rt.Style.FontSize = 9

        rt.style.Ffont-size: 9pt; font-family: 宋体;">宋体"

        rt.Width = 178.5

        rt.Cols(0).Width = 60 

        rt.Cols(2).Width = 40

        rt.Height = 10

        'rt.Style.GridLines.All = New prt.LineDef '将网格线类型设为默认类型

        rt.Rows.Count = 2  ' 二行

        rt.Cols.Count = 3  ' 三列

  

        rt.Cells(0,0).Text = "审批编号:"  & r2("审批编号")

        rt.Cells(1,0).Text = "申请人:"    & r2("申请人")

        rt.Cells(0,1).Text = "审批人:"    & r2("审批人")

        rt.Cells(1,1).Text = "部门:"      & r2("部门")

        rt.Cells(0,2).Text = "提交时间:"  & r2("提交时间")

        rt.Cells(1,2).Text = "报销总额:"  & r2("报销总额")

        doc.Body.Children.Add(rt) '将表格对象加入到报表中

       

        '========== 明细表 ==================================

        rt = New prt.RenderTable

        rt.Style.FontSize = 9

        rt.style.F

        cmd.CommandText =" select 出发时间,出发地,到达时间,到达地,当日返回 as 当日,车费,油补,过道费 as 过道,餐补,宿费,其他费用 as 其它,费用小计 as 小计 f rom{差旅费记录表1} where 审批编号  = '" & spbh & "'"

        dt1 = cmd.ExecuteReader()

       

        Dim Count As Integer = 0

        For Each Col As DataCol In Dt1.DataCols

            rt.Cells(0,Count).Text = Col.Name

            For r As Integer = 0 To dt1.DataRows.Count - 1

                rt.Cells(r +1,Count).Text = dt1.DataRows(r)(Col.Name)

            Next

           

            ' 设置列宽------使用循环设置,减少代码量------

            Dim lk As Integer() = New Integer(){20,25,20,25,9,10,10,10,10,10,10,15} '列宽

            Dim c As Integer

            For c = 0 To 11

                rt.Cols(c).Width = lk(c)

            Next

            rt.Width = "Auto"

            Count = Count + 1

        Next

        rt.Style.GridLines.All = New prt.Linedef

        rt.CellStyle.Spacing.All = 0.8

        rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center

        rt.Style.Spacing.Bottom = 1

        doc.Body.Children.Add(rt)

       

        '========= 主表() ================================================

        rt = New prt.RenderTable

        'rt.Style.GridLines.All = New prt.LineDef '将网格线类型设为默认类型

        rt.Style.FontSize = 9 '字体大小为9

        rt.style.Ffont-size: 9pt; font-family: 宋体;">宋体"

        rt.Width = 178.5

        rt.Rows.Count = 2

        rt.Cols.Count = 3

        rt.Cols(1).Width = 50 

        rt.Cols(2).Width = 40

        rt.Cells(1,0).SpanCols = 3

        rt.Rows(0).Height = 5

        rt.Rows(1).Height = 20

        rt.Cols(2).Style.TextAlignHorz =prt.AlignHorzEnum.Right

        rt.Cells(0,0).text = "出差人员:"  & r2("出差人员")

        rt.Cells(0,1).text = "打印人:"  & user.name

        rt.Cells(0,2).text = "打印日期:"  & sj

        rt.Cells(1,0).text = "出差任务:"  & r2("出差任务")

        doc.Body.Children.Add(rt)

       

        'doc.Preview()

        doc.Print()

    Next

End If

 

其中红色部分该如何参数化?


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106209 积分:540168 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/6/2 11:46:00 [只看该作者]

如果列名和格式是固定的,通过数组传入即可。否则不适合使用函数处理

 回到顶部
帅哥哟,离线,有人找我吗?
czy66ds
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1684 积分:16374 威望:0 精华:0 注册:2013/7/31 13:03:00
  发帖心情 Post By:2020/6/2 16:11:00 [只看该作者]

如何把

rt.Cells(0,0).text = "出差人员:"  & r2("出差人员")

rt.Cells(0,1).text = "打印人:"  & user.name

rt.Cells(0,2).text = "打印日期:"  & sj

rt.Cells(1,0).text = "出差任务:"  & r2("出差任务")

传进来?

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106209 积分:540168 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/6/2 16:27:00 [只看该作者]

dim n1() as string = {"出差人员","出差任务"}
Functions.Execute("xxx",n1,false)

-------
dim n1() as string = args(0)

rt.Cells(0,0).text = n1(0) & ":"  & r2(n1(0))

rt.Cells(0,1).text = "打印人:"  & user.name

rt.Cells(0,2).text = "打印日期:"  & sj

rt.Cells(1,0).text = n1(1) & ":"  & r2(n1(1))


 回到顶部