Visual Basic 2010 - 动态标签,控件和记录数据

我发布这个后,通过搜索失去我的时间&没有得到正确的答案。Visual Basic 2010 - 动态标签,控件和记录数据

我的要求是创建一个许可证制度。 当我点击“新许可证”按钮(位于tabcontrol上面的表单的顶部)时,表单&上有一个选项卡控件,应该打开一个新的选项卡(名为“新许可证”),其上带有文本框。 每次点击“新许可证”按钮,同时打开相同类型的选项卡。 当我们在文本字段中选择一个选项卡&填充&点击“发行许可证”按钮(位于上方的TabControl形式的顶部),标签应同时有专门的许可证文本字段中的数据保存到Access数据库关闭数。

我创建的形式&“新证”,“发行许可证”按钮& TabControl的是在用户控件“ucPermit”。 我很惊讶创建这些动态标签&将这些数据获取到数据库中。

'' '' ''' '' 附件 '' '' '' '' '' '' '' ''' '' '' '' '' ''' '' ''” '''

@DonA

我在窗体上有两个面板。 面板01(左侧)有按钮“摘要,许可证,LOTO,HotWork”。 当每个按钮被点击时,相应的用户控件(在运行时加载到右侧的面板02上)出现在前面。

Public Class Home 

Dim ucSummary As New ucSummary

Dim ucPermitMain As New ucPermitMain

Dim ucLotoMain As New ucLotoMain

Dim ucHotWorkMain As New ucHotWorkMain

Private Sub Home_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

lblDate.Text = Format(Now, "MMMM dd, yyyy")

lblTime.Text = Format(Now, "h:mm tt")

btnSummary.BackColor = Color.LightGreen

Panel2.Controls.Add(ucSummary)

ucSummary.Dock = DockStyle.Fill

Panel2.Controls.Add(ucPermitMain)

ucPermitMain.Dock = DockStyle.Fill

Panel2.Controls.Add(ucLotoMain)

ucLotoMain.Dock = DockStyle.Fill

Panel2.Controls.Add(ucHotWorkMain)

ucHotWorkMain.Dock = DockStyle.Fill

End Sub

Private Sub btnSummary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSummary.Click

btnSummary.BackColor = Color.LightGreen

btnPermit.BackColor = Color.LightBlue

btnLoto.BackColor = Color.LightBlue

btnHotWork.BackColor = Color.LightBlue

ucSummary.BringToFront()

End Sub

Private Sub btnPermit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPermit.Click

btnSummary.BackColor = Color.LightBlue

btnPermit.BackColor = Color.LightGreen

btnLoto.BackColor = Color.LightBlue

btnHotWork.BackColor = Color.LightBlue

ucPermitMain.BringToFront()

End Sub

Private Sub btnLoto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoto.Click

btnSummary.BackColor = Color.LightBlue

btnPermit.BackColor = Color.LightBlue

btnLoto.BackColor = Color.LightGreen

btnHotWork.BackColor = Color.LightBlue

ucLotoMain.BringToFront()

End Sub

Private Sub btnHotWork_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHotWork.Click

btnSummary.BackColor = Color.LightBlue

btnPermit.BackColor = Color.LightBlue

btnLoto.BackColor = Color.LightBlue

btnHotWork.BackColor = Color.LightGreen

ucHotWorkMain.BringToFront()

End Sub

End Class

我刚开始&目前的工作许可证部分与ucPermitMain用户控件的作品。 它有一个工具条(tsPermit)在顶部&下面是一个空的tabcontrol(tcPermit)。 Toolstrip有按钮“NewPermit,问题,关闭”(现在..更多与设计) 每次NewPermit被点击新的标签与其上的文本框并行打开。 当选择一个特定的选项卡&单击“发布”时,选定选项卡的文本框中的数据将被放入数据库“PTW.accdb”,&选项卡以关闭。

Public Class ucPermitMain 

Dim PTW As New OleDb.OleDbConnection

Dim ucPermit As New ucPermit

Dim txtbox As New TextBox

Public Sub New()

' This call is required by the designer.

InitializeComponent()

' Add any initialization after the InitializeComponent() call.

PTW = New OleDb.OleDbConnection

PTW.ConnectionString = "Provider=Microsoft.ACE.Oledb.12.0; Data Source=" & Application.StartupPath & "\PTW.accdb"

End Sub

Public Sub tsbtnNewPermit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnNewPermit.Click

tsbtnClose.Visible = True

tsbtnClose.Enabled = True

Dim CTP As New CustomTabPage("New PTW", New Object)

Me.tcPermit.TabPages.Add(CTP)

tcPermit.SelectTab(tcPermit.TabPages.Count - 1)

End Sub

Public Sub tsbtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnClose.Click

tcPermit.TabPages.RemoveAt(tcPermit.SelectedIndex)

'This bottom code is telling it to remove the selected tab and countdown minus (-) 1 (one)

If tcPermit.TabPages.Count > 0 Then

tcPermit.SelectTab(tcPermit.SelectedIndex)

Else

tsbtnClose.Visible = False

tsbtnClose.Enabled = False

End If

End Sub

Public Sub tsbtnIssue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnIssue.Click

Dim cmd As New OleDb.OleDbCommand

Dim CTB As CustomTextBox

If Not PTW.State = ConnectionState.Open Then

'open connection if it is not yet open

PTW.Open()

End If

cmd.Connection = PTW

cmd.CommandText = "INSERT INTO tblPermit(ptwNo)" & _

"VALUES('" & ?????????????? & "')"

cmd.ExecuteNonQuery()

End Sub

End Class

CustomTextBox & CustomTabPage是两个不同的类来创建自定义这些控件。

Imports System.Windows.Forms 

Public Class CustomTabPage

Inherits TabPage

Public Sub New(ByVal Name As String, ByVal NewConstruct As Object)

InitTextBox(1)

Me.Text = Name

End Sub

Private Sub InitTextBox(ByVal Num As Integer)

Dim LocX As Integer = 10

Dim LocY As Integer = 10

Dim CTB As New CustomTextBox("")

CTB.Location = New System.Drawing.Point(LocX, LocY)

Me.Controls.Add(CTB)

End Sub

End Class

Imports System.Windows.Forms

Public Class CustomTextBox

Inherits TextBox

Public Sub New(ByVal Name As String)

Me.Text = Name

End Sub

End Class

这是唯一的代码,我现在高达它们&可能不是最优化的实现。 希望你会花时间去完成。

回答:

这里的教训是有Data Layer,这一层的所有数据保存到数据库的方法和逻辑。当新标签生成时,您有一个属性允许它访问Data Layer。它可能甚至需要一些封装(UserControl)与一组控制相同的逻辑来保存/验证数据。

您还应该显示一些代码 - 在寻求帮助之前,您可以付出代价。

以上是 Visual Basic 2010 - 动态标签,控件和记录数据 的全部内容, 来源链接: utcz.com/qa/265710.html

回到顶部