frmMain.vb 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. 'Author: wuguoying
  2. Imports System.Drawing.Text
  3. Imports System.Object
  4. Imports System.Text
  5. 'Imports Microsoft.VisualBasic.Strings
  6. Public Class frmMain
  7. Inherits System.Windows.Forms.Form
  8. Public Declare Function InitComm Lib "termb.dll" (ByVal port As Integer) As Integer
  9. Public Declare Function Authenticate Lib "termb.dll" () As Integer
  10. Public Declare Function Read_Content Lib "termb.dll" (ByVal active As Integer) As Integer
  11. Public Declare Function Read_Content_Path Lib "termb.dll" (ByVal fileName As String, ByVal active As Integer) As Integer
  12. Public Declare Function CloseComm Lib "termb.dll" () As Integer
  13. Public Const Ver = "身份证阅读演示程序 公安部第一研究所 版权所有"
  14. Public Const ReadState = "读卡状态"
  15. Public Const OpenPortError = "打开串口失败!"
  16. Public Const TimeOutError = "通讯超时!"
  17. Public Const RecError = "操作失败!"
  18. Public Const XpError = "相片解码错误!"
  19. Public Const FileExtError = "wlt文件后缀错误!"
  20. Public Const FileOpenError = "wlt文件打开错误!"
  21. Public Const FileFormatError = "wlt文件格式错误!"
  22. Public Const JmError = "软件未授权!"
  23. Public Const CardError = "卡认证错误!"
  24. Public Const UnknowError = "未知错误!"
  25. Public Const Swipe = "请放卡..."
  26. Public Const ReadOK = "读卡成功!请放下一张卡..."
  27. Public Const ReadError = "读卡失败!请重新放卡..."
  28. Public Const NewAddError = "读最新住址失败!"
  29. Public Const IINSNDNError = "读芯片号失败!"
  30. Public Const Reading = "正在读卡..."
  31. Const NewAddOK = "读最新住址成功!请放下一张卡..."
  32. Public bcc, TimeOutFlag As Byte
  33. Dim state As Boolean
  34. Dim OutByte() As Byte
  35. Dim RecCount, i, j As Long
  36. Dim ReadResult, PortNum As Integer
  37. Dim ComPort, ReadMode, tmp As String
  38. Dim nametmp, sextmp, nationtmp, borntmp, addresstmp, IDNtmp, regtmp, datetmp As String
  39. Dim RecTmp(), RecByte() As String
  40. Dim ReadCount As Long
  41. Friend WithEvents Label1 As System.Windows.Forms.Label
  42. Dim CommFlag As Boolean
  43. #Region " Windows 窗体设计器生成的代码 "
  44. Public Sub New()
  45. MyBase.New()
  46. '该调用是 Windows 窗体设计器所必需的。
  47. InitializeComponent()
  48. '在 InitializeComponent() 调用之后添加任何初始化
  49. End Sub
  50. '窗体重写 dispose 以清理组件列表。
  51. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  52. If disposing Then
  53. If Not (components Is Nothing) Then
  54. components.Dispose()
  55. End If
  56. End If
  57. MyBase.Dispose(disposing)
  58. End Sub
  59. 'Windows 窗体设计器所必需的
  60. Private components As System.ComponentModel.IContainer
  61. '注意: 以下过程是 Windows 窗体设计器所必需的
  62. '可以使用 Windows 窗体设计器修改此过程。
  63. '不要使用代码编辑器修改它。
  64. Friend WithEvents lblSignGov As System.Windows.Forms.Label
  65. Friend WithEvents Photo As System.Windows.Forms.PictureBox
  66. Friend WithEvents lblID As System.Windows.Forms.Label
  67. Friend WithEvents lblAddress As System.Windows.Forms.Label
  68. Friend WithEvents lblBirth As System.Windows.Forms.Label
  69. Friend WithEvents lblNation As System.Windows.Forms.Label
  70. Friend WithEvents lblSex As System.Windows.Forms.Label
  71. Friend WithEvents lblName As System.Windows.Forms.Label
  72. Friend WithEvents lblLimitedDate As System.Windows.Forms.Label
  73. Friend WithEvents sbState As System.Windows.Forms.StatusBar
  74. Friend WithEvents Timer1 As System.Windows.Forms.Timer
  75. Friend WithEvents Timer2 As System.Windows.Forms.Timer
  76. Friend WithEvents ReadingState As System.Windows.Forms.StatusBarPanel
  77. Friend WithEvents ReaderState As System.Windows.Forms.StatusBarPanel
  78. Friend WithEvents Button1 As System.Windows.Forms.Button
  79. Friend WithEvents Button2 As System.Windows.Forms.Button
  80. Friend WithEvents lblNewAddress As System.Windows.Forms.Label
  81. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  82. Me.components = New System.ComponentModel.Container
  83. Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmMain))
  84. Me.lblSignGov = New System.Windows.Forms.Label
  85. Me.Photo = New System.Windows.Forms.PictureBox
  86. Me.lblID = New System.Windows.Forms.Label
  87. Me.lblAddress = New System.Windows.Forms.Label
  88. Me.lblBirth = New System.Windows.Forms.Label
  89. Me.lblNation = New System.Windows.Forms.Label
  90. Me.lblSex = New System.Windows.Forms.Label
  91. Me.lblName = New System.Windows.Forms.Label
  92. Me.lblLimitedDate = New System.Windows.Forms.Label
  93. Me.sbState = New System.Windows.Forms.StatusBar
  94. Me.ReadingState = New System.Windows.Forms.StatusBarPanel
  95. Me.ReaderState = New System.Windows.Forms.StatusBarPanel
  96. Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
  97. Me.Timer2 = New System.Windows.Forms.Timer(Me.components)
  98. Me.Button1 = New System.Windows.Forms.Button
  99. Me.Button2 = New System.Windows.Forms.Button
  100. Me.lblNewAddress = New System.Windows.Forms.Label
  101. Me.Label1 = New System.Windows.Forms.Label
  102. CType(Me.Photo, System.ComponentModel.ISupportInitialize).BeginInit()
  103. CType(Me.ReadingState, System.ComponentModel.ISupportInitialize).BeginInit()
  104. CType(Me.ReaderState, System.ComponentModel.ISupportInitialize).BeginInit()
  105. Me.SuspendLayout()
  106. '
  107. 'lblSignGov
  108. '
  109. Me.lblSignGov.Anchor = System.Windows.Forms.AnchorStyles.None
  110. Me.lblSignGov.BackColor = System.Drawing.Color.Transparent
  111. Me.lblSignGov.Font = New System.Drawing.Font("SimSun", 15.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  112. Me.lblSignGov.ForeColor = System.Drawing.Color.Blue
  113. Me.lblSignGov.ImeMode = System.Windows.Forms.ImeMode.NoControl
  114. Me.lblSignGov.Location = New System.Drawing.Point(197, 360)
  115. Me.lblSignGov.Name = "lblSignGov"
  116. Me.lblSignGov.Size = New System.Drawing.Size(432, 24)
  117. Me.lblSignGov.TabIndex = 60
  118. '
  119. 'Photo
  120. '
  121. Me.Photo.BackColor = System.Drawing.Color.Transparent
  122. Me.Photo.ImeMode = System.Windows.Forms.ImeMode.NoControl
  123. Me.Photo.Location = New System.Drawing.Point(616, 128)
  124. Me.Photo.Name = "Photo"
  125. Me.Photo.Size = New System.Drawing.Size(120, 144)
  126. Me.Photo.TabIndex = 59
  127. Me.Photo.TabStop = False
  128. '
  129. 'lblID
  130. '
  131. Me.lblID.Anchor = System.Windows.Forms.AnchorStyles.None
  132. Me.lblID.BackColor = System.Drawing.Color.Transparent
  133. Me.lblID.Font = New System.Drawing.Font("SimSun", 15.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  134. Me.lblID.ForeColor = System.Drawing.Color.Blue
  135. Me.lblID.ImeMode = System.Windows.Forms.ImeMode.NoControl
  136. Me.lblID.Location = New System.Drawing.Point(253, 300)
  137. Me.lblID.Name = "lblID"
  138. Me.lblID.Size = New System.Drawing.Size(328, 28)
  139. Me.lblID.TabIndex = 58
  140. Me.lblID.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
  141. '
  142. 'lblAddress
  143. '
  144. Me.lblAddress.Anchor = System.Windows.Forms.AnchorStyles.None
  145. Me.lblAddress.BackColor = System.Drawing.Color.Transparent
  146. Me.lblAddress.Font = New System.Drawing.Font("SimSun", 15.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  147. Me.lblAddress.ForeColor = System.Drawing.Color.Blue
  148. Me.lblAddress.ImageAlign = System.Drawing.ContentAlignment.TopLeft
  149. Me.lblAddress.ImeMode = System.Windows.Forms.ImeMode.NoControl
  150. Me.lblAddress.Location = New System.Drawing.Point(141, 216)
  151. Me.lblAddress.Name = "lblAddress"
  152. Me.lblAddress.Size = New System.Drawing.Size(440, 56)
  153. Me.lblAddress.TabIndex = 57
  154. '
  155. 'lblBirth
  156. '
  157. Me.lblBirth.Anchor = System.Windows.Forms.AnchorStyles.None
  158. Me.lblBirth.BackColor = System.Drawing.Color.Transparent
  159. Me.lblBirth.Font = New System.Drawing.Font("SimSun", 15.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  160. Me.lblBirth.ForeColor = System.Drawing.Color.Blue
  161. Me.lblBirth.ImeMode = System.Windows.Forms.ImeMode.NoControl
  162. Me.lblBirth.Location = New System.Drawing.Point(141, 184)
  163. Me.lblBirth.Name = "lblBirth"
  164. Me.lblBirth.Size = New System.Drawing.Size(256, 24)
  165. Me.lblBirth.TabIndex = 56
  166. Me.lblBirth.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
  167. '
  168. 'lblNation
  169. '
  170. Me.lblNation.Anchor = System.Windows.Forms.AnchorStyles.None
  171. Me.lblNation.BackColor = System.Drawing.Color.Transparent
  172. Me.lblNation.Font = New System.Drawing.Font("SimSun", 15.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  173. Me.lblNation.ForeColor = System.Drawing.Color.Blue
  174. Me.lblNation.ImeMode = System.Windows.Forms.ImeMode.NoControl
  175. Me.lblNation.Location = New System.Drawing.Point(429, 152)
  176. Me.lblNation.Name = "lblNation"
  177. Me.lblNation.Size = New System.Drawing.Size(136, 48)
  178. Me.lblNation.TabIndex = 55
  179. '
  180. 'lblSex
  181. '
  182. Me.lblSex.Anchor = System.Windows.Forms.AnchorStyles.None
  183. Me.lblSex.BackColor = System.Drawing.Color.Transparent
  184. Me.lblSex.Font = New System.Drawing.Font("SimSun", 15.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  185. Me.lblSex.ForeColor = System.Drawing.Color.Blue
  186. Me.lblSex.ImeMode = System.Windows.Forms.ImeMode.NoControl
  187. Me.lblSex.Location = New System.Drawing.Point(141, 152)
  188. Me.lblSex.Name = "lblSex"
  189. Me.lblSex.Size = New System.Drawing.Size(80, 24)
  190. Me.lblSex.TabIndex = 54
  191. Me.lblSex.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
  192. '
  193. 'lblName
  194. '
  195. Me.lblName.Anchor = System.Windows.Forms.AnchorStyles.None
  196. Me.lblName.BackColor = System.Drawing.Color.Transparent
  197. Me.lblName.Font = New System.Drawing.Font("SimSun", 15.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  198. Me.lblName.ForeColor = System.Drawing.Color.Blue
  199. Me.lblName.ImeMode = System.Windows.Forms.ImeMode.NoControl
  200. Me.lblName.Location = New System.Drawing.Point(141, 120)
  201. Me.lblName.Name = "lblName"
  202. Me.lblName.Size = New System.Drawing.Size(424, 24)
  203. Me.lblName.TabIndex = 53
  204. Me.lblName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
  205. '
  206. 'lblLimitedDate
  207. '
  208. Me.lblLimitedDate.Anchor = System.Windows.Forms.AnchorStyles.None
  209. Me.lblLimitedDate.BackColor = System.Drawing.Color.Transparent
  210. Me.lblLimitedDate.Font = New System.Drawing.Font("SimSun", 15.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  211. Me.lblLimitedDate.ForeColor = System.Drawing.Color.Blue
  212. Me.lblLimitedDate.ImeMode = System.Windows.Forms.ImeMode.NoControl
  213. Me.lblLimitedDate.Location = New System.Drawing.Point(197, 392)
  214. Me.lblLimitedDate.Name = "lblLimitedDate"
  215. Me.lblLimitedDate.Size = New System.Drawing.Size(544, 24)
  216. Me.lblLimitedDate.TabIndex = 61
  217. '
  218. 'sbState
  219. '
  220. Me.sbState.Font = New System.Drawing.Font("SimSun", 12.0!)
  221. Me.sbState.ImeMode = System.Windows.Forms.ImeMode.NoControl
  222. Me.sbState.Location = New System.Drawing.Point(0, 551)
  223. Me.sbState.Name = "sbState"
  224. Me.sbState.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.ReadingState, Me.ReaderState})
  225. Me.sbState.ShowPanels = True
  226. Me.sbState.Size = New System.Drawing.Size(794, 24)
  227. Me.sbState.TabIndex = 63
  228. '
  229. 'ReadingState
  230. '
  231. Me.ReadingState.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring
  232. Me.ReadingState.Name = "ReadingState"
  233. Me.ReadingState.Width = 388
  234. '
  235. 'ReaderState
  236. '
  237. Me.ReaderState.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring
  238. Me.ReaderState.Name = "ReaderState"
  239. Me.ReaderState.Width = 388
  240. '
  241. 'Timer1
  242. '
  243. '
  244. 'Timer2
  245. '
  246. '
  247. 'Button1
  248. '
  249. Me.Button1.BackColor = System.Drawing.SystemColors.Control
  250. Me.Button1.Font = New System.Drawing.Font("SimSun", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
  251. Me.Button1.Image = CType(resources.GetObject("Button1.Image"), System.Drawing.Image)
  252. Me.Button1.ImageAlign = System.Drawing.ContentAlignment.TopCenter
  253. Me.Button1.Location = New System.Drawing.Point(88, 488)
  254. Me.Button1.Name = "Button1"
  255. Me.Button1.Size = New System.Drawing.Size(72, 56)
  256. Me.Button1.TabIndex = 64
  257. Me.Button1.Text = "最新住址"
  258. Me.Button1.TextAlign = System.Drawing.ContentAlignment.BottomCenter
  259. Me.Button1.UseVisualStyleBackColor = False
  260. '
  261. 'Button2
  262. '
  263. Me.Button2.BackColor = System.Drawing.SystemColors.Control
  264. Me.Button2.Font = New System.Drawing.Font("SimSun", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
  265. Me.Button2.Image = CType(resources.GetObject("Button2.Image"), System.Drawing.Image)
  266. Me.Button2.ImageAlign = System.Drawing.ContentAlignment.TopCenter
  267. Me.Button2.Location = New System.Drawing.Point(232, 488)
  268. Me.Button2.Name = "Button2"
  269. Me.Button2.Size = New System.Drawing.Size(64, 56)
  270. Me.Button2.TabIndex = 65
  271. Me.Button2.Text = "退 出"
  272. Me.Button2.TextAlign = System.Drawing.ContentAlignment.BottomCenter
  273. Me.Button2.UseVisualStyleBackColor = False
  274. '
  275. 'lblNewAddress
  276. '
  277. Me.lblNewAddress.Anchor = System.Windows.Forms.AnchorStyles.None
  278. Me.lblNewAddress.BackColor = System.Drawing.Color.Transparent
  279. Me.lblNewAddress.Font = New System.Drawing.Font("SimSun", 15.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  280. Me.lblNewAddress.ForeColor = System.Drawing.Color.FromArgb(CType(CType(192, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer))
  281. Me.lblNewAddress.ImeMode = System.Windows.Forms.ImeMode.NoControl
  282. Me.lblNewAddress.Location = New System.Drawing.Point(197, 424)
  283. Me.lblNewAddress.Name = "lblNewAddress"
  284. Me.lblNewAddress.Size = New System.Drawing.Size(544, 40)
  285. Me.lblNewAddress.TabIndex = 66
  286. Me.lblNewAddress.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
  287. '
  288. 'Label1
  289. '
  290. Me.Label1.Anchor = System.Windows.Forms.AnchorStyles.None
  291. Me.Label1.BackColor = System.Drawing.Color.Transparent
  292. Me.Label1.Font = New System.Drawing.Font("SimSun", 15.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  293. Me.Label1.ForeColor = System.Drawing.Color.Green
  294. Me.Label1.ImeMode = System.Windows.Forms.ImeMode.NoControl
  295. Me.Label1.Location = New System.Drawing.Point(312, 504)
  296. Me.Label1.Name = "Label1"
  297. Me.Label1.Size = New System.Drawing.Size(424, 24)
  298. Me.Label1.TabIndex = 67
  299. Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
  300. '
  301. 'frmMain
  302. '
  303. Me.AutoScaleBaseSize = New System.Drawing.Size(8, 19)
  304. Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
  305. Me.ClientSize = New System.Drawing.Size(794, 575)
  306. Me.Controls.Add(Me.Label1)
  307. Me.Controls.Add(Me.lblNewAddress)
  308. Me.Controls.Add(Me.Button2)
  309. Me.Controls.Add(Me.Button1)
  310. Me.Controls.Add(Me.sbState)
  311. Me.Controls.Add(Me.lblLimitedDate)
  312. Me.Controls.Add(Me.lblSignGov)
  313. Me.Controls.Add(Me.Photo)
  314. Me.Controls.Add(Me.lblID)
  315. Me.Controls.Add(Me.lblAddress)
  316. Me.Controls.Add(Me.lblBirth)
  317. Me.Controls.Add(Me.lblNation)
  318. Me.Controls.Add(Me.lblSex)
  319. Me.Controls.Add(Me.lblName)
  320. Me.Font = New System.Drawing.Font("SimSun", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
  321. Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
  322. Me.Name = "frmMain"
  323. Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
  324. CType(Me.Photo, System.ComponentModel.ISupportInitialize).EndInit()
  325. CType(Me.ReadingState, System.ComponentModel.ISupportInitialize).EndInit()
  326. CType(Me.ReaderState, System.ComponentModel.ISupportInitialize).EndInit()
  327. Me.ResumeLayout(False)
  328. End Sub
  329. #End Region
  330. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  331. Dim PortNum1, PortNum2 As Integer
  332. Dim ans As Integer
  333. Me.Text = Ver
  334. lblName.Text = ""
  335. lblSex.Text = ""
  336. lblAddress.Text = ""
  337. lblBirth.Text = ""
  338. lblID.Text = ""
  339. lblLimitedDate.Text = ""
  340. lblSignGov.Text = ""
  341. lblNation.Text = ""
  342. lblNewAddress.Text = ""
  343. Photo.Image = Nothing
  344. PortNum1 = 1
  345. ans = InitComm(PortNum1) '开串口
  346. If ans <> 1 Then
  347. PortNum2 = 2
  348. ans = InitComm(PortNum2) '再开串口
  349. If ans <> 1 Then
  350. 'MsgBox("打开串口失败!", , "错误")
  351. 'End
  352. PortNum2 = 1001
  353. ans = InitComm(PortNum2) 'USB
  354. If ans <> 1 Then
  355. sbState.Panels(0).Text = "设备无法识别或通讯口错误!"
  356. Else
  357. sbState.Panels(1).Text = "连接USB" & "口,状态正常!"
  358. Timer2.Interval = 300
  359. Timer2.Enabled = True
  360. state = True
  361. End If
  362. Else
  363. sbState.Panels(1).Text = "连接COM" & PortNum2 & "口,波特率115200,状态正常!"
  364. Timer2.Interval = 300
  365. Timer2.Enabled = True
  366. state = True
  367. End If
  368. Else
  369. sbState.Panels(1).Text = "连接COM" & PortNum1 & "口,波特率115200,状态正常!"
  370. Timer2.Interval = 300
  371. Timer2.Enabled = True
  372. state = True
  373. End If
  374. 'Timer2.Interval = 300
  375. 'Timer2.Enabled = True
  376. Timer1.Interval = 20000
  377. Timer1.Enabled = False
  378. state = True
  379. End Sub
  380. Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
  381. Dim ans As Integer
  382. 'Timer2.Enabled = False
  383. '显示状态
  384. If state = True Then '读卡状态
  385. Select Case ReadResult
  386. Case 0
  387. sbState.Panels(0).Text = Swipe
  388. Case 1
  389. sbState.Panels(0).Text = ReadOK
  390. Case 6
  391. sbState.Panels(0).Text = NewAddError
  392. Case 7
  393. sbState.Panels(0).Text = NewAddOK
  394. Case -1 '相片解码错误
  395. 'Call Display()
  396. 'If Not (Photo.Image Is Nothing) Then
  397. ' Photo.Image.Dispose()
  398. ' Photo.Image = Nothing
  399. 'End If
  400. sbState.Panels(0).Text = XpError
  401. Case -2 '解码错
  402. sbState.Panels(0).Text = FileExtError
  403. Case -3 '解码错
  404. sbState.Panels(0).Text = FileOpenError
  405. Case -4 '解码错
  406. sbState.Panels(0).Text = FileFormatError
  407. Case -5 '软件未授权
  408. sbState.Panels(0).Text = JmError
  409. Case Else '读卡失败
  410. sbState.Panels(0).Text = ReadError
  411. End Select
  412. End If
  413. ans = Authenticate() '卡认证
  414. '卡认证成功
  415. If ans = 1 Then
  416. lblName.Text = ""
  417. lblSex.Text = ""
  418. lblAddress.Text = ""
  419. lblBirth.Text = ""
  420. lblID.Text = ""
  421. lblLimitedDate.Text = ""
  422. lblSignGov.Text = ""
  423. lblNation.Text = ""
  424. lblNewAddress.Text = ""
  425. Label1.Text = ""
  426. If Not (Photo.Image Is Nothing) Then
  427. 'Else
  428. Photo.Image.Dispose()
  429. Photo.Image = Nothing
  430. End If
  431. Application.DoEvents()
  432. sbState.Panels(0).Text = Reading
  433. ans = Read_Content(1) '读基本信息
  434. Select Case ans
  435. Case 1 '读卡成功
  436. ReadResult = 1
  437. Call Display()
  438. Timer1.Enabled = True
  439. '// ReadCount = ReadCount + 1
  440. '// MainForm.StatusBar1.Panels("count_status").Text = "计数:" + LTrim(Str(ReadCount))
  441. '// Timer3.Enabled = True
  442. Photo.Image = System.Drawing.Image.FromFile("zp.bmp") '显示照片
  443. Case 3 '读卡成功
  444. ReadResult = 1
  445. Call Display()
  446. Timer1.Enabled = True
  447. '// ReadCount = ReadCount + 1
  448. '// MainForm.StatusBar1.Panels("count_status").Text = "计数:" + LTrim(Str(ReadCount))
  449. '// Timer3.Enabled = True
  450. Label1.Text = "有指纹信息!"
  451. Photo.Image = System.Drawing.Image.FromFile("zp.bmp") '显示照片
  452. Case -1 '相片解码错误
  453. Call Display()
  454. If Not (Photo.Image Is Nothing) Then
  455. Photo.Image.Dispose()
  456. Photo.Image = Nothing
  457. End If
  458. ReadResult = -1
  459. Case -2 'wlt文件后缀错误
  460. ReadResult = -2
  461. Case -3 'wlt文件打开错误
  462. ReadResult = -3
  463. Case -4 'wlt文件格式错误
  464. ReadResult = -4
  465. Case -5 '软件未授权
  466. ReadResult = -5
  467. Case Else '读卡失败
  468. ReadResult = 2
  469. End Select
  470. End If
  471. 'Timer2.Enabled = True
  472. End Sub
  473. Public Sub Display()
  474. Dim bytWZ(255) As Byte
  475. Dim bytName(29) As Byte
  476. Dim bytSex(1) As Byte
  477. Dim bytNation(3) As Byte
  478. Dim bytBirth(15) As Byte
  479. Dim bytAddress(69) As Byte
  480. Dim bytID(35) As Byte
  481. Dim bytSignGov(29) As Byte
  482. Dim bytStartDate(31) As Byte
  483. Dim bytEndDate(15) As Byte
  484. Dim strTemp As String
  485. Dim iLoop As Integer
  486. Dim uni As New UnicodeEncoding
  487. FileOpen(1, "wz.txt", OpenMode.Binary, OpenAccess.Read)
  488. FileGet(1, bytWZ)
  489. 'Console.WriteLine(hellow)
  490. FileClose(1)
  491. For iLoop = 0 To 29
  492. bytName(iLoop) = bytWZ(iLoop)
  493. Next
  494. Me.lblName.Text = uni.GetString(bytName)
  495. For iLoop = 30 To 31
  496. bytSex(iLoop - 30) = bytWZ(iLoop)
  497. Next
  498. 'Me.lblSex.Text = uni.GetString(bytSex)
  499. Select Case uni.GetString(bytSex)
  500. Case "0"
  501. Me.lblSex.Text = "未知"
  502. Case "1"
  503. Me.lblSex.Text = "男"
  504. Case "2"
  505. Me.lblSex.Text = "女"
  506. Case Else
  507. Me.lblSex.Text = "未说明"
  508. End Select
  509. For iLoop = 32 To 35
  510. bytNation(iLoop - 32) = bytWZ(iLoop)
  511. Next
  512. Me.lblNation.Text = GetNation(uni.GetString(bytNation))
  513. For iLoop = 36 To 51
  514. bytBirth(iLoop - 36) = bytWZ(iLoop)
  515. Next
  516. strTemp = uni.GetString(bytBirth)
  517. Me.lblBirth.Text = strTemp.Substring(0, 4) & "年" & strTemp.Substring(4, 2) & "月" & strTemp.Substring(6, 2) & "日"
  518. For iLoop = 52 To 121
  519. bytAddress(iLoop - 52) = bytWZ(iLoop)
  520. Next
  521. Me.lblAddress.Text = uni.GetString(bytAddress)
  522. For iLoop = 122 To 157
  523. bytID(iLoop - 122) = bytWZ(iLoop)
  524. Next
  525. Me.lblID.Text = uni.GetString(bytID)
  526. For iLoop = 158 To 187
  527. bytSignGov(iLoop - 158) = bytWZ(iLoop)
  528. Next
  529. Me.lblSignGov.Text = uni.GetString(bytSignGov)
  530. For iLoop = 188 To 219
  531. bytStartDate(iLoop - 188) = bytWZ(iLoop)
  532. Next
  533. 'For iLoop = 201 To 216
  534. ' bytEndDate(iLoop - 201) = bytWZ(iLoop )
  535. 'Next
  536. strTemp = uni.GetString(bytStartDate)
  537. If Len(Trim(strTemp)) = 10 Then
  538. Me.lblLimitedDate.Text = strTemp.Substring(0, 4) & "年" & strTemp.Substring(4, 2) & "月" & strTemp.Substring(6, 2) & "日--" & strTemp.Substring(8, 2)
  539. Else
  540. Me.lblLimitedDate.Text = strTemp.Substring(0, 4) & "年" & strTemp.Substring(4, 2) & "月" & strTemp.Substring(6, 2) & "日--" & strTemp.Substring(8, 4) & "年" & strTemp.Substring(12, 2) & "月" & strTemp.Substring(14, 2) & "日"
  541. End If
  542. End Sub
  543. Public Function GetNation(ByVal strNationcode As String) As String
  544. Dim strNationArray As String() = {"汉", "蒙古", "回", "藏", "维吾尔", "苗", "彝", "壮", "布依", "朝鲜", "满", "侗", "瑶", "白", "土家", "哈尼", "哈萨克", "傣", "黎", "傈僳", "佤", "畲", "高山", "拉祜", "水", "东乡", "纳西", "景颇", "柯尔克孜", "土", "达斡尔", "仫佬", "羌", "布朗", "撒拉", "毛南", "仡佬", "锡伯", "阿昌", "普米", "塔吉克", "怒", "乌孜别克", "俄罗斯", "鄂温克", "德昂", "保安", "裕固", "京", "塔塔尔", "独龙", "鄂伦春", "赫哲", "门巴", "珞巴", "基诺"}
  545. If Trim(strNationcode) <> "" Then
  546. If ((CByte(Trim(strNationcode)) - 1) >= 0) And ((CByte(Trim(strNationcode)) - 1) <= 55) Then
  547. GetNation = strNationArray(CByte(Trim(strNationcode)) - 1)
  548. Else
  549. GetNation = "其他"
  550. End If
  551. End If
  552. End Function
  553. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  554. Timer1.Enabled = False
  555. lblName.Text = ""
  556. lblSex.Text = ""
  557. lblAddress.Text = ""
  558. lblBirth.Text = ""
  559. lblID.Text = ""
  560. lblLimitedDate.Text = ""
  561. lblSignGov.Text = ""
  562. lblNation.Text = ""
  563. lblNewAddress.Text = ""
  564. Label1.Text = ""
  565. If Not (Photo.Image Is Nothing) Then
  566. 'Else
  567. Photo.Image.Dispose()
  568. Photo.Image = Nothing
  569. End If
  570. End Sub
  571. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  572. CloseComm()
  573. Me.Close()
  574. 'End
  575. End Sub
  576. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  577. Dim iReturn As Integer
  578. Dim bytNewAddress(69) As Byte
  579. Dim uni As New UnicodeEncoding
  580. Timer1.Enabled = False
  581. iReturn = Read_Content(3)
  582. If iReturn = 1 Then
  583. 'sbState.Panels(0).Text = "读最新住址成功!"
  584. FileOpen(1, "newadd.txt", OpenMode.Binary, OpenAccess.Read)
  585. FileGet(1, bytNewAddress)
  586. FileClose(1)
  587. ReadResult = 7
  588. Me.lblNewAddress.Text = uni.GetString(bytNewAddress)
  589. Else
  590. ReadResult = 6
  591. 'sbState.Panels(0).Text = "读最新住址失败!"
  592. End If
  593. Timer1.Enabled = True
  594. End Sub
  595. End Class