 |
|
แสดงค่า เชื่อมต่อ ไม่เชื่อมต่อ ใน datagridviewtextbox ครับ |
|
 |
|
|
 |
 |
|
แค่ใส่ค่าเข้าไปก็ได้แล้ว
|
 |
 |
 |
 |
Date :
2017-07-31 15:32:50 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 3 เขียนโดย : lamaka.tor เมื่อวันที่ 2017-07-31 16:21:05
รายละเอียดของการตอบ ::
ตัวนี้เป็นโค้ดที่อยู่หน้า Form1 ธรรมดาครับ
Code (VB.NET)
Imports MySql.Data.MySqlClient
Imports System.Data.SqlClient
Public Class Form1
Public axLoop As New zkemkeeper.CZKEM
#Region "Communication"
Private bIsConnected = False
Private bIsConnected2 = False
Private iMachineNumber As Integer
Private iMachinenumber2 As Integer
Private Sub btnconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnconnect.Click
Dim idwErrorCode As Integer
For i As Integer = 0 To myDgv.Rows.Count - 1
If myDgv.Rows(i).Cells(0).Value IsNot Nothing Then
Dim id As [String] = myDgv.Rows(i).Cells(1).Value.ToString()
Dim ip As [String] = myDgv.Rows(i).Cells(2).Value.ToString()
Dim port As [String] = myDgv.Rows(i).Cells(3).Value.ToString()
bIsConnected = axLoop.Connect_Net(ip.Trim(), Convert.ToInt32(port.Trim()))
If bIsConnected = True Then
btnconnect.Text = "ไม่เชื่อมต่อ"
btnconnect.Refresh()
status.DataGridView.ForeColor = Color.Green
status.DataGridView.Text = "เชื่อมต่อสำเร็จ"
iMachineNumber = 1 'In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
If axLoop.RegEvent(iMachineNumber, 65535) = True Then 'Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
AddHandler axLoop.OnFinger, AddressOf AxLoop_OnFinger
AddHandler axLoop.OnFingerFeature, AddressOf AxLoop_OnFingerFeature
AddHandler axLoop.OnVerify, AddressOf AxLoop_OnVerify
AddHandler axLoop.OnAttTransactionEx, AddressOf AxLoop_OnAttTransactionEx
AddHandler axLoop.OnEnrollFingerEx, AddressOf AxLoop_OnEnrollFingerEx
AddHandler axLoop.OnDeleteTemplate, AddressOf AxLoop_OnDeleteTemplate
AddHandler axLoop.OnNewUser, AddressOf AxLoop_OnNewUser
AddHandler axLoop.OnAlarm, AddressOf AxLoop_OnAlarm
AddHandler axLoop.OnDoor, AddressOf AxLoop_OnDoor
AddHandler axLoop.OnWriteCard, AddressOf AxLoop_OnWriteCard
AddHandler axLoop.OnEmptyCard, AddressOf AxLoop_OnEmptyCard
AddHandler axLoop.OnHIDNum, AddressOf AxLoop_OnHIDNum
End If
Else
axLoop.GetLastError(idwErrorCode)
MsgBox("ไม่พบไดร์เวอร์,ErrorCode=" & idwErrorCode, MsgBoxStyle.Exclamation, "Error")
End If
End If
Next
Cursor = Cursors.Default
End Sub
Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
For i As Integer = 0 To myDgv.Rows.Count - 2
If myDgv.Rows(i).Cells(0).Value IsNot Nothing Then
Dim id As [String] = myDgv.Rows(i).Cells(1).Value.ToString()
Dim ip As [String] = myDgv.Rows(i).Cells(2).Value.ToString()
Dim port As [String] = myDgv.Rows(i).Cells(3).Value.ToString()
bIsConnected = axLoop.Connect_Net(ip.Trim(), Convert.ToInt32(port.Trim()))
Cursor = Cursors.Default
axLoop.Disconnect()
RemoveHandler axLoop.OnFinger, AddressOf AxLoop_OnFinger
RemoveHandler axLoop.OnFingerFeature, AddressOf AxLoop_OnFingerFeature
RemoveHandler axLoop.OnVerify, AddressOf AxLoop_OnVerify
RemoveHandler axLoop.OnAttTransactionEx, AddressOf AxLoop_OnAttTransactionEx
RemoveHandler axLoop.OnEnrollFingerEx, AddressOf AxLoop_OnEnrollFingerEx
RemoveHandler axLoop.OnDeleteTemplate, AddressOf AxLoop_OnDeleteTemplate
RemoveHandler axLoop.OnNewUser, AddressOf AxLoop_OnNewUser
RemoveHandler axLoop.OnAlarm, AddressOf AxLoop_OnAlarm
RemoveHandler axLoop.OnDoor, AddressOf AxLoop_OnDoor
RemoveHandler axLoop.OnWriteCard, AddressOf AxLoop_OnWriteCard
RemoveHandler axLoop.OnEmptyCard, AddressOf AxLoop_OnEmptyCard
RemoveHandler axLoop.OnHIDNum, AddressOf AxLoop_OnHIDNum
bIsConnected = False
status.DataGridView.ForeColor = Color.Red
status.DataGridView.Text = "ไม่เชื่อมต่อ"
Cursor = Cursors.Default
Return
End If
Next
End Sub
#End Region
#Region "RealTime Events"
'When you place your finger on sensor of the device,this event will be triggered
Private Sub AxLoop_OnFinger()
ListView1.Items.Add("<<--มีการ สแกนลายนิ้วมือ-->>")
End Sub
'After you have placed your finger on the sensor(or swipe your card to the device),this event will be triggered.
'If you passes the verification,the returned value userid will be the user enrollnumber,or else the value will be -1;
Private Sub AxLoop_OnVerify(ByVal iUserID As Integer)
ListView1.Items.Add("กำลังตรวจสอบลายนิ้วมือ...")
If iUserID <> -1 Then
ListView1.Items.Add("ลายนิ้วมือ ถูกต้อง")
Else
ListView1.Items.Add("ลายนิ้วมือผิดพลาดหรือไม่มีข้อมูลในระบบ ครับ...!")
End If
End Sub
'If your fingerprint(or your card) passes the verification,this event will be triggered
Private Sub AxLoop_OnAttTransactionEx(ByVal sEnrollNumber As String, ByVal iIsInValid As Integer, ByVal iAttState As Integer, ByVal iVerifyMethod As Integer, _
ByVal iYear As Integer, ByVal iMonth As Integer, ByVal iDay As Integer, ByVal iHour As Integer, ByVal iMinute As Integer, ByVal iSecond As Integer, ByVal iWorkCode As Integer)
ListView1.Items.Clear()
Dim objConn As New MySqlConnection
Dim objCmd As New MySqlCommand
Dim strConnString, strSQL As String
strConnString = "Server=www.ohotime.com;User Id=ohotime; Password=mit260914; Database=ohotime_pepo; Pooling=false"
objConn.ConnectionString = strConnString
objConn.Open()
Dim intNumRows As Integer
strSQL = "INSERT INTO checkinout (USERID,CHECKTIME,CHECKTYPE,WorkCode,UserExtFmt) VALUES ('" & sEnrollNumber & "','" & iYear.ToString() & "-" & iMonth.ToString() & "-" & iDay.ToString() & " " & iHour.ToString() & ":" & iMinute.ToString() & ":" & iSecond.ToString() & "','" & iAttState.ToString() & "','" & 0 & "','" & 0 & "')"
objCmd = New MySqlCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar()
objConn.Close()
objConn = Nothing
ListView1.Items.Add("บันทึกข้อมูลเรียบร้อยครับ...!")
ListView1.Items.Add("รายละเอียด ดังนี้")
ListView1.Items.Add("รหัส ID : " & sEnrollNumber)
ListView1.Items.Add("...isInvalid:" & iIsInValid.ToString())
ListView1.Items.Add("สถานะ : " & iAttState.ToString())
ListView1.Items.Add("...VerifyMethod:" & iVerifyMethod.ToString())
ListView1.Items.Add("...Workcode:" & iWorkCode.ToString()) 'the difference between the event OnAttTransaction and OnAttTransactionEx
ListView1.Items.Add("วัน/เวลา : " & iYear.ToString() & "-" & iMonth.ToString() & "-" & iDay.ToString() & " " & iHour.ToString() & ":" & iMinute.ToString() & ":" & iSecond.ToString())
End Sub
'When you have enrolled your finger,this event will be triggered and return the quality of the fingerprint you have enrolled
Private Sub AxLoop_OnFingerFeature(ByVal iScore As Integer)
If iScore < 0 Then
ListView1.Items.Add("The quality of your fingerprint is poor")
Else
ListView1.Items.Add("RTEvent OnFingerFeature Has been Triggered...Score:" & iScore.ToString())
End If
End Sub
'When you have deleted one one fingerprint template,this event will be triggered.
Private Sub AxLoop_OnDeleteTemplate(ByVal iEnrollNumber As Integer, ByVal iFingerIndex As Integer)
ListView1.Items.Add("RTEvent OnDeleteTemplate Has been Triggered...")
ListView1.Items.Add("...UserID=" & iEnrollNumber.ToString() & " FingerIndex=" & iFingerIndex.ToString())
End Sub
'When you have enrolled a new user,this event will be triggered.
Private Sub AxLoop_OnNewUser(ByVal iEnrollNumber As Integer)
ListView1.Items.Add("RTEvent OnNewUser Has been Triggered...")
ListView1.Items.Add("...NewUserID=" & iEnrollNumber.ToString())
End Sub
'When you swipe a card to the device, this event will be triggered to show you the card number.
Private Sub AxLoop_OnHIDNum(ByVal iCardNumber As Integer)
ListView1.Items.Add("RTEvent OnHIDNum Has been Triggered...")
ListView1.Items.Add("...Cardnumber=" & iCardNumber.ToString())
End Sub
'When you are enrolling your finger,this event will be triggered.
Private Sub AxLoop_OnEnrollFingerEx(ByVal sEnrollNumber As String, ByVal iFingerIndex As Integer, ByVal iActionResult As Integer, ByVal iTemplateLength As Integer)
If iActionResult = 0 Then
ListView1.Items.Add("RTEvent OnEnrollFigerEx Has been Triggered....")
ListView1.Items.Add(".....UserID: " & sEnrollNumber & " Index: " & iFingerIndex.ToString() & " tmpLen: " & iTemplateLength.ToString())
Else
ListView1.Items.Add("RTEvent OnEnrollFigerEx Has been Triggered Error,actionResult=" + iActionResult.ToString())
End If
End Sub
'/When the dismantling machine or duress alarm occurs, trigger this event.
Private Sub AxLoop_OnAlarm(ByVal iAlarmType As Integer, ByVal iEnrollNumber As Integer, ByVal iVerified As Integer)
ListView1.Items.Add("RTEvnet OnAlarm Has been Triggered...")
ListView1.Items.Add("...alarmType=" & iAlarmType.ToString())
ListView1.Items.Add("...enrollNumber=" & iEnrollNumber.ToString())
ListView1.Items.Add("...verified=" & iVerified.ToString())
End Sub
'Door sensor event
Private Sub AxLoop_OnDoor(ByVal iEventType As Integer)
ListView1.Items.Add("RTEvent Ondoor Has been Triggered...")
ListView1.Items.Add("...EventType=" & iEventType.ToString())
End Sub
'When you have emptyed the Mifare card,this event will be triggered.
Private Sub AxLoop_OnEmptyCard(ByVal iActionResult As Integer)
ListView1.Items.Add("RTEvent OnEmptyCard Has been Triggered...")
If iActionResult = 0 Then
ListView1.Items.Add("...Empty Mifare Card OK")
Else
ListView1.Items.Add("...Empty Failed")
End If
End Sub
'When you have written into the Mifare card ,this event will be triggered.
Private Sub AxLoop_OnWriteCard(ByVal iEnrollNumber As Integer, ByVal iActionResult As Integer, ByVal iLength As Integer)
ListView1.Items.Add("RTEvent OnWriteCard Has been Triggered...")
If iActionResult = 0 Then
ListView1.Items.Add("...Write Mifare Card OK")
ListView1.Items.Add("...EnrollNumber=" & iEnrollNumber.ToString())
ListView1.Items.Add("...TmpLength=" & iLength.ToString())
Else
ListView1.Items.Add("...Write Failed")
End If
End Sub
#End Region
End Class
|
ประวัติการแก้ไข 2017-07-31 16:45:59
 |
 |
 |
 |
Date :
2017-07-31 16:45:18 |
By :
tokyoes |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 3 เขียนโดย : lamaka.tor เมื่อวันที่ 2017-07-31 16:21:05
รายละเอียดของการตอบ ::
ตัวนี้เป็นโค้ดของ Form1Designer
Code (VB.NET)
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.myDgv = New System.Windows.Forms.DataGridView()
Me.Column1 = New System.Windows.Forms.DataGridViewCheckBoxColumn()
Me.id = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.ip = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.port = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.status = New System.Windows.Forms.DataGridViewTextBoxColumn()
Me.btnconnect = New System.Windows.Forms.Button()
Me.btnadd = New System.Windows.Forms.Button()
Me.btndelete = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.ListView1 = New System.Windows.Forms.ListView()
Me.btncancel = New System.Windows.Forms.Button()
CType(Me.myDgv, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'myDgv
'
Me.myDgv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
Me.myDgv.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.Column1, Me.id, Me.ip, Me.port, Me.status})
Me.myDgv.Location = New System.Drawing.Point(12, 51)
Me.myDgv.Name = "myDgv"
Me.myDgv.Size = New System.Drawing.Size(463, 180)
Me.myDgv.TabIndex = 0
'
'Column1
'
Me.Column1.HeaderText = ""
Me.Column1.Name = "Column1"
Me.Column1.Width = 20
'
'id
'
Me.id.DataPropertyName = "id"
Me.id.HeaderText = "ID"
Me.id.Name = "id"
Me.id.Width = 40
'
'ip
'
Me.ip.DataPropertyName = "ip"
Me.ip.HeaderText = "IP/DNS"
Me.ip.Name = "ip"
Me.ip.Width = 80
'
'port
'
Me.port.DataPropertyName = "port"
Me.port.HeaderText = "port"
Me.port.Name = "port"
Me.port.Width = 40
'
'status
'
Me.status.HeaderText = "สถานะ"
Me.status.Name = "status"
'
'btnconnect
'
Me.btnconnect.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(222, Byte))
Me.btnconnect.Location = New System.Drawing.Point(24, 262)
Me.btnconnect.Name = "btnconnect"
Me.btnconnect.Size = New System.Drawing.Size(87, 33)
Me.btnconnect.TabIndex = 1
Me.btnconnect.Text = "เชื่อมต่อ"
Me.btnconnect.UseVisualStyleBackColor = True
'
'btnadd
'
Me.btnadd.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(222, Byte))
Me.btnadd.Location = New System.Drawing.Point(295, 262)
Me.btnadd.Name = "btnadd"
Me.btnadd.Size = New System.Drawing.Size(87, 33)
Me.btnadd.TabIndex = 2
Me.btnadd.Text = "เพิ่ม"
Me.btnadd.UseVisualStyleBackColor = True
'
'btndelete
'
Me.btndelete.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(222, Byte))
Me.btndelete.Location = New System.Drawing.Point(388, 262)
Me.btndelete.Name = "btndelete"
Me.btndelete.Size = New System.Drawing.Size(87, 33)
Me.btndelete.TabIndex = 3
Me.btndelete.Text = "ลบ"
Me.btndelete.UseVisualStyleBackColor = True
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Font = New System.Drawing.Font("Brush Script MT", 20.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(383, 9)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(92, 33)
Me.Label1.TabIndex = 4
Me.Label1.Text = "OhoTime"
'
'ListView1
'
Me.ListView1.Location = New System.Drawing.Point(481, 12)
Me.ListView1.Name = "ListView1"
Me.ListView1.Size = New System.Drawing.Size(353, 313)
Me.ListView1.TabIndex = 5
Me.ListView1.UseCompatibleStateImageBehavior = False
'
'btncancel
'
Me.btncancel.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(222, Byte))
Me.btncancel.Location = New System.Drawing.Point(117, 262)
Me.btncancel.Name = "btncancel"
Me.btncancel.Size = New System.Drawing.Size(87, 33)
Me.btncancel.TabIndex = 6
Me.btncancel.Text = "ยกเลิก"
Me.btncancel.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(884, 337)
Me.Controls.Add(Me.btncancel)
Me.Controls.Add(Me.ListView1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btndelete)
Me.Controls.Add(Me.btnadd)
Me.Controls.Add(Me.btnconnect)
Me.Controls.Add(Me.myDgv)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.myDgv, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents myDgv As System.Windows.Forms.DataGridView
Friend WithEvents btnconnect As System.Windows.Forms.Button
Friend WithEvents btnadd As System.Windows.Forms.Button
Friend WithEvents btndelete As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Column1 As System.Windows.Forms.DataGridViewCheckBoxColumn
Friend WithEvents Column2 As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents Column3 As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents Column4 As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents txtIP As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents txtPort As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents ListView1 As System.Windows.Forms.ListView
Friend WithEvents status As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents btncancel As System.Windows.Forms.Button
Friend WithEvents id As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents ip As System.Windows.Forms.DataGridViewTextBoxColumn
Friend WithEvents port As System.Windows.Forms.DataGridViewTextBoxColumn
End Class
|
 |
 |
 |
 |
Date :
2017-07-31 16:47:11 |
By :
tokyoes |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
If bIsConnected = True Then
myDgv.Rows(i).Cells(4).Value = "เชื่อมต่อแล้ว"
Else
myDgv.Rows(i).Cells(4).Value = "เชื่อมล้มเหลว"
End If
น่าจะประมาณนี้นะ เพราะไม่เห็นมีในโค้ด
|
 |
 |
 |
 |
Date :
2017-07-31 16:58:21 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|