Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim dbobj As New ConnSqlServer.db
Dim Strno As String = txtNo.Text
Dim sql As String = "Delete from Strdrug where Strno='" & Strno & "'"
Dim strSql As String = "select * from Strdrug"
Dim ds As New DataSet
Dim strSql1 As String = "select Strno from Strdrug where Strno = '" & Me.txtNo.Text & "'"
Dim myReturn As DialogResult
Dim dr As System.Data.SqlClient.SqlDataReader
dr = dbobj.DataReader(strSql1)
If dr.Read() Then
If txtNo.Text <> "" Then
myReturn = Windows.Forms.MessageBox.Show("确定要删除资料吗?", "删除资料", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
If myReturn = Windows.Forms.DialogResult.OK Then
dbobj.RunSql(sql)
MessageBox.Show("删除成功")
dbobj.ReturnDataSet(strSql, ds)
Me.DataGridView1.DataSource = ds.Tables(0)
Me.txtName.Text = ""
Me.txtNo.Text = ""
Me.txtAddress.Text = ""
Me.txtPrice.Text = ""
Me.txtNumber.Text = ""
Me.txtFun.Text = ""
Me.txtType.Text = ""
End If
Else
MessageBox.Show("编号不能为空!")
End If
Else
MessageBox.Show("无此编号")
End If
End Sub
Private Sub btnUpdata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdata.Click
Dim dbobj As New ConnSqlServer.db
Dim Strno As String = txtNo.Text
Dim sql As String = "Update Strdrug Set Strname='" & Me.txtName.Text & "', Strfun='" & Me.txtFun.Text & "', Strnumber='" & Me.txtNumber.Text & "', Strprice='" & Me.txtPrice.Text & "',Strtype='" & Me.txtType.Text & "',Straddress='" & Me.txtAddress.Text & "' where Strno='" & Strno & "'"
Dim dr As System.Data.SqlClient.SqlDataReader
Dim myReturn As DialogResult
Dim ds As New DataSet
dr = dbobj.DataReader(sql)
Dim strSql As String = "select * from Strdrug"
Dim strSql1 As String = "select Strno from Strdrug where Strno = '" & Me.txtNo.Text & "'"
dr = dbobj.DataReader(strSql1)
If dr.Read() Then
If txtNo.Text <> "" And txtName.Text <> "" Then
myReturn = Windows.Forms.MessageBox.Show("确定要修改资料吗?", "修改资料", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
If myReturn = Windows.Forms.DialogResult.OK Then
dbobj.RunSql(sql)
MessageBox.Show("修改成功")
dbobj.ReturnDataSet(strSql, ds)
Me.DataGridView1.DataSource = ds.Tables(0)
End If
Else
MessageBox.Show("编号和药品名称不能为空!")
End If
Else
MessageBox.Show("无此编号")
End If
End Sub
Private Sub btnCancle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancle.Click
Me.txtName.Text = ""
Me.txtNo.Text = ""
Me.txtFun.Text = ""
Me.txtNumber.Text = ""
Me.txtPrice.Text = ""
Me.txtType.Text = ""
Me.txtAddress.Text = ""
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim strSql As String = "select * from Strdrug where Strname like '%" & Me.txtName.Text & "%'"
Dim ds As New DataSet
Dim dbobj As New ConnSqlServer.db
Dim dr As System.Data.SqlClient.SqlDataReader
dr = dbobj.DataReader(strSql)
If dr.Read() And Me.txtName.Text <> "" Then
dbobj.ReturnDataSet(strSql, ds)
Me.DataGridView1.DataSource = ds.Tables(0)
www.751com.cn
Private Sub DataGridView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick
Dim i As Integer
i = Me.DataGridView1.CurrentRow.Index
Me.txtNo.Text = Trim(DataGridView1.Item(0, i).Value)
Me.txtName.Text = Trim(DataGridView1.Item(1, i).Value)
Me.txtFun.Text = Trim(DataGridView1.Item(2, i).Value)
Me.txtNumber.Text = Trim(DataGridView1.Item(3, i).Value)
Me.txtPrice.Text = Trim(DataGridView1.Item(4, i).Value)
Me.txtType.Text = Trim(DataGridView1.Item(5, i).Value)
Me.txtAddress.Text = Trim(DataGridView1.Item(6, i).Value)
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim dbobj As New ConnSqlServer.db
Dim sql As String = "Insert into Strdrug Values('" & Me.txtNo.Text & "','" & Me.txtName.Text & "','" & Me.txtFun.Text & "','" & Me.txtNumber.Text & "','" & Me.txtPrice.Text & "','" & Me.txtType.Text & "','" & Me.txtAddress.Text & "')"
Dim strSql1 As String = "select Strno from Strdrug where Strno = '" & Me.txtNo.Text & "'"
Dim myReturn As DialogResult
Dim ds As New DataSet
Dim dr As System.Data.SqlClient.SqlDataReader
dr = dbobj.DataReader(strSql1)
If Not dr.Read() Then
If txtNo.Text <> "" And txtName.Text <> "" Then
myReturn = Windows.Forms.MessageBox.Show("确定要添加资料吗?", "添加资料", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
If myReturn = Windows.Forms.DialogResult.OK Then
dbobj.RunSql(sql)
MessageBox.Show("添加成功")
strSql1 = "select * from Strdrug"
dbobj.ReturnDataSet(strSql1, ds)
Me.DataGridView1.DataSource = ds.Tables(0)
End If
Else
MessageBox.Show("编号或药品名称不能为空!")
End If
Else
MessageBox.Show("此编号已存在")
End If
End Sub
End Class