📄 datamange.vb
字号:
Public Class DataManger
Private Sub FormDatabase_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: 这行代码将数据加载到表“Preg_FileDataSet.User”中。您可以根据需要移动或移除它。
Me.UserTableAdapter.Fill(Me.Preg_FileDataSet.User)
'TODO: 这行代码将数据加载到表“Preg_FileDataSet.Pregnant”中。您可以根据需要移动或移除它。
Me.PregnantTableAdapter.Fill(Me.Preg_FileDataSet.Pregnant)
'TODO: 这行代码将数据加载到表“Preg_FileDataSet.User”中。您可以根据需要移动或移除它。
Me.UserTableAdapter.Fill(Me.Preg_FileDataSet.User)
'TODO: 这行代码将数据加载到表“Preg_FileDataSet.Pregnant”中。您可以根据需要移动或移除它。
Me.PregnantTableAdapter.Fill(Me.Preg_FileDataSet.Pregnant)
'TODO: 这行代码将数据加载到表“Preg_FileDataSet.User”中。您可以根据需要移动或移除它。
Me.UserTableAdapter.Fill(Me.Preg_FileDataSet.User)
'TODO: 这行代码将数据加载到表“Preg_FileDataSet.Pregnant”中。您可以根据需要移动或移除它。
Me.PregnantTableAdapter.Fill(Me.Preg_FileDataSet.Pregnant)
'TODO: 这行代码将数据加载到表“Preg_FileDataSet.Hospital”中。您可以根据需要移动或移除它。
End Sub
Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.Click
Try
If Me.DataGridView1.CurrentRow.Cells.Item(0).Value.Equals(System.DBNull.Value) Then
Me.yunfuID.Text = ""
Me.yunfuming.Text = ""
Me.chuangweihao.Text = ""
Me.zhuyuanhao.Text = ""
Me.yunzhou.Text = ""
Me.gp.Text = ""
Me.nianling.Text = ""
Me.shuoming.Text = ""
Else
Me.yunfuID.Text = Me.DataGridView1.CurrentRow.Cells.Item(0).Value
Me.yunfuming.Text = Me.DataGridView1.CurrentRow.Cells.Item(1).Value
Me.chuangweihao.Text = Me.DataGridView1.CurrentRow.Cells.Item(2).Value
Me.zhuyuanhao.Text = Me.DataGridView1.CurrentRow.Cells.Item(3).Value
Me.yunzhou.Text = Me.DataGridView1.CurrentRow.Cells.Item(4).Value
Me.gp.Text = Me.DataGridView1.CurrentRow.Cells.Item(5).Value
Me.nianling.Text = Me.DataGridView1.CurrentRow.Cells.Item(6).Value
Me.shuoming.Text = Me.DataGridView1.CurrentRow.Cells.Item(7).Value
End If
Catch ex As Exception
Exit Sub
End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim mRes As MsgBoxResult = MessageBox.Show("Are you sure to delete this record?", "Record deleting ", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If mRes = MsgBoxResult.No Then
Exit Sub
Else
Dim MySQL As String = Login.MySqlDataBaseConnectionString
Dim MyDataCon As New Odbc.OdbcConnection(MySQL)
MyDataCon.Open()
Try
Dim MySQLStr As String = "Delete from [pregnant] where preg_ID=" & CInt(Me.yunfuID.Text)
Dim MyComm As Odbc.OdbcCommand = MyDataCon.CreateCommand
MyComm.CommandText = MySQLStr
MyComm.ExecuteNonQuery()
If MyDataCon.State = ConnectionState.Open Then
MyDataCon.Close()
End If
Dim Mytable As New Preg_fileDataSet.PregnantDataTable
Me.PregnantTableAdapter.Fill(Mytable)
Me.DataGridView1.DataSource = Mytable
Me.DataGridView1.Refresh()
Catch ex As Exception
MessageBox.Show("The operation achieved failure! Please check if you have followed the right step!", "Error", MessageBoxButtons.OK)
End Try
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mRes As MsgBoxResult = MessageBox.Show("To add new data, please confirm the information you have finished is correct. Continue or not?", "Adding", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Dim result As String = ""
If mRes = MsgBoxResult.No Then
Exit Sub
Else
Dim MySQL As String = Login.MySqlDataBaseConnectionString
Dim MyDataCon As New Odbc.OdbcConnection(MySQL)
MyDataCon.Open()
Dim MySQLStr As String = "select max(Preg_ID) from [pregnant]"
Dim MyComm As Odbc.OdbcCommand = MyDataCon.CreateCommand
MyComm.CommandText = MySQLStr
Try
result = MyComm.ExecuteScalar
Catch ex As Exception
result = "100000"
End Try
result += 1 '计算序号ID
MySQLStr = "insert into [pregnant] values (" & result & ",'" & Me.yunfuming.Text & "','" & Me.chuangweihao.Text & "','"
MySQLStr += Me.zhuyuanhao.Text & "','" & Me.yunzhou.Text & "','" & Me.gp.Text & "','" & Me.nianling.Text & "','" & Me.shuoming.Text & "')"
MyComm.CommandText = MySQLStr
MyComm.ExecuteNonQuery()
If MyDataCon.State = ConnectionState.Open Then
MyDataCon.Close()
End If
Dim Mytable As New Preg_fileDataSet.PregnantDataTable
Me.PregnantTableAdapter.Fill(Mytable)
Me.DataGridView1.DataSource = Mytable
Me.DataGridView1.Refresh()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim mRes As MsgBoxResult = MessageBox.Show("To modify the data, please confirm the information you have finished is correct. Continue or not?", "Updating", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If mRes = MsgBoxResult.No Then
Exit Sub
Else
Dim MySQL As String = Login.MySqlDataBaseConnectionString
Dim MyDataCon As New Odbc.OdbcConnection(MySQL)
MyDataCon.Open()
Try
Dim MySQLStr As String = "update [pregnant] set Preg_Name='" & Me.yunfuming.Text & "',Preg_BedID='" & Me.chuangweihao.Text & "',Preg_HosID='" & Me.zhuyuanhao.Text & "',Preg_Week='" & Me.yunzhou.Text & "',Preg_GP='" & Me.gp.Text & "',Preg_Age='" & Me.nianling.Text & "',Preg_Note='" & Me.shuoming.Text & "' where Preg_ID=" & CInt(Me.yunfuID.Text)
Dim MyComm As Odbc.OdbcCommand = MyDataCon.CreateCommand
MyComm.CommandText = MySQLStr
MyComm.ExecuteNonQuery()
If MyDataCon.State = ConnectionState.Open Then
MyDataCon.Close()
End If
Dim Mytable As New Preg_fileDataSet.PregnantDataTable
Me.PregnantTableAdapter.Fill(Mytable)
Me.DataGridView1.DataSource = Mytable
Me.DataGridView1.Refresh()
Catch ex As Exception
MessageBox.Show("The operation achieved failure! Please check whether you have followed the right step!", "Error", MessageBoxButtons.OK)
End Try
End If
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
Close()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim mRes As MsgBoxResult = MessageBox.Show("Are you sure to delete this record?", "Deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If mRes = MsgBoxResult.No Then
Exit Sub
Else
Dim MySQL As String = Login.MySqlDataBaseConnectionString
Dim MyDataCon As New Odbc.OdbcConnection(MySQL)
MyDataCon.Open()
Try
Dim MySQLStr As String = "Delete from [User] where User_ID=" & CInt(Me.TextBox1.Text)
Dim MyComm As Odbc.OdbcCommand = MyDataCon.CreateCommand
MyComm.CommandText = MySQLStr
MyComm.ExecuteNonQuery()
If MyDataCon.State = ConnectionState.Open Then
MyDataCon.Close()
End If
Dim Mytable As New Preg_fileDataSet.UserDataTable
Me.UserTableAdapter.Fill(Mytable)
Me.DataGridView2.DataSource = Mytable
Me.DataGridView2.Refresh()
Catch ex As Exception
MessageBox.Show("The operation achieved failure! Please check whether you have followed the right step!", "Error", MessageBoxButtons.OK)
End Try
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim mRes As MsgBoxResult = MessageBox.Show("To add new data, please confirm the information you have finished is correct. Continue or not?", "Adding record", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Dim result As String = ""
If mRes = MsgBoxResult.No Then
Exit Sub
Else
Dim MySQL As String = Login.MySqlDataBaseConnectionString
Dim MyDataCon As New Odbc.OdbcConnection(MySQL)
MyDataCon.Open()
Dim MySQLStr As String = "select max(User_ID) from [User]"
Dim MyComm As Odbc.OdbcCommand = MyDataCon.CreateCommand
MyComm.CommandText = MySQLStr
Try
result = MyComm.ExecuteScalar
Catch ex As Exception
result = "100000"
End Try
result += 1 '计算序号ID
MySQLStr = "insert into [User] values (" & result & ",'" & Me.TextBox2.Text & "','" & Me.TextBox4.Text & "','" & Me.ComboBox1.Text & "')"
MyComm.CommandText = MySQLStr
MyComm.ExecuteNonQuery()
If MyDataCon.State = ConnectionState.Open Then
MyDataCon.Close()
End If
Dim Mytable As New Preg_fileDataSet.UserDataTable
Me.UserTableAdapter.Fill(Mytable)
Me.UserTableAdapter.Update(Mytable)
Me.DataGridView2.DataSource = Mytable
Me.DataGridView2.Refresh()
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim mRes As MsgBoxResult = MessageBox.Show("To modify the data, please confirm the information you have finished is correct. Continue or not?", "Updating", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If mRes = MsgBoxResult.No Then
Exit Sub
Else
Dim MySQL As String = Login.MySqlDataBaseConnectionString
Dim MyDataCon As New Odbc.OdbcConnection(MySQL)
MyDataCon.Open()
Try
Dim MySQLStr As String = "update [User] set User_Name='" & Me.TextBox2.Text & "',User_Psw='" & Me.TextBox4.Text & "',User_Type='" & Me.ComboBox1.Text & "' where User_ID=" & CInt(Me.TextBox1.Text)
Dim MyComm As Odbc.OdbcCommand = MyDataCon.CreateCommand
MyComm.CommandText = MySQLStr
MyComm.ExecuteNonQuery()
If MyDataCon.State = ConnectionState.Open Then
MyDataCon.Close()
End If
Dim Mytable As New Preg_fileDataSet.UserDataTable
Me.UserTableAdapter.Fill(Mytable)
Me.DataGridView2.DataSource = Mytable
Me.DataGridView2.Refresh()
Catch ex As Exception
MessageBox.Show("The operation achieved failure! Please check whether you have followed the right step!", "Error", MessageBoxButtons.OK)
End Try
End If
End Sub
Private Sub DataGridView2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView2.Click
Try
If Me.DataGridView2.CurrentRow.Cells.Item(0).Value.Equals(System.DBNull.Value) Then
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
Me.TextBox4.Text = ""
Me.ComboBox1.Text = ""
Else
Me.TextBox1.Text = Me.DataGridView2.CurrentRow.Cells.Item(0).Value
Me.TextBox2.Text = Me.DataGridView2.CurrentRow.Cells.Item(1).Value
Me.TextBox4.Text = Me.DataGridView2.CurrentRow.Cells.Item(2).Value
Me.ComboBox1.Text = Me.DataGridView2.CurrentRow.Cells.Item(3).Value
End If
Catch ex As Exception
Exit Sub
End Try
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -