ASP.NET图书馆管理信息系统

news2024/11/23 10:56:01

摘  要

本文首先阐述了基于.NET Framework平台的图书馆管理信息系统的开发背景以及其实践意义,其次说明了图书馆管理信息系统的功能以及相比同类软件的创新之处。然后就图书馆管理系统开发中所使用的一些的技术进行研究探讨。主要针对数据库的设计技术、存储过程技术、ADO.NET技术以及用SQL Server .NET Framework 数据提供程序访问SQLserver2000数据库技术四个方面进行了研究。最后还附上了图书馆管理信息系统的安装说明、简单使用说明和一些通用性的经典代码。笔者化了大量的时间用于程序设计,这也是笔者工作的重点,所开发的软件具有实用价值,所编写的代码对.NET程序员也有很好的参考性。在系统的开发过程中,笔者深刻体会到了.NET平台的强大性、优越性以及存储过程在提高数据访问性能和增强数据访问安全性上所起到的重要作用。此外,对于关系代数在数据库科学里的应用,笔者在编程过程中也做了一定的研究。

关键词: 数据库;.NET Framework;ADO.NET;存储过程;SQL Server .NET Framework 数据提供程序

图书馆管理系统基于Microsoft公司最新的.NET Framework平台构建,编码的基本语言是VB.NET。开发过程中统一使用.NET框架的数据类型、方法,抛弃了原来vb6的内容。充分体现了.NET的优越性,使软件易安装部署、易维护。系统使用ADO.NET+SQLserver2000模式,数据层基本都基于存储过程构建,使得速度更快、安全性更高。

2.1系统提供的功能:

   针对图书馆管理员设计的部分

    管理部分是一个基于WinForms的windows窗体应用程序,主要为图书馆管理人员提供服务。截图如下:

管理部分提供以下功能:

  1. 用户功能。(提供登陆验证、用户切换,管理员锁定系统等功能。)
  2. 事务处理  

    图书证挂失管理。(可以针对读者情况对图书证进行挂失,以防冒借。)

    借书、还书管理。(实现日常图书借阅及归还。)

  1. 数据管理

    图书、读者管理。(实现图书、读者的添加,删除,编辑。)

  1. 综合查询统计。(可以根据不同条件的组合检索图书或读者以及借阅数据,对检索出来的数据可提供多种方式的操作:导出为Excel格式、pdf格式、或导出为水晶报表以便打印等。)
  2. 系统设定。(设置一些图书馆基本规则,如读者类别、图书类别、读者借阅最大天数等,此外设定数据服务器信息也在这里。)
  3. 帮助功能。(提供一个chm帮助文档,帮助图书馆工作人员快速适应本系统,此外还提供在线问题反馈,软件更新提示等功能。)

   针对读者设计的部分:

   由于读者的多元性和位置不确定性,该部分采取基于B/S的方式实现。代码使用ASP.NET编写,利用ASP.NET的优点,可以自动适应多种客户浏览器。截图如下:


    读者只需要有一台联网的计算机和一个常用WEB浏览器。就可以轻松的进行图书查询、更改个人信息、向图书馆反馈信息等。该部分主要提供以下功能:

  1. 登陆验证。(防止读者信息被盗用。)
  2. 图书查询。(一个综合的图书查询系统,可以方便的使读者查到需要的书籍。)
  3. 读者个人信息查询以及管理。(可以适当的更改一些读者个人的资料,如email等,此外在这里还可以查到读者当前的、所有的借阅记录等。)
  4. 信息服务。(定期公布超期的读者列表,以及新到的图书等信息。)

5.1存储过程

--备份数据的存储过程

--将数据库备份到服务器C:\下,文件名为 当前日期+.zjx

ALTER PROCEDURE BACKUPmyData   

AS

    DECLARE @path varchar(15)

    set @path=convert(varchar,getdate(),112)

    set @path='C:\'+@path+'.zjx'

    BACKUP DATABASE lib2004

         TO Disk = @path

    WITH FORMAT,

    NAME = 'Full Backup of lib2004'

    RETURN

/*检索某图书是哪位读者借去的*/

ALTER PROCEDURE Book1IsBorrowByWho

    @Book_code nvarchar(50)

AS

SELECT Au_id

FROM borrow

WHERE (book_code = @Book_code) AND (Return_date IS NULL)

    RETURN

/*检索某图书是否在馆*/

/*检索在馆的图书 只要图书id不在 借阅记录没有归还的记录 里 就表示在馆*/

/*不在馆 则返回0

  在馆  返回1 */

ALTER PROCEDURE Book1IsInLib

    @Book_code nvarchar(50)

AS

SELECT COUNT(*) as IsInLib

FROM book

WHERE Book_code = @Book_code AND Book_code IN

          (SELECT book_code

         FROM Book

         WHERE Book_code NOT IN

                   (SELECT borrow.Book_code

                  FROM borrow

                  WHERE Return_date IS NULL))

    RETURN

/* 用于获取一位读者的

    当前借阅书数,

    总共借阅书数,

    可借书数

    最大借阅时间

    输入参数Au_id */

ALTER PROCEDURE Get1AuInfo

    @Au_id nvarchar(50), /*1*/

    @BorrowNo int output,

    @BorrowNoCurrent int output,

    @MaxBorrowDays int output,

    @MaxBorrowBooks int output

AS

    begin transaction

   

    SELECT @BorrowNo=COUNT(*)

    FROM borrow

    WHERE (Au_id = @Au_id)

   

    SELECT @BorrowNoCurrent=COUNT(*)

    FROM borrow

    WHERE (Au_id = @Au_id) AND (Return_date IS NULL)

    SELECT @MaxBorrowDays=ausort.Au_borrowdays ,

          @MaxBorrowBooks=ausort.Au_borrowbooks

    FROM ausort INNER JOIN

          au ON ausort.Au_sort = au.Au_sort

    WHERE (au.Au_id = @Au_id)

   

    commit transaction

    RETURN

/* 用于获取一位读者所有超期的借书列表 Au_id */

/*author:翟靖轩 */

ALTER PROCEDURE Select1AuMaxDateBookList

    @Au_id nvarchar(50) /*1*/

AS

    SELECT borrow.book_code AS 图书条码号, book.Book_name AS 图书题名,

          borrow.Borrow_date AS 借阅日期, borrow.Should_date AS 应还日期

    FROM book INNER JOIN

          borrow ON book.Book_code = borrow.book_code

    WHERE (borrow.Au_id = @Au_id) AND (borrow.Return_date IS NULL) AND

          (borrow.Should_date < GETDATE())

    ORDER BY borrow.Should_date DESC

    RETURN

/*返回超期的所有读者*/

/*author:翟靖轩 2004-5-10*/

ALTER PROCEDURE SelectMaxDateAuList

AS

    SELECT borrow.Au_id AS 借书证号, au.Au_name AS 读者姓名,

          borrow.book_code AS 图书条码号, book.Book_name AS 图书名称,

          borrow.Borrow_date AS 借书日期, borrow.Should_date AS 应归还日期

    FROM borrow INNER JOIN

          au ON borrow.Au_id = au.Au_id INNER JOIN

          book ON borrow.book_code = book.Book_code

    WHERE (borrow.Return_date IS NULL) AND (GETDATE() > borrow.Should_date)

    ORDER BY borrow.Au_id   

    RETURN

/*查询一个读者的所有借阅记录  包括已经借过的已经归还的书籍

 作者:翟靖轩

 日期:2004-5-2 */        

ALTER PROCEDURE SelectAuAllBorrowList

    @Au_id nvarchar(50)

AS

    SELECT book.Book_code AS 条码号, book.Book_name AS 图书题名,

          borrow.Borrow_date AS 借阅日期, borrow.Return_date AS 归还日期,

          borrow.Should_date AS 应归还日期, book.Book_isbn AS ISBN号,

          book.Book_pub AS 出版社, book.Book_sort AS 图书分类,

          book.Book_author AS 图书作者

    FROM book LEFT OUTER JOIN

          borrow ON book.Book_code = borrow.book_code

    WHERE (borrow.Au_id = @Au_id)

    ORDER BY borrow.Return_date, borrow.Borrow_date DESC

    RETURN

/* 综合图书查询 */

-- 查询所有在馆图书

ALTER PROCEDURE searchBookInLib

    @Book_code nvarchar(50)='',

    @Book_name nvarchar(50)='',

    @Book_pub nvarchar(50)='',

    @Book_isbn nvarchar(50)='',

    @Book_pubdate smalldatetime='1900-01-01',

    @Book_author nvarchar(50)='',  

    @Book_sort nvarchar(50)='' 

AS

    SELECT Book_code AS 条形码, Book_name AS 图书名称, Book_author AS 图书作者,

          Book_pub AS 出版社, Book_isbn AS ISBN号, Book_pubdate AS 出版日期,

          Book_page AS 图书页数, Book_price AS 图书价格, Book_adddate AS 入馆日期,

          Book_place AS 存放位置, Book_sort AS 图书分类

    FROM book

    WHERE (Book_code LIKE '%' + @Book_code + '%') AND

          (Book_name LIKE '%' + @Book_name + '%') AND

          (Book_pub LIKE '%' + @Book_pub + '%') AND

          (Book_isbn LIKE '%' + @Book_isbn + '%') AND

          (Book_author LIKE '%' + @Book_author + '%') AND

          (Book_sort LIKE '%' + @Book_sort + '%') AND

          (Book_pubdate > @Book_pubdate) and       

           Book_code not IN

                   (SELECT borrow.Book_code

                  FROM borrow

                  WHERE Return_date IS NULL)       

    RETURN

5.2  winForms代码选录

一个用于执行存储过程的类

Imports System.Data

Imports System.Data.SqlClient

Public Class CdataService

    Protected Connection As SqlConnection

    Private m_DSN As String

    '构建一个带有参数的sqlcommand

    Private Overloads Function CreateCommand(ByVal sprocName As String, ByVal parameters() As IDataParameter) As SqlCommand

        Dim command As SqlCommand = New SqlCommand(sprocName, Connection)

        command.CommandType = CommandType.StoredProcedure

        Dim para As SqlParameter

        For Each para In parameters

            command.Parameters.Add(para)

        Next

        command.Parameters.Add(New SqlParameter("Return Value", _

        SqlDbType.Int, _

        4, _

        System.Data.ParameterDirection.ReturnValue, _

         False, _

          0, _

          0, _

          String.Empty, _

          DataRowVersion.Default, _

          Nothing))

        Return command

    End Function

    '构建一个没有参数的sqlcommand

    Private Overloads Function CreateCommand(ByVal sprocName As String) As SqlCommand

        Dim command As SqlCommand = New SqlCommand(sprocName, Connection)

        command.CommandType = CommandType.StoredProcedure

        command.Parameters.Add(New SqlParameter("Return Value", _

        SqlDbType.Int, _

        4, _

        System.Data.ParameterDirection.ReturnValue, _

         False, _

          0, _

          0, _

          String.Empty, _

          DataRowVersion.Default, _

          Nothing))

        Return command

    End Function

    Public ReadOnly Property DSN() As String

        Get

            Return m_DSN

        End Get

    End Property

    Public Overloads Function RunSP(ByVal sprocName As String) As Int32

        Dim result As Int32

        Connection.Open()

        Dim command As SqlCommand = Me.CreateCommand(sprocName)

        command.ExecuteNonQuery()

        result = CType(command.Parameters("Return Value").Value, Int32)

        Me.Connection.Close()

        Return result

    End Function

    Public Overloads Function RunSP(ByVal sprocName As String, ByVal parameters() As IDataParameter) As Int32

        Dim result As Int32

        Connection.Open()

        Dim command As SqlCommand = Me.CreateCommand(sprocName, parameters)

        command.ExecuteNonQuery()

        result = CType(command.Parameters("Return Value").Value, Int32)

        Me.Connection.Close()

        Return result

    End Function

    Public Overloads Function RunSP(ByVal sprocName As String, _

   ByVal parameters() As IDataParameter, ByVal DataSet As DataSet) As Int32

        Dim result As Int32

        Dim sqlDA As New SqlDataAdapter

        Connection.Open()

        sqlDA.SelectCommand = Me.CreateCommand(sprocName, parameters)

        sqlDA.Fill(DataSet, "SourceTable")

        result = CType(sqlDA.SelectCommand.Parameters("Return Value").Value, Int32)

        Connection.Close()

        Return result

    End Function

    Public Overloads Function RunSP(ByVal sprocName As String, _

    ByRef DataSet1 As DataSet) As Int32

        Dim result As Int32

        Dim sqlDA As New SqlDataAdapter

        Connection.Open()

        sqlDA.SelectCommand = Me.CreateCommand(sprocName)

        sqlDA.Fill(DataSet1)

        result = CType(sqlDA.SelectCommand.Parameters("Return Value").Value, Int32)

        Connection.Close()

        Return result

    End Function

    Public Overloads Function RunSP(ByVal sprocName As String, _

       ByVal parameters() As IDataParameter, ByRef DataSet As DataSet, ByVal TableName As String) As Int32

        Dim result As Int32

        Dim sqlDA As New SqlDataAdapter

        Connection.Open()

        sqlDA.SelectCommand = Me.CreateCommand(sprocName, parameters)

        sqlDA.Fill(DataSet, TableName)

        result = CType(sqlDA.SelectCommand.Parameters("Return Value").Value, Int32)

        Connection.Close()

        Return result

    End Function

    Public Function Construct(ByVal ConstructString As String)

        m_DSN = ConstructString

    End Function

    Public Function Activate()

        Connection = New SqlConnection(m_DSN)

    End Function

    Public Function Deactivate()

        Connection = Nothing

    End Function

    Public Sub New()

    End Sub

    Public Sub New(ByVal ConstrucString As String)

        Construct(ConstrucString)

        Me.Activate()

    End Sub

    Protected Overrides Sub Finalize()

        MyBase.Finalize()

        Me.Deactivate()

    End Sub

End Class

图书查询窗体的全部代码frmBookQuery.vb

Imports System.Data.SqlClient

Imports System.Drawing.Printing

Public Class frmBookQuery

    Inherits library.frmBase

#Region " Windows 窗体设计器生成的代码 "

    此处略去

