📄 frmwarehouse.vb
字号:
'txtWarehouseID
'
Me.txtWarehouseID.Location = New System.Drawing.Point(72, 32)
Me.txtWarehouseID.Name = "txtWarehouseID"
Me.txtWarehouseID.ReadOnly = True
Me.txtWarehouseID.Size = New System.Drawing.Size(112, 21)
Me.txtWarehouseID.TabIndex = 1
Me.txtWarehouseID.Text = ""
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(16, 32)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(23, 17)
Me.Label1.TabIndex = 0
Me.Label1.Text = "ID:"
'
'frmWarehouse
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(520, 349)
Me.Controls.Add(Me.GroupBox2)
Me.Controls.Add(Me.GroupBox1)
Me.MaximizeBox = False
Me.Name = "frmWarehouse"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "仓库信息管理"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub frmWarehouse_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'导入仓库信息
freshData()
End Sub
'将仓库信息添加到ListView控件
Private Sub freshData()
Dim myValues(3) As String
Dim myListItem As ListViewItem
Dim Params() As SqlParameter = {}
If myDataObj.ExecuteSP("sp_GetAllWarehouse", Params, drSqlServer) = True Then
If lstWarehouse.Items.Count > 0 Then
lstWarehouse.Items.Clear()
End If
While drSqlServer.Read()
myValues(0) = drSqlServer("WarehouseID").ToString()
myValues(1) = drSqlServer("WarehouseName").ToString()
myValues(2) = drSqlServer("WarehouseDescr").ToString()
myListItem = New ListViewItem(myValues)
lstWarehouse.Items.Add(myListItem)
End While
drSqlServer.Close()
End If
End Sub
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
If strCommand = "add" Then
If txtWarehouseName.Text.Trim() = "" Then
MsgBox("请完整填写详细", MsgBoxStyle.Exclamation)
Exit Sub
End If
Dim STRSQL = "SELECT * FROM WAREHOUSE WHERE WAREHOUSENAME='" & txtWarehouseName.Text.Trim() & "'"
myDataObj.ExecuteSQL(STRSQL, drSqlServer)
If drSqlServer.Read() Then
MsgBox("此仓库已存在", MsgBoxStyle.Exclamation)
txtWarehouseID.Text = ""
txtWarehouseName.Text = ""
txtDescr.Text = ""
drSqlServer.Close()
Else
drSqlServer.Close()
Dim Params() As SqlParameter = _
{New SqlParameter("@WarehouseName", SqlDbType.VarChar), _
New SqlParameter("@WarehouseDescr", SqlDbType.VarChar)}
Params(0).Value = txtWarehouseName.Text.Trim()
Params(1).Value = txtDescr.Text.Trim()
myDataObj.ExecuteSP("sp_InsertWarehouse", Params)
MsgBox("添加完毕", MsgBoxStyle.Information)
freshData()
End If
ElseIf strCommand = "update" Then
Dim Params() As SqlParameter = _
{New SqlParameter("@WarehouseID", SqlDbType.Int), _
New SqlParameter("@WarehouseName", SqlDbType.VarChar), _
New SqlParameter("@WarehouseDescr", SqlDbType.VarChar)}
params(0).Value = txtWarehouseID.Text.Trim
Params(1).Value = txtWarehouseName.Text.Trim
Params(2).Value = txtDescr.Text.Trim
myDataObj.ExecuteSP("sp_UpdateWarehouse", Params)
MsgBox("更新完毕", MsgBoxStyle.Information)
Else
Me.Close()
End If
freshData() '刷新数据显示
btnAdd.Enabled = True
btnUpdate.Enabled = True
btnDel.Enabled = True
txtWarehouseName.Enabled = False
txtDescr.Enabled = False
strCommand = ""
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
txtWarehouseName.Enabled = True
txtDescr.Enabled = True
btnUpdate.Enabled = False
btnDel.Enabled = False
txtWarehouseID.Text = ""
txtWarehouseName.Text = ""
txtDescr.Text = ""
strCommand = "add"
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
txtWarehouseName.Enabled = True
txtDescr.Enabled = True
btnAdd.Enabled = False
btnDel.Enabled = False
strCommand = "update"
End Sub
'删除记录
Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
If MsgBox("确定要删除记录:" & txtWarehouseID.Text & "?", MsgBoxStyle.OKCancel) = MsgBoxResult.OK Then
Dim Params() As SqlParameter = _
{New SqlParameter("@WarehouseID", SqlDbType.VarChar)}
Params(0).Value = txtWarehouseID.Text
myDataObj.ExecuteSP("sp_DelWarehouse", Params)
Dim strSQL = "SELECT * FROM WAREHOUSE WHERE WAREHOUSEID='" & Params(0).Value & "'"
myDataObj.ExecuteSQL(strSQL, drSqlServer)
If drSqlServer.Read() Then
MsgBox("此仓库信息已在其它地方引用,不可删除!", MsgBoxStyle.Information)
Else
MsgBox("删除完毕", MsgBoxStyle.Information)
End If
drSqlServer.Close()
freshData()
End If
End Sub
'显示详细的资料
Private Sub lstWarehouse_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstWarehouse.Click
txtWarehouseID.Text = lstWarehouse.SelectedItems(0).SubItems(0).Text
txtWarehouseName.Text = lstWarehouse.SelectedItems(0).SubItems(1).Text
txtDescr.Text = lstWarehouse.SelectedItems(0).SubItems(2).Text
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
If strCommand = "add" Then
txtWarehouseID.Text = ""
txtWarehouseName.Text = ""
txtDescr.Text = ""
btnAdd.Enabled = True
btnUpdate.Enabled = True
btnDel.Enabled = True
txtWarehouseName.Enabled = False
txtDescr.Enabled = False
ElseIf strCommand = "update" Then
btnAdd.Enabled = True
btnUpdate.Enabled = True
btnDel.Enabled = True
txtWarehouseName.Enabled = False
txtDescr.Enabled = False
Else
Me.Close()
End If
strCommand = ""
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -