vb.net - Objects within Arrays, and changing their properties -
this program seat booking system , having problems when checking availability of each seat.
when form loads, array created , stores seat names in. each seat check box displayed button. sql statement runs , finds records null customer id field, seat id of seat , show date of friday. if number of records returned = 1, color of check box button turn green, else turn red.
the code check availability works perfectly, i'm not sure how change colour of checkbox in position of array change. believe because array holding strings, not objects. have done lot of research on , cannot seem find solution.
what need name of seat (a1,a2, etc.) stored in array can used in sql statement, way change color of seat. there 197 seats in total, why going need array.
i appreciate solution problem , provide information below including screenshot of database table, screenshot of form design , code.
database table: http://gyazo.com/0cf669a1c2144b7174066bdbbd29d3a3
form design: http://gyazo.com/b9400018cccd61afb83518e3754df2d4
private sub frmseatplan_load(sender system.object, e system.eventargs) handles mybase.load dim seat(11, 15) string dim seatname string dim sql string dim da oledb.oledbdataadapter seat(1, 1) = a1.name seat(1, 2) = a2.name seat(1, 3) = a3.name seat(1, 4) = a4.name seat(1, 5) = a5.name seat(1, 6) = a6.name seat(1, 7) = a7.name seat(1, 8) = a8.name seat(1, 9) = a9.name seat(1, 10) = a10.name seat(1, 11) = a11.name seat(1, 12) = a12.name seat(1, 13) = a13.name seat(1, 14) = a14.name dim x integer dim y integer y = 1 1 x = 1 14 seatname = seat(y, x) con.connectionstring = dbprovider & dbsource con.open() 'opens connection database sql = "select * bookings show_id = 'friday' , customer_id null , seat_id ='" & seatname & "'" da = new oledb.oledbdataadapter(sql, con) 'create data adapter store filtered data using sql code msgbox(sql) da.fill(ds, seat(y, x)) 'count number of records empty customer id, show id of friday , seat id of seat. dim recordcount integer recordcount = ds.tables(seat(y, x)).rows.count msgbox(recordcount) if recordcount = 1 'change backcolor green else 'change backcolor red end if con.close() next x next y end sub
put controls in array, instead of names. use name property array when need it, , can access backcolor or other properties/methods when need them too.
like this:
private sub frmseatplan_load(sender system.object, e system.eventargs) handles mybase.load dim seat(11, 15) control '** changed string ** dim seatname string dim sql string dim da oledb.oledbdataadapter seat(1, 1) = a1 seat(1, 2) = a2 seat(1, 3) = a3 seat(1, 4) = a4 seat(1, 5) = a5 seat(1, 6) = a6 seat(1, 7) = a7 seat(1, 8) = a8 seat(1, 9) = a9 seat(1, 10) = a10 seat(1, 11) = a11 seat(1, 12) = a12 seat(1, 13) = a13 seat(1, 14) = a14 dim x integer dim y integer y = 1 1 x = 1 14 seatname = seat(y, x).name con.connectionstring = dbprovider & dbsource con.open() 'opens connection database sql = "select * bookings show_id = 'friday' , customer_id null , seat_id ='" & seatname & "'" da = new oledb.oledbdataadapter(sql, con) 'create data adapter store filtered data using sql code msgbox(sql) da.fill(ds, seat(y, x).name) 'count number of records empty customer id, show id of friday , seat id of seat. dim recordcount integer recordcount = ds.tables(seat(y, x).name).rows.count msgbox(recordcount) if recordcount = 1 'change backcolor green seat(x, y).backcolor = color.green else 'change backcolor red seat(x, y).backcolor = color.red end if con.close() next x next y end sub
Comments
Post a Comment