#End Region

    Private Sub frmBookQuery_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        With Me.dbgBookList

            .Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _

                Or System.Windows.Forms.AnchorStyles.Left) _

                Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)

            .BackColor = System.Drawing.Color.Snow

            .BackgroundColor = System.Drawing.SystemColors.ActiveCaptionText

            .CaptionVisible = False

            .HeaderForeColor = System.Drawing.SystemColors.ControlText

            .ReadOnly = True

        End With

        BindComboBox1()

        Me.cboBook_sort.Text = ""

    End Sub

    Function search()

      

        Dim cn As New SqlClient.SqlConnection(cnstr)

        Dim cmd As New SqlCommand

        Dim da As SqlDataAdapter

        Dim ds As New DataSet

        With cmd

            If Me.radAllBook.Checked = True Then

                .CommandText = "searchBook"

            Else

                .CommandText = "searchBookInlib"

            End If

            .CommandType = CommandType.StoredProcedure

            .Connection = cn

        End With

        Dim mBook_code As New SqlParameter("@Book_code", SqlDbType.NVarChar, 50) '1

        Dim mBook_name As New SqlParameter("@Book_name", SqlDbType.NVarChar, 50) '2

        Dim mBook_pub As New SqlParameter("@Book_pub", SqlDbType.NVarChar, 50) '3

        Dim mBook_isbn As New SqlParameter("@Book_isbn", SqlDbType.NVarChar, 50) '4

        Dim mBook_pubdate As New SqlParameter("@Book_pubdate", SqlDbType.SmallDateTime, 4)

        Dim mBook_author As New SqlParameter("@Book_author", SqlDbType.NVarChar, 50) '6

        Dim mBook_sort As New SqlParameter("@Book_sort", SqlDbType.NVarChar, 50) '11

        With cmd.Parameters

            .Add(mBook_code)

            .Add(mBook_name)

            .Add(mBook_pub)

            .Add(mBook_isbn)

            .Add(mBook_pubdate)

            .Add(mBook_author)

            .Add(mBook_sort)

        End With

        '赋值

        mBook_code.Value = Me.txtBook_code.Text.Trim  '1

        mBook_name.Value = Me.txtBook_name.Text.Trim  '2

        mBook_pub.Value = Me.txtBook_pub.Text.Trim  '3

        mBook_isbn.Value = Me.txtBook_isbn.Text.Trim  '4

        mBook_pubdate.Value = Me.dtpBook_pubdate.Value '5

        mBook_author.Value = Me.txtBook_author.Text.Trim   '6

        mBook_sort.Value = Me.cboBook_sort.Text.Trim   '11

        da = New SqlDataAdapter(cmd)

        Try

            da.Fill(ds)

            ds.Tables(0).Columns(0).Caption = "图书条码号"

            Me.dbgBookList.DataSource = ds.Tables(0)

            Me.Label8.Text = "共检索到" + ds.Tables(0).Rows.Count.ToString + "条记录"

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        Finally

            cn.Close()

            If Not cn Is Nothing Then

                cn.Dispose()

            End If

        End Try

    End Function

    Function BindComboBox1()

        Dim cnLib2004 As SqlConnection

        Dim cmdbooksort As SqlCommand

        Dim drBooksort As SqlDataReader

        cnLib2004 = New SqlConnection(cnstr)

        cmdbooksort = New SqlCommand

        With cmdbooksort

            .CommandType = CommandType.StoredProcedure

            .Connection = cnLib2004

            .CommandText = "selectBookSort"

        End With

        Try

            cnLib2004.Open()

            drBooksort = cmdbooksort.ExecuteReader

            Dim myarr As New ArrayList

            While drBooksort.Read

                myarr.Add(drBooksort.Item(0))

            End While

            Me.cboBook_sort.DataSource = myarr

        Catch ex As Exception

            MessageBox.Show(ex.Message)

            Me.Close()

        Finally

            cnLib2004.Close()

        End Try

    End Function

    Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick

        If e.Button Is Me.tbtnQuery Then

            search()

        ElseIf e.Button Is Me.tbtnExit Then

            Me.Close()

        ElseIf e.Button Is Me.tbtnReset Then

            frmClear()

        ElseIf e.Button Is Me.tbtnExcel Then

            excel()

        ElseIf e.Button Is Me.tbtnPrint Then

            print()

        End If

    End Sub

    Private Sub frmClear()

        Dim p1 As Control

        Dim u As New Label

        For Each p1 In Me.Panel2.Controls

            If Not p1.GetType Is u.GetType Then

                p1.Text = ""

            End If

        Next

        Me.cboBook_sort.Text = ""

        Me.radAllBook.Checked = True

        Me.dtpBook_pubdate.Value = "1990-1-1"

        Me.txtBook_code.Focus()

        Me.dbgBookList.DataSource = Nothing

    End Sub

  Sub excel()

        Dim tableAu As DataTable

        tableAu = CType(Me.dbg.DataSource, DataTable)

        If tableAu Is Nothing Then

            MessageBox.Show("没有任何记录可以导出!", "error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

            Exit Sub

        End If

     

        Dim myfrm As New frmShowProgress

        myfrm.Show("正在建立excel对象...")

        Try

            Dim exl As New Microsoft.Office.Interop.Excel.ApplicationClass

            Dim workbook As Microsoft.Office.Interop.Excel.Workbook

            Dim sheet As Microsoft.Office.Interop.Excel.Worksheet

            workbook = CType(exl.Workbooks.Add(), Microsoft.Office.Interop.Excel.Workbook)

            sheet = CType(workbook.Sheets(1), Microsoft.Office.Interop.Excel.Worksheet)

            Dim mycount, mycolumn As Int16

            With tableAu

                myfrm.setMsg("正在导出数据,请等待......")

                For mycount = 0 To .Rows.Count - 1

                    For mycolumn = 0 To .Columns.Count - 1

                        With sheet

                            .Cells(mycount + 2, mycolumn + 1) = tableAu.Rows(mycount).Item(mycolumn)

                        End With

                    Next

                    'MsgBox(CType(mycount / .Rows.Count * 100, Int16))

                    myfrm.setProgress(CType(mycount / .Rows.Count * 100, Int16))

                Next

                myfrm.setMsg("正在设定excel表头格式...")

                For mycolumn = 0 To .Columns.Count - 1

                    exl.Workbooks(1).Worksheets(1).cells(1, mycolumn + 1) = .Columns(mycolumn).ColumnName

                    exl.Workbooks(1).Worksheets(1).cells(1, mycolumn + 1).Font.Bold = True

                Next

            End With

            myfrm.setProgress(100)

            myfrm.Close()

            'workbook.SaveAs(myfile)

            sheet.Application.Visible = True

            'exl.Quit()          

            Catch ex As Exception

            MessageBox.Show("导出失败!", "fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)           

            myfrm.Close()

        End Try

    End Sub

    Private Sub print()

        Dim tableAu As DataTable

        tableAu = CType(Me.dbgBookList.DataSource, DataTable)

        If tableAu Is Nothing Then

            MessageBox.Show("没有任何记录可以导出!", "error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

            Exit Sub

        End If

        Dim myfrm2 As New frmStatus

        myfrm2.Show("正在导出报表...")

        Dim myfrm As New frmShowReport

        Dim rtd As New crtBook

        rtd.SetDataSource(tableAu)

        myfrm.Text = "报表输出窗口..."

        myfrm.rpt.ReportSource = rtd

        myfrm.rpt.DisplayGroupTree = False

        myfrm2.Close()

        myfrm.ShowDialog()

    End Sub

End Class

登陆窗体代码frmLogin.vb

Public Class frmLogin

    Inherits System.Windows.Forms.Form

    Public IsLogSuccess As Boolean

Public strLogUser As String

#Region " Windows 窗体设计器生成的代码 "

    此处略……

    #End Region

Private Sub frmLogin_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

        IsLogSuccess = False     

    End Sub

    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click       

        IsLogSuccess = validateLogin(Me.txtUser.Text.Trim, Me.txtPwd.Text.Trim)

        If IsLogSuccess = True Then

            strLogUser = Me.txtUser.Text.Trim

            Me.Close()

        Else

            MessageBox.Show("密码错误!", "请重新登陆!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

        End If

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

        Me.Close()

    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

        Dim grbrush As Drawing2D.LinearGradientBrush

        grbrush = New Drawing2D.LinearGradientBrush(New Point(0, 0), _

         New Point(sender.Width, sender.Height), Color.DarkSlateGray, Color.White)

        sender.CreateGraphics.FillRectangle(grbrush, New Rectangle(0, 0, sender.Width, sender.Height))

    End Sub

End Class

将数据服务器信息序列化为xml文件的类

Imports System.Xml.Serialization

Imports System.IO

Imports System.Collections

Public Class CsetCnInfo

    Structure CnInfo

        Public server As String

        Public database As String

        Public uid As String

        Public password As String

    End Structure

    Private mCC(4) As String

    Public Function setCnTofile()

        Dim mcn As CnInfo

        mcn.server = mCC(0)

        mcn.database = mCC(1)

        mcn.uid = mCC(2)

        mcn.password = mCC(3)

        Dim xmlS As New XmlSerializer(GetType(CnInfo))

        Dim txtwt As TextWriter = New StreamWriter("cninfo.xml")

        xmlS.Serialize(txtwt, mCn)

        txtwt.Close()

    End Function

    Public Function GetCnFromfile() As String

        Dim mcn As CnInfo

        Dim xmls As New XmlSerializer(GetType(CnInfo))

        Dim txtwt As TextReader = New StreamReader("cninfo.xml")

        Try

            mcn = xmls.Deserialize(txtwt)

            mCC(0) = mcn.server

            mCC(1) = mcn.database

            mCC(2) = mcn.uid

            mCC(3) = mcn.password

        Catch ex As Exception

            Throw ex

        Finally

            txtwt.Close()

        End Try

        Return returnCnstr()

    End Function

    Public Function returnCnstr() As String

        Return "server=" + mCC(0) + ";database=" _

        + mCC(1) + ";uid=" + mCC(2) + ";pwd=" + mCC(3)

    End Function

    Public Property cnstr() As String()

        Get

            Return mCC

        End Get

        Set(ByVal Value As String())

            Value.CopyTo(mCC, 0)

        End Set

    End Property

    Public Sub New()

    End Sub

End Class

验证登陆的函数

Public Function validateLogin(ByVal uid As String, ByVal pwd As String) As Boolean

        Dim IsCorrect As Boolean = False

        Dim cnmy As New SqlConnection(cnstr)

        Dim cmd As New SqlCommand

        With cmd

            .Connection = cnmy

            .CommandType = CommandType.Text

            .CommandText = "select count(*) from manager where Man_id=@Man_id and Man_pwd=@Man_pwd"

        End With

        Dim mMan_id As New SqlParameter("@Man_id", SqlDbType.NVarChar, 50)

        Dim mMan_pwd As New SqlParameter("@Man_pwd", SqlDbType.NVarChar, 12)

        With cmd.Parameters

            .Add(mMan_id)

            .Add(mMan_pwd)

        End With

        mMan_id.Value = uid

        mMan_pwd.Value = pwd

        Try

            cnmy.Open()

            If cmd.ExecuteScalar = 1 Then

                IsCorrect = True

            End If

        Catch ex As Exception

            MessageBox.Show("登陆验证时数据库发生错误" + vbCrLf + ex.Message, _

            "error", MessageBoxButtons.OK, MessageBoxIcon.Stop)

            Return False

        Finally

            cnmy.Close()

            If Not cnmy Is Nothing Then

                cnmy.Dispose()

            End If

        End Try

        Return IsCorrect

    End Function

5.3  ASP.NET WebForms代码选录

显示读者基本信息Userinfo.aspx的页面后置代码(CodeBehind)

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        '在此处放置初始化页的用户代码

        If Session("UID") Is Nothing Then

            Page.Response.Redirect("login.aspx")

        End If

        If Not IsPostBack Then

            If Not Session("UID") Is Nothing Then

                AuTextBind(Session("UID"))

                setBorrowState(Session("UID"))

            Else

                Page.Response.Redirect("login.aspx")

            End If

        End If

    End Sub

    '显示某读者基本情况

    Function AuTextBind(ByVal strAu_id As String)

        Dim cnlib2004 As SqlConnection

        Dim cmdAuBorrowList As SqlCommand

        Dim drAuBorrowList As SqlDataReader

        cnlib2004 = New SqlConnection(ConfigurationSettings.AppSettings("cncstr"))

        cmdAuBorrowList = New SqlCommand

        With cmdAuBorrowList

            .CommandType = CommandType.StoredProcedure

            .CommandText = "Select1Au"

            .Connection = cnlib2004

        End With

        Dim mAu_id As New SqlParameter("@Au_id", SqlDbType.NVarChar, 50) '1

        cmdAuBorrowList.Parameters.Add(mAu_id)

        mAu_id.Value = strAu_id

        Try

            cnlib2004.Open()

            drAuBorrowList = cmdAuBorrowList.ExecuteReader(CommandBehavior.SingleRow)

            With drAuBorrowList

                If .Read() Then

                    Me.spAuadddate.InnerHtml = CType(.Item("Au_adddate"), String)

                    Me.spAuadr.InnerHtml = .Item("Au_adr")

                    Me.spAuname.InnerHtml = .Item("Au_name")

                    Me.spAusex.InnerHtml = .Item("Au_sex")

                    Me.spAusort.InnerHtml = .Item("Au_sort")

                    Me.spAuid.InnerHtml = strAu_id

                    Me.spAuemail.InnerHtml = .Item("Au_email")

                    Me.spAuremarks.InnerHtml = .Item("Au_remarks")

                Else

                  

                End If

            End With

        Catch ex As Exception

            Response.Write(ex.Message)

        Finally

            cnlib2004.Close()

        End Try

    End Function

    '显示读者借书状态 最大借书册书,当前借书册数 等

    Function setBorrowState(ByVal strAu_id As String)

        Dim cnlib2004 As SqlConnection

        Dim cmd As SqlCommand

        Dim dr As SqlDataReader

        Dim CurBorrowNo As Int16

        Dim AllborrowNo As Int16

        Dim BorrowDays As Int16

        Dim BorrowBooks As Int16

        cnlib2004 = New SqlConnection(ConfigurationSettings.AppSettings("cncstr"))

        cmd = New SqlCommand

        With cmd

            .CommandType = CommandType.StoredProcedure

            .CommandText = "SelectAuCurrentBorrowNo"

            .Connection = cnlib2004

        End With

        Dim mAu_id As New SqlParameter("@Au_id", SqlDbType.NVarChar, 50) '1

        cmd.Parameters.Add(mAu_id)

        mAu_id.Value = strAu_id

        Try

            cnlib2004.Open()

            CurBorrowNo = CType(cmd.ExecuteScalar, Int16)

            cmd.CommandText = "SelectAuAllBorrowNo"

            AllborrowNo = CType(cmd.ExecuteScalar, Int16)

            cmd.CommandText = "SelectAuSortInfo"

            dr = cmd.ExecuteReader(CommandBehavior.SingleRow)

            While dr.Read()

                BorrowDays = dr.Item("Au_borrowdays")

                BorrowBooks = dr.Item("Au_borrowbooks")

            End While

            Me.spTotalBorrowNo.InnerHtml = "共借书" + AllborrowNo.ToString + "册"

            Me.spMaxBorrowDays.InnerHtml = BorrowDays.ToString + "天"

            Me.spBorrowQinkuang.InnerHtml = "[" + CurBorrowNo.ToString + "/"

            Me.spBorrowQinkuang.InnerHtml += BorrowBooks.ToString + "]"

        Catch ex As Exception

            Response.Redirect("error.aspx?errmsg=" + ex.Message)

        Finally

            cnlib2004.Close()

        End Try

    End Function

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1640481.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

2024五一杯数学建模竞赛A题完整成品论文和代码分析:建立钢板切割的工艺路径动态规划、贪心与分层优化模型

2024五一杯数学建模竞赛A题&#xff1a;建立钢板切割的工艺路径动态规划、贪心与分层优化模型 2024五一数学建模A题完整代码和成品论文获取↓↓↓↓↓ https://www.yuque.com/u42168770/qv6z0d/gyoz9ou5upvkv6nx?singleDoc# 本文文章较长&#xff0c;建议先目录。经过不懈的…

基于深度学习检测恶意流量识别框架(80+特征/99%识别率)

基于深度学习检测恶意流量识别框架 目录 基于深度学习检测恶意流量识别框架简要示例a.检测攻击类别b.模型训练结果输出参数c.前端检测页面d.前端训练界面e.前端审计界面&#xff08;后续更新了&#xff09;f.前端自学习界面&#xff08;自学习模式转换&#xff09;f1.自学习模式…

vue3 element-plus 让el-container占满屏幕

在刚开始用element-plus的布局时&#xff0c;发现无法占满屏幕&#xff1a; 在App.vue中添加如下css代码&#xff1a; <style>html, body, #app {margin: 0;padding: 0;height: 100%;} </style>同时布局代码所在的component如下所示&#xff1a; <template&g…

正点原子[第二期]Linux之ARM(MX6U)裸机篇学习笔记-8.1--C语言LED驱动程序

前言&#xff1a; 本文是根据哔哩哔哩网站上“正点原子[第二期]Linux之ARM&#xff08;MX6U&#xff09;裸机篇”视频的学习笔记&#xff0c;在这里会记录下正点原子 I.MX6ULL 开发板的配套视频教程所作的实验和学习笔记内容。本文大量引用了正点原子教学视频和链接中的内容。…

对stm32F103RCT6原理图解析(详细)

最近想了解一下原理图为什么这样设计&#xff0c;又发现网上虽然有相关的解析&#xff0c;但是不全面&#xff0c;所以唉还是自己动手&#xff0c;丰衣足食吧。 MCU部分 核心芯片STM32F103RCT6 (8条消息) stm32命名规则_BachelorTse的博客-CSDN博客 这里有芯片相关的命名规则…

在Windows中,matplotlibcpp的使用

0 前言 本篇文章记录一个c库的使用&#xff1a;matplotlib-cpp&#xff0c;其作用是在c中调用python的matplotlib&#xff0c;实现绘图操作。 对于Windows环境下使用该库的文章&#xff0c;发现文章依然存在一些问题&#xff0c;总是存在报错不能解决&#xff0c;花费了较多的…

QT的TcpServer

Server服务器端 QT版本5.6.1 界面设计 工程文件&#xff1a; 添加 network 模块 头文件引入TcpServer类和TcpSocket&#xff1a;QTcpServer和QTcpSocket #include <QTcpServer> #include <QTcpSocket>创建server对象并实例化&#xff1a; /*h文件中*/QTcpServer…

Python根据预设txt生成“你画我猜”题目PPT(素拓活动小工具)

Python根据预设txt生成“你画我猜”题目PPT&#xff08;素拓活动小工具&#xff09; 场景来源 去年单位内部的一次素拓活动&#xff0c;分工负责策划设置其中的“你画我猜”环节&#xff0c;网络上搜集到题目文字后&#xff0c;想着如何快速做成对应一页一页的PPT。第一时间想…

观察者模式实战:解密最热门的设计模式之一

文章目录 前言一、什么是观察者模式二、Java实现观察者模式2.1 观察者接口2.2 具体观察者2.3 基础发布者2.4 具体发布者2.5 消息发送 三、Spring实现观察者模式3.1 定义事件类3.2 具体观察者3.3 具体发布者3.4 消息发送 总结 前言 随着系统的复杂度变高&#xff0c;我们就会采…

Google 发布 CodeGemma 7B,8K上下文,性能超CodeLlama 13B

CodeGemma简介 CodeGemma模型是谷歌的社区开放编程模型&#xff0c;专门针对代码领域进行优化。一系列功能强大的轻量级模型&#xff0c;能够执行多种编程任务&#xff0c;如中间代码填充、代码生成、自然语言理解、数学推理和指令遵循。CodeGemma模型是在大约500B个主要为英语…

【算法入门教育赛1D】环形密码 - 字符串 | C++题解与代码

题目链接&#xff1a;https://www.starrycoding.com/problem/161 题目描述 小 e e e有一个宝箱&#xff0c;这个宝箱有一个长度为 n n n的密码&#xff0c;但是这个密码校验器是一个环形&#xff0c;意思是只要密码从任意一位开始读&#xff08;读到最后一位回到第一位继续&a…

每日OJ题_贪心算法二⑤_力扣870. 优势洗牌(田忌赛马)

目录 力扣870. 优势洗牌&#xff08;田忌赛马&#xff09; 解析代码 力扣870. 优势洗牌&#xff08;田忌赛马&#xff09; 870. 优势洗牌 难度 中等 给定两个长度相等的数组 nums1 和 nums2&#xff0c;nums1 相对于 nums2 的优势可以用满足 nums1[i] > nums2[i] 的索引…

Redis - Zset 有序集合

前言 它保留了集合不能有重复成员的特点&#xff0c;但与集合不同的是&#xff0c;有序集合中的每个元素都有⼀个唯⼀的浮点类型的分数&#xff08;score&#xff09;与之关联&#xff0c;有序集合中的元素是可以维护有序性的&#xff0c;但这个有序不是⽤下标作为排序依据⽽是…

笔记13-OSError: [Errno 24] Too many open files

文章目录 参考文献失败尝试系列查看发现&#xff0c;似乎是因为线程数有限制 修改配置先查查看 增加文件数限制&#xff0c;然后使用命令运行&#xff08;成功&#xff09; 参考文献 Linux 最大可以打开多少文件描述符&#xff1f; OSError: [Errno 24] Too many open files错…

Redis-单机安装

试图从官网注册不了我也不知道什么情况。 网盘自取吧&#xff0c;链接&#xff1a;https://pan.baidu.com/s/1KERBQaH9gCT10AGt9z0_jg?pwdyjen 安装比较简单&#xff0c;照着敲就完了每一步都试过了&#xff0c;先单机安装&#xff0c;后面搭建集群。 1.将安装包放到/usr/…

一文带你了解MySQL的索引分类

文章目录 ☃️分类☃️演示图☃️思考☃️总结 欢迎来到 请回答1024 的博客 &#x1f353;&#x1f353;&#x1f353;欢迎来到 请回答1024的博客 关于博主&#xff1a; 我是 请回答1024&#xff0c;一个追求数学与计算的边界、时间与空间的平衡&#xff0c;0与1的延伸的后端开…

C++之set/map相关实现

看着上面的图片&#xff0c;你可能对set和map的多样变化产生疑惑&#xff0c;下面我们就来详细讲解他们的区别以及实现 一.set/map 首先&#xff0c;在这里我们要声明&#xff0c;如果你对二叉搜索树一点都不了解的话&#xff0c;建议你先去将搜索二叉树学会再来学习这里的内…

MFC 列表控件删除实例(源码下载)

1、本程序基于前期我的博客文章《MFC下拉菜单打钩图标存取实例&#xff08;源码下载) 》 2、程序功能选中列表控件某一项&#xff0c;删除按钮由禁止变为可用&#xff0c;点击删除按钮&#xff0c;选中的项将删除。 3、首先在主界面添加一个删除参数按钮。 4、在myDlg.cpp 文件…

Python语言零基础入门——文件

目录 一、文件的基本概念 1.文件 2.绝对路径与相对路径 3.打开文件的模式 二、文件的读取 三、文件的追加 四、文件的写入 五、with语句 六、csv文件 1.csv文件的读取 2.csv文件的写入 七、练习题&#xff1a;实现日记本 一、文件的基本概念 1.文件 文件是以计算…

win10禁止自动更新的终极方法

添加注册表值 1.运行&#xff0c;输入regedit 2.打开注册表编辑器依次进入以下路径“计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings”。 3.在Settings项中&#xff0c;新建DWORD&#xff08;32位&#xff09;值(D)&#xff0c;重命名为以下命名“Fl…