Imports System.Data.SqlServerCe
Imports System.Data
Public Class frmlog
Dim strUser As String
Public Property _strUser() As String
Get
Return strUser
End Get
Set(ByVal value As String)
strUser = value
End Set
End Property
Public Sub LoadInfor()
Dim objconn As New SqlCeConnection
Dim objcmd As New SqlCeCommand
Dim dtAdapter As New SqlCeDataAdapter
Dim dt As New DataTable
Dim strconnstring, strSQL As String
Dim directory As String = My.Application.Info.DirectoryPath
strconnstring = "Data source=C:\Users\WIN 7\Desktop\Projact\WindowsApplication1\WindowsApplication1\Database1.sdf;"
objconn.ConnectionString = strconnstring
objconn.Open()
strSQL = "SELECT * FROM myTable WHERE id = '" & strUser & "'"
dtAdapter = New SqlCeDataAdapter(strSQL, objconn)
dtAdapter.Fill(dt)
If dt.Rows.Count > 0 Then
Me.lblUser.Text = strUser
Me.lblName.Text = dt.Rows(0)("name")
Me.lblSurname.Text = dt.Rows(0)("surname")
Me.lblNumber.Text = dt.Rows(0)("number")
End If
objconn.Close()
objconn = Nothing
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objConn As SqlCeConnection
objConn = New SqlCeConnection("Data source=C:\Users\WIN 7\Desktop\Projact\WindowsApplication1\WindowsApplication1\Database1.sdf;")
objConn.Open()
Dim objCmd As New SqlCeCommand
Dim strSQL As String
Dim intnumrows As Integer
strSQL = "SELECT COUNT(*) FROM saveTable where COMPUTER = '" & txtcomputer.Text & "'"
objCmd = New SqlCeCommand(strSQL, objConn)
intnumrows = objCmd.ExecuteScalar
If intnumrows > 0 Then
MessageBox.Show("คอมพิวเตอร์เครื่องนี้มีคนจองแล้ว")
Else
strSQL = "insert into [saveTable]([ID],[NAME],[SURNAME],[DEPARTMENT],[NUMBER],[YEAR],[TIME],[COMPUTER])valuse" & "('" & Me.lblUser.Text & "','" & Me.lblName.Text & "','" & Me.lblSurname.Text & "','" & Me.lblNumber.Text & "','" & Now & "','" & Me.txtcomputer.Text & "')"
objCmd = New SqlCeCommand
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
objCmd.ExecuteNonQuery()
Try
objConn = New SqlCeConnection("Data source=C:\Users\WIN 7\Desktop\Projact\WindowsApplication1\WindowsApplication1\Database1.sdf;")
objConn.Open()
objCmd = New SqlCeCommand(strSQL, objConn)
strSQL = "insert into [backdata]([ID],[NAME],[SURNAME],[DEPARTMENT],[NUMBER],[YEAR],[TIME],[COMPUTER])valuse" & "('" & Me.lblUser.Text & "','" & Me.lblName.Text & "','" & Me.lblSurname.Text & "','" & Me.lblNumber.Text & "','" & Now & "','" & Me.txtcomputer.Text & "')"
objCmd = New SqlCeCommand
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
objCmd.ExecuteNonQuery()
MessageBox.Show("บันทึกข้อมูลแล้ว")
If txtcomputer.Text = 1 Then
RadioButton1.Checked = True
ElseIf txtcomputer.Text = 2 Then
RadioButton2.Checked = True
ElseIf txtcomputer.Text = 3 Then
RadioButton3.Checked = True
ElseIf txtcomputer.Text = 4 Then
RadioButton4.Checked = True
ElseIf txtcomputer.Text = 8 Then
RadioButton5.Checked = True
ElseIf txtcomputer.Text = 7 Then
RadioButton6.Checked = True
ElseIf txtcomputer.Text = 6 Then
RadioButton7.Checked = True
ElseIf txtcomputer.Text = 5 Then
RadioButton8.Checked = True
ElseIf txtcomputer.Text = 12 Then
RadioButton9.Checked = True
ElseIf txtcomputer.Text = 11 Then
RadioButton10.Checked = True
ElseIf txtcomputer.Text = 10 Then
RadioButton11.Checked = True
ElseIf txtcomputer.Text = 9 Then
RadioButton12.Checked = True
End If
Dim f As New frmlogin
f.Show()
Me.Hide()
Catch ex As Exception
MessageBox.Show("Error")
End Try
End If
End Sub