Imports System.Data.OleDb
Imports System.Data
Public Class FormCustomer
Dim myConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Car\MyProject.accdb")
Dim mycommand As New OleDbCommand
Dim myDataSet As DataSet = New DataSet()
Dim myDataView As DataView = New DataView()
Dim sqlSelect As String
Dim Cnn As New OleDbConnection(Cnnstring)
Dim Cnnstring As String
Dim da As OleDbDataAdapter
Dim dttable As DataTable
Private Sub ShowData()
Dim gen As Integer
If TextBox2.Text = "" Then
TextBox3.Text = "CT0001"
Else
gen = (TextBox2.Text.Substring(2, 4)) + 1
TextBox3.Text = "CT" & gen.ToString("0000")
End If
End Sub
Private Sub FormCustomer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MyProjectDataSet.Customer' table. You can move, or remove it, as needed.
Me.CustomerTableAdapter.Fill(Me.MyProjectDataSet.Customer)
'TODO: This line of code loads data into the 'MyProjectDataSet.Customer' table. You can move, or remove it, as needed.
Me.CustomerTableAdapter.Fill(Me.MyProjectDataSet.Customer)
myConn.Open()
da = New OleDb.OleDbDataAdapter("Select Max(ID_Customer) as ID_Customer from Customer", myConn)
myDataSet = New DataSet("Customer")
da.Fill(myDataSet, "Customer")
Try
TextBox2.DataBindings.Add("text", myDataSet, "Customer.ID_Customer")
Catch ex As System.ArgumentException
MessageBox.Show(ex.Message)
End Try
myConn.Close()
TextBox2.DataBindings.Clear()
ShowData()
TextBox1.Text = "0"
Panel1.Visible = True
'Panel2.Visible = False
' ID_CustomerTextBox.Visible = True
' BindingNavigatorAddNewItem.Enabled = True
' ToolStripButton1.Enabled = False
'ToolStripButton2.Enabled = True
' CustomerBindingNavigatorSaveItem.Enabled = False
' BindingNavigatorDeleteItem.Enabled = False
' ToolStripButton6.Enabled = False
' ToolStripButton4.Enabled = True
'TextBox2.Visible = False
TextBox1.Visible = False
'DELTextBox.Visible = False
End Sub
Private Sub CustomerBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomerBindingNavigatorSaveItem.Click
Me.Validate()
Me.CustomerBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.MyProjectDataSet)
End Sub
Private Sub ProvinceComboBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ProvinceComboBox.KeyPress
e.Handled = True
End Sub
Private Sub TypeCarComboBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TypeCarComboBox.KeyPress
e.Handled = True
End Sub
Private Sub BrandCarComboBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles BrandCarComboBox.KeyPress
e.Handled = True
End Sub
Private Sub ColorCarComboBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ColorCarComboBox.KeyPress
e.Handled = True
End Sub
Private Sub NumPhoeTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles NumPhoeTextBox.KeyPress
Dim KeyAscii As Short = Asc(e.KeyChar)
Select Case KeyAscii
Case 47 To 58
e.Handled = False
Case 8, 13, 46 ' Backspace = 8, Enter = 13, Delete = 46
e.Handled = False
Case Else
e.Handled = True
End Select
End Sub
Private Sub NameTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles NameTextBox.KeyPress
If (e.KeyChar >= "0" And e.KeyChar <= "9") Then
e.Handled = True
Else : e.Handled = False
End If
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
If (TextBox1.Text = "0") Then
MessageBox.Show("ทำการกรอกข้อมูลให้ครบถ้วน!!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If (NameTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่ชื่อ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
NameTextBox.Focus()
Exit Sub
End If
If (AddressTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่นามสกุล !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
AddressTextBox.Focus()
Exit Sub
End If
If (ProvinceComboBox.Text = "-----ระบุ-----") Then
MessageBox.Show("กรุณาเลือกจังหวัด !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
ProvinceComboBox.Focus()
Exit Sub
End If
If (NumPhoeTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่เบอร์โทรศัพท์ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
NumPhoeTextBox.Focus()
Exit Sub
End If
If (AddressTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่ที่อยู่ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
AddressTextBox.Focus()
Exit Sub
End If
If (TypeCarComboBox.Text = "-----โปรดเลือก-----") Then
MessageBox.Show("กรุณาเลือกประเภทรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
TypeCarComboBox.Focus()
Exit Sub
End If
If (BrandCarComboBox.Text = "-----โปรดเลือก-----") Then
MessageBox.Show("กรุณาเลือกยี่ห้อรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
BrandCarComboBox.Focus()
Exit Sub
End If
If (GanerationCarTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่รุ่นรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
GanerationCarTextBox.Focus()
Exit Sub
End If
If (ColorCarComboBox.Text = "-----โปรดเลือก-----") Then
MessageBox.Show("กรุณาเลือกสีรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
ColorCarComboBox.Focus()
Exit Sub
End If
If (CarRegistrationTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่ทะเบียนรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
CarRegistrationTextBox.Focus()
Exit Sub
End If
If (EngineCarNumberTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่หมายเลขเครื่อง !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
EngineCarNumberTextBox.Focus()
Exit Sub
End If
If (BodyCarMemberTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่หมายเลขตัวถัง !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
BodyCarMemberTextBox.Focus()
Exit Sub
End If
Dim mbr As MsgBoxResult
mbr = MsgBox("ท่านต้องการบันทึกข้อมูลหรือไม่", _
MsgBoxStyle.YesNo + _
MsgBoxStyle.Question + _
MsgBoxStyle.ApplicationModal, _
"บันทึกข้อมูล")
If (mbr = MsgBoxResult.Yes) Then
ID_CustomerTextBox.Text = TextBox3.Text
TextBox2.Text = TextBox3.Text
Cnnstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Car\MyProject.accdb"
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
myConn.Open()
Dim db = "INSERT INTO Customer ([ID_Customer],[Name],[Address],[Province],[NumPhoe],[TypeCar],[BrandCar],[GanerationCar],[ColorCar],[CarRengistration],[EngineCarNumber],[BodyCarMember])"
db &= "VALUES('" & ID_CustomerTextBox.Text & "','" & NameTextBox.Text & "','" & AddressTextBox.Text & "','" & ProvinceComboBox.Text & "','" & NumPhoeTextBox.Text & "','" & TypeCarComboBox.Text & "','" & BrandCarComboBox.Text & "','" & GanerationCarTextBox.Text & "','" & ColorCarComboBox.Text & "','" & CarRegistrationTextBox.Text & "','" & EngineCarNumberTextBox.Text & "','" & BodyCarMemberTextBox.Text & "','0') "
mycommand = New OleDb.OleDbCommand(db, myConn)
mycommand.ExecuteNonQuery()
myConn.Close()
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "บันทึกข้อมูล")
Me.CustomerTableAdapter.Fill(Me.MyProjectDataSet.Customer)
sortCustomer()
'ShowData()
'blockdata()
'ID_CustomerTextBox.Focus()
TextBox1.Text = "0"
Panel1.Visible = False
'Panel2.Visible = True
TextBox3.Visible = False
ID_CustomerTextBox.Visible = True
BindingNavigatorAddNewItem.Enabled = True
ToolStripButton1.Enabled = False
'ToolStripButton2.Enabled = True
CustomerBindingNavigatorSaveItem.Enabled = False
BindingNavigatorDeleteItem.Enabled = True
'ToolStripButton6.Enabled = False
TextBox2.Visible = False
'ToolStripButton4.Enabled = True
'ToolStripButton5.Enabled = True
End If
End Sub
Private Sub sortCustomer()
Try
Me.CustomerTableAdapter.Fill(Me.MyProjectDataSet.Customer)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub cleardata()
ID_CustomerTextBox.Text = ""
NameTextBox.Text = ""
AddressTextBox.Text = ""
ProvinceComboBox.Text = ""
NumPhoeTextBox.Text = ""
TypeCarComboBox.Text = ""
BrandCarComboBox.Text = ""
GanerationCarTextBox.Text = ""
ColorCarComboBox.Text = ""
CarRegistrationTextBox.Text = ""
EngineCarNumberTextBox.Text = ""
BodyCarMemberTextBox.Text = ""
End Sub
Private Sub blockdata()
ID_CustomerTextBox.Text = ""
NameTextBox.Text = ""
AddressTextBox.Text = ""
ProvinceComboBox.Text = ""
NumPhoeTextBox.Text = ""
TypeCarComboBox.Text = ""
BrandCarComboBox.Text = ""
GanerationCarTextBox.Text = ""
ColorCarComboBox.Text = ""
CarRegistrationTextBox.Text = ""
EngineCarNumberTextBox.Text = ""
BodyCarMemberTextBox.Text = ""
End Sub
Public Sub ReadMyData(ByVal myConnString As String)
On Error GoTo ErrorHandler
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
End With
Me.Validate()
Me.CustomerBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.MyProjectDataSet)
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "บันทึกข้อมูล")
'NAMETextBox.Focus()
TextBox1.Text = "0"
ErrorHandler:
End Sub
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
'TODO: This line of code loads data into the 'StockGearDataSet.Staff' table. You can move, or remove it, as needed.
Me.CustomerTableAdapter.Fill(Me.MyProjectDataSet.Customer)
cleardata()
ShowData()
ProvinceComboBox.Text = "-----โปรดเลือก-----"
TypeCarComboBox.Text = "-----โปรดเลือก-----"
BrandCarComboBox.Text = "-----โปรดเลือก-----"
ColorCarComboBox.Text = "-----โปรดเลือก-----"
Panel1.Visible = True
'Panel2.Visible = True
TextBox3.Visible = True
ID_CustomerTextBox.Visible = False
TextBox3.Enabled = False
ID_CustomerTextBox.Enabled = False
ToolStripButton1.Enabled = True
BindingNavigatorDeleteItem.Enabled = False
CustomerBindingNavigatorSaveItem.Enabled = True
ToolStripButton2.Enabled = False
BindingNavigatorDeleteItem.Enabled = False
'ToolStripButton6.Enabled = True
' ToolStripButton4.Enabled = False
NameTextBox.Focus()
TextBox1.Text = "1"
TextBox1.Visible = False
TextBox2.Visible = False
'ToolStripButton5.Enabled = False
End Sub
End Class
Erro
mycommand = New OleDb.OleDbCommand(db, myConn)
mycommand.ExecuteNonQuery()
พึ่งเห็นว่าโชว์ data ของคุณไม่ใช่การ call data เพื่อมาโชว์อีกครั้งงั้นง่ายๆก็หลังจาก save เส็ดแล้วก้อเรียก page load ขึ้นมาอีกครั้งก็ได้ค่ะ ก็จะได้ข้อมูลที่ update ใน grid
Imports System.Data.OleDb
Imports System.Data
Public Class FormCustomer
Dim myConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Car\MyProject.accdb")
Dim mycommand As New OleDbCommand
Dim myDataSet As DataSet = New DataSet()
Dim myDataView As DataView = New DataView()
Dim sqlSelect As String
Dim Cnn As New OleDbConnection(Cnnstring)
Dim Cnnstring As String
Dim da As OleDbDataAdapter
Dim dttable As DataTable
Private Sub ShowData()
Dim gen As Integer
If TextBox2.Text = "" Then
TextBox3.Text = "CT0001"
Else
gen = (TextBox2.Text.Substring(2, 4)) + 1
TextBox3.Text = "CT" & gen.ToString("0000")
End If
End Sub
Private Sub FormCustomer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MyProjectDataSet.Customer' table. You can move, or remove it, as needed.
Me.CustomerTableAdapter.Fill(Me.MyProjectDataSet.Customer)
'TODO: This line of code loads data into the 'MyProjectDataSet.Customer' table. You can move, or remove it, as needed.
Me.CustomerTableAdapter.Fill(Me.MyProjectDataSet.Customer)
myConn.Open()
da = New OleDb.OleDbDataAdapter("Select Max(ID_Customer) as ID_Customer from Customer", myConn)
myDataSet = New DataSet("Customer")
da.Fill(myDataSet, "Customer")
Try
TextBox2.DataBindings.Add("text", myDataSet, "Customer.ID_Customer")
Catch ex As System.ArgumentException
MessageBox.Show(ex.Message)
End Try
myConn.Close()
TextBox2.DataBindings.Clear()
ShowData()
TextBox1.Text = "0"
Panel1.Visible = False
Panel2.Visible = True
' ID_CustomerTextBox.Visible = True
' BindingNavigatorAddNewItem.Enabled = True
ToolStripButton1.Enabled = False
ToolStripButton2.Enabled = True
CustomerBindingNavigatorSaveItem.Enabled = False
BindingNavigatorDeleteItem.Enabled = False
ToolStripButton6.Enabled = True
ToolStripButton4.Enabled = False
ToolStripButton3.Enabled = True
ToolStripButton5.Enabled = True
TextBox2.Visible = False
TextBox1.Visible = False
DELTextBox.Visible = False
End Sub
Private Sub CustomerBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomerBindingNavigatorSaveItem.Click
Dim mbr As MsgBoxResult
mbr = MsgBox("ท่านต้องการบันทึกการแก้ไขข้อมูลหรือไม่", _
MsgBoxStyle.YesNo + _
MsgBoxStyle.Question + _
MsgBoxStyle.ApplicationModal, _
"บันทึกข้อมูล")
If (mbr = MsgBoxResult.Yes) Then
Me.Validate()
Me.CustomerBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.MyProjectDataSet)
MessageBox.Show("บันทึกการแก้ไขข้อมูลเรียบร้อยแล้ว", "บันทึกข้อมูล")
'Panel1.Visible = False
Panel2.Visible = True
BindingNavigatorAddNewItem.Enabled = True
ToolStripButton1.Enabled = False
CustomerBindingNavigatorSaveItem.Enabled = False
BindingNavigatorDeleteItem.Enabled = True
ToolStripButton2.Enabled = True
ToolStripButton6.Enabled = True
ToolStripButton4.Enabled = False
TextBox2.Visible = False
ToolStripButton5.Enabled = False
ToolStripButton3.Enabled = True
End If
End Sub
Private Sub NumPhoeTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles NumPhoeTextBox.KeyPress
Dim KeyAscii As Short = Asc(e.KeyChar)
Select Case KeyAscii
Case 47 To 58
e.Handled = False
Case 8, 13, 46 ' Backspace = 8, Enter = 13, Delete = 46
e.Handled = False
Case Else
e.Handled = True
End Select
End Sub
Private Sub NameTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles NameTextBox.KeyPress
If (e.KeyChar >= "0" And e.KeyChar <= "9") Then
e.Handled = True
Else : e.Handled = False
End If
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
If (TextBox1.Text = "0") Then
MessageBox.Show("ทำการกรอกข้อมูลให้ครบถ้วน!!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If (NameTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่ชื่อ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
NameTextBox.Focus()
Exit Sub
End If
If (AddressTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่นามสกุล !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
AddressTextBox.Focus()
Exit Sub
End If
If (ProvinceComboBox.Text = "") Then
MessageBox.Show("กรุณาเลือกจังหวัด !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
ProvinceComboBox.Focus()
Exit Sub
End If
If (NumPhoeTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่เบอร์โทรศัพท์ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
NumPhoeTextBox.Focus()
Exit Sub
End If
If (AddressTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่ที่อยู่ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
AddressTextBox.Focus()
Exit Sub
End If
If (TypeCarComboBox.Text = "") Then
MessageBox.Show("กรุณาเลือกประเภทรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
TypeCarComboBox.Focus()
Exit Sub
End If
If (BrandCarComboBox.Text = "") Then
MessageBox.Show("กรุณาเลือกยี่ห้อรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
BrandCarComboBox.Focus()
Exit Sub
End If
If (GanerationCarTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่รุ่นรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
GanerationCarTextBox.Focus()
Exit Sub
End If
If (ColorCarComboBox.Text = "") Then
MessageBox.Show("กรุณาเลือกสีรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
ColorCarComboBox.Focus()
Exit Sub
End If
If (CarRegistrationTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่ทะเบียนรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
CarRegistrationTextBox.Focus()
Exit Sub
End If
If (EngineCarNumberTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่หมายเลขเครื่อง !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
EngineCarNumberTextBox.Focus()
Exit Sub
End If
If (BodyCarMemberTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่หมายเลขตัวถัง !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
BodyCarMemberTextBox.Focus()
Exit Sub
End If
Dim mbr As MsgBoxResult
mbr = MsgBox("ท่านต้องการบันทึกข้อมูลหรือไม่", _
MsgBoxStyle.YesNo + _
MsgBoxStyle.Question + _
MsgBoxStyle.ApplicationModal, _
"บันทึกข้อมูล")
If (mbr = MsgBoxResult.Yes) Then
ID_CustomerTextBox.Text = TextBox3.Text
TextBox2.Text = TextBox3.Text
Cnnstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Car\MyProject.accdb"
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
myConn.Open()
Dim db = "INSERT INTO Customer (ID_Customer,Name,Address,Province,NumPhoe,TypeCar,BrandCar,GanerationCar,ColorCar,CarRegistration,EngineCarNumber,BodyCarMember)"
db &= "VALUES('" & ID_CustomerTextBox.Text & "','" & NameTextBox.Text & "','" & AddressTextBox.Text & "','" & ProvinceComboBox.Text & "','" & NumPhoeTextBox.Text & "','" & TypeCarComboBox.Text & "','" & BrandCarComboBox.Text & "','" & GanerationCarTextBox.Text & "','" & ColorCarComboBox.Text & "','" & CarRegistrationTextBox.Text & "','" & EngineCarNumberTextBox.Text & "','" & BodyCarMemberTextBox.Text & "') "
mycommand = New OleDb.OleDbCommand(db, myConn)
mycommand.ExecuteNonQuery()
myConn.Close()
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "บันทึกข้อมูล")
Me.CustomerTableAdapter.Fill(Me.MyProjectDataSet.Customer)
Controls.Clear()
InitializeComponent()
FormCustomer_Load(Me, Nothing)
sortCustomer()
ShowData()
blockdata()
NameTextBox.Focus()
TextBox1.Text = "0"
Panel1.Visible = False
Panel2.Visible = True
TextBox3.Visible = False
ID_CustomerTextBox.Visible = True
BindingNavigatorAddNewItem.Enabled = True
ToolStripButton1.Enabled = False
ToolStripButton2.Enabled = True
CustomerBindingNavigatorSaveItem.Enabled = False
BindingNavigatorDeleteItem.Enabled = True
ToolStripButton6.Enabled = True
TextBox2.Visible = False
'ToolStripButton4.Enabled = True
ToolStripButton3.Enabled = True
End If
End Sub
Private Sub sortCustomer()
Try
Me.CustomerTableAdapter.Fill(Me.MyProjectDataSet.Customer)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub cleardata()
ID_CustomerTextBox.Text = ""
NameTextBox.Text = ""
AddressTextBox.Text = ""
ProvinceComboBox.Text = ""
NumPhoeTextBox.Text = ""
TypeCarComboBox.Text = ""
BrandCarComboBox.Text = ""
GanerationCarTextBox.Text = ""
ColorCarComboBox.Text = ""
CarRegistrationTextBox.Text = ""
EngineCarNumberTextBox.Text = ""
BodyCarMemberTextBox.Text = ""
End Sub
Private Sub blockdata()
ID_CustomerTextBox.Text = ""
NameTextBox.Text = ""
AddressTextBox.Text = ""
ProvinceComboBox.Text = ""
NumPhoeTextBox.Text = ""
TypeCarComboBox.Text = ""
BrandCarComboBox.Text = ""
GanerationCarTextBox.Text = ""
ColorCarComboBox.Text = ""
CarRegistrationTextBox.Text = ""
EngineCarNumberTextBox.Text = ""
BodyCarMemberTextBox.Text = ""
End Sub
Public Sub ReadMyData(ByVal myConnString As String)
On Error GoTo ErrorHandler
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
End With
Me.Validate()
Me.CustomerBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.MyProjectDataSet)
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "บันทึกข้อมูล")
NameTextBox.Focus()
TextBox1.Text = "0"
ErrorHandler:
End Sub
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
'TODO: This line of code loads data into the 'StockGearDataSet.Staff' table. You can move, or remove it, as needed.
Me.CustomerTableAdapter.Fill(Me.MyProjectDataSet.Customer)
cleardata()
ShowData()
Panel1.Visible = True
Panel2.Visible = False
TextBox3.Visible = True
ID_CustomerTextBox.Visible = False
TextBox3.Enabled = False
ID_CustomerTextBox.Enabled = False
ToolStripButton1.Enabled = True
BindingNavigatorDeleteItem.Enabled = False
CustomerBindingNavigatorSaveItem.Enabled = False
ToolStripButton2.Enabled = True
BindingNavigatorDeleteItem.Enabled = False
'ToolStripButton6.Enabled = True
ToolStripButton4.Enabled = True
NameTextBox.Focus()
TextBox1.Text = "1"
TextBox1.Visible = False
TextBox2.Visible = False
'ToolStripButton5.Enabled = False
DELTextBox.Visible = False
End Sub
Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
'TODO: This line of code loads data into the 'StockGearDataSet.Staff' table. You can move, or remove it, as needed.
Me.CustomerTableAdapter.Fill(Me.MyProjectDataSet.Customer)
sortCustomer()
Panel1.Visible = True
Panel2.Visible = False
BindingNavigatorAddNewItem.Enabled = False
ToolStripButton1.Enabled = False
ToolStripButton2.Enabled = True
CustomerBindingNavigatorSaveItem.Enabled = False
BindingNavigatorDeleteItem.Enabled = False
ToolStripButton4.Enabled = False
ToolStripButton6.Enabled = True
ToolStripButton3.Enabled = True
End Sub
Private Sub ToolStripButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton6.Click
TextBox3.Visible = False
ID_CustomerTextBox.Visible = True
ID_CustomerTextBox.Enabled = False
Panel1.Visible = True
Panel2.Visible = False
ToolStripButton1.Enabled = False
ToolStripButton2.Enabled = False
BindingNavigatorDeleteItem.Enabled = True
CustomerBindingNavigatorSaveItem.Enabled = True
ToolStripButton6.Enabled = False
TextBox2.Visible = False
ToolStripButton4.Enabled = True
BindingNavigatorAddNewItem.Enabled = False
ToolStripButton5.Enabled = False
End Sub
Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
Dim mbr As MsgBoxResult
mbr = MsgBox("ท่านต้องการปิดหน้านี้หรือไม่", _
MsgBoxStyle.YesNo + _
MsgBoxStyle.Question + _
MsgBoxStyle.ApplicationModal, _
"บันทึกข้อมูล")
If (mbr = MsgBoxResult.Yes) Then
Me.Close()
End If
End Sub
Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
Dim mbr As MsgBoxResult
mbr = MsgBox("ท่านต้องการลบข้อมูลนี้หรือไม่", _
MsgBoxStyle.YesNo + _
MsgBoxStyle.Question + _
MsgBoxStyle.ApplicationModal, _
"บันทึกข้อมูล")
If (mbr = MsgBoxResult.Yes) Then
DELTextBox.Text = "1"
Me.Validate()
Me.CustomerBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.MyProjectDataSet)
sortCustomer()
MessageBox.Show("ลบข้อมูลเรียบร้อยแล้ว", "บันทึกข้อมูล")
End If
End Sub
End Class
If (TextBox1.Text = "0") Then
MessageBox.Show("ทำการกรอกข้อมูลให้ครบถ้วน!!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If (NameTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่ชื่อ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
NameTextBox.Focus()
Exit Sub
End If
If (AddressTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่นามสกุล !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
AddressTextBox.Focus()
Exit Sub
End If
If (ProvinceComboBox.Text = "") Then
MessageBox.Show("กรุณาเลือกจังหวัด !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
ProvinceComboBox.Focus()
Exit Sub
End If
If (NumPhoeTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่เบอร์โทรศัพท์ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
NumPhoeTextBox.Focus()
Exit Sub
End If
If (AddressTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่ที่อยู่ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
AddressTextBox.Focus()
Exit Sub
End If
If (TypeCarComboBox.Text = "") Then
MessageBox.Show("กรุณาเลือกประเภทรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
TypeCarComboBox.Focus()
Exit Sub
End If
If (BrandCarComboBox.Text = "") Then
MessageBox.Show("กรุณาเลือกยี่ห้อรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
BrandCarComboBox.Focus()
Exit Sub
End If
If (GanerationCarTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่รุ่นรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
GanerationCarTextBox.Focus()
Exit Sub
End If
If (ColorCarComboBox.Text = "") Then
MessageBox.Show("กรุณาเลือกสีรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
ColorCarComboBox.Focus()
Exit Sub
End If
If (CarRegistrationTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่ทะเบียนรถ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
CarRegistrationTextBox.Focus()
Exit Sub
End If
If (EngineCarNumberTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่หมายเลขเครื่อง !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
EngineCarNumberTextBox.Focus()
Exit Sub
End If
If (BodyCarMemberTextBox.Text = "") Then
MessageBox.Show("กรุณาใส่หมายเลขตัวถัง !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
BodyCarMemberTextBox.Focus()
Exit Sub
End If
Dim mbr As MsgBoxResult
mbr = MsgBox("ท่านต้องการบันทึกข้อมูลหรือไม่", _
MsgBoxStyle.YesNo + _
MsgBoxStyle.Question + _
MsgBoxStyle.ApplicationModal, _
"บันทึกข้อมูล")
If (mbr = MsgBoxResult.Yes) Then
ID_CustomerTextBox.Text = TextBox3.Text
TextBox2.Text = TextBox3.Text
Cnnstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Car\MyProject.accdb"
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
myConn.Open()
Dim db = "INSERT INTO Customer (ID_Customer,Name,Address,Province,NumPhoe,TypeCar,BrandCar,GanerationCar,ColorCar,CarRegistration,EngineCarNumber,BodyCarMember)"
db &= "VALUES('" & ID_CustomerTextBox.Text & "','" & NameTextBox.Text & "','" & AddressTextBox.Text & "','" & ProvinceComboBox.Text & "','" & NumPhoeTextBox.Text & "','" & TypeCarComboBox.Text & "','" & BrandCarComboBox.Text & "','" & GanerationCarTextBox.Text & "','" & ColorCarComboBox.Text & "','" & CarRegistrationTextBox.Text & "','" & EngineCarNumberTextBox.Text & "','" & BodyCarMemberTextBox.Text & "') "
mycommand = New OleDb.OleDbCommand(db, myConn)
mycommand.ExecuteNonQuery()
myConn.Close()
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "บันทึกข้อมูล")
Me.CustomerTableAdapter.Fill(Me.MyProjectDataSet.Customer)
Controls.Clear()
InitializeComponent()
FormCustomer_Load(Me, Nothing)