📄 location.vb
字号:
Public Class frmLocation
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents btnModify As System.Windows.Forms.Button
Friend WithEvents btnAdd As System.Windows.Forms.Button
Friend WithEvents grdLocation As System.Windows.Forms.DataGrid
Friend WithEvents btnDelete As System.Windows.Forms.Button
Friend WithEvents btnClose As System.Windows.Forms.Button
Friend WithEvents btnSave As System.Windows.Forms.Button
Friend WithEvents txtLocation As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.txtLocation = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.btnModify = New System.Windows.Forms.Button
Me.btnAdd = New System.Windows.Forms.Button
Me.grdLocation = New System.Windows.Forms.DataGrid
Me.btnDelete = New System.Windows.Forms.Button
Me.btnClose = New System.Windows.Forms.Button
Me.btnSave = New System.Windows.Forms.Button
CType(Me.grdLocation, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'txtLocation
'
Me.txtLocation.Location = New System.Drawing.Point(160, 40)
Me.txtLocation.Name = "txtLocation"
Me.txtLocation.Size = New System.Drawing.Size(120, 21)
Me.txtLocation.TabIndex = 12
Me.txtLocation.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(160, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 24)
Me.Label1.TabIndex = 11
Me.Label1.Text = "存放位置"
'
'btnModify
'
Me.btnModify.Location = New System.Drawing.Point(64, 256)
Me.btnModify.Name = "btnModify"
Me.btnModify.Size = New System.Drawing.Size(48, 23)
Me.btnModify.TabIndex = 10
Me.btnModify.Text = "修改"
'
'btnAdd
'
Me.btnAdd.Location = New System.Drawing.Point(8, 256)
Me.btnAdd.Name = "btnAdd"
Me.btnAdd.Size = New System.Drawing.Size(48, 23)
Me.btnAdd.TabIndex = 6
Me.btnAdd.Text = "添加"
'
'grdLocation
'
Me.grdLocation.DataMember = ""
Me.grdLocation.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.grdLocation.Location = New System.Drawing.Point(8, 8)
Me.grdLocation.Name = "grdLocation"
Me.grdLocation.ReadOnly = True
Me.grdLocation.Size = New System.Drawing.Size(136, 232)
Me.grdLocation.TabIndex = 5
'
'btnDelete
'
Me.btnDelete.Location = New System.Drawing.Point(120, 256)
Me.btnDelete.Name = "btnDelete"
Me.btnDelete.Size = New System.Drawing.Size(48, 23)
Me.btnDelete.TabIndex = 7
Me.btnDelete.Text = "删除"
'
'btnClose
'
Me.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnClose.Location = New System.Drawing.Point(232, 256)
Me.btnClose.Name = "btnClose"
Me.btnClose.Size = New System.Drawing.Size(48, 23)
Me.btnClose.TabIndex = 8
Me.btnClose.Text = "关闭"
'
'btnSave
'
Me.btnSave.Location = New System.Drawing.Point(176, 256)
Me.btnSave.Name = "btnSave"
Me.btnSave.Size = New System.Drawing.Size(48, 23)
Me.btnSave.TabIndex = 9
Me.btnSave.Text = "保存"
'
'frmLocation
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.CancelButton = Me.btnClose
Me.ClientSize = New System.Drawing.Size(288, 285)
Me.Controls.Add(Me.txtLocation)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btnModify)
Me.Controls.Add(Me.btnAdd)
Me.Controls.Add(Me.grdLocation)
Me.Controls.Add(Me.btnDelete)
Me.Controls.Add(Me.btnClose)
Me.Controls.Add(Me.btnSave)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.MaximizeBox = False
Me.Name = "frmLocation"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "设置存放位置"
CType(Me.grdLocation, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private locationds As New DataSet
Private Sub frmLocation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
OleConn.SelectQuery("select * from 存放位置", locationds)
If locationds.Tables.Count > 0 Then
grdLocation.SetDataBinding(locationds, "Table")
grdLocation.CurrentRowIndex = 0
txtLocation.Text = grdLocation.Item(0, 0)
End If
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
End Sub
Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If txtLocation.Text = "" Then
MsgBox("请输入存放位置")
txtLocation.Focus()
Else
Try
Dim dr As DataRow = locationds.Tables(0).NewRow()
dr(0) = txtLocation.Text
locationds.Tables(0).Rows.Add(dr)
If grdLocation.CurrentRowIndex > 0 Then
txtLocation.Text = grdLocation.Item(grdLocation.CurrentRowIndex, 0)
Else
grdLocation.CurrentRowIndex = 0
txtLocation.Text = grdLocation.Item(0, 0)
End If
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
End If
End Sub
Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
If txtLocation.Text = "" Then
MsgBox("请输入存放位置")
txtLocation.Focus()
Else
Try
Dim str As String = "存放位置='" & grdLocation.Item(grdLocation.CurrentRowIndex, 0) & "'"
Dim dr As DataRow() = locationds.Tables(0).Select(str)
dr(0).Delete()
If grdLocation.CurrentRowIndex > 0 Then
txtLocation.Text = grdLocation.Item(grdLocation.CurrentRowIndex, 0)
Else
grdLocation.CurrentRowIndex = 0
txtLocation.Text = grdLocation.Item(0, 0)
End If
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
End If
End Sub
Private Sub btnModify_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnModify.Click
If txtLocation.Text = "" Then
MsgBox("请输入存放位置")
txtLocation.Focus()
ElseIf grdLocation.CurrentRowIndex < 0 Then
MsgBox("请先选择要修改的存放位置")
grdLocation.Focus()
Else
Try
Dim str As String = "存放位置='" & grdLocation.Item(grdLocation.CurrentRowIndex, 0) & "'"
Dim dr As DataRow() = locationds.Tables(0).Select(str)
dr(0).BeginEdit()
dr(0).Item(0) = txtLocation.Text
dr(0).EndEdit()
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
End If
End Sub
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
OleConn.UpDate(locationds.Tables(0))
locationds.AcceptChanges()
Catch ex As Exception
OleConn.DisplayError(ex)
End Try
End Sub
Private Sub grdLocation_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles grdLocation.MouseDown
Dim hti As DataGrid.HitTestInfo
hti = grdLocation.HitTest(e.X, e.Y)
If hti.Type = DataGrid.HitTestType.Cell Or hti.Type = DataGrid.HitTestType.RowHeader Then
txtLocation.Text = grdLocation.Item(hti.Row, 0)
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -