Hey folks.

I hope you can all help me. Basically, I'm designing a small GUI Windows program that allow staff at a cinema to reserve seats for customers. There will be a total of 60 seats in the cinema. I have two classes in my program:-

1.) MainForm.vb - used for I/O actions and user interaction
2.) SeatManager.vb - used to hold and handle the background methods and functions that make the program work

Here is the code for my MainForm.vb class thusfar:-

Public Class MainForm

    Private Const m_totalNumberOfSeats As Integer = 60
    Private m_seatManager As SeatManager

    Public Sub New()

        InitializeComponent()
        m_seatManager = New SeatManager(m_totalNumberOfSeats)
        InitializeGUI()
    End Sub

    ''' <summary>
    ''' Method called from the MainForm() method. This method is called when the form
    ''' is opened by the program (on initialisation).
    ''' </summary>
    Private Sub InitializeGUI()
        rbtnReservation.Checked = True              'Sets the Reserve button as being chosen
        lstReservations.Items.Clear()               'Clears the list displaying all seats and reservations
        txtCustomerName.Text = String.Empty         'Sets the name textbox as emtpy
        txtSeatPrice.Text = String.Empty

    End Sub
End Class

...and here's my code for the SeatManager.vb class:-

Public Class SeatManager

    Dim m_nameList As String()
    Dim m_priceList As Double()
    Dim m_totalNumberOfSeats As Integer

    Public Sub New(ByVal maxNumberOfSeats)
        m_totalNumberOfSeats = maxNumberOfSeats
        m_nameList = New String(m_totalNumberOfSeats - 1) {}
        m_priceList = New Double(m_totalNumberOfSeats - 1) {}
    End Sub

End Class

Basically, when the program opens, the lstReservations list in the MainForm class will be populated with a total of 60 (m_totalNumberOfSeats) entries to represent 60 seats. Each of these seats will contain the index number from the array m_nameList; this index number (+1) will represent the seat number and then in the lstReservations list, after the seat number, I'd like it to contain the respective entry from the m_nameList array. As all entries will be held in RAM, when the GUI is opened, all m_nameList array entries will be empty. As the user uses the program, they can highlight a row in the lstReservations list and then use the GUI textboxes to enter the customer's name which will then be populated into the respective array entry.

Can anyone offer any pointers as to how to, when the GUI opens, ensure that the lstReservations list takes all of the blank entries from the m_nameList array and from there, I can highlight a row to carry out further methods on?

Thanks in advance

IMO the easy way is to use a dataset.
The dataset can contain a table holding a row for each seat with the relevant seat info.

The dataset can be persisted on a XML file when exiting, and can be retireved at the start of the program.

As is in XML format, you can use XMLNotepad from MS to populate it the very first time.

Hope this helps

May I point out that it's bad practise to keep the data in RAM?

PS: It's also bad practise to hard code the 60 seats into the program. It would be easy enough to use application settings to hold this info without hard coding it.

@adam_k: can you be so kind to argue your points?

Thanks in advance.

Original poster said: "As all entries will be held in RAM, when the GUI is opened, all m_nameList array entries will be empty. As the user uses the program, they can highlight a row in the lstReservations list and then use the GUI textboxes to enter the customer's name which will then be populated into the respective array entry."

This assumes that the PC will never shut down, by accident, by hardware malfunction or lack of electricity. Keeping the data in RAM, without saving and presenting the user a clean array to start reserving from scratch - by design - IS bad practise.

Your suggestion lolafuertes is improving this, but still the XML file should be saved every x minutes or after a seat has changed.

About hard coding the seats numbers: It is always a good idea to avoid using data in your code. Programs should act on data and not contain them.
If in 5 years time the cinema expands, the programmer will receive a call to rebuild the program with 70 seats this time.
If the code for this program exists, the programmer will only need to find a way to make it compatible with whatever we will be using by then - try converting a VB 5 to .NET - or find the appropriate environment to change the code and compile as VB .Net Framework x.
Same applies if original poster tries to sell this program to another cinema.

I've been supporting a program for a while now. I find the way it was written brilliant and without limitations. That is because the programmer created everything dynamic and configurable. All queries to the database where written in a table in the database and the connection string to the registry.
I've changed about 80% of the existing queries and created a few of my own, without a problem and without giving the creator a call.

commented: HI:) +10

@adam_k. Thanks for your feedback.

I will always agree that data in RAM is not a good practice, but I will not discuss the design quality of the program, almost on this thread, because that's not the question from scrivomcdivo.

Obviously, hard coding is always a bad practice also, but, again, I will not discuss the design quality of the program. Many programming teachers teach with bad designs in order to focus the solution on a distinct point, ie an array research or update algorithm, and because I do not know if this is the case, I do not discuss the design quality of the program.

Also, you are right when you say that, in order not to loose the info, is required to save the data after some time or after each relevant update. But this is a must how-to for any data layer you use.

Arguing on my answer, one of the advantages to use a dataset is that the number of rows can be increased o diminished when needed without nedd to recode the program.

Using an external editor like XMLNotepad to populate the dataset does not implies the need to recompile the program when defining the rows. Also this provides an external-to-the-program cheep (free) tool to mantain the data if neded.

Sorry for the long rant. You can see I agree with you.
Cheers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.