-2

I'm posting this after losing my time by searching & got no proper answer.

My requirement is to create a permit system. There is a tabcontrol on the form & when I click on "New Permit" button (located top of the form above tabcontrol), a new tab should open (named "NEW Permit") with text boxes on it. Each time "New Permit" button is clicked, same type of tabs to be opened parallely. When we select a one tab & fill in the text fields & click on "Issue Permit" button (located top of the form above tabcontrol), tab should be closed while saving the data in text fields to a access database with a dedicated permit number.

I have created the form & the "New Permit","Issue Permit" buttons & tabcontrol are on a usercontrol "ucPermit". I'm struck in creating those dynamic tabs & getting the data on those into a database.

'''''''''' Annex ''''''''''''''''''''''''''''''''''''''

@DonA

I have two panels on the form. Panel 01 (on left) has buttons "Summary, Permit, LOTO, HotWork". When each button is clicked respective usercontrol (loaded onto panel 02 on right at runtime) comes to front.

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

I have just started & currently working on Permit section which works with ucPermitMain usercontrol. It has a toolstrip (tsPermit) on top & an empty tabcontrol (tcPermit) below. Toolstrip has buttons "NewPermit, Issue, Close" (for now..more to come with design) Each time NewPermit is clicked new tabs open parallely with text boxes on it. When selected a particular tab & "Issue" is clicked, the data on the selected tab's text boxes to be put into database "PTW.accdb", & tab to be closed.

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 are two seperate classes to create these custom controls.

 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

This is only code I have done upto now & they may be not optimized. Hope you will spend your time to go through.

uboy
  • 1
  • 4

1 Answers1

0

The lesson here is to have a Data Layer, this layer has all the methods and logic for saving data to the database. When the new tab is built you have a property that allows it to access the Data Layer. It might even need some encapsulation(UserControl) with having a group of control that the same logic for saving/validating data.

You also should show some code - an effort on your part before asking for help.

OneFineDay
  • 9,004
  • 3
  • 26
  • 37
  • I did - I feel my statement still stands. Each permit should be a UserControl and get and sets data by making calls to the `DAL` - Data Access Layer. This just might be a little above your head right now, but if you persist and keep working on it you will make it. – OneFineDay Aug 05 '13 at 14:27
  • Mhhh...could you please gimme a start with DAL ? – uboy Aug 06 '13 at 03:11