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

2024-05-03 22:20

本文主要是介绍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

这篇关于ASP.NET图书馆管理信息系统的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/957783

相关文章

poj 1258 Agri-Net(最小生成树模板代码)

感觉用这题来当模板更适合。 题意就是给你邻接矩阵求最小生成树啦。~ prim代码:效率很高。172k...0ms。 #include<stdio.h>#include<algorithm>using namespace std;const int MaxN = 101;const int INF = 0x3f3f3f3f;int g[MaxN][MaxN];int n

如何在Visual Studio中调试.NET源码

今天偶然在看别人代码时,发现在他的代码里使用了Any判断List<T>是否为空。 我一般的做法是先判断是否为null,再判断Count。 看了一下Count的源码如下: 1 [__DynamicallyInvokable]2 public int Count3 {4 [__DynamicallyInvokable]5 get

2、PF-Net点云补全

2、PF-Net 点云补全 PF-Net论文链接:PF-Net PF-Net (Point Fractal Network for 3D Point Cloud Completion)是一种专门为三维点云补全设计的深度学习模型。点云补全实际上和图片补全是一个逻辑,都是采用GAN模型的思想来进行补全,在图片补全中,将部分像素点删除并且标记,然后卷积特征提取预测、判别器判别,来训练模型,生成的像

java计算机毕设课设—停车管理信息系统(附源码、文章、相关截图、部署视频)

这是什么系统? 资源获取方式在最下方 java计算机毕设课设—停车管理信息系统(附源码、文章、相关截图、部署视频) 停车管理信息系统是为了提升停车场的运营效率和管理水平而设计的综合性平台。系统涵盖用户信息管理、车位管理、收费管理、违规车辆处理等多个功能模块,旨在实现对停车场资源的高效配置和实时监控。此外,系统还提供了资讯管理和统计查询功能,帮助管理者及时发布信息并进行数据分析,为停车场的科学

.NET 自定义过滤器 - ActionFilterAttribute

这个代码片段定义了一个自定义的 ASP.NET Core 过滤器(GuardModelStateAttribute),用于在控制器动作执行之前验证模型状态(ModelState)。如果模型状态无效,则构造一个 ProblemDetails 对象来描述错误,并返回一个 BadRequest 响应。 代码片段: /// <summary>/// 验证 ModelState 是否有效/// </

.Net Mvc-导出PDF-思路方案

效果图: 导语:     在我们做项目的过程中,经常会遇到一些服务性的需求,感到特别困扰,明明实用的价值不高,但是还是得实现;     因此小客在这里整理一下自己导出PDF的一些思路,供大家参考。     网上有很多导出PDF运用到的插件,大家也可以看看其他插件的使用,学习学习; 提要:     这里我使用的是-iTextSharp,供大家参考参考,借鉴方案,完善思路,补充自己,一起学习

.net MVC 导出Word--思路详解

序言:          一般在项目的开发过程中,总会接收到一个个需求,其中将数据转换成Work来下载,是一个很常见的需求;          那么,我们改如何处理这种需求,并输出实现呢?          在做的过程中,去思考 1、第一步:首先确认,Work的存在位置,并创建字符输出路:             //在的项目中创建一个存储work的文件夹             string

asp.net 中GridView的使用方法

可以看看,学习学习 https://blog.csdn.net/zou15093087438/article/details/79637042

基于ASP+ACCESS的教师信息管理系统

摘要 随着我国社会主义市场经济的发展和改革开放的不断深入,计算机的应用已遍及国民经济的各个领域,计算机来到我们的工作和生活中,改变着我们和周围的一切。在以前,学校用手工处理教师档案以及工资发放等繁多的工作和数据时,人手总会出现些不必要的错误和问题,特别是在查找,统计和保存方面。与此相适应,用计算机代替手工管理,是信息社会发展的必然趋势,也是我们计算机工作者的责任。教师信息管理系统开发主要包括数据

ASP.NET状态管理的总结

由于HTTP协议的无状态特性,导致在ASP.NET编程中,每个请求都会在服务端从头到执行一次管线过程, 对于ASP.NET页面来说,Page对象都会重新创建,所有控件以及内容都会重新生成, 因此,如果希望上一次的页面状态能够在后续页面中保留,则必需引入状态管理功能。   ASP.NET为了实现状态管理功能,提供了8种方法,可帮助我们在页面之间或者整个用户会话期间保留状态数据。 这些方法分为二类: