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

摘  要

本文首先阐述了基于.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.mzph.cn/news/831472.shtml

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

相关文章

Copilot Venture Studio創始合伙人楊林苑確認出席“邊緣智能2024 - AI開發者峰會”

隨著AI技術的迅猛發展&#xff0c;全球正逐步進入邊緣計算智能化與分布式AI深度融合的新時代&#xff0c;共同書寫著分布式智能創新應用的壯麗篇章。邊緣智能&#xff0c;作為融合邊緣計算和智能技術的新興領域&#xff0c;正逐漸成為推動AI發展的關鍵力量。借助分布式和去中心…

Docker——部署LNMP架构

目录 一、LNMP架构概述 1.项目环境 2.服务器环境 3.需求 二、搭建Linux系统基础镜像 三、部署Nginx 1.建立工作目录 2.编写Dockerfile脚本 3.准备Nginx.conf配置文件 4.生成镜像 5.创建自定义网络 6.启动镜像容器 7.验证Nginx 三、部署Mysql 1.建立工作目录 2.编…

【Docker第一课】docker的基本命令和试启动容器(详细图解)

目录 知识梗概 docker的初步了解 了解docker常用命令 试开启容器&#xff08;这里演示nginx、python3和mysql&#xff09; 1、nginx容器的启动 2、python3容器的启动 docker的作用 虚拟机与容器的区别 写在前面&#xff1a; 本专栏你将了解docker一些入门知识&#xff…

如何使用 ArcGIS Pro 查找小区最近的地铁站

学习 GIS 除了可以用在工作上之外&#xff0c;还可以将其运用到生活之中&#xff0c;比如查找距离小区最近的地铁站&#xff0c;这里为大家介绍一下查找的方法&#xff0c;希望能对你有所帮助。 数据来源 教程所使用的数据是从水经微图中下载的POI数据&#xff0c;除了POI数据…

a-table 控制列的展示和隐藏

一、业务场景&#xff1a; 最近在使用 Antd-vue 组件库的时候&#xff0c;a-table需要根据不同角色的权限显示和隐藏 columns的列 为了避免大家走弯路&#xff0c;为大家整理了一下&#xff0c;粘走可以直接用的那种 二、具体实现步骤&#xff1a; 1.在需要显示与隐藏的列增加一…

Git客户端(TortoiseGit)使用详解

1.概述 使用TortoiseGit比直接使用git 客户端和命令实现代码版本管理更为方便&#xff0c;本文根据实际使用情况作一些记录&#xff0c;特别是对于解决冲突的处理。 2.Git安装与配置 下载 Git - Downloads&#xff0c; 可参考Git安装步骤完成Git的安装与配置。 3.TortoiseG…

python学习笔记B-20:序列实战--处理千年虫

将2位数表达的年份&#xff0c;转换为用4位数表达&#xff1a; print("将列表中的2位数年份转换为4位数年份") lst[88,89,90,00,99] print(lst) for index in range(len(lst)):if len(str(lst[index]))2:lst[index] 1900int(lst[index])elif len(str(lst[index]))1…

收单外包机构备案情况分析,广东备案机构遥遥领先

孟凡富 4月30日&#xff0c;中国支付清算协会公示了最新一批收单外包服务备案机构&#xff0c;较上期增加了689家。其中&#xff0c;新增聚合支付技术服务备案机构达6家。截至4月末&#xff0c;备案的收单外包服务机构总数为27714家&#xff0c;同时取消了330家机构的备案资格&…

spring-security 学习笔记一 --- 基于默认配置

1.前言 本文主要讲解 spring-security 在不做任何配置情况下&#xff0c;它的启动流程和认证过程。 1. 准备工作 这里是基于springboot 2.2.5版本对应 spring-security 5.2.2版本演示的 &#xff08;按我下面导入即可&#xff0c;版本是它自己匹配的&#xff09; 引入依赖 &…

SpringBoot-@Transactional注解失效

Transactional注解失效 Transactional失效场景 以下是一些常见导致Transactional注解失效的场景&#xff0c;配合相应的Java代码演示&#xff1a; 1、方法修饰符非公开&#xff08;非public&#xff09; Transactional注解失效的原因在于Spring事务管理器如何实现对事务的代…

【跟马少平老师学AI】-【神经网络是怎么实现的】(七-2)word2vec模型

一句话归纳&#xff1a; 1&#xff09;CBOW模型&#xff1a; 2c个向量是相加&#xff0c;而不是拼接。 2&#xff09;CBOW模型中的哈夫曼树&#xff1a; 从root开始&#xff0c;向左为1&#xff0c;向右为0。叶子结点对应词有中的一个词。每个词对应唯一的编码。词编码不等长。…

Redis基本數據結構 ― String

Redis基本數據結構 ― String 介紹常用命令範例1. 為字串鍵設值/取得字串鍵的值2. 查看字串鍵的過期時間3. 如何為key設置時間?4. 如何刪除指定key?5. 如何增加value的值?6. 獲取value值的長度 介紹 字串鍵是Redis中最基本的鍵值對類型&#xff0c;這種類型的鍵值對會在數據…

Spring - 10 ( 9000 字 Spring 入门级教程 )

一&#xff1a;MyBatis 进阶 动态 SQL 是 Mybatis 的强大特性之⼀&#xff0c;能够完成不同条件下不同的 sql 拼接。 1.1 if 标签 在注册用户的时候&#xff0c;可能会有这样⼀个问题&#xff0c;如下图所示&#xff1a; 注册分为两种字段&#xff1a;必填字段和非必填字段&…

Vue ui 创建vue项目,详细使用攻略。

1.安装及启动 1.1 Vue ui 使用前提是全局安装vue.js 命令如下 npm install vue -g 1.2 安装过Vue.js 之后 随便在自己系统的一个地方打开命令面板 1.3 使用命令启动vue ui面板创建项目 vue ui 如图运行后显示这种就是启动成功&#xff0c;成功之后会弹出页面或者直接访问你的…

伦敦金的交易时间段都适合投资吗?

是所有的交易时间段都适合投资。首先&#xff0c;让我们了解伦敦金的交易时间。伦敦金市场的交易时间分为两个主要时段&#xff1a;亚洲盘和欧美盘。亚洲盘通常在北京时间早晨6点至下午5点半左右&#xff0c;而欧美盘则从北京时间晚上8点半开始&#xff0c;一直到次日早晨4点半…

痉挛性斜颈患者早上运动还是下午运动更合适?选对了让治疗更简单!【北京仁爱堂】

对于痉挛性斜颈患者来说&#xff0c;选择合适的运动时间对于治疗的效果和舒适度至关重要。那么&#xff0c;痉挛性斜颈患者早上运动还是下午运动更合适呢&#xff1f;本文将从多个角度对此进行分析&#xff0c;帮助患者找到最适合自己的运动时间。 首先&#xff0c;我们需要了…

特征提取(Feature Extraction)常见统计特征笔记(三)

统计特征是描述数据集中值的一组量&#xff0c;通常用于了解数据的分布、集中趋势和变异程度。常见的统计特征包括均值、中位数、众数、标准差、方差等。下面会详细解释每个统计特征&#xff0c;并给出相应的Python代码。 1、均值&#xff08;Mean&#xff09;&#xff1a;所有…

Python的使用

1、打印&#xff1a;print&#xff08;‘hello’&#xff09; 2、Python的除法是数学意义上的除法 print&#xff08;2/3&#xff09; 输出&#xff1a;0.6666... 3、a18 a‘hello’ print(a) 可以直接输出 4、**2 表示2的平方 5、打印类型 print&#xff08;type&am…

答案自在你心——不求事事皆如愿,只求件件都无悔

时光荏苒&#xff0c;弹指间&#xff0c;似如梦初醒般又迎来了大学的第二个五一假期。多数人看来&#xff0c;又是一个千载难逢的度假时光&#xff0c;于我而言&#xff0c;心里却一直紧绷一根迟迟难以松弛的弦。也许是习惯了平常忙忙碌碌的生活节奏&#xff0c;突然停下来&…

linux下载压缩包

比如我要下载的压缩包地址为&#xff1a; http://calvin.inf.ed.ac.uk/wp-content/uploads/data/cocostuffdataset/cocostuff-10k-v1.1.zip 1.创建文件夹并切换到这个目录下 2.用wget获取压缩包 压缩包下好了 3.解压 如果是 tar.gz包解压 tar -zxvf 也可以解压到具体的目录…