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

📄 bookbussiness.cs

📁 网上那个书店开发系统论文,需要的朋友可以下载参考哦
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
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;
using System.Collections.Generic;
using System.Data.SqlClient;
using BookManage.Model;

namespace BookManage.DAL
{
    /// <summary>
    /// 图书的借阅,归还操作
    /// </summary>
    public class BookBusiness
    {
        public BookBusiness()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        /// <summary>
        /// 获取已经借出的图书
        /// </summary>
        /// <returns></returns>
        public IList<BookLentInfo> GetBookLendList()
        {
            const string cmdText = "select l.blid,l.username,l.bookid,l.starttime,l.endtime,b.bookname,b.bookCode from booklent l,booklist b where l.bookid=b.bookid order by endtime";
            IList<BookLentInfo> blInfo = new List<BookLentInfo>();
            using (SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, cmdText, null))
            {
                while (dr.Read())
                {
                    EMUserProfile profile = new EMUserProfile(string.Empty, dr.GetString(1), string.Empty, 0);
                    BookInfo bi = new BookInfo(string.Empty, dr.GetString(5), BookSatus.Lent, dr.GetString(6), dr.GetInt32(2), null);
                    BookLentInfo bli = new BookLentInfo(bi, profile, dr.GetInt32(0), dr.GetDateTime(4), dr.GetDateTime(3));
                    blInfo.Add(bli);
                }
            }
            return blInfo;
        }

        /// <summary>
        /// 获取用户借入的图书
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public IList<BookLentInfo> GetBookLendListByUserName(string userName)
        {
            const string cmdText = "select l.blid,l.username,l.bookid,l.starttime,l.endtime,b.bookname,b.bookCode from booklent l,booklist b where l.bookid=b.bookid and l.username=@username order by endtime";
            IList<BookLentInfo> blInfo = new List<BookLentInfo>();
            SqlParameter param = new SqlParameter("@username", SqlDbType.VarChar, 20);
            param.Value = userName;
            using (SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, cmdText, param))
            {
                while (dr.Read())
                {
                    EMUserProfile profile = new EMUserProfile(string.Empty, dr.GetString(1), string.Empty, 0);
                    BookInfo bi = new BookInfo(string.Empty, dr.GetString(5), BookSatus.Lent, dr.GetString(6), dr.GetInt32(2), null);
                    BookLentInfo bli = new BookLentInfo(bi, profile, dr.GetInt32(0), dr.GetDateTime(4), dr.GetDateTime(3));
                    blInfo.Add(bli);
                }
            }
            return blInfo;
        }

        /// <summary>
        /// 借书
        /// </summary>
        /// <param name="bookId"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static int LendBook(int bookId, string userName)
        {
            DateTime startTime = DateTime.Now;
            DateTime endTime = startTime.AddDays(BookLentInfo.MostBorrowDays);
            const string cmdText = "upBookLentAdd";
            SqlParameter[] param = new SqlParameter[]{
            new SqlParameter("@bookid",SqlDbType.Int),
            new SqlParameter("@userName",SqlDbType.VarChar),
            new SqlParameter("@mostBorrowBooks",SqlDbType.Int),
            new SqlParameter("@starttime",SqlDbType.DateTime),
            new SqlParameter("@endtime",SqlDbType.DateTime),
            new SqlParameter("@result",SqlDbType.Int)
        };
            param[0].Value = bookId;
            param[1].Value = userName;
            param[2].Value = BookLentInfo.MostBorrowBooks;
            param[3].Value = startTime;
            param[4].Value = endTime;
            param[5].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, cmdText, param);
            return (int)param[5].Value;
        }

        /// <summary>
        /// 还书
        /// </summary>
        /// <param name="blId"></param>
        /// <returns></returns>
        public int ReturnBook(int blId)
        {
            const string cmdText = "update booklist set bookStatus=0 where bookid=(select bookid from booklent where blId=@blid);delete from booklent where blId=@blId";
            SqlParameter param = new SqlParameter("@blId", SqlDbType.Int);
            param.Value = blId;
            int result = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, cmdText, param);
            return result;
        }

        /// <summary>
        /// 用户已借书数量
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public int BorrowedBookAmount(string userName)
        {
            const string cmdText = "select count(*) from booklent where userName=@userName";
            SqlParameter param = new SqlParameter("@userName", SqlDbType.VarChar, 20);
            param.Value = userName;
            int amount = (int)(SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, cmdText, param));
            return amount;
        }

        /// <summary>
        /// 用户是否有到期图书未还
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public bool HasExpiredBook(string userName)
        {
            bool expired = false;
            const string cmdText = "select * from booklent where userName=@userName and endtime>getdate()";
            SqlParameter param = new SqlParameter("@userName", SqlDbType.VarChar, 20);
            param.Value = userName;
            using (SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, cmdText, param))
            {
                while (dr.Read())
                {
                    expired = true;
                }
            }
            return expired;
        }
    }


}

⌨️ 快捷键说明

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