goods.vb
来自「本文件为进销存管理系统的代码 在VB的环境下运行 用比较简单的结构完成的」· VB 代码 · 共 179 行
VB
179 行
Imports System.Data.SqlClient
Public Class Goods
'显示货品类别
Public Shared Sub ShowGoodsGroup(ByVal tv As TreeView)
Try
Dim x(ParentGroupCount()) As Integer '建立与表中行数相同大小的数组
Dim i As Integer = 0
Dim con As New SqlConnection(ConString)
Dim cmd As New SqlCommand("ShowParentGroup", con)
cmd.CommandType = CommandType.StoredProcedure
con.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader
'添加根节点
tv.Nodes.Add("电脑")
'添加父节点
For Each tn As TreeNode In tv.Nodes
While reader.Read
tn.Nodes.Add(reader(1) & "-" & reader(0))
x(i) = Val(reader(1)) '取出每个父类的ID按顺序存如数组,以便子类的查找
i = i + 1
End While
Next
reader.Close()
con.Close()
i = 0 '按顺序取出父ID,因为子节点是按顺序添加的
'添加子节点
For Each tn As TreeNode In tv.Nodes
For Each tn2 As TreeNode In tn.Nodes
Dim cmd2 As New SqlCommand("ShowChildGroupByID", con)
cmd2.CommandType = CommandType.StoredProcedure
cmd2.Parameters.Add("@ParentGroup", x(i)) '以父节类ID为参数,查找其子类
con.Open()
Dim reader2 As SqlDataReader = cmd2.ExecuteReader
While reader2.Read
tn2.Nodes.Add(reader2(1) & "-" & reader2(0))
End While
i = i + 1
reader2.Close()
con.Close()
Next
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "错误")
End Try
End Sub
'求父类中类别的数目
Shared Function ParentGroupCount() As Integer
Try
Dim t As Integer = 0 '数组大小
Dim con As New SqlConnection(ConString)
Dim cmd As New SqlCommand("ShowParentGroup", con)
cmd.CommandType = CommandType.StoredProcedure
con.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader
While reader.Read
t = t + 1
End While
reader.Close()
con.Close()
Return t
Catch ex As Exception
MessageBox.Show(ex.Message, "错误")
End Try
End Function
'显示父类
'根据存储过程,利用users.showAdmin实现
'显示子类,根据父类ID
Public Shared Sub ShowCGroup(ByVal cmb As ComboBox, ByVal i As Integer)
Try
Dim con As New SqlConnection(ConString)
Dim cmd As New SqlCommand("ShowChildGroupByID", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@ParentGroup", i)
con.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader
While reader.Read
cmb.Items.Add(reader(0))
End While
reader.Close()
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "错误")
End Try
End Sub
'添加父类
Public Shared Sub AddParentGroup(ByVal name As String)
Try
Dim con As New SqlConnection(ConString)
Dim cmd As New SqlCommand("insert_bssTable_GoodsParentGroups_1", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@GoodsGroupName", name)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "错误")
End Try
End Sub
'添加子类
Public Shared Sub AddChildGroup(ByVal name As String, ByVal parentgroup As String)
Try
Dim con As New SqlConnection(ConString)
Dim cmd As New SqlCommand("insert_bssTable_GoodsChildGroups_1", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@GroupName", name)
cmd.Parameters.Add("@ParentsGroup", parentgroup)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "错误")
End Try
End Sub
'查找货品ID
Public Shared Function FindGoosID(ByVal name As String) As String
Try
Dim con As New SqlConnection(ConString)
Dim cmd As New SqlCommand("FindGoodsID", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@GoodsName", name)
con.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader
While reader.Read
Return reader(0)
End While
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "错误")
End Try
End Function
'检查货品号
'利用stock.CheckID实现
'添加,修改货品信息
Public Shared Sub AddModGoods(ByVal a() As String)
Try
Dim con As New SqlConnection(ConString)
Dim cmd As New SqlCommand(storename, con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@GoodsID", a(0))
cmd.Parameters.Add("@GoodsName", a(1))
cmd.Parameters.Add("@GoodsPGroup", a(2))
cmd.Parameters.Add("@GoodsCGroup", a(3))
cmd.Parameters.Add("@GoodsMax", a(4))
cmd.Parameters.Add("@GoodsMin", a(5))
cmd.Parameters.Add("@GoodsRemark", a(6))
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "错误")
End Try
End Sub
'删除货品信息
Public Shared Sub DelGoods(ByVal id As String)
Try
Dim con As New SqlConnection(ConString)
Dim cmd As New SqlCommand(storename, con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@GoodsID", id)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "错误")
End Try
End Sub
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?