Public Class dal_DealStudentInfo
Public Function AddRecord(ByVal RecInfo As Student) As Boolean
'……
'连接数据库
'……
'……
Try
'SQL语句向数据库中写入数据
'……
Return True
Catch
Return False
Finally
'关闭数据库
End Try
End Function
Public Function IsExist() As Boolean
'查询数据库,如果存在该卡,则返回True,不存在则返回false
If '存在
Return True
Else
Return False
End If
End Function
End Class
Public Class bll_ControlStudent
Public Function AddStudent(ByVal student As Student) As String
Dim DealStudent As New dal_DealStudentInfo
If Not (DealStudent.IsExist) Then
If DealStudent.AddRecord(student) Then
Return "注册成功"
Else
Return "注册失败"
End If
Else
Return "该卡已经存在,请重新输入卡号"
End If
End Function
End Class
Public Class frmRegister
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Dim strMsg As String
Dim student As New Student(Trim(txtCardNo.Text), Trim(txtStuName.Text), Trim(txtStuNo.Text), Trim(txtDepartment.Text), Val(txtMoney.Text))
Dim ControlStudent As New bll_ControlStudent
strMsg = ControlStudent.AddStudent(student)
MessageBox.Show(strMsg)
End Sub
Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class