Foxtable(狐表)用户栏目专家坐堂 → 我想把两个结构一样的窗口加个选项合并为一个窗口,结果报错!


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

主题:我想把两个结构一样的窗口加个选项合并为一个窗口,结果报错!

美女呀,离线,留言给我吧!
采菊东篱下
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1881 积分:10374 威望:0 精华:0 注册:2019/4/6 8:45:00
我想把两个结构一样的窗口加个选项合并为一个窗口,结果报错!  发帖心情 Post By:2021/11/9 14:53:00 [显示全部帖子]

这代码在第一个窗口中没问题的,效果如下:

图片点击可在新窗口打开查看此主题相关图片如下:qq图片20211109144712.png
图片点击可在新窗口打开查看

代码如下:
Dim doc As New PrintDoc '定义一个报表
doc.Stacking = prt.StackingRulesEnum.InlineLeftToRight '设置排列方式
If e.Form.Controls("TextBox4").Value Is Nothing OrElse e.Form.Controls("TextBox5").Value Is Nothing Then
    messagebox.show("模板长宽不能为空")
    Return
End If
If e.Form.Controls("RadioButton1").Checked = True And e.Form.Controls("ComboBox1").text = e.form.controls("combobox1").items(0) Then
    doc.PageSetting.Width = 297 'A3纸张宽度,单位为毫米
    doc.PageSetting.Height = 420  'A3纸张高度,单位为毫米
ElseIf e.Form.Controls("RadioButton2").Checked = True And e.Form.Controls("ComboBox1").text = e.form.controls("combobox1").items(1) Then
    doc.PageSetting.Width = 210 'A4纸张宽度,单位为毫米
    doc.PageSetting.Height = 297  'A4纸张高度,单位为毫米
ElseIf e.Form.Controls("RadioButton2").Checked = True And e.Form.Controls("ComboBox1").text = e.form.controls("combobox1").items(2) Then
    doc.PageSetting.Width = 148.5 'A5纸张宽度,单位为毫米
    doc.PageSetting.Height = 210  'A5纸张高度,单位为毫米
ElseIf e.Form.Controls("RadioButton2").Checked = True And e.Form.Controls("ComboBox1").text = e.form.controls("combobox1").items(3) Then
    doc.PageSetting.Width = 257 'B4纸张宽度,单位为毫米
    doc.PageSetting.Height = 364  'B4纸张高度,单位为毫米
ElseIf e.Form.Controls("RadioButton2").Checked = True And e.Form.Controls("ComboBox1").text = e.form.controls("combobox1").items(4) Then
    doc.PageSetting.Width = 176 'B5纸张宽度,单位为毫米
    doc.PageSetting.Height = 250  'B5纸张高度,单位为毫米
ElseIf e.Form.Controls("RadioButton2").Checked = True And e.Form.Controls("ComboBox1").text = e.form.controls("combobox1").items(5) Then
    doc.PageSetting.Width = 420 'A2纸张宽度,单位为毫米
    doc.PageSetting.Height = 594  'A2纸张高度,单位为毫米
ElseIf e.Form.Controls("RadioButton2").Checked = True And e.Form.Controls("ComboBox1").text = e.form.controls("combobox1").items(6) Then
    doc.PageSetting.Width = 105 'A6纸张宽度,单位为毫米
    doc.PageSetting.Height = 148  'A6纸张高度,单位为毫米
ElseIf e.Form.Controls("RadioButton1").Checked = True And e.Form.Controls("TextBox1").text IsNot Nothing And e.Form.Controls("TextBox2").text IsNot Nothing Then
    doc.PageSetting.Width = Val(e.Form.Controls("TextBox2").Value) '自定义纸张宽度,单位为毫米
    doc.PageSetting.Height = Val(e.Form.Controls("TextBox1").Value)  '自定义纸张高度,单位为毫米
Else
    messagebox.show("纸张规格不能为空")
    Return
End If
If e.Form.Controls("ComboBox2").Value Is Nothing Then
    messagebox.show("棋赛名称不能为空")
    Return
End If
Dim c1 As Double = e.Form.Controls("TextBox4").Value
Dim c2 As Double = e.Form.Controls("TextBox5").Value
Dim c3 As Double = Val(doc.PageSetting.Width)
Dim c4 As Double = Val(doc.PageSetting.Height)
Doc.PageSetting.LeftMargin = (c3 - c1*(Math.Floor(c3/c1)))/2 '设置左边距
Doc.PageSetting.RightMargin = (c3 - c1*(Math.Floor(c3/c1)))/2 '设置右边距
Doc.PageSetting.TopMargin = (c4 - c2*(Math.Floor(c4/c2)))/2 '设置上边距
Doc.PageSetting.BottomMargin = (c4 - c2*(Math.Floor(c4/c2)))/2 '设置下边距
For i As Integer = 0 To DataTables("基本信息").SQLCompute("Count(姓名)","[棋赛名称] = '" & e.Form.Controls("ComboBox2").text & "' And [身份] = '裁判'") - 1
    Dim rt As New prt.RenderTable() '定义一个表格对象
    Dim drs As List(Of DataRow) = DataTables("基本信息").SQLSelect("[棋赛名称] = '" & e.Form.Controls("ComboBox2").text & "'And [身份] = '裁判'")
    If drs IsNot Nothing Then
        rt.Style.GridLines.All = New prt.LineDef '将网格线类型设为默认类型
        rt.Style.GridLines.Horz = new Prt.LineDef(Color.white)
        rt.Style.GridLines.Vert = new Prt.LineDef(Color.white)
        rt.Width = c1 '表格宽度为
        rt.Height = c2
        rt.Style.Spacing.All = 2 '和其他对象之间的间隔为2mm
        rt.SplitVertBehavior = prt.SplitBehaviorEnum.Never '避免垂直换页的时候,表格被分割成两部分.
        rt.Rows.Count = 9 '设置总行数
        rt.Cols.Count = 8 '设置总列数
        rt.Rows(0).Height = 5
        rt.Cols(0).Width = 3
        rt.cells(0,0).SpanCols = 8
        rt.cells(1,1).SpanCols = 6
        rt.Cols(1).Width = 2
        rt.Cells(1,1).Style.FontBold = True
        rt.Cells(1,1).Style.FontName = e.Form.Controls("FontPicker1").Value
        rt.Cells(1,1).Style.FontSize = e.Form.Controls("ComboBox3").Value
        rt.cells(1,1).Text = e.Form.Controls("ComboBox2").text
        rt.cells(1,1).Style.TextAlignHorz = prt.AlignHorzEnum.Center
        rt.cells(1,1).Style.TextAlignVert = prt.AlignHorzEnum.Center
        rt.Cells(2,1).SpanCols = 6
        If drs(i).IsNull("棋赛副名") Then
            rt.Cells(2,1).Text = Nothing
            rt.Rows(2).Height = 0
        Else
            rt.Cells(2,1).Text = drs(i)("棋赛副名")
        End If
        rt.Cells(2,1).Style.FontName = e.Form.Controls("FontPicker2").Value
        rt.Cells(2,1).Style.FontSize = e.Form.Controls("ComboBox4").Value
        rt.Cells(2,1).Style.TextAlignHorz = prt.AlignHorzEnum.Center
        rt.cells(2,1).Style.TextAlignVert = prt.AlignHorzEnum.Center
        rt.Cols(2).Width = 14
        rt.Rows(3).Height = 2
        rt.cells(4,1).SpanCols = 2
        rt.Cells(4,1).SpanRows = 2
        rt.Cells(4,1).Text = "相片"
        rt.Cells(4,1).Style.TextAlignHorz = prt.AlignHorzEnum.Center
        rt.cells(4,1).Style.TextAlignVert = prt.AlignHorzEnum.Center
        rt.Cells(4,1).Style.GridLines.Left = New prt.LineDef
        rt.Cells(4,1).Style.GridLines.Right = New prt.LineDef
        rt.Cells(4,1).Style.GridLines.Top = New prt.LineDef
        rt.Cells(4,1).Style.GridLines.Bottom = New prt.LineDef
        rt.Rows(4).Height = 18
        rt.Cols(3).Width = 2
        rt.Cells(4,4).SpanCols = 3
        rt.Cells(4,4).SpanRows = 2
        rt.Cells(4,4).Text = "裁判"
        rt.Cells(4,4).Style.FontName = e.Form.Controls("FontPicker3").Value
        rt.Cells(4,4).Style.FontSize = e.Form.Controls("ComboBox5").Value
        rt.Cells(4,4).Style.TextAlignHorz = prt.AlignHorzEnum.Center
        rt.cells(4,4).Style.TextAlignVert = prt.AlignHorzEnum.Center
        rt.Rows(6).Height = 2
        rt.Cols(6).Width = 2
        rt.cells(7,2).SpanCols = 4
        rt.Cells(7,2).Text= drs(i)("姓名")
        rt.Cells(7,2).Style.FontName = e.Form.Controls("FontPicker4").Value
        rt.Cells(7,2).Style.FontSize = e.Form.Controls("ComboBox6").Value
        rt.Cells(7,2).Style.TextAlignHorz = prt.AlignHorzEnum.Center
        rt.cells(7,2).Style.TextAlignVert = prt.AlignHorzEnum.Center
        rt.cells(8,0).SpanCols = 8
        rt.Rows(8).Height = 5
        rt.Cols(7).Width = 3
        doc.Body.Children.Add(rt) '将表格对象加入到报表中
    Else
        Return
    End If
Next
Doc.Preview() '预览报表

参赛者的代码与之一样,于是我加了一个身份选项希望减少一个窗口,结果报错:
[此贴子已经被作者于2021/11/9 22:43:18编辑过]

 回到顶部
美女呀,离线,留言给我吧!
采菊东篱下
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1881 积分:10374 威望:0 精华:0 注册:2019/4/6 8:45:00
  发帖心情 Post By:2021/11/9 14:58:00 [显示全部帖子]

红色标注代码是我改动过的地方:
Dim doc As New PrintDoc '定义一个报表
doc.Stacking = prt.StackingRulesEnum.InlineLeftToRight '设置排列方式
If e.Form.Controls("TextBox4").Value Is Nothing OrElse e.Form.Controls("TextBox5").Value Is Nothing Then
    messagebox.show("模板长宽不能为空")
    Return
End If
If e.Form.Controls("RadioButton1").Checked = True And e.Form.Controls("ComboBox1").text = e.form.controls("combobox1").items(0) Then
    doc.PageSetting.Width = 297 'A3纸张宽度,单位为毫米
    doc.PageSetting.Height = 420  'A3纸张高度,单位为毫米
ElseIf e.Form.Controls("RadioButton2").Checked = True And e.Form.Controls("ComboBox1").text = e.form.controls("combobox1").items(1) Then
    doc.PageSetting.Width = 210 'A4纸张宽度,单位为毫米
    doc.PageSetting.Height = 297  'A4纸张高度,单位为毫米
ElseIf e.Form.Controls("RadioButton2").Checked = True And e.Form.Controls("ComboBox1").text = e.form.controls("combobox1").items(2) Then
    doc.PageSetting.Width = 148.5 'A5纸张宽度,单位为毫米
    doc.PageSetting.Height = 210  'A5纸张高度,单位为毫米
ElseIf e.Form.Controls("RadioButton2").Checked = True And e.Form.Controls("ComboBox1").text = e.form.controls("combobox1").items(3) Then
    doc.PageSetting.Width = 257 'B4纸张宽度,单位为毫米
    doc.PageSetting.Height = 364  'B4纸张高度,单位为毫米
ElseIf e.Form.Controls("RadioButton2").Checked = True And e.Form.Controls("ComboBox1").text = e.form.controls("combobox1").items(4) Then
    doc.PageSetting.Width = 176 'B5纸张宽度,单位为毫米
    doc.PageSetting.Height = 250  'B5纸张高度,单位为毫米
ElseIf e.Form.Controls("RadioButton2").Checked = True And e.Form.Controls("ComboBox1").text = e.form.controls("combobox1").items(5) Then
    doc.PageSetting.Width = 420 'A2纸张宽度,单位为毫米
    doc.PageSetting.Height = 594  'A2纸张高度,单位为毫米
ElseIf e.Form.Controls("RadioButton2").Checked = True And e.Form.Controls("ComboBox1").text = e.form.controls("combobox1").items(6) Then
    doc.PageSetting.Width = 105 'A6纸张宽度,单位为毫米
    doc.PageSetting.Height = 148  'A6纸张高度,单位为毫米
ElseIf e.Form.Controls("RadioButton1").Checked = True And e.Form.Controls("TextBox1").text IsNot Nothing And e.Form.Controls("TextBox2").text IsNot Nothing Then
    doc.PageSetting.Width = Val(e.Form.Controls("TextBox2").Value) '自定义纸张宽度,单位为毫米
    doc.PageSetting.Height = Val(e.Form.Controls("TextBox1").Value)  '自定义纸张高度,单位为毫米
Else
    messagebox.show("纸张规格不能为空")
    Return
End If
If e.Form.Controls("ComboBox2").Value Is Nothing Then
    messagebox.show("棋赛名称不能为空")
    Return
End If
If e.Form.Controls("ComboBox7").Value Is Nothing Then
    messagebox.show("身份不能为空")
    Return
End If
Dim c1 As Double = e.Form.Controls("TextBox4").Value
Dim c2 As Double = e.Form.Controls("TextBox5").Value
Dim c3 As Double = Val(doc.PageSetting.Width)
Dim c4 As Double = Val(doc.PageSetting.Height)
Doc.PageSetting.LeftMargin = (c3 - c1*(Math.Floor(c3/c1)))/2 '设置左边距
Doc.PageSetting.RightMargin = (c3 - c1*(Math.Floor(c3/c1)))/2 '设置右边距
Doc.PageSetting.TopMargin = (c4 - c2*(Math.Floor(c4/c2)))/2 '设置上边距
Doc.PageSetting.BottomMargin = (c4 - c2*(Math.Floor(c4/c2)))/2 '设置下边距
If e.Form.Controls("ComboBox7").text = e.Form.Controls("ComboBox7").items(0) Then
    For i As Integer = 0 To DataTables("基本信息").SQLCompute("Count(姓名)","[棋赛名称] = '" & e.Form.Controls("ComboBox2").text & "' And [身份] = '" & e.Form.Controls("ComboBox7").items(0) & "'") - 1
        Dim rt As New prt.RenderTable() '定义一个表格对象
        Dim drs As List(Of DataRow) = DataTables("基本信息").SQLSelect("[棋赛名称] = '" & e.Form.Controls("ComboBox2").text & "'And [身份] = '" & e.Form.Controls("ComboBox7").items(0) & "'")
        If drs IsNot Nothing Then
            rt.Style.GridLines.All = New prt.LineDef '将网格线类型设为默认类型
            rt.Style.GridLines.Horz = new Prt.LineDef(Color.white)
            rt.Style.GridLines.Vert = new Prt.LineDef(Color.white)
            rt.Width = c1 '表格宽度为
            rt.Height = c2
            rt.Style.Spacing.All = 2 '和其他对象之间的间隔为2mm
            rt.SplitVertBehavior = prt.SplitBehaviorEnum.Never '避免垂直换页的时候,表格被分割成两部分.
            rt.Rows.Count = 9 '设置总行数
            rt.Cols.Count = 8 '设置总列数
            rt.Rows(0).Height = 5
            rt.Cols(0).Width = 3
            rt.cells(0,0).SpanCols = 8


 回到顶部
美女呀,离线,留言给我吧!
采菊东篱下
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1881 积分:10374 威望:0 精华:0 注册:2019/4/6 8:45:00
  发帖心情 Post By:2021/11/9 15:03:00 [显示全部帖子]

 下载信息  [文件大小:   下载次数: ]
点击浏览该文件:象棋排赛111.foxdb
代码太长了不复了直接上传,有相片的胸牌排版窗口按钮中的代码加入了
If e.Form.Controls("ComboBox7").text = e.Form.Controls("ComboBox7").items(0) Then
    For i As Integer = 0 To DataTables("基本信息").SQLCompute("Count(姓名)","[棋赛名称] = '" & e.Form.Controls("ComboBox2").text & "' And [身份] = '" & e.Form.Controls("ComboBox7").items(0) & "'") - 1
        Dim rt As New prt.RenderTable() '定义一个表格对象
        Dim drs As List(Of DataRow) = DataTables("基本信息").SQLSelect("[棋赛名称] = '" & e.Form.Controls("ComboBox2").text & "'And [身份] = '" & e.Form.Controls("ComboBox7").items(0) & "'")
后错,这样写代码也太长,应可以简化。

 回到顶部
美女呀,离线,留言给我吧!
采菊东篱下
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1881 积分:10374 威望:0 精华:0 注册:2019/4/6 8:45:00
  发帖心情 Post By:2021/11/9 15:05:00 [显示全部帖子]

原来的代码跟第一个窗口:有相片的裁判胸牌的代码差不多。

 回到顶部
美女呀,离线,留言给我吧!
采菊东篱下
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1881 积分:10374 威望:0 精华:0 注册:2019/4/6 8:45:00
  发帖心情 Post By:2021/11/9 20:27:00 [显示全部帖子]


图片点击可在新窗口打开查看此主题相关图片如下:qq图片20211109202307.png
图片点击可在新窗口打开查看
提示一直无法关闭,只能用Ctil+shift+Del强行关闭。
[此贴子已经被作者于2021/11/9 20:29:04编辑过]

 回到顶部
美女呀,离线,留言给我吧!
采菊东篱下
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1881 积分:10374 威望:0 精华:0 注册:2019/4/6 8:45:00
  发帖心情 Post By:2021/11/9 20:28:00 [显示全部帖子]

我把最后的代码改为
        Else
            Return
        End If
    Next
    Doc.Preview() '预览报表
End If
也一样报错。

 回到顶部
美女呀,离线,留言给我吧!
采菊东篱下
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1881 积分:10374 威望:0 精华:0 注册:2019/4/6 8:45:00
  发帖心情 Post By:2021/11/9 21:25:00 [显示全部帖子]

第2个有相片的胸牌排版窗口是有问题的,第1个有相片的胸牌排版没问题的,第1个窗口的代码把编号改为裁判就是第2个窗口原来的代码,由于代码差不多,于是我在第2个窗口加个身份选项,用条件语句判断,使到参赛人或裁判有相片的胸牌排版能在同一个窗口实现,在第2个窗口测试选项、数据如下:

图片点击可在新窗口打开查看此主题相关图片如下:qq图片20211109212402.png
图片点击可在新窗口打开查看
输上上面的数据后按右下角的按钮,弹出报错,在第一个窗口输上述数据(没有身份选项)可正常显示。

[此贴子已经被作者于2021/11/9 22:45:16编辑过]

 回到顶部
美女呀,离线,留言给我吧!
采菊东篱下
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1881 积分:10374 威望:0 精华:0 注册:2019/4/6 8:45:00
  发帖心情 Post By:2021/11/9 22:01:00 [显示全部帖子]

在窗口的AfterLoad事件中已经设置了条件了,哦,这条件要写在按钮里吧?
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.CommandText = "SELECT DISTINCT 棋赛名称,比赛已结束 Fro m {基本信息} WHERE [比赛已结束] = False Or [比赛已结束] Is null"
dt = cmd.ExecuteReader
If dt IsNot Nothing Then
    Dim qsmc As WinForm.ComboBox = e.form.Controls("ComboBox2")
    qsmc.Combolist = dt.SQLGetComboListString("棋赛名称","[比赛已结束] = False Or [比赛已结束] Is null")
End If
e.Form.Controls("FontPicker1").Value = "华文楷体"
e.Form.Controls("ComboBox3").Value = 18
e.Form.Controls("FontPicker2").Value = "华文楷体"
e.Form.Controls("ComboBox4").Value = 12
e.Form.Controls("FontPicker3").Value = "华文楷体"
If e.Form.Controls("ComboBox7").text = e.Form.Controls("ComboBox7").items(0) Then
    e.Form.Controls("ComboBox5").Value = 48
ElseIf e.Form.Controls("ComboBox7").text = e.Form.Controls("ComboBox7").items(1) Then
    e.Form.Controls("ComboBox5").Value = 36
End If
e.Form.Controls("FontPicker4").Value = "华文楷体"
e.Form.Controls("ComboBox6").Value = 28

 回到顶部
美女呀,离线,留言给我吧!
采菊东篱下
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:八尾狐 帖子:1881 积分:10374 威望:0 精华:0 注册:2019/4/6 8:45:00
  发帖心情 Post By:2021/11/9 22:05:00 [显示全部帖子]

If e.Form.Controls("ComboBox7").text = e.Form.Controls("ComboBox7").items(0) Then
    e.Form.Controls("ComboBox5").Value = 48
ElseIf e.Form.Controls("ComboBox7").text = e.Form.Controls("ComboBox7").items(1) Then
    e.Form.Controls("ComboBox5").Value = 36
End If
改在按钮里行了,谢谢指出,不然还茫茫然不知所措!
[此贴子已经被作者于2021/11/9 22:05:44编辑过]

 回到顶部