📄 frmbilllist.frm
字号:
Height = 255
Left = 3720
TabIndex = 8
Top = 1680
Width = 855
End
Begin VB.Label Label3
Caption = "父项编号"
Height = 255
Left = 6600
TabIndex = 6
Top = 840
Width = 855
End
Begin VB.Label Label2
Caption = "物料名称"
Height = 255
Left = 5280
TabIndex = 4
Top = 840
Width = 855
End
Begin VB.Label Label1
Caption = "物料编号"
Height = 255
Left = 3600
TabIndex = 2
Top = 840
Width = 855
End
End
Attribute VB_Name = "frmBillList"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private bAdd As Boolean
Private bLevel As Boolean
'InitTree是用递归方法初始化TreeView控件的节点
Private Sub InitTree(ByRef ndParentNode As Node, ByVal sParentIndex As String)
Dim db As New DataBases
Dim rs As Recordset
Dim ndNew As Node
Set rs = db.RunSelectSQL("SELECT * FROM 物料清单 WHERE 父项编号='" + sParentIndex + "'")
While (Not rs.EOF)
Set ndNew = trvList.Nodes.Add(ndParentNode, 4, , rs("物料编号"))
InitTree ndNew, rs("物料编号")
rs.MoveNext
Wend
db.CloseConn
End Sub
Private Sub btnSearch_Click()
Dim frm As New frmSelectProduct
frm.Show vbModal
End Sub
Private Sub Form_Load()
Dim db As New DataBases
Dim rs As Recordset
Dim ndNew As Node
Set rs = db.RunSelectSQL("SELECT * FROM 物料清单 WHERE 父项编号='0'")
While Not rs.EOF
Set ndNew = trvList.Nodes.Add(, , , rs("物料编号"))
InitTree ndNew, rs("物料编号")
rs.MoveNext
Wend
SetToolBarState (True)
End Sub
Private Sub trvList_NodeClick(ByVal Node As MSComctlLib.Node)
Dim db As New DataBases
Dim rs As Recordset
Dim strSQL As String
strSQL = "select a.物料编号,物料名称,计量单位,"
strSQL = strSQL + "规格型号,计划类别,品牌,颜色,"
strSQL = strSQL + "进货提前期,a.低层码,生产车间,父项编号,"
strSQL = strSQL + "需要数量,领料车间,领料库房,损耗率,审核日期 from 物料清单 as a ,"
strSQL = strSQL + "物料主文件 as b where a.物料编号 = b.物料编号"
strSQL = strSQL + " and a.物料编号= '" + trvList.SelectedItem.Text + "'"
Set rs = db.RunSelectSQL(strSQL)
txbID.Text = rs("物料编号")
If rs("物料名称").ActualSize > 0 Then
txbName.Text = rs("物料名称")
End If
If rs("父项编号").ActualSize > 0 Then
txbPID.Text = rs("父项编号")
End If
If rs("需要数量").ActualSize > 0 Then
txbCount.Text = rs("需要数量")
End If
If rs("低层码").ActualSize > 0 Then
txbCode.Text = rs("低层码")
End If
If rs("领料车间").ActualSize > 0 Then
txbWorkShop.Text = rs("领料车间")
End If
If rs("领料库房").ActualSize > 0 Then
txbDepot.Text = rs("领料库房")
End If
If rs("损耗率").ActualSize > 0 Then
txbRate.Text = rs("损耗率")
End If
If rs("审核日期").ActualSize > 0 Then
txbCheckDate.Text = rs("审核日期")
End If
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Dim db As New DataBases
Dim rs As Recordset
If StrComp(Button.Key, "btnAddChild") = 0 Then '增加子节点
Set rs = db.RunSelectSQL("select * from 物料清单 where 物料编号='" + Trim(trvList.SelectedItem.Text) + " '")
txbPID.Text = rs("物料编号")
bAdd = True
bLevel = False
Clear
SetToolBarState (False)
btnSearch.Enabled = True
ElseIf StrComp(Button.Key, "btnAdd") = 0 Then '同级节点
Set rs = db.RunSelectSQL("select * from 物料清单 where 物料编号='" + Trim(trvList.SelectedItem.Text) + " '")
txbPID.Text = rs("父项编号")
bAdd = True
bLevel = True
Clear
SetToolBarState (False)
btnSearch.Enabled = True
ElseIf StrComp(Button.Key, "btnModify") = 0 Then '修改
bAdd = False
SetToolBarState (False)
MsgBox "物料编号,物料名称等请在物料主文件中修改!", , "生成管理系统"
ElseIf StrComp(Button.Key, "btnDelete") = 0 Then '删除
DeleteData
ElseIf StrComp(Button.Key, "btnSave") = 0 Then '保存
If bAdd = False Then
SaveForUpdate
SetToolBarState (True)
btnSearch.Enabled = True
Else
SaveForAdd
SetToolBarState (True)
btnSearch.Enabled = True
End If
ElseIf StrComp(Button.Key, "btnCancel") = 0 Then '取消
btnSearch.Enabled = True
SetToolBarState (True)
ElseIf StrComp(Button.Key, "btnExit") = 0 Then '退出
Hide
End If
End Sub
'该函数用来清空输入框
Private Sub Clear()
Me.txbCheckDate.Text = ""
Me.txbCode.Text = ""
Me.txbCount.Text = ""
Me.txbDepot.Text = ""
Me.txbID.Text = ""
Me.txbName.Text = ""
Me.txbRate.Text = ""
Me.txbWorkShop = ""
End Sub
'该函数用来改变ToolBar的状态
Private Sub SetToolBarState(ByVal bState As Boolean)
Toolbar1.Buttons("btnAddChild").Enabled = bState
Toolbar1.Buttons("btnAdd").Enabled = bState
Toolbar1.Buttons("btnModify").Enabled = bState
Toolbar1.Buttons("btnDelete").Enabled = bState
Toolbar1.Buttons("btnSave").Enabled = Not bState
Toolbar1.Buttons("btnCancel").Enabled = Not bState
End Sub
'该函数实现删除操作
Private Sub DeleteData()
If Not IsNull(trvList.SelectedItem) Then
'不能删除具有子节点的节点
If trvList.SelectedItem.Child Is Nothing Then
If MsgBox("你确认删除此数据?", vbYesNo, "删除") = vbYes Then
'生成SQL语句更新数据
Dim db As New DataBases
Dim strSQL As String
strSQL = "delete from 物料清单 "
strSQL = strSQL + " where 物料编号='" + Trim(txbID.Text) + "'"
db.RunSelectSQL (strSQL)
db.CloseConn
trvList.Nodes.Clear
Form_Load
' trvList.Nodes.Remove (trvList.SelectedItem)
End If
Else
MsgBox "请先删除该项的全部子项", , "生成管理系统"
End If
End If
End Sub
'该函数实现增加操作
Private Sub SaveForAdd()
'获得单击的节点的数据
Dim db As New DataBases
Dim rs As Recordset
'生成SQL语句插入新的数据
Dim strSQL As String
strSQL = "insert into 物料清单(父项编号,物料编号,需要数量,"
strSQL = strSQL + "领料车间,领料库房,损耗率,"
strSQL = strSQL + "审核日期,低层码) values ('"
strSQL = strSQL + Trim(txbPID.Text) + "','" + Trim(txbID.Text) + "','"
strSQL = strSQL + Trim(txbCount.Text) + "','"
strSQL = strSQL + Trim(txbWorkShop.Text) + "','"
strSQL = strSQL + Trim(txbDepot.Text) + "','"
strSQL = strSQL + Trim(txbRate.Text) + "','"
strSQL = strSQL + Trim(txbCheckDate.Text) + "','"
strSQL = strSQL + Trim(txbCode.Text) + "')"
db.RunSelectSQL (strSQL)
db.CloseConn
trvList.Nodes.Clear
Dim ndNew As Node
Set rs = db.RunSelectSQL("SELECT * FROM 物料清单 WHERE 父项编号='0'")
While Not rs.EOF
Set ndNew = trvList.Nodes.Add(, , , rs("物料编号"))
InitTree ndNew, rs("物料编号")
rs.MoveNext
Wend
End Sub
'该函数实现修改操作
Private Sub SaveForUpdate()
'更新数据表
'获得单击的节点的数据
Dim sID As String
sID = trvList.SelectedItem.Text
'生成SQL语句更新数据
Dim db As New DataBases
Dim strSQL As String
strSQL = "update 物料清单 set 需要数量='"
strSQL = strSQL + Trim(txbCount.Text) + "',"
strSQL = strSQL + "领料车间='" + Trim(txbWorkShop.Text) + "',"
strSQL = strSQL + "领料库房='" + Trim(Me.txbDepot.Text) + "',"
strSQL = strSQL + "损耗率='" + Trim(Me.txbRate.Text) + "',"
strSQL = strSQL + "审核日期='" + Trim(Me.txbCheckDate.Text) + "'"
strSQL = strSQL + " where 物料编号='" + Trim(sID) + "'"
db.RunSelectSQL (strSQL)
db.CloseConn
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -