座位预约VB项目 [英] Seat reservation VB project

查看:105
本文介绍了座位预约VB项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,所以我有这个项目,我正在建设一个使用vb.net和访问数据库的电影院的座位预订程序。我使用pictureboxes作为我的座位,我也有行号和列号,所以我想要当我点击一个图片框时,它会自动显示座位号和行号,并在表单重新加载时预订座位但到目前为止,代码只会更改为我预订代码的图像,并且没有任何内容进入数据库显示预订座位。我需要你们帮帮忙。看看我的vb代码。



我尝试过的事情:



Hi guys so i have this project that i am building for a seat reservation program for a cinema using vb.net and access database.I am using pictureboxes as my seats and also i have row numbers and column numbers ,so i want when i click a picturebox it show the seat number and row number automatically and also so booked seats when the form reloads but so far the code only changes to the images that i have code for when it is booked and nothing goes to the database to show booked seats .I need you help guys.Take a look that my vb code.

What I have tried:

Imports System.Data.OleDb
Public Class Form1

    Dim availableicon As New System.Drawing.Bitmap(My.Resources.available)
    Dim provisionalicon As New System.Drawing.Bitmap(My.Resources.provisional)
    Dim bookedicon As New System.Drawing.Bitmap(My.Resources.booked)


    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim c As Control

        For Each c In Me.Controls
            If TypeOf (c) Is PictureBox Then
                CType(c, PictureBox).Image = availableicon
                AddHandler c.Click, AddressOf A10_Click
            End If
            Dim stSQL As String
            stSQL = "SELECT BookingID,CustomerID,seat From Bookings"

            Dim ConnectionString As String
            ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\West\Desktop\TMS\TicketBooking.accdb"

            Dim conBookings As OleDbConnection

            conBookings = New OleDbConnection
            conBookings.ConnectionString = ConnectionString
            conBookings.Open()

            Dim cmdSelectBookings As OleDbCommand
            cmdSelectBookings = New OleDbCommand
            cmdSelectBookings.CommandText = stSQL
            cmdSelectBookings.Connection = conBookings

            Dim databaseBookings As New DataSet
            Dim databookings As New OleDbDataAdapter(cmdSelectBookings)
            databookings.Fill(databaseBookings, "Bookings")
            conBookings.Close()

            'MessageBox.Show(databaseBookings.Tables("Bookings").Rows.Count)

           
        Next
        Call UpdateBookings()
    End Sub
        Sub UpdateBookings()
        Dim stSQL As String
        stSQL = "SELECT BookingID,CustomerID,seat From Bookings"

        Dim ConnectionString As String
        ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ West\Desktop\TMS\TicketBooking.accdb"

        Dim conBookings As OleDbConnection

        conBookings = New OleDbConnection
        conBookings.ConnectionString = ConnectionString
        conBookings.Open()

        Dim cmdSelectBookings As OleDbCommand
        cmdSelectBookings = New OleDbCommand
        cmdSelectBookings.CommandText = stSQL
        cmdSelectBookings.Connection = conBookings

        Dim databaseBookings As New DataSet
        Dim databookings As New OleDbDataAdapter(cmdSelectBookings)
        databookings.Fill(databaseBookings, "Bookings")
        conBookings.Close()
    End Sub




    Private Sub picturebox10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If CType(sender, PictureBox).Image Is availableicon Then
            CType(sender, PictureBox).Image = provisionalicon
        ElseIf CType(sender, PictureBox).Image Is provisionalicon Then
            CType(sender, PictureBox).Image = bookedicon




        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncontinue.Click
        Dim c As Control
        Dim bselected As Boolean
        For Each c In Me.Controls
            If TypeOf (c) Is PictureBox Then
                If CType(c, PictureBox).Image Is provisionalicon Then
                    bselected = True
                    Exit For
                End If

            End If
        Next
        If bselected = False Then
            MessageBox.Show("please select at least one seat to book")
            Exit Sub
        End If

        Dim stSQLInsert As String
        stSQLInsert = "INSERT INTO Bookings(SEATID,ROW,NUMBER)"
        Dim ConnectionString As String
        ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\West\Desktop\TMS\TicketBooking.accdb"

        Dim conBookings As OleDbConnection

        conBookings = New OleDbConnection
        conBookings.ConnectionString = ConnectionString
        conBookings.Open()

        Dim cmdSelectBookings As OleDbCommand
        cmdSelectBookings = New OleDbCommand
        cmdSelectBookings.Connection = conBookings




        Dim iseatnum As Integer
        For Each c In Me.Controls
            If TypeOf (c) Is PictureBox Then
                If CType(c, PictureBox).Image Is provisionalicon Then
                    
                    stSQLInsert = "INSERT INTO Bookings(SEATID,ROW,NUMBER) VALUES('" & Me.txtcustomer.Text & "'," & iseatnum & ")"
                    cmdSelectBookings.CommandText = stSQLInsert
                    cmdSelectBookings.ExecuteNonQuery()
                End If
            End If
        Next
        conBookings.Close()

        Call UpdateBookings()

    End Sub
End Class

推荐答案

stSQLInsert = "INSERT INTO Bookings(SEATID,ROW,NUMBER) VALUES('" & Me.txtcustomer.Text & "'," & iseatnum & ")"



不是解决方案你的问题,但你有另一个问题。

永远不要通过连接字符串来构建SQL查询。迟早,您将使用用户输入来执行此操作,这会打开一个名为SQL注入的漏洞,这对您的数据库很容易并且容易出错。

名称中的单引号你的程序崩溃。如果用户输入像Brian O'Conner这样的名称可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞,崩溃是最少的问题,恶意用户输入,并且它被提升为具有所有凭据的SQL命令。

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]

按示例进行SQL注入攻击 [ ^ ]

PHP:SQL注入 - 手册 [ ^ ]

SQL注入预防备忘单 - OWASP [ ^ ]

我该怎么办?解释没有技术术语的SQL注入? - 信息安全堆栈交换 [ ^ ]


Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]


这篇关于座位预约VB项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