📄 frmproduct.vb
字号:
Me.txtPModel.Size = New System.Drawing.Size(320, 21)
Me.txtPModel.TabIndex = 46
Me.txtPModel.Text = ""
'
'Label8
'
Me.Label8.ForeColor = System.Drawing.Color.Red
Me.Label8.Location = New System.Drawing.Point(256, 8)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(400, 24)
Me.Label8.TabIndex = 47
Me.Label8.Text = "前面带※的必须填写!"
'
'frmProduct
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(440, 182)
Me.Controls.Add(Me.Label8)
Me.Controls.Add(Me.txtPModel)
Me.Controls.Add(Me.txtPName)
Me.Controls.Add(Me.txtFId)
Me.Controls.Add(Me.txtPId)
Me.Controls.Add(Me.Label7)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.bunUpdate)
Me.Controls.Add(Me.bunNext)
Me.Controls.Add(Me.bunCancel)
Me.Controls.Add(Me.bunSave)
Me.Controls.Add(Me.bunSearch)
Me.Controls.Add(Me.bunDelete)
Me.Controls.Add(Me.bunAdd)
Me.Controls.Add(Me.bunPrevious)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frmProduct"
Me.Text = "商品数据表"
Me.ResumeLayout(False)
End Sub
#End Region
Private myDataAdapter As New SqlClient.SqlDataAdapter
Private myDataReader As SqlClient.SqlDataReader
Private myDataSet As DataSet = New DataSet("Product")
Private TableName As String
Private myIndex As Integer = 0
Private RowsMax As Integer
Private Sub Pshowfield()
Dim currRows() As DataRow = myDataSet.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
Dim myRow As DataRow = currRows(myIndex)
txtPId.Text = myRow(0)
txtFId.Text = myRow(1)
txtPName.Text = myRow(2)
txtPModel.Text = myRow(3)
End Sub
Private Sub bunCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunCancel.Click
On Error GoTo ErrorHandle
If RowsMax < 0 Then
txtPId.Text = ""
txtFId.Text = ""
txtPName.Text = ""
txtPModel.Text = ""
Exit Sub
End If
Pshowfield()
Exit Sub
ErrorHandle:
ShowErr()
End Sub
Private Sub bunDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunDelete.Click
On Error GoTo ErrorHandle
If RowsMax < 0 Then
MsgBox("库中没有可删除的记录!", , "商品数据表")
Exit Sub
End If
If MsgBox("是否删除?", 36, "提示") = vbYes Then
Dim myRow As DataRow = myDataSet.Tables(0).Rows(myIndex)
Dim strsql As String = "delete from product where p_id='" & myRow("p_id") & "'"
Dim mycommand As New SqlClient.SqlCommand(strsql, db)
db.Open()
mycommand.ExecuteNonQuery()
db.Close()
myRow.Delete()
myDataSet.AcceptChanges()
RowsMax = RowsMax - 1
If RowsMax >= 0 Then
myIndex = myIndex - 1
Pshowfield()
Exit Sub
Else
txtPId.Text = ""
txtPName.Text = ""
txtFId.Text = ""
txtPModel.Text = ""
bunPrevious.Enabled = False
bunDelete.Enabled = False
bunSearch.Enabled = False
bunSave.Enabled = False
bunNext.Enabled = False
Exit Sub
End If
Else
Exit Sub
End If
Exit Sub
ErrorHandle:
ShowErr()
End Sub
Private Sub bunNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunNext.Click
On Error Resume Next
If myIndex < RowsMax Then
myIndex = myIndex + 1
End If
Pshowfield()
End Sub
Private Sub bunPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunPrevious.Click
On Error Resume Next
If myIndex > 0 Then
myIndex = myIndex - 1
End If
Pshowfield()
End Sub
Private Sub bunSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunSave.Click
On Error GoTo ErrorHandle
Dim myRow As DataRow = myDataSet.Tables(0).Rows(myIndex)
myRow("p_id") = txtPId.Text
myRow("f_id") = txtFId.Text
myRow("p_name") = txtPName.Text
myRow("p_model") = txtPModel.Text
myDataSet.AcceptChanges()
Dim strsql As String = "update product set f_id='" & myRow("f_id") & "', p_name='" & myRow("p_name") & "', p_model=" & myRow("p_model") & "' where p_id='" & myRow("p_id") & "'"
Dim mycommand As New SqlClient.SqlCommand(strsql, db)
db.Open()
mycommand.ExecuteNonQuery()
db.Close()
MsgBox("已经保存修改", , "商品数据表")
Exit Sub
ErrorHandle:
ShowErr()
End Sub
Private Sub bunSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunSearch.Click
On Error GoTo ErrorHandle
Dim IDQuery As String
Dim NameQuery As String
Dim myRow As DataRow
myIndex = 0
IDQuery = InputBox("输入要搜索的商品编号:", "按商品ID搜索")
Dim currRows() As DataRow = myDataSet.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
For Each myRow In currRows
If myRow("p_id") Like "*" & LCase(IDQuery) & "*" Then
Pshowfield()
Exit Sub
Else
myIndex = myIndex + 1
End If
Next
MsgBox("没有找到符合条件的记录", , "商品数据表")
Exit Sub
Exit Sub
ErrorHandle:
ShowErr()
End Sub
Private Sub frmFactory_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
ShowStatus("数据管理--", "商品数据表")
End Sub
Private Sub frmFactory_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
Me.Dispose()
Me.Close()
ShowStatus("", "")
ProductTableOpened = False
TableMenuEnable()
End Sub
Private Sub frmProduct_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
TableName = CurrentTable
Dim strSelectProduct As String = "select * from Product"
Dim cmdSelectProduct As New SqlClient.SqlCommand(strSelectProduct, db)
myDataAdapter.SelectCommand = cmdSelectProduct
Dim xx As SqlCommandBuilder = New SqlCommandBuilder(myDataAdapter)
db.Open()
myDataAdapter.Fill(myDataSet)
db.Close()
bunAdd.Enabled = False
Dim currRows() As DataRow = myDataSet.Tables(0).Select(Nothing, Nothing, DataViewRowState.CurrentRows)
RowsMax = currRows.Length - 1
If RowsMax < 0 Then
myIndex = -1
MsgBox("数据库中没有记录", , "商品数据表")
bunPrevious.Enabled = False
bunDelete.Enabled = False
bunSearch.Enabled = False
bunSave.Enabled = False
bunNext.Enabled = False
Else
Pshowfield()
End If
End Sub
Private Sub bunUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bunUpdate.Click
db.Open()
myDataAdapter.Update(myDataSet)
db.Close()
MsgBox("已经更新到数据库", , "商品数据表")
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -