我有一个用于餐厅管理的VB.NET项目。我在数据库中有一个实体,我存储餐馆餐桌数据(忙或不,等)。
我可以使用此代码在DataGridView
中显示数据,但这仅显示为一行:
Dim conexao As MySqlConnection = connection
Dim comando As MySqlCommand = New MySqlCommand("PCD_TABLE_SHOW", conexao)
comando.CommandType = CommandType.StoredProcedure
Dim dt As MySqlDataAdapter = New MySqlDataAdapter(comando)
Dim tabela As DataTable = New DataTable
Try
conexao.Open()
dt.Fill(tabela)
FormVenda.dgvVenda.DataSource = tabela
Catch ex As Exception
MessageBoxEx.Show(ex.Message)
Finally
conexao.Close()
End Try
我桌子的挤压或多或少是这样的:
Create table table_(Cod_table int autincrement,Name_table varchar (20),Bus_table bit,Desc_table varchar (50))
我只想将此表的name_table字段显示为表单上的按钮。 我想知道如何在表单中显示所有按钮形状的表格并更改颜色(如果它繁忙与否),如下图所示:
答案 0 :(得分:0)
我已经找到了解决方案:
Dim UserButtons As List(Of Button) = New List(Of Button)
Private Sub Gettable()
Try
Dim conexao As MySqlConnection = connection
conexao.Open()
Dim cmdText As String = "PCD_SHOW_TABLE"
Dim cmd As MySqlCommand = New MySqlCommand(cmdText)
cmd.CommandType = CommandType.StoredProcedure
' cmd.Parameters.AddWithValue("@d1")
Color.LightGreen.ToArgb()
cmd.Connection = conexao
Dim rdr As MySqlDataReader
rdr = cmd.ExecuteReader()
FlowLayoutPanel1.Controls.Clear()
Do While (rdr.Read())
Dim btn As New Button
btn.Text = rdr.GetValue(1)
' btn.TextAlign = ContentAlignment.MiddleCenter
'Dim btnColor As Color = Color.FromArgb(Val(rdr.GetValue(1)))
'btn.BackColor = btnColor
' btn.FlatStyle = FlatStyle.Popup
btn.Width = 100
btn.Height = 80
btn.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
UserButtons.Add(btn)
FlowLayoutPanel1.Controls.Add(btn)
AddHandler btn.Click, AddressOf Me.Button1_Click
Loop
conexao.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub