Completed support for US barcode scanner

This commit is contained in:
JackCarterSmith 2017-06-19 11:42:05 +02:00
parent 877e863e3e
commit 57fe42308d
5 changed files with 126 additions and 43 deletions

View File

@ -27,6 +27,7 @@ Partial Class AddMachine_ID
Me.AddMachine_ID_CancelButton = New System.Windows.Forms.Button()
Me.NextButton = New System.Windows.Forms.Button()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.RandomIDButton = New System.Windows.Forms.Button()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
@ -82,6 +83,16 @@ Partial Class AddMachine_ID
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Nouvel ID"
'
'RandomIDButton
'
Me.RandomIDButton.Enabled = False
Me.RandomIDButton.Location = New System.Drawing.Point(247, 88)
Me.RandomIDButton.Name = "RandomIDButton"
Me.RandomIDButton.Size = New System.Drawing.Size(59, 23)
Me.RandomIDButton.TabIndex = 102
Me.RandomIDButton.Text = "Aléatoire"
Me.RandomIDButton.UseVisualStyleBackColor = True
'
'AddMachine_ID
'
Me.AcceptButton = Me.NextButton
@ -89,6 +100,7 @@ Partial Class AddMachine_ID
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.CausesValidation = False
Me.ClientSize = New System.Drawing.Size(360, 167)
Me.Controls.Add(Me.RandomIDButton)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.NextButton)
Me.Controls.Add(Me.AddMachine_ID_CancelButton)
@ -112,4 +124,5 @@ Partial Class AddMachine_ID
Friend WithEvents AddMachine_ID_CancelButton As Button
Friend WithEvents NextButton As Button
Friend WithEvents GroupBox1 As GroupBox
Friend WithEvents RandomIDButton As Button
End Class

View File

@ -24,4 +24,12 @@
NextButton.Enabled = False
End If
End Sub
Private Sub RandomIDButton_Click(sender As Object, e As EventArgs) Handles RandomIDButton.Click
newIDBox.Text = Main.GenerateRandomID()
End Sub
Private Sub newIDBox_KeyDown(sender As Object, e As KeyEventArgs) Handles newIDBox.KeyDown
newIDBox.Text = newIDBox.Text & Main.ScannerInterpreterFRLayout(e)
End Sub
End Class

View File

@ -27,6 +27,7 @@ Partial Class IDGenerator
Me.GenerateNewIDButton = New System.Windows.Forms.Button()
Me.CloseButtonNewID = New System.Windows.Forms.Button()
Me.PictureBox1 = New System.Windows.Forms.PictureBox()
Me.newRandomIDBox = New System.Windows.Forms.MaskedTextBox()
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
@ -69,7 +70,7 @@ Partial Class IDGenerator
Me.Barcode1.RotationAngle = IDAutomation.Windows.Forms.LinearBarCode.RotationAngles.Zero_Degrees
Me.Barcode1.ShowText = True
Me.Barcode1.ShowTextLocation = IDAutomation.Windows.Forms.LinearBarCode.HRTextPositions.Bottom
Me.Barcode1.Size = New System.Drawing.Size(171, 75)
Me.Barcode1.Size = New System.Drawing.Size(171, 74)
Me.Barcode1.SuppSeparationCM = 0.5!
Me.Barcode1.SymbologyID = IDAutomation.Windows.Forms.LinearBarCode.Symbologies.Code39
Me.Barcode1.TabIndex = 0
@ -79,11 +80,11 @@ Partial Class IDGenerator
Me.Barcode1.UPCESystem = "0"
Me.Barcode1.WhiteBarIncrease = 0!
Me.Barcode1.XDimensionCM = 0.0298!
Me.Barcode1.XDimensionMILS = 11.7715!
Me.Barcode1.XDimensionMILS = 11.7714!
'
'GenerateNewIDButton
'
Me.GenerateNewIDButton.Location = New System.Drawing.Point(12, 145)
Me.GenerateNewIDButton.Location = New System.Drawing.Point(12, 171)
Me.GenerateNewIDButton.Name = "GenerateNewIDButton"
Me.GenerateNewIDButton.Size = New System.Drawing.Size(198, 23)
Me.GenerateNewIDButton.TabIndex = 1
@ -93,7 +94,7 @@ Partial Class IDGenerator
'CloseButtonNewID
'
Me.CloseButtonNewID.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.CloseButtonNewID.Location = New System.Drawing.Point(51, 170)
Me.CloseButtonNewID.Location = New System.Drawing.Point(51, 196)
Me.CloseButtonNewID.Name = "CloseButtonNewID"
Me.CloseButtonNewID.Size = New System.Drawing.Size(126, 23)
Me.CloseButtonNewID.TabIndex = 2
@ -110,25 +111,39 @@ Partial Class IDGenerator
Me.PictureBox1.TabIndex = 3
Me.PictureBox1.TabStop = False
'
'newRandomIDBox
'
Me.newRandomIDBox.AllowDrop = True
Me.newRandomIDBox.AsciiOnly = True
Me.newRandomIDBox.BeepOnError = True
Me.newRandomIDBox.Location = New System.Drawing.Point(64, 145)
Me.newRandomIDBox.Mask = "9999999999"
Me.newRandomIDBox.Name = "newRandomIDBox"
Me.newRandomIDBox.Size = New System.Drawing.Size(100, 20)
Me.newRandomIDBox.TabIndex = 4
Me.newRandomIDBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
'
'IDGenerator
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.CancelButton = Me.CloseButtonNewID
Me.ClientSize = New System.Drawing.Size(224, 203)
Me.ClientSize = New System.Drawing.Size(224, 226)
Me.Controls.Add(Me.newRandomIDBox)
Me.Controls.Add(Me.CloseButtonNewID)
Me.Controls.Add(Me.GenerateNewIDButton)
Me.Controls.Add(Me.Barcode1)
Me.Controls.Add(Me.PictureBox1)
Me.MaximizeBox = False
Me.MaximumSize = New System.Drawing.Size(240, 242)
Me.MaximumSize = New System.Drawing.Size(240, 265)
Me.MinimizeBox = False
Me.MinimumSize = New System.Drawing.Size(240, 242)
Me.MinimumSize = New System.Drawing.Size(240, 265)
Me.Name = "IDGenerator"
Me.ShowIcon = False
Me.Text = "Générer de nouveaux IDs"
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
@ -136,4 +151,5 @@ Partial Class IDGenerator
Friend WithEvents GenerateNewIDButton As Button
Friend WithEvents CloseButtonNewID As Button
Friend WithEvents PictureBox1 As PictureBox
Friend WithEvents newRandomIDBox As MaskedTextBox
End Class

View File

@ -1,25 +1,28 @@
Imports System.Text
Public Class IDGenerator
Public Class IDGenerator
Private Sub IDGenerator_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Randomize()
GenerateNewIDBarcode()
End Sub
Private Sub GenerateNewIDBarcode()
'Génération d'un nouvel ID
Dim s As String = "0123456789"
Dim r As New Random
Dim sb As New StringBuilder
generate:
sb.Clear()
For i As Integer = 1 To 10
Dim idx As Integer = r.Next(0, 9)
sb.Append(s.Substring(idx, 1))
Next
'Génération d'un nouvel ID
Dim newIDRandom As String = Main.GenerateRandomID()
'Vérification si pas déjà existant
If Not Main.CheckIDAlreadyUsed(sb.ToString()) Then Barcode1.DataToEncode = sb.ToString() Else GoTo generate
If Not Main.CheckIDAlreadyUsed(newIDRandom) Then
newRandomIDBox.Text = newIDRandom
Barcode1.DataToEncode = newIDRandom
Else
GoTo generate
End If
End Sub
Private Sub newRandomIDBox_TextChanged(sender As Object, e As EventArgs) Handles newRandomIDBox.TextChanged
If newRandomIDBox.Text.Length() = 10 Then Barcode1.DataToEncode = newRandomIDBox.Text
End Sub
Private Sub newRandomIDBox_KeyDown(sender As Object, e As KeyEventArgs) Handles newRandomIDBox.KeyDown
newRandomIDBox.Text = newRandomIDBox.Text & Main.ScannerInterpreterFRLayout(e)
End Sub
Private Sub GenerateNewIDButton_Click(sender As Object, e As EventArgs) Handles GenerateNewIDButton.Click

View File

@ -1,4 +1,5 @@
Imports System.Data.SQLite
Imports System.Text
Public Class Main
Dim manualID_selected As Boolean = False
@ -9,6 +10,9 @@ Public Class Main
ListAllInv()
End Sub
''' <summary>
''' Function to check if app is running for the first time
''' </summary>
Private Sub CheckIfFirstRun()
If Not My.Computer.FileSystem.FileExists("db.sqlite") Then
If MsgBox("La base de données SQLite est introuvable ou inaccesible, souhaitez-vous la régénérer ?", 4161, "Base SQLite absente ou inacessible") = 1 Then
@ -19,6 +23,11 @@ Public Class Main
End If
End Sub
''' <summary>
''' Check if an ID is already used in the SQLite DB
''' </summary>
''' <param name="idToCheck">ID to check</param>
''' <returns>True = ID already used</returns>
Public Function CheckIDAlreadyUsed(idToCheck As String) As Boolean
Dim dtr As SQLiteDataReader
@ -44,6 +53,58 @@ Public Class Main
Return True
End Function
''' <summary>
''' ID Generator with 10 digits from 0 to 9 returned with String
''' </summary>
''' <returns>String correspond to ID generate</returns>
Public Function GenerateRandomID() As String
Dim s As String = "0123456789"
Dim r As New Random
Dim sb As New StringBuilder
sb.Clear()
For i As Integer = 1 To 10
Dim idx As Integer = r.Next(0, 9)
sb.Append(s.Substring(idx, 1))
Next
Return sb.ToString()
End Function
''' <summary>
''' Convert US key from barcode scanner to FR key
''' </summary>
''' <param name="scanKey">Event of keyDown</param>
''' <returns>Converted string key</returns>
Public Function ScannerInterpreterFRLayout(scanKey As KeyEventArgs) As String
Select Case scanKey.KeyCode.ToString()
Case "D0"
Return "0"
Case "D1"
Return "1"
Case "D2"
Return "2"
Case "D3"
Return "3"
Case "D4"
Return "4"
Case "D5"
Return "5"
Case "D6"
Return "6"
Case "D7"
Return "7"
Case "D8"
Return "8"
Case "D9"
Return "9"
End Select
Return Nothing
End Function
''' <summary>
''' Construct the basic structure of SQLite DB
''' </summary>
Private Sub RegenerateDB()
Dim genesis_seq As String = "
CREATE TABLE `computers_desc` (
@ -88,6 +149,9 @@ Public Class Main
End Try
End Sub
''' <summary>
''' Liste all object from DB into list dialog
''' </summary>
Public Sub ListAllInv()
idList.Clear()
Dim dtr As SQLiteDataReader
@ -319,28 +383,7 @@ Public Class Main
End Sub
Private Sub IDBox_KeyDown(sender As Object, e As KeyEventArgs) Handles IDBox.KeyDown
Select Case e.KeyCode.ToString()
Case "D0"
IDBox.Text = IDBox.Text & "0"
Case "D1"
IDBox.Text = IDBox.Text & "1"
Case "D2"
IDBox.Text = IDBox.Text & "2"
Case "D3"
IDBox.Text = IDBox.Text & "3"
Case "D4"
IDBox.Text = IDBox.Text & "4"
Case "D5"
IDBox.Text = IDBox.Text & "5"
Case "D6"
IDBox.Text = IDBox.Text & "6"
Case "D7"
IDBox.Text = IDBox.Text & "7"
Case "D8"
IDBox.Text = IDBox.Text & "8"
Case "D9"
IDBox.Text = IDBox.Text & "9"
End Select
IDBox.Text = IDBox.Text & ScannerInterpreterFRLayout(e)
End Sub
Private Sub GénérerDesIDsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles GénérerDesIDsToolStripMenuItem.Click