# data[].attributes.attachment_link.readable_text
��Imports System.Data.SqlClient
Public Class Form1
    Private con As SqlConnection
    Private WithEvents danh_sach As BindingManagerBase
    Public lenh As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '��ng d�n k�t n�i sql server
        Dim constring As String = "Data Source=PHAMSANG\SQLPS;Initial Catalog=Vemaybay;Integrated Security=True"
        con = New SqlConnection(constring)
        Xuat_chuyenbay()
    End Sub
    Private Sub Xuat_chuyenbay()
        Dim lenh As String
        'In ra �y � t�t c� c�c c�t v� ch�n th�m c�t STT � tr��c M� chuy�n bay(MaCB)
        lenh = "SELECT ROW_NUMBER() OVER (ORDER BY MaCB) AS [STT], MaCB,MaMB,SanBay,ChangBay,NgayBay,Quay,TinhTrang FROM ChuyenBay"
        Dim cmd As New SqlCommand(lenh, con)
        con.Open()
        Dim bang_doc As SqlDataReader = cmd.ExecuteReader
        Dim dttable As New DataTable("ChuyenBay")
        dttable.Load(bang_doc, LoadOption.OverwriteChanges)
        con.Close()
        DataGrid1.DataSource = dttable
        danh_sach = Me.BindingContext(dttable)
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If ComboBox1.Text = "" Then
            MsgBox("Xin m�i nh�p ch�c nng!", 0, "Th�ng b�o")
        Else
            If ComboBox1.Text = "Th�m chuy�n bay" Then
                ThemCB.Show()
            Else
                If ComboBox1.Text = "S�a th�ng tin chuy�n bay" Then
                    SuaCB.Show()
                Else
                    If ComboBox1.Text = "X�a chuy�n bay" Then
                        XoaCB.Show()
                    Else
                        If ComboBox1.Text = "T�m ki�m chuy�n bay" Then
                            TimKiem.Show()
                        Else
                            If ComboBox1.Text = "In CrystalReportCB" Then
                                FormRP.Show()
                            Else
                                FormRP2.Show()
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If MsgBox("B�n c� mu�n tho�t kh�ng?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Tho�t") = MsgBoxResult.Yes Then
            Me.Close()
        End If
    End Sub

End Class

# data[].attributes.attachment_link.readable_text
��Imports System.Data.SqlClient
Public Class ThemCB
    Private con As SqlConnection
    Private WithEvents danh_sach As BindingManagerBase
    Public lenh As String
    Private Sub ThemCB_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim constring As String = "Data Source=PHAMSANG\SQLPS;Initial Catalog=Vemaybay;Integrated Security=True"
        con = New SqlConnection(constring)
        Xuat_chuyenbay()
    End Sub
    Private Sub Xuat_chuyenbay()
        Dim lenh As String
        lenh = "SELECT ROW_NUMBER() OVER (ORDER BY MaCB) AS [STT], MaCB,MaMB,SanBay,ChangBay,NgayBay,Quay,TinhTrang FROM ChuyenBay"
        Dim cmd As New SqlCommand(lenh, con)
        con.Open()
        Dim bang_doc As SqlDataReader = cmd.ExecuteReader
        Dim dttable As New DataTable("ChuyenBay")
        dttable.Load(bang_doc, LoadOption.OverwriteChanges)
        con.Close()
        Form1.DataGrid1.DataSource = dttable
        danh_sach = Me.BindingContext(dttable)
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim c%
        Dim check As Boolean
        'Khai b�o bi�n check ki�u �ng/sai l�y d� li�u t� Textbox6.Text
        check = Information.IsNumeric(TextBox6.Text)
        For I = 0 To danh_sach.Count - 1
            danh_sach.Position = I
            'So s�nh d� li�u c�a TextBox1 sau khi c�t b� c�c kho�ng tr�ng th�a v� d� li�u c�a MaCB trong CSDL
            'N�u b�ng nhau th� tr� v� c = 1
            'N�u kh�ng b�ng th� c kh�ng c� gi� tr�
            If Trim(TextBox1.Text) = danh_sach.Current("MaCB") Then
                c = 1
            End If
        Next
        If MsgBox("B�n c� mu�n th�m kh�ng?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Th�m") = MsgBoxResult.Yes Then
            If TextBox1.Text = "" Or ComboBox1.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or DateTimePicker1.Text = "" Or
                TextBox6.Text = "" Or TextBox7.Text = "" Then
                MsgBox("Ch�a nh�p gi� tr�!!!")
            Else
                If c = 1 Then
                    MsgBox("M� chuy�n bay � t�n t�i")
                Else
                    'N�u bi�n check kh�c ki�u d� li�u s� th� tr� v� False
                    If check = False Then
                        MsgBox("Nh�p gi� tr� s� v�o Qu�y!")
                    Else
                        lenh = "insert into ChuyenBay(MaCB,MaMB,SanBay,ChangBay,NgayBay,Quay,TinhTrang) values('" &
                        TextBox1.Text & "', '" & ComboBox1.Text & "', N'" & TextBox3.Text & "', N'" &
                        TextBox4.Text & "', '" & DateTimePicker1.Text & "', '" & TextBox6.Text & "', N'" & TextBox7.Text & "')"
                        Dim cmd As New SqlCommand(lenh, con)
                        con.Open()
                        cmd.ExecuteNonQuery()
                        con.Close()
                        Xuat_chuyenbay()
                        MsgBox("� th�m!")
                        Me.Close()
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If MsgBox("B�n c� mu�n tho�t kh�ng?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Tho�t") = MsgBoxResult.Yes Then
            Me.Close()
        End If
    End Sub

End Class