|
生产管理系统.rar
(107.68 KB, 下载次数: 30)
我出现的问题是当我删除子节点时没有删除数据表的数据,添加子节点时好像会多一个,不知道怎么回事,请高手帮我修改一下
代码如下 :
Private Sub 添加为子级_Click()
On Error GoTo Err_添加为子级_Click
Set Rs = New ADODB.Recordset
Me.twvMStruct.LineStyle = tvwTreeLines
If IsNull(Me![物料ID]) = True Then
MsgBox "请输入 物料ID,它不可以为空!", vbOKOnly, "输入物料ID"
Me![物料ID].SetFocus
ElseIf IsNull(Me![名称]) = True Then
MsgBox "请输入 名称,它不可以为空!", vbOKOnly, "输入名称"
Me![名称].SetFocus
ElseIf IsNull(Me![需要数量]) = True Then
MsgBox "请输入 需要数量,它不可以为空!", vbOKOnly, "输入需要数量"
Me![需要数量].SetFocus
Else
'判断待添加的节点名称是否已经存在
For i = 1 To twvMStruct.Nodes.Count
If twvMStruct.Nodes(i).Selected Then
Set MSNode = Me.twvMStruct.Nodes.Add(Me.twvMStruct.Nodes(i).Key, tvwChild, Me![名称], Me![名称])
Me.twvMStruct.Nodes(i).Expanded = True
STemp = "select * from 物料结构"
Rs.Open STemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Rs.MoveFirst
For j = 1 To Rs.RecordCount
'判断被选中物料节点的节点值与数据集中名称 是否相等
If Rs("名称") = Me.twvMStruct.Nodes(i).Key Then
'如果相等,则把当前数据集指针所指向的记录字段值赋予strMSG变量组
strMSG(0) = Rs("物料ID")
strMSG(1) = Rs("名称")
strMSG(2) = Rs("级别")
'退出for next 循环语句
Exit For
Else
'如果不相等,则把记录指针移到下一条记录
Rs.MoveNext
End If
Next j
Rs.AddNew
'把strMSG变量组中的值赋予新添加记录对应的字段中
Rs("上级ID") = strMSG(0)
Rs("上级名称") = strMSG(1)
Rs("物料ID") = Me![物料ID]
Rs("名称") = Me![名称]
Rs("级别") = strMSG(2) + 1
Rs("需要数量") = Me![需要数量]
Rs("领料车间") = Me![领料车间]
Rs("领料库房") = Me![领料库房]
Rs("审核日期") = Me![审核日期]
Rs("备注") = Me![备注]
Rs.Update
End If
Next i
Me.twvMStruct.Refresh
End If
Set Rs = Nothing
Exit_添加为子级_Click:
Exit Sub
Err_添加为子级_Click:
MsgBox Err.Description
Resume Exit_添加为子级_Click
End Sub
Private Sub 删除节点_Click()
On Error GoTo Err_删除节点_Click
Set Rs = New ADODB.Recordset
STemp = "select * from 物料结构"
Rs.Open STemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
For i = 1 To twvMStruct.Nodes.Count
If twvMStruct.Nodes(i).Selected Then
twvMStruct.Nodes.Remove twvMStruct.SelectedItem.Index
Rs.MoveFirst
For j = 1 To Rs.RecordCount
MsgBox j
If Rs("名称") = Me.twvMStruct.Nodes(i).Key Then
Rs.Delete 1
j = Rs.RecordCount + 1
Else
Rs.MoveNext
End If
Next j
End If
Next i
Set Rs = Nothing
Exit_删除节点_Click:
Exit Sub
Err_删除节点_Click:
MsgBox Err.Description
Resume Exit_删除节点_Click
End Sub
|
|