2013-05-04 4 views
0

이 프로그램은 좌석 예약 시스템이며 각 좌석의 가용성을 확인할 때 문제가 있습니다.배열 내의 객체 및 속성 변경

폼이로드되면 배열이 만들어져 시트 이름이 저장됩니다. 각 시트는 버튼으로 표시된 확인란입니다. SQL 문은 실행되고 null 고객 ID 필드, 해당 좌석의 좌석 ID 및 금요일의 표시 날짜가있는 레코드를 찾습니다. 반환되는 레코드 수 = 1이면 확인란의 뒷면 색이 녹색으로 바뀌고 그렇지 않으면 빨간색으로 바뀝니다.

가용성을 확인하는 코드는 완벽하게 작동합니다. 변경하려는 배열의 위치에있는 확인란의 뒤쪽 색상을 변경하는 방법을 모르겠습니다. 배열이 문자열이 아니라 객체를 보유하고 있기 때문이라고 생각합니다. 나는 이것에 대해 많은 연구를 해왔고 해결책을 찾을 수없는 것 같습니다.

필요한 것은 SQL 문에서 사용할 수 있도록 배열에 저장 될 시트 이름 (A1, A2 등)뿐 아니라 해당 시트의 뒤쪽 색상을 변경하는 방법입니다 . 총 197 석이 있기 때문에 배열로이 작업을 수행해야합니다.

나는이 문제에 대한 해결책을 매우 고맙게 생각하며 데이터베이스 테이블의 스크린 샷, 양식 디자인의 스크린 샷 및 코드를 포함하여 아래의 모든 정보를 제공 할 것입니다.

데이터베이스 테이블 : http://gyazo.com/0cf669a1c2144b7174066bdbbd29d3a3

양식 디자인 : http://gyazo.com/b9400018cccd61afb83518e3754df2d4

Private Sub frmSeatPlan_Load(sender As System.Object, e As System.EventArgs)  Handles MyBase.Load 
    Dim seat(11, 15) As String 
    Dim seatname As String 
    Dim sql As String 
    Dim da As 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 As Integer 
    Dim y As Integer 
    For y = 1 To 1 
     For x = 1 To 14 
      seatname = seat(y, x) 

      con.ConnectionString = dbProvider & dbSource 
      con.Open() 'opens the connection to the database 

      sql = "SELECT * FROM Bookings where show_id = 'friday' AND customer_ID is null AND seat_id ='" & seatname & "'" 
      da = New OleDb.OleDbDataAdapter(sql, con) 'create a data adapter to store the filtered data using the SQL code 
      MsgBox(sql) 
      da.Fill(ds, seat(y, x)) 

      'count the number of records with an empty customer id, the show ID of Friday and the seat ID of this seat. 
      Dim recordCount As Integer 
      recordCount = ds.Tables(seat(y, x)).Rows.Count 
      MsgBox(recordCount) 

      If recordCount = 1 Then 
       'change backcolor to green 


      Else 
       'change backcolor to red 

      End If 

      con.Close() 


     Next x 
    Next y 
End Sub 
+0

편집 이전 질문 http://stackoverflow.com/questions/16342882/vb-2010-changing-object-properties-in-a-loop을하기보다는 새로 만들기 – user1937198

+0

@ user1937198 죄송합니다. 이전 질문을 삭제했습니다. 희망이 문제를 해결. – darkjoe31

+0

페이지로드가 페이지 당 197 개의 DB 쿼리로 인해 고가가 될 때까지이 사이트에서 예상하는로드 유형은 무엇입니까? – user1937198

답변

0

은 자신의 이름 대신, 배열의 컨트롤을 넣습니다. 그런 다음 필요에 따라 배열에서 Name 속성을 사용하고 필요할 때 BackColor 나 다른 속성/메서드에 액세스 할 수 있습니다. 이처럼

:

Private Sub frmSeatPlan_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 
    Dim seat(11, 15) As Control '** changed from String ** 
    Dim seatname As String 
    Dim sql As String 
    Dim da As 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 As Integer 
    Dim y As Integer 
    For y = 1 To 1 
     For x = 1 To 14 
      seatname = seat(y, x).Name 

      con.ConnectionString = dbProvider & dbSource 
      con.Open() 'opens the connection to the database 

      sql = "SELECT * FROM Bookings where show_id = 'friday' AND customer_ID is null AND seat_id ='" & seatname & "'" 
      da = New OleDb.OleDbDataAdapter(sql, con) 'create a data adapter to store the filtered data using the SQL code 
      MsgBox(sql) 
      da.Fill(ds, seat(y, x).Name) 

      'count the number of records with an empty customer id, the show ID of Friday and the seat ID of this seat. 
      Dim recordCount As Integer 
      recordCount = ds.Tables(seat(y, x).Name).Rows.Count 
      MsgBox(recordCount) 

      If recordCount = 1 Then 
       'change backcolor to green 
       seat(x, y).BackColor = Color.Green 
      Else 
       'change backcolor to red 
       seat(x, y).BackColor = Color.Red 
      End If 

      con.Close() 

     Next x 
    Next y 
End Sub 
+0

고마워요! 그것은 그 문제를 해결 한 것으로 보이지만 또 다른 문제가 발생한 것처럼 보입니다. 이제 프로그램을 실행하면 x = 2가 될 때까지 루프가 실행되고 A1 만 표시된 양식이 표시됩니다. 코드의 다른 내용이 변경 사항과 충돌합니까? 또는 내 루프에 오류가 있습니까? – darkjoe31

+0

글쎄, 기술적으로 또 다른 질문이지만, 아마 어딘가에 오류가 발생합니다. 오류 처리 (Try..Catch)를 추가하거나 디버거로 단계별 실행하십시오. – RBarryYoung

+0

문제가 해결되었습니다 :) 감사합니다! – darkjoe31