?? form1.vb
字號:
Option Explicit On
Option Strict On
Imports System
Imports System.IO
Public Class Form1
Public Class hero
Private s_bar As String
Private s_name As String
Private s_spec As String
Private s_buydate As String
Private s_user_na As String
Private s_zjqq As String
Private s_qj As String
Private s_mana As String
Public Property mybar() As String
Get
Return s_bar
End Get
Set(ByVal value As String)
s_bar = value
End Set
End Property
Public Property myname() As String
Get
Return s_name
End Get
Set(ByVal value As String)
s_name = value
End Set
End Property
Public Property myspec() As String
Get
Return s_spec
End Get
Set(ByVal value As String)
s_spec = value
End Set
End Property
Public Property mybuydate() As String
Get
Return s_buydate
End Get
Set(ByVal value As String)
s_buydate = value
End Set
End Property
Public Property myuser() As String
Get
Return s_user_na
End Get
Set(ByVal value As String)
s_user_na = value
End Set
End Property
Public Property myzjqq() As String
Get
Return s_zjqq
End Get
Set(ByVal value As String)
s_zjqq = value
End Set
End Property
Public Property myqj() As String
Get
Return s_qj
End Get
Set(ByVal value As String)
s_qj = value
End Set
End Property
Public Property mymana() As String
Get
Return s_mana
End Get
Set(ByVal value As String)
s_mana = value
End Set
End Property
End Class
Dim heroList As New SortedList
Dim n_item As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdexit.Click
Me.Close()
End Sub
Private Sub txtDep_id_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDep_id.KeyDown
Select Case e.KeyCode
Case Keys.Enter
If txtDep_id.Text = "" Then
MessageBox.Show("部門不能為空!")
txtDep_id.Focus()
Else
Dim line As String
Dim reok As Integer = 0
Dim sr As StreamReader = New StreamReader("\Flash Disk\zichanqingcha\dep.txt", System.Text.Encoding.Default)
Do While sr.Peek() > 0
line = sr.ReadLine()
If Trim(txtDep_id.Text) = Trim(Mid(line, 1, 8)) Then
reok = 1
txtDep_name.Text = Trim(Mid(line, 9, 20))
End If
Loop
sr.Close()
sr = Nothing
If reok = 0 Then
MessageBox.Show("無此部門,請重新輸入!")
txtDep_id.Text = ""
txtDep_name.Text = ""
txtDep_id.Focus()
End If
txtBarcode.Focus()
End If
Case Keys.F22
If txtDep_id.Text <> "" Then
txtBarcode.Focus()
End If
End Select
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If (e.KeyCode = Keys.F22) Then
txtBarcode.Focus()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ListView1.View = View.Details
Me.ListView1.HeaderStyle = ColumnHeaderStyle.Clickable
Me.ListView1.FullRowSelect = True
Me.ListView1.Columns.Add("資產條碼", 100, HorizontalAlignment.Center)
Me.ListView1.Columns.Add("資產名稱", 140, HorizontalAlignment.Center)
Me.ListView1.Columns.Add("規格型號", 100, HorizontalAlignment.Center)
Me.ListView1.Columns.Add("購置日期", 80, HorizontalAlignment.Center)
Me.ListView1.Columns.Add("使用人", 100, HorizontalAlignment.Center)
Me.ListView1.Columns.Add("組件齊全", 60, HorizontalAlignment.Center)
Me.ListView1.Columns.Add("是否清潔", 60, HorizontalAlignment.Center)
Me.ListView1.Columns.Add("規范管理", 60, HorizontalAlignment.Center)
End Sub
Private Sub txtDep_id_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDep_id.Validated
If txtDep_id.Text = "" Then
MessageBox.Show("部門不能為空!")
txtDep_id.Focus()
Else
Dim line As String
Dim reok As Integer = 0
Dim sr As StreamReader = New StreamReader("\Flash Disk\zichanqingcha\dep.txt", System.Text.Encoding.Default)
Do While sr.Peek() > 0
line = sr.ReadLine()
If Trim(txtDep_id.Text) = Trim(Mid(line, 1, 8)) Then
reok = 1
txtDep_name.Text = Trim(Mid(line, 9, 20))
End If
Loop
sr.Close()
sr = Nothing
If reok = 0 Then
MessageBox.Show("無此部門,請重新輸入!")
txtDep_id.Text = ""
txtDep_name.Text = ""
txtDep_id.Focus()
End If
txtBarcode.Focus()
End If
End Sub
Private Sub txtBarcode_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtBarcode.KeyDown
If e.KeyCode = Keys.Enter Then
Dim dt As Date = DateTime.Now
Dim scandate As String = dt.ToLocalTime.ToString
Dim line As String
Dim sline As String
Dim barok As Integer = 0
Dim barsum As Integer = 0
Dim iItem As ListViewItem
Dim aHero As hero
aHero = New hero
iItem = New ListViewItem
aHero.mybar = txtBarcode.Text
If File.Exists("\Flash Disk\zichanqingcha\pd.txt") Then
Dim psr As StreamReader = New StreamReader("\Flash Disk\zichanqingcha\pd.txt", System.Text.Encoding.Default)
Do While psr.Peek() > 0
sline = psr.ReadLine()
If Trim(txtBarcode.Text) = Trim(Mid(sline, 1, 13)) Then
barsum = 1
End If
Loop
psr.Close()
psr = Nothing
End If
If barsum = 0 Then
Dim sr As StreamReader = New StreamReader("\Flash Disk\zichanqingcha\zichan.txt", System.Text.Encoding.Default)
Do While sr.Peek() > 0
line = sr.ReadLine()
If Trim(txtBarcode.Text) = Trim(Mid(line, 1, 13)) Then
barok = 1
aHero.myname = Mid(line, 14, 15)
aHero.mybuydate = Mid(line, 62, 6)
aHero.myuser = Mid(line, 68, 12)
aHero.myspec = Mid(line, 80, 16)
End If
Loop
sr.Close()
sr = Nothing
Dim zjqq As String
Dim qj As String
Dim tsgl As String
If chek1.Checked = True Then
zjqq = "1"
Else
zjqq = "0"
End If
If chek2.Checked = True Then
qj = "1"
Else
qj = "0"
End If
If chek3.Checked = True Then
tsgl = "1"
Else
tsgl = "0"
End If
If barok = 0 Then
labbar.Text = "注意:條碼不存在!"
Else
labbar.Text = ""
End If
aHero.myzjqq = zjqq
aHero.myqj = qj
aHero.mymana = tsgl
iItem.Text = aHero.mybar
iItem.Tag = aHero
iItem.SubItems.Add(aHero.myname)
iItem.SubItems.Add(aHero.myspec)
iItem.SubItems.Add(aHero.mybuydate)
iItem.SubItems.Add(aHero.myuser)
iItem.SubItems.Add(aHero.myzjqq)
iItem.SubItems.Add(aHero.myqj)
iItem.SubItems.Add(aHero.mymana)
ListView1.Items.Add(iItem)
heroList.Add(aHero.mybar, aHero)
ListView1.Items.Item(n_item).Selected = True
n_item = n_item + 1
ListView1.Refresh()
'ListBox1.Items.Add(txtBarcode.Text + Space(13 - Len(txtBarcode.Text)) + Space(2) + lname + Space(2) + lspec + Space(2) + lbuydate + Space(2) + luser_na + Space(2) + scandate)
If File.Exists("\Flash Disk\zichanqingcha\pd.txt") Then
Dim sw As StreamWriter = New StreamWriter("\Flash Disk\zichanqingcha\pd.txt", True) 'true是指以追加的方式打開指定文件
sw.WriteLine(Trim(txtBarcode.Text) + Space(13 - Len(Trim(txtBarcode.Text))) + Trim(txtDep_id.Text) + Space(8 - Len(Trim(txtDep_id.Text))) + Mid(scandate, 1, 2) + Mid(scandate, 4, 2) + Mid(scandate, 7, 2) + zjqq + qj + tsgl)
sw.Flush()
sw.Close()
sw = Nothing
Else
Using sw As StreamWriter = File.CreateText("\Flash Disk\zichanqingcha\pd.txt")
sw.WriteLine(Trim(txtBarcode.Text) + Space(13 - Len(Trim(txtBarcode.Text))) + Trim(txtDep_id.Text) + Space(8 - Len(Trim(txtDep_id.Text))) + Mid(scandate, 1, 2) + Mid(scandate, 4, 2) + Mid(scandate, 7, 2) + zjqq + qj + tsgl)
sw.Close()
End Using
End If
Else
MessageBox.Show("該條碼已盤點過!")
End If
txtBarcode.Text = ""
txtBarcode.Focus()
End If
End Sub
End Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -