⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookinfo.aspx.cs

📁 图书管理的相关流程,借书还书流程,比较详细
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class BookInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            userAcctent();
        }
    }

    private void userAcctent()
    {
        string strSql = null;
        if (Session["bookID"] != null)
        {
            int bookID = Int32.Parse(Session["bookID"].ToString());

            strSql = "SELECT [bookID],[bookName],[bookWriter],[bookFrom],[bookContent],[bookNum],[bookSite] FROM [bookInfo] WHERE [bookID]='" + bookID + "'";
            BookInfos bookinfos = new BookInfos();
            bookinfos = DBhelper.sqlBookInfo(strSql);

            txtBookName.Text = bookinfos.BookName;
            txtBookWriter.Text = bookinfos.BookWriter;
            txtBookFrom.Text = bookinfos.BookFrom;
            txtBookContent.Text = bookinfos.BookContent;
            txtBookNum.Text = bookinfos.BookNum.ToString();
            txtBookSite.Text = bookinfos.BookSite;
        }

        int UserID = Int32.Parse(Session["uid"].ToString());
        strSql = "SELECT [userID],[userLoginID],[userPwd],[userName],[userStatus] FROM [userInfo] WHERE [userID] ='" + UserID + "'";
        UserInfo userinfo = new UserInfo();
        userinfo = DBhelper.sqlUserInfo(strSql);

        if (userinfo.UserStatus == 0)
        {
            Button3.Visible = false;
            Button4.Visible = false;
        }
        else
        {
            txtBookName.Enabled = false;
            txtBookWriter.Enabled = false;
            txtBookFrom.Enabled = false;
            txtBookContent.Enabled = false;
            txtBookNum.Enabled = false;
            txtBookSite.Enabled = false;
            Button1.Visible = false;
            Button2.Visible = false;
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        if (!txtBookName.Text.Equals("") && !txtBookWriter.Text.Equals("") && !txtBookFrom.Text.Equals("") && !txtBookContent.Text.Equals("") && !txtBookNum.Text.Equals("") && !txtBookSite.Text.Equals(""))
        {
            BookInfos bookinfos = new BookInfos();
            bookinfos.BookName = txtBookName.Text;
            bookinfos.BookWriter = txtBookWriter.Text;
            bookinfos.BookFrom = txtBookFrom.Text;
            bookinfos.BookContent = txtBookContent.Text;
            bookinfos.BookNum = Int32.Parse(txtBookNum.Text);
            bookinfos.BookSite = txtBookSite.Text;

            string strSql = null;

            if (Session["bookID"] != null)
            {
                int bookID = Int32.Parse(Session["bookID"].ToString());
                strSql = "UPDATE [bookInfo] SET [bookName]='" + bookinfos.BookName + "',[bookWriter]= '" + bookinfos.BookWriter + "',[bookFrom]='" + bookinfos.BookFrom + "',[bookContent]='" + bookinfos.BookContent + "',[bookNum]='" + bookinfos.BookNum + "',[bookSite]='" + bookinfos.BookSite + "' WHERE [bookID]='" + bookID + "'";
            }
            else
            {
                strSql = "INSERT INTO [bookInfo]([bookName],[bookWriter],[bookFrom],[bookContent],[bookNum],[bookSite]) VALUES('" + bookinfos.BookName + "','" + bookinfos.BookWriter + "','" + bookinfos.BookFrom + "','" + bookinfos.BookContent + "','" + bookinfos.BookNum + "','" + bookinfos.BookSite + "')";
            }
            int i = DBhelper.sqlinit(strSql);

            if (i > 0)
            {
                Response.Redirect("BookManager.aspx");
            }
        }
        else
        {
            txtMsg.Text = "请完整的填写图书信息!";
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("BookManager.aspx");
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        int UserID = Int32.Parse(Session["uid"].ToString());
        string strSql = "SELECT [borrowID],[bookName],[bookWriter],[bookFrom],[borrowDate] FROM [bookInfo],[borrowInfo] Where [bookInfo].[bookID]=[borrowInfo].[bookID] AND [borrowInfo].[borrowStatus]=0 AND [borrowInfo].[userID]='" + UserID + "'";
        if (DBhelper.sqlLoad(strSql).Rows.Count < 5)
        {
            int bookID = Int32.Parse(Session["bookID"].ToString());
            strSql = "SELECT [borrowID] FROM [borrowInfo] Where [bookID]='" + bookID + "' AND [borrowStatus]=0 AND [userID]='" + UserID + "'";
            if (DBhelper.sqlLoad(strSql).Rows.Count == 0)
            {
                strSql = "UPDATE [bookInfo] SET [bookNum]=[bookNum]-1 WHERE [bookID]='" + bookID + "'";
                int i = DBhelper.sqlinit(strSql);
                string borrowDate = DateTime.Now.ToString("yyyy-MM-dd"); 
                strSql = "INSERT INTO [borrowInfo]([bookID],[userID],[borrowDate],[borrowStatus]) VALUES('" + bookID + "','" + UserID + "','" + borrowDate + "',0)";
                i = DBhelper.sqlinit(strSql);
                if (i > 0)
                {
                    Response.Redirect("BorrowManager.aspx");
                }
            }
            else
            {
                txtMsg.Text = "此书正被您借阅!";
            }
        }
        else
        {
            txtMsg.Text = "一个人只能借5本书!请您先还书!";
        }

    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        Response.Redirect("BorrowManager.aspx");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -