'判断分拣大类
If vars("分拣类别")="蔬菜" Then
'建立符合状态的订单集合
Dim drs1 As List(of DataRow)
drs1 = DataTables("订单表").Select("订单状态 = 'PMC已确认'")
Dim x As Integer = 1 '名称后缀初始值
Dim y As Integer = 20 '水平位置初始值
Dim z As Integer = 10 '垂直位置初始值
Dim k As Single = e.Form.Controls("SplitContainer1").Panel2.Width '分栏的宽度
'遍历订单
For Each dr1 As DataRow In drs1
'查询对应的大类
Dim dr1_1 As DataRow = DataTables("基础资料表").find("对应大类 = '" & dr1("物料类别") & "'")
'如果不符合,跳过
If dr1_1("分拣部") <> "蔬菜" Then
Continue For
'如果符合
Else
'遍历控件判断是否已存在对应的控件
Dim n As Integer = 0 '定义变量判断是否存在对应控件
For Each c As WinForm.Control In e.Form.Controls
If Typeof c Is WinForm.Button Then '判断控件是否是文本框
Dim b As WinForm.Button = c '使用特定类型的变量引用控件
If b.Text = dr1("物料名称")
n = 1
End If
End If
Next
'如果存在,则跳过
If n = 1 Then
Continue For
Else '如果不存在,则新建控件
Dim but As WinForm.Button
but = e.Form.CreateControl("Button" & x , ControlTypeEnum.Button)
x=x+1
If y + 200 > k Then '这里的200等于宽度加Y的初始值20
y = 20
z = z + 70
but.SetBounds(y, z, 180, 60) '统一设置位置与大小(水平,垂直,宽度,高度)
Else
but.SetBounds(y, z, 180, 60) '统一设置位置与大小(水平,垂直,宽度,高度)
y = y+200
End If
but.Text = dr1("物料名称") '显示内容
but.ReadOnly = True '设置为只读
but.TextAlign = HorizontalAlignment.Center '对齐方式
but.Font = New Font("宋体",16)
but.BackColor = Color.white
but.FlatStyle = FlatStyle.Flat
but.BorderSize = 2
but.BorderColor = Color.red
'but.Enabled = False
e.Form.Controls("SplitContainer1").Panel2.AddControl(but)
End If
End If
Next
End If