Results 1 to 34 of 34

Thread: [RESOLVED] Which control can I use?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Resolved [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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    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

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Which control can I use?

    What are your field names, and how are you loading the ListView?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    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:
    1. Private Sub PopulateList(pList As ListView, _
    2.                          pRst As ADODB.Recordset)
    3.     On Error Resume Next
    4.     Dim i As Long
    5.     Dim iColCount As Long
    6.     Dim sColName As String
    7.     Dim sColValue As String
    8.     Dim oCH As ColumnHeader
    9.     Dim oLI As ListItem
    10.     Dim oSI As ListSubItem
    11.     Dim oFld As ADODB.Field
    12.  
    13.     With pList
    14.         .View = lvwReport
    15.         .GridLines = True
    16.         .FullRowSelect = True
    17.         .ListItems.Clear
    18.         .Sorted = False
    19.         pRst.MoveFirst
    20.         ' set up column headers
    21.  
    22.         For Each oFld In pRst.Fields
    23.             sColName = cn(oFld.Name)
    24.             Set oCH = .ColumnHeaders.Add()
    25.             oCH.Text = sColName
    26.             iColCount = iColCount + 1
    27.         Next oFld
    28.  
    29.         Do Until pRst.EOF
    30.             i = 0
    31.             ' setup fiprst column as a listitem
    32.             sColValue = cn(pRst.Fields(i).Value)
    33.             Set oLI = .ListItems.Add()
    34.             oLI.Text = sColValue
    35.             ' add the remaining columns
    36.             'as subitems
    37.  
    38.             For i = 1 To iColCount
    39.                 Set oSI = oLI.ListSubItems.Add()
    40.                 oSI.Text = cn(pRst(i))
    41.             Next ' next column
    42.             pRst.MoveNext
    43.         Loop ' Next record
    44.         ' refresh it all
    45.         .Refresh
    46.         ' make sure 1st row can be seen
    47.         .ListItems(1).EnsureVisible
    48.     End With
    49. End Sub


    I hope this is sufficient info.

    Thanks
    Last edited by osemollie; Jun 28th, 2006 at 11:33 AM.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Which control can I use?

    How can I post a screenshot to a thread in a forum?

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  8. #8
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    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..

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Which control can I use?

    Hi,
    Attached is the GUI that am trying to implement for my checkout form. Thanks
    Attached Images Attached Images  

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Which control can I use?

    Help

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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?

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Which control can I use?

    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

  13. #13
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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:
    1. Dim lstMovieItem As ListItem
    2.  
    3. For Each lstMovieItem In ListView1.ListItems
    4.    sSQL = "INSERT INTO Orders (PatronID, MovieID, MovieName, etc) VALUES  _
    5.       (cboPatron.ItemData(cboPatron.ListIndex), lstMovieItem.Text, lstMovieItem.Subitem(1), etc)"
    6.    cnADO.Execute sSQL
    7. Next

    Just wrap everything in a transaction. cnADO.BeginTrans, CommitTrans, etc

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Which control can I use?

    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

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    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)?

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    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.?
    Last edited by osemollie; Jul 4th, 2006 at 08:02 AM.

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Which control can I use?

    Guys, am stuck and need your help. Anyone?

  18. #18
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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:
    1. 'set an error trap
    2. Connection.BeginTrans
    3. 'do all your inserts and/or updates here
    4. ...
    5. 'you got here because there were no errors
    6. Connection.CommitTrans 'let everything you did be done for real
    7. Exit Sub
    8.  
    9. ErrorTrap:
    10.   Connection.RollbackTrans 'throw away everything you did
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    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)?
    Any idea how I can print?
    Last edited by osemollie; Jul 7th, 2006 at 07:32 AM.

  20. #20
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Which control can I use?

    Something like
    VB Code:
    1. Private Sub cmdPrint_Click()
    2. Dim lstMovieItem As ListItem
    3.  
    4.   Printer.Print Trim(txtPatronName.Text)
    5.   Printer.Print Format(dtDate,"MMM dd, yyyy")
    6.   Printer.Print lstResourceType.Text [COLOR=Green]'or whatever control it[/COLOR]'s showing on
    7.   Printer.Print 'for a blank line
    8.   For Each lstMovieItem In ListView1.ListItems
    9.   Printer.Print vbTab; lstMovieItem.Text; ", "; lstMovieItem.Subitem(1)
    10.   Next lstMovieItem
    11.   Printer.EndDoc
    12.  
    13. End sub
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    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.
    Last edited by osemollie; Jul 10th, 2006 at 08:03 AM.

  22. #22

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    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.?
    Any help on the above

  23. #23
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Which control can I use?

    Printer.Print vbTab; lstMovieItem.Text; ", "; lstMovieItem.Subitem(1); ", "; lstMovieItem.Subitem(2); ", "; lstMovieItem.Subitem(2) ...
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  24. #24

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    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?

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Which control can I use?

    How can I code so that my printing includes columnheaders from a ListView control?

  26. #26
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Which control can I use?

    VB Code:
    1. Printer.Print "Header Item 1"; vbTab; "Header Item 2"; vbTab; "Header Item 3"; vbTab; "Header Item 4" ...
    2. Printer.Print Right$("             " & lstMovieItem.Text, 13); vbTab; Right$("             " & lstMovieItem.Subitem(1), 13); vbTab; _
    3.  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.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  27. #27

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    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:
    1. '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?

  28. #28

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Which control can I use?

    Any suggestions?

  29. #29

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Which control can I use?

    Any ideas concerning adding the selected movies into the ListView control will be appreciated. Thanks.

  30. #30
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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:
    1. Dim MyItem As ListItem
    2. Do While Not AdoRs.EOF
    3.  Set MyItem = ListView1.ListItems.Add(, , AdoRs.Fields.Item("movieid").Value)
    4.     MyItem.SubItems(1) = AdoRs.Fields.Item("movietitle").Value
    5.     MyItem.SubItems(2) = etc 'until all movies in recordset are added
    6.     AdoRs.MoveNext
    7. Loop
    I'm using AdoRs as my recordset object. Change that to your recordset object name.

  31. #31

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    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?

  32. #32
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  33. #33

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    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.

  34. #34

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    475

    Re: Which control can I use?

    Guys help me with date calculations. See post 33 above. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width