-
[RESOLVED] Which control can I use?
Hi all,
I am doing a movie application an I need your advice. At the moment am doing the GUI for lending out the movies. I have a combobox (lookup table) for holding the customer details from the customer table and another combobox (lookup table) for holding movie titles from the movies table. The idea is when I select a customer from the combo, and then select the movie they want to borrow, when i click on a command button (cmdSelect), the selected movie in the movies combo should be transfered into this control where it is listed as selected. (Like it is done in the supermarket applications where each item you buy is scanned and its details appear in a grid like control that indicates item description, price, discount etc) A user is allowed to borrow a maximum of three movies per day. All the selected movies should be held in a listed format in this control. After the selection, there is another command button (cmdCheckOutAllSelected) which when clicked, all the selected movies should be inserted into an orders table indicating the customer id, and the three or less movies that are appearing in this control. Note I should also be able to remove a selected movie from the control
1- Can this be implemented? If yes, which is the best control that can hold these selected movies and which can be manipulated using code to INSERT the selected movies into the DB?
2- how can I code to ensure that the selected movies are inserted into the DB
Does this make sense?
thanks
-
Re: Which control can I use?
Quote:
Originally Posted by osemollie
1- Can this be implemented?
Yes
Quote:
Originally Posted by osemollie
which is the best control that can hold these selected movies
I would use a ListView control for this
Quote:
Originally Posted by osemollie
and which can be manipulated using code to INSERT the selected movies into the DB?
The type of control is irrelevant. Your INSERT would be an SQL query executed from your DB connection object.
-
Re: Which control can I use?
Hack,
I am able to code and have the selected items appear in a listview but I don't know how to code so that all the listed items (1-3) in a ListView can get inserted into the orders table and still bear the same customer ID. How can I do that? Any sample code?
Thanks
-
Re: Which control can I use?
What are your field names, and how are you loading the ListView?
-
Re: Which control can I use?
- For the customer combobox the table is Customer (customerId, Firstname, lastName, address, telephone)
- For the movies combobox, the table is movies (movieId, title, genre, category)
- I also have 2 datepickers on the form. datePicker (dtOrderDate) and a datePicker (dtDueDate)
- 2 command button (cmdAddItemToList) and (cmdCheckOutAllListedItems)
- The orders table (orderId, customerId, OrderDate, DueDate, returnDate)
- The orderDetails table (orderId, movieId, ItemcostPerDay, ItemDiscount, ItemSubTotal)
- Intend to display the following as columnheaders in the ListView control, (#, movietitle, DueDate, ItemcostPerDay, ItemDiscount, ItemSubTotal, Total)
To load the ListView am using:-
VB Code:
Private Sub PopulateList(pList As ListView, _
pRst As ADODB.Recordset)
On Error Resume Next
Dim i As Long
Dim iColCount As Long
Dim sColName As String
Dim sColValue As String
Dim oCH As ColumnHeader
Dim oLI As ListItem
Dim oSI As ListSubItem
Dim oFld As ADODB.Field
With pList
.View = lvwReport
.GridLines = True
.FullRowSelect = True
.ListItems.Clear
.Sorted = False
pRst.MoveFirst
' set up column headers
For Each oFld In pRst.Fields
sColName = cn(oFld.Name)
Set oCH = .ColumnHeaders.Add()
oCH.Text = sColName
iColCount = iColCount + 1
Next oFld
Do Until pRst.EOF
i = 0
' setup fiprst column as a listitem
sColValue = cn(pRst.Fields(i).Value)
Set oLI = .ListItems.Add()
oLI.Text = sColValue
' add the remaining columns
'as subitems
For i = 1 To iColCount
Set oSI = oLI.ListSubItems.Add()
oSI.Text = cn(pRst(i))
Next ' next column
pRst.MoveNext
Loop ' Next record
' refresh it all
.Refresh
' make sure 1st row can be seen
.ListItems(1).EnsureVisible
End With
End Sub
I hope this is sufficient info.
Thanks
-
Re: Which control can I use?
How can I post a screenshot to a thread in a forum?
-
Re: Which control can I use?
Quote:
Originally Posted by osemollie
How can I post a screenshot to a thread in a forum?
Take a screen shoot, save it a file with something like Microsoft Paint, and then add it as an attachment.
-
Re: Which control can I use?
to take a SCREENSHOOT you can use the "PrintScreen" key on your keyborad
then paste it either to your windows paint or excel to modify the image height and length..
-
1 Attachment(s)
Re: Which control can I use?
Hi,
Attached is the GUI that am trying to implement for my checkout form. Thanks
-
Re: Which control can I use?
-
Re: Which control can I use?
Quote:
Originally Posted by osemollie
Hack,
I am able to code and have the selected items appear in a listview but I don't know how to code so that all the listed items (1-3) in a ListView can get inserted into the orders table and still bear the same customer ID. How can I do that? Any sample code?
Thanks
I'm looking at your form but do not see any indication of a customer ID. Where is that coming from?
-
Re: Which control can I use?
Quote:
I'm looking at your form but do not see any indication of a customer ID. Where is that coming from?
The customer ID is gotten from the cboPatron combobox which is a lookup table that displays customer names but picks the customerId for use in code
Thanks
-
Re: Which control can I use?
You will loop through the listitems and insert each listitem/record one by one to the orders table...jusr refer to the values held in the other controls for values that are similar for the listitem/record group
VB Code:
Dim lstMovieItem As ListItem
For Each lstMovieItem In ListView1.ListItems
sSQL = "INSERT INTO Orders (PatronID, MovieID, MovieName, etc) VALUES _
(cboPatron.ItemData(cboPatron.ListIndex), lstMovieItem.Text, lstMovieItem.Subitem(1), etc)"
cnADO.Execute sSQL
Next
Just wrap everything in a transaction. cnADO.BeginTrans, CommitTrans, etc
-
Re: Which control can I use?
Quote:
Just wrap everything in a transaction. cnADO.BeginTrans, CommitTrans, etc
Honestly speaking I don't know how to use the transaction thing. How do I do code that? Where can I get a tutorial on the same so that I can learn something on how to us it?
Thanks
-
Re: Which control can I use?
Looking at my GUI above, how can I code so that am able to print out the Patron name, date/time of transaction, resouceType, movies borrowed (as they appear in the ListView) on the click of the command button (cmdPrint)?
-
Re: Which control can I use?
Looking at my GUI above, when u click on Add selected command button, the selected item should be displayed in the ListView. How can I code in such away that the text of the selected item in the combo is displayed in the ListView but I still get the selected item's itemdata for use in my INSERT code into the checkout table.?
-
Re: Which control can I use?
Guys, am stuck and need your help. Anyone?
-
Re: Which control can I use?
Quote:
Originally Posted by osemollie
Honestly speaking I don't know how to use the transaction thing. How do I do code that? Where can I get a tutorial on the same so that I can learn something on how to us it?
It's pretty much:
VB Code:
'set an error trap
Connection.BeginTrans
'do all your inserts and/or updates here
...
'you got here because there were no errors
Connection.CommitTrans 'let everything you did be done for real
Exit Sub
ErrorTrap:
Connection.RollbackTrans 'throw away everything you did
-
Re: Which control can I use?
Quote:
Looking at my GUI above, how can I code so that am able to print out the Patron name, date/time of transaction, resouceType, movies borrowed (as they appear in the ListView) on the click of the command button (cmdPrint)?
Any idea how I can print?
-
Re: Which control can I use?
Something like
VB Code:
Private Sub cmdPrint_Click()
Dim lstMovieItem As ListItem
Printer.Print Trim(txtPatronName.Text)
Printer.Print Format(dtDate,"MMM dd, yyyy")
Printer.Print lstResourceType.Text [COLOR=Green]'or whatever control it[/COLOR]'s showing on
Printer.Print 'for a blank line
For Each lstMovieItem In ListView1.ListItems
Printer.Print vbTab; lstMovieItem.Text; ", "; lstMovieItem.Subitem(1)
Next lstMovieItem
Printer.EndDoc
End sub
-
Re: Which control can I use?
I was able to print the items in the ListView, however, it only printed column one and the first subitem in the listView. How do I get it to print all subitems in the listview and also the columnheaders?
Thanks.
-
Re: Which control can I use?
Quote:
Looking at my GUI above, when u click on Add selected command button, the selected item should be displayed in the ListView. How can I code in such away that the text of the selected item in the combo is displayed in the ListView but I still get the selected item's itemdata for use in my INSERT code into the checkout table.?
Any help on the above
-
Re: Which control can I use?
Printer.Print vbTab; lstMovieItem.Text; ", "; lstMovieItem.Subitem(1); ", "; lstMovieItem.Subitem(2); ", "; lstMovieItem.Subitem(2) ...
-
Re: Which control can I use?
Thanks Al42 for your help. I seem to be getting somewhere. I have seen receipts printed having columnheaders and even align the selected items in the ListView to their respective columnheaders, might you have an idea about that?
-
Re: Which control can I use?
How can I code so that my printing includes columnheaders from a ListView control?
-
Re: Which control can I use?
VB Code:
Printer.Print "Header Item 1"; vbTab; "Header Item 2"; vbTab; "Header Item 3"; vbTab; "Header Item 4" ...
Printer.Print Right$(" " & lstMovieItem.Text, 13); vbTab; Right$(" " & lstMovieItem.Subitem(1), 13); vbTab; _
Right$(" " & lstMovieItem.Subitem(2), 13); vbTab; Right$(" " & lstMovieItem.Subitem(2), 13) ...
The 13 is the length of the item in the header - you want to make sure that the data takes as much space as the header (adjust each column for your needs) or the columns won't line up.
-
Re: Which control can I use?
Looking at my GUI above, when u click on Add selected command button, the selected item from the movie title combobox (cboTitle) should be displayed in the ListView after the following code is run and all the fields in the code displayed in the ListView.
VB Code:
'strSQL = "SELECT movieInfo.movieId, movieInfo.title, MediaType.StrKey, MediaType.DefRentPricePerDay, MediaType.DefRentPeriodInDays FROM movieInfo INNER JOIN MediaType ON movieInfo.media_catId = MediaType.media_catId WHERE movieId = " & cboTitle.ItemData(cboTitle.ListIndex)
Remember, I should be able to add atleast 3 movies into the ListView control.
Is this possible?
-
Re: Which control can I use?
-
Re: Which control can I use?
Any ideas concerning adding the selected movies into the ListView control will be appreciated. Thanks.
-
Re: Which control can I use?
Quote:
Originally Posted by osemollie
Any ideas concerning adding the selected movies into the ListView control will be appreciated. Thanks.
VB Code:
Dim MyItem As ListItem
Do While Not AdoRs.EOF
Set MyItem = ListView1.ListItems.Add(, , AdoRs.Fields.Item("movieid").Value)
MyItem.SubItems(1) = AdoRs.Fields.Item("movietitle").Value
MyItem.SubItems(2) = etc 'until all movies in recordset are added
AdoRs.MoveNext
Loop
I'm using AdoRs as my recordset object. Change that to your recordset object name.
-
Re: Which control can I use?
Thanks HACK!! I knew you will help me out!! It works just like I wanted it. Now, after selecting the movies am interested in I only want to display all the fields in the recordset EXCEPT the movieId HOWEVER I need the movieId of each movie in the listview inorder to use it in my INSERT code when checking out the selected movies from the ListView control. Can this be done? I have also heard of carrying a non-displaying/hidden column in a ListView how is that implemented?
-
Re: Which control can I use?
You would have to have the movie id in your listview in order to do what you need to do (providing I'm understanding your needs correctly.)
You can insert the movie id in a column that does not display simply by having that column further over on the right than the control itself has been drawn. Caution: when you do this, the horizontal scrollbar will autosize itself so that column, although not displayed by default, can be scrolled to. I don't know if this would be an issue.
-
Re: Which control can I use?
Sorry, I had used a wrong thread to post my question. The question is:
----------
Looking at the GUI above, you will realise there is a button for the resource type and movie title. The title combo is populated depending on the resource type selected in the resource type combo. Movies are lend out depending on the type, eg
- VHS = 4 days
- VCD = 3 days
- DVD = 2 days
I wish to automatically update the dueDate automatically depending on the resource type and the checkout date.
I also have an a admin table where the users should be able to set the number of days they want to allow their customers to borrow movies instead of depending on the default dates set by the application. How can I do that.
-
Re: Which control can I use?
Guys help me with date calculations. See post 33 above. Thanks