小区物业管理系统-数据库交互

Posted CaoPengCheng&

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了小区物业管理系统-数据库交互相关的知识,希望对你有一定的参考价值。

小区物业管理系统-数据库交互

UserDao 用户登录数据库交互

Imports System.Data.SqlClient
Imports System.Data.OleDb

'模块:UserDao
'作用:用户登录数据库交互
'@author:CaoPengCheng
Module UserDao
    Dim conn As String = sqlconn()
    Dim conn2 As String = sqlconn2()
    '方法:userSelectUsername();
    '作用:用于查询三个登录用户是否存在
    '参数:(username,table)
    '返回值:用户名是否存在于表中(int),1存在,否在不存在
    Public Function userSelectUsername(user As User)

        Dim f As Integer
        Try
            Dim objconn As New SqlConnection(conn2)
            Dim strsql1 As String = "select count(*) from " & user.tableGet() & "  where username='" & user.usernameGet() & "'"
            objconn.Open()
            Dim objcmd As New SqlCommand(strsql1, objconn)
            f = objcmd.ExecuteScalar
            objconn.Close()
            objcmd.Dispose()
        Catch ex As Exception
            MsgBox("userServletUsername" + ex.Message)
        End Try

        If (f > 0) Then
            Return 1
        Else
            Return 0
        End If
    End Function
    '方法:userSelectPassworld();
    '作用:用于三个登录用户的不同表的密码判断
    '参数:(username,table)
    '返回值:1密码正确
    Public Function userSelectPassworld(user As User)

        Dim f As Integer
        Try
            Dim objconn As New OleDbConnection(conn) '创建连接对象
            Dim objAdap As OleDbDataAdapter '创建适配对象
            Dim objDataSet As New DataSet '创建数据集对象
            Dim strsql As String = "select password from " & user.tableGet() & " where username='" & user.usernameGet() & "'"
            objAdap = New OleDbDataAdapter(strsql, conn)
            objDataSet.Reset() '清除数据集
            objAdap.Fill(objDataSet, "User") '第二个参数就是给这个虚拟表起个名字
            f = objDataSet.Tables("User").Rows(0).Item(0)
        Catch ex As Exception
            MsgBox("userServletPassworld" + ex.Message)
        End Try

        If (Int(user.passwordGet()) = f) Then
            Return 1
        Else
            Return 0
        End If
    End Function
    '方法:userSelect();
    '作用:用户表数据查询
    '参数:(username,table)
    '返回值:user
    Public Function userSelect(username As String, table As String)
        Dim user As New User()

        Try
            Dim objconn As New OleDbConnection(conn) '创建连接对象
            Dim objAdap As OleDbDataAdapter '创建适配对象
            Dim objDataSet As New DataSet '创建数据集对象

            Dim strsql As String = "select username,password from " & table & " where username='" & username & "'"

            objAdap = New OleDbDataAdapter(strsql, objconn)
            'MsgBox("1")
            objDataSet.Reset() '清除数据集
            'MsgBox("2")
            objAdap.Fill(objDataSet, "User") '第二个参数就是给这个虚拟表起个名字
            'MsgBox("3")
            user.usernameSet(Trim(objDataSet.Tables("User").Rows(0).Item(0)))
            user.passwordSet(Trim(objDataSet.Tables("User").Rows(0).Item(1)))
        Catch ex As Exception
            MsgBox("userSelect:" + ex.Message)
        End Try
        Return user
    End Function
    '方法:userUpdata();
    '作用:用户密码修改
    '参数:(user)
    Public Function userUpdata(user As User)
        ' MsgBox(user.tableGet())
        'MsgBox(user.passwordGet())
        'MsgBox(user.usernameGet())
        Try
            Dim strsql As String = "update " & user.tableGet() & " set password ='" & user.passwordGet() & "' where username ='" & user.usernameGet() & "'"
            Dim objconn As New SqlConnection(conn2)
            Dim objcmd As New SqlCommand(strsql, objconn)

            objconn.Open()
            objcmd.ExecuteNonQuery()

            MsgBox("修改成功!")

            objconn.Close()
        Catch ex As Exception
            MsgBox("userUpdata:" + ex.Message)
        End Try
        Return user
    End Function
    '方法:userInsert();
    '作用:用户密码修改
    '参数:(user)
    Public Function userInsert(user As User)
        Try
            Dim strsql As String = "insert " & user.tableGet() & " values ('" & user.usernameGet() & "',123);"
            Dim objconn As New SqlConnection(conn2)
            Dim objcmd As New SqlCommand(strsql, objconn)

            objconn.Open()
            objcmd.ExecuteNonQuery()

            'MsgBox("成功!")

            objconn.Close()
        Catch ex As Exception
            MsgBox("userInsert:" + ex.Message)
        End Try
        Return user
    End Function
    '方法:UserDelete();
    '作用:业主信息删除
    '参数:(proprietor)

    Public Sub UserDelete(pno As String)
        Try
            Dim strsql As String = "delete from User_Proprietor where username='" & pno & "'"
            Dim objconn As New SqlConnection(conn2)
            Dim objcmd As New SqlCommand(strsql, objconn)

            objconn.Open()
            objcmd.ExecuteNonQuery()
            'MsgBox("删除成功")
            objconn.Close()
        Catch ex As Exception
            MsgBox("UserDelete:" + ex.Message)
        End Try

    End Sub
    '方法:UserDeletePropetyManager();
    '作用:业主信息删除
    '参数:(proprietor)

    Public Sub UserDeletePropetyManager(pno As String)
        Try
            Dim strsql As String = "delete from User_PropetyManager where username='" & pno & "'"
            Dim objconn As New SqlConnection(conn2)
            Dim objcmd As New SqlCommand(strsql, objconn)

            objconn.Open()
            objcmd.ExecuteNonQuery()
            'MsgBox("删除成功")
            objconn.Close()
        Catch ex As Exception
            MsgBox("UserDelete:" + ex.Message)
        End Try

    End Sub
End Module

ProprietorDao 业主数据库交互

Imports System.Data.OleDb
Imports System.Data.SqlClient

'模块:ProprietorDao
'作用:业主数据库交互
'@author:CaoPengCheng
Module ProprietorDao
    Dim conn As String = sqlconn()
    Dim conn2 As String = sqlconn2()
    '方法:ProprietorSelect();
    '作用:业主信息查询
    '参数:(pno)
    Public Function ProprietorSelect(pno As String)
        Dim proprietor As New Proprietor
        Try
            Dim objconn As New OleDbConnection(conn) '创建连接对象
            Dim objAdap As OleDbDataAdapter '创建适配对象
            Dim objDataSet As New DataSet '创建数据集对象
            Dim strsql As String = "select * from Proprietor where Pno ='" & pno & "'"

            objAdap = New OleDbDataAdapter(strsql, objconn)
            objDataSet.Reset() '清除数据集
            objAdap.Fill(objDataSet, "Pro") '第二个参数就是给这个虚拟表起个名字

            ' For i = 0 To 7
            'MsgBox(objDataSet.Tables("Pro").Rows(0).Item(i))
            'Next
            proprietor.pnoSet(objDataSet.Tables("Pro").Rows(0).Item(0))
            proprietor.pnameSet(objDataSet.Tables("Pro").Rows(0).Item(1))
            proprietor.p_bnoSet(objDataSet.Tables("Pro").Rows(0).Item(2))
            proprietor.p_gnoSet(objDataSet.Tables("Pro").Rows(0).Item(3))
            proprietor.psexSet(objDataSet.Tables("Pro").Rows(0).Item(4))
            proprietor.pageSet(objDataSet.Tables("Pro").Rows(0).Item(5))
            proprietor.pnativeSet(objDataSet.Tables("Pro").Rows(0).Item(6))
            Return proprietor
        Catch ex As Exception
            MsgBox("ProprietorSelect" + ex.Message)
        End Try
        Return 0
    End Function

    '方法:proprietorUpdata();
    '作用:业主信息修改
    '参数:(proprietor)

    Public Sub proprietorUpdata(proprietor As Proprietor)
        Try
            ' MsgBox(proprietor.pnameGet)
            ' MsgBox(proprietor.psexGet)
            'MsgBox(proprietor.pageGet)
            'MsgBox(proprietor.pnativeGet)
            ' MsgBox("pno=" + proprietor.pnoGet)
            Dim strsql As String = "update Proprietor set Pname='" & proprietor.pnameGet & "',Psex='" & proprietor.psexGet & "',Page='" & proprietor.pageGet & "',Pnative='" & proprietor.pnativeGet & "',P_Bno='" & proprietor.p_bnoGet & "',P_Gno='" & proprietor.p_gnoGet & "' where Pno='" & proprietor.pnoGet & "'"
            Dim objconn As New SqlConnection(conn2)
            Dim objcmd As New SqlCommand(strsql, objconn)

            objconn.Open()
            objcmd.ExecuteNonQuery()

            MsgBox("修改成功!")

            objconn.Close()
        Catch ex As Exception
            MsgBox("proprietorUpdata:" + ex.Message)
        End Try

    End Sub
    '方法:proprietorSelectCount();
    '作用:业主信息存在查询
    '参数:(proprietor)
    Public Function proprietorSelectCount(pno As String)
        Dim f As Integer
        Try
            Dim objconn As New SqlConnection(conn2)
            Dim strsql1 As String = "select count(*) from Proprietor  where Pno='" & pno & "' or Pname ='" & pno & "'"
            objconn.Open()
            Dim objcmd As New SqlCommand(strsql1, objconn)
            f = objcmd.ExecuteScalar
            objconn.Close()
            objcmd.Dispose()
        Catch ex As Exception
            MsgBox("proprietorSelectCount" + ex.Message)
        End Try

        Return f
    End Function
    '方法:proprietorCount();
    '作用:业主个数
    '参数:(proprietor)
    Public Function proprietorCount()
        Dim f As Integer
        Try
            Dim objconn As New SqlConnection(conn2)
            Dim strsql1 As String = "select count(*) from Proprietor"
            objconn.Open()
            Dim objcmd As New SqlCommand(strsql1, objconn)
            f = objcmd.ExecuteScalar
            objconn.Close()
            objcmd.Dispose()
        Catch ex As Exception
            MsgBox("proprietorCount" + ex.Message)
        End Try

        Return f
    End Function
    '方法:ProprietorSelectForPnoName();
    '作用:业主信息查询
    '参数:(pno)
    Public Function ProprietorSelectForPnoName(pnoandName As String)
        Dim proprietor As New Proprietor
        Try
            Dim objconn As New OleDbConnection(conn) '创建连接对象
            Dim objAdap As OleDbDataAdapter '创建适配对象
            Dim objDataSet As New DataSet '创建数据集对象
            Dim strsql As String = "select * from Proprietor where Pno ='" & pnoandName & "' or Pname ='" & pnoandName & "'"

            objAdap = New OleDbDataAdapter(strsql, objconn)
            objDataSet.Reset() '清除数据集
            objAdap.Fill(objDataSet, "Pro") '第二个参数就是给这个虚拟表起个名字

            ' For i = 0 To 7
            'MsgBox(objDataSet.Tables("Pro").Rows(0).Item(i))
            'Next

            proprietor.pnoSet(objDataSet.Tables("Pro").Rows(0).Item(0))
            proprietor.pnameSet(objDataSet.Tables("Pro").Rows(0).Item(1))
            proprietor.p_bnoSet(objDataSet.Tables("Pro").Rows(0).Item(2))
            proprietor.p_gnoSet(objDataSet.Tables("Pro").Rows(0).Item(3))
            proprietor.psexSet(objDataSet.Tables("Pro").Rows(0).Item(4))
            proprietor.pageSet(objDataSet.Tables("Pro").Rows(0).Item(5))
            proprietor.pnativeSet(objDataSet.Tables("Pro").Rows(0).Item(6))
            Return proprietor
        Catch ex As Exception
            MsgBox("ProprietorSelectForPnoName" + ex.Message)
        End Try
        Return 0
    End Function
    '方法:proprietorInsert();
    '作用:业主信息修改
    '参数:(proprietor)

    Public Sub proprietorInsert(proprietor As Proprietor)
        Try
            Dim strsql As String = "insert into Proprietor values ('" & proprietor.pnoGet & "','" & proprietor.pnameGet & "','" & proprietor.p_bnoGet & "','" & proprietor.p_gnoGet & "','" & proprietor.psexGet & "'," & proprietor.pageGet & ",'" & proprietor.pnativeGet & "')"
            Dim objconn As New SqlConnection(conn2)
            Dim objcmd As New SqlCommand(strsql, objconn)

            objconn.Open()
            objcmd.ExecuteNonQuery()
            'MsgBox("Success")
            objconn.Close()
        Catch ex As Exception
            MsgBox("proprietorInsert:" + ex.Message)
        End Try

    End Sub
    '方法:proprietorDelete();
    '作用:业主信息删除
    '参数:(proprietor)

    Public Sub proprietorDelete(pno As String)
        Try
            Dim strsql As String = "delete from Proprietor where Pno='" & pno & "'"
            Dim objconn As New SqlConnection(conn2)
            Dim objcmd As New SqlCommand(strsql, objconn)

            objconn.Open()
            objcmd.ExecuteNonQuery()
            'MsgBox("删除成功")
            objconn.Close()
        Catch ex As Exception
            MsgBox("proprietorDelete:" + ex.Message)
        End Try
    End Sub
    '方法:ProprietorSelectLike();
    '作用:业主信息模糊查询
    '参数:(pno)
    Public Function ProprietorSelectLike(pnoandName As String)
        Dim pro(100) As Proprietor
        Try
            Dim objconn As New OleDbConnection(conn) '创建连接对象
            Dim objAdap As OleDbDataAdapter '创建适配对象
            Dim objDataSet As New DataSet '创建数据集对象
            Dim strsql As String = "select * from Proprietor where Pno like '" & pnoandName & "%' or Pname like '" & pnoandName & "%'"

            objAdap = New OleDbDataAdapter(strsql, objconn)
            objDataSet.Reset() '清除数据集
            objAdap.Fill(objDataSet, "Pro") '第二个参数就是给这个虚拟表起个名字

            ' For i = 0 To 7
            'MsgBox(objDataSet.Tables("Pro").Rows(0).Item(i))
            'Next
            For i = 0 To Int(objDataSet.Tables("Pro").Rows.Count) - 1
                Dim proprietor As New Proprietor
                proprietor.pnoSet(objDataSet.Tables("Pro").Rows(i).Item(0))
                proprietor.pnameSet(objDataSet.Tables("Pro").Rows(i).Item(1))
                proprietor.p_bnoSet(objDataSet.Tables("Pro").Rows(i).Item(2))
                proprietor.p_gnoSet(objDataSet.Tables("Pro").Rows(i).Item(3))
                proprietor.psexSet(objDataSet.Tables("Pro").Rows(i).Item(4))
                proprietor.pageSet(objDataSet.Tables("Pro").Rows(i).Item(5))
                proprietor.pnativeSet(objDataSet.Tables("Pro").Rows(i).Item(6))
                pro(i + 1) = proprietor
            Next



        Catch ex As Exception
            MsgBox("ProprietorSelectForPnoName" + ex.Message)
        End Try
        Return pro
    End Function
    '方法:proprietorCountLike();
    '作用:业主个数
    '参数:(proprietor)
    Public Function proprietorCountLike(pnoandName As String)
        Dim f As Integer
        Try
            Dim objconn As New SqlConnection(conn2)
            Dim strsql1 As String = "select count(*) from Proprietor where Pno like '" & pnoandName & "%' or Pname like '" & pnoandName & "%'"
            objconn.Open()
            Dim objcmd As New SqlCommand(strsql1, objconn)
            f = objcmd.ExecuteScalar
            objconn.Close()
            objcmd.Dispose()
        Catch ex As Exception
            MsgBox("proprietorCount" + ex.Message)
        End Try

        以上是关于小区物业管理系统-数据库交互的主要内容,如果未能解决你的问题,请参考以下文章

基于Springboot的小区物业管理系统

java毕设开源了,springboot+layui的小区物业管理系统

java毕设开源了,springboot+layui的小区物业管理系统

基于mysql+php098安置小区物业管理系统

计算机毕业设计-物业管理系统代码-基于SSM的智能小区物业系统代码-java社区物业水电缴费系统代码

小区物业管理系统-总结-需求分析