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

📄 bookinfomag.cs

📁 这是一个图书馆管理用的简化系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BMS
{
    public partial class BookInfoMag : Form
    {
        public BookInfoMag()
        {
            InitializeComponent();
        }

        private void B_BookID_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.abc123(e);
        }

        private void B_ReaderID_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.abc123(e);
        }

        private void Speed_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.num(Speed,e);
        }

        private void R_BookID_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.abc123(e);
        }

        private void Amerce_Num_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !Check.num(Amerce_Num,e);
        }

        private void BookInfoMag_Load(object sender, EventArgs e)
        {
            String Sql = "Select * from BRinf ";
            Return_Time.Value = DateTime.Now.AddMonths(2);
            BookInfo.DataSource = Operator.SelectSql(Sql).Tables[0];
            if (Value.Borrowreturn != "")
            { 
                BorrowReadQuery brq = new BorrowReadQuery();
                if (Value.Borrowreturn == "续借")
                {
                    B_BookID.Text = Value.Bookid;
                    B_ReaderID.Text = Value.readerid;
                }
                else
                {
                    R_BookID.Text = Value.Bookid;
                }
                R_BookID_Leave(sender, e);
            }
        }

        private void BorrowBook_Click(object sender, EventArgs e)
        {
           
            string Sql1, Sql2,Sql = "begin tran;insert into BRinf (Readerid,readername,bookid,bookname,borrowtime,"
                +"limitReturntime,Returntime,overtime,Spend,Money,id,isReturn,operater) values({0})";
            DataSet ds;
            if (Value.Borrowreturn == "续借")
            {
                Sql = "update brinf set limitReturntime = '"
                    + (DateTime.Now.AddMonths(2)).ToString().Substring(0, DateTime.Now.ToString().IndexOf(" ")-1)
                    + "' where Readerid = '" + B_ReaderID.Text.Trim() + "' and Bookid = '"
                    + B_BookID.Text.Trim() + "';";
                if (Operator.ExecuteSql(Sql) <= 0)
                {
                    MessageBox.Show("续借失败!", "读者续借");
                
                }
                BookInfoMag_Load(sender, e);
                return;
            }
            if (B_BookID.Text.Trim() != "" && B_ReaderID.Text.Trim() != "")
            {
                int i;
                string msg = "用户已借图书:";
                Sql1 = "select bookid,bookname from brinf where Readerid = '" + B_ReaderID.Text.Trim() + "'and isreturn ='否';";
                ds = Operator.SelectSql(Sql1);
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    for (i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        msg += "1.图书编号:"+ds.Tables[0].Rows[i].ItemArray[0].ToString().Trim()+"\t";
                        msg+="书名:"+ds.Tables[0].Rows[i].ItemArray[1].ToString().Trim()+"\n";
                    }
                    msg += "按确定继续,按消取中止操作!";
                    DialogResult dlr = MessageBox.Show(msg,"读者借阅",MessageBoxButtons.OKCancel);
                    if (dlr == DialogResult.Cancel)
                    {
                        return;
                    }
                   
                }
                string Rid, Rname, Bid, Bname, Btime, LRtime, Rtime, Otime, BRSpeed, Money,Pid,id, IsR;
                Sql1 = "select * from Reader where readerid = '" + B_ReaderID.Text.Trim() + "';";
                ds = Operator.SelectSql(Sql1);

                Rid = B_ReaderID.Text.Trim();
                Bid = B_BookID.Text.Trim();
                Rname = ds.Tables[0].Rows[0].ItemArray[1].ToString().Trim();
                IsR = "否";

                ds = new DataSet();
                Sql1 = "select bookname,Published from bookinf where bookid = '" + B_BookID.Text.Trim() + "';";
                ds = Operator.SelectSql(Sql1);
                
                Bname = ds.Tables[0].Rows[0].ItemArray[0].ToString().Trim();
                Pid = ds.Tables[0].Rows[0].ItemArray[1].ToString().Trim();
                Btime = "getdate()";
                LRtime = Return_Time.Value.ToString().Substring(0, Return_Time.Value.ToString().IndexOf(" "));
                Rtime = "getdate()";
                Otime = "0";
                BRSpeed = Speed.Text.Trim();
                if (BRSpeed.Length == 0)
                {
                    BRSpeed = "0";
                }
                if (B_BookID.Text.Trim() == "")
                {
                    return;
                }
                Sql1 = "select Bookstate from bookinf where bookid = '" + B_BookID.Text.Trim() + "';";
                ds = Operator.SelectSql(Sql1);
                if (!(ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Rows[0].ItemArray[0].ToString().Trim() == "在库"))
                {
                    MessageBox.Show("输入的图书编号有误或图书已借出,请仔细核对!", "读者借阅");
                    B_BookID.Focus();
                    B_BookID.Text = "";
                    return;
                }
                Money = "0";
                id = Operator.select("select count(*) from brinf").ToString().Trim()+1;
               
                Sql2 = "'" + Rid + "','" + Rname + "','" + Bid + "','" + Bname + "'," + Btime + ",'" 
                    + LRtime + "'," + Rtime + ","+ Otime + "," + BRSpeed + "," + Money + "," + id 
                    + ",'" + IsR + "','" + Value.CurrentLoger1 + "'";
               
                Sql = string.Format(Sql,Sql2);
                Sql += "update booktable set bookstocks = bookstocks - 1 where Publishid = "+ Pid +";";
                Sql += "update bookinf set Bookstate = '借出' where bookid = '"+B_BookID.Text.Trim()+"';commit tran;";
                
                if (Operator.ExecuteSql(Sql) <= 0)
                {
                    MessageBox.Show("借阅失败!", "读者借阅");
                }
            }
            else
            {
                MessageBox.Show("请输入完整的阅信息!", "读者借阅");
                return;
            }
            BookInfoMag_Load(sender, e);
        }

        private void B_BookID_Leave(object sender, EventArgs e)
        {
            string Sql;
            if (B_BookID.Text.Trim() == "")
            {
                return;
            }
            Sql = "select * from breakbook where bookID ='" + B_BookID.Text.Trim() + "';";
            DataSet ds = Operator.SelectSql(Sql);
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                MessageBox.Show("此图书已报损不能外借!","读者借阅");
                return;
            }
            Sql = "select Bookstate from bookinf where bookid = '" + B_BookID.Text.Trim() + "';";
            ds = Operator.SelectSql(Sql);
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Rows[0].ItemArray[0].ToString().Trim() == "在库")
            {
                return;
            }
            else
            {
                MessageBox.Show("输入的图书编号有误或图书已借出,请仔细核对!","读者借阅");
                B_BookID.Focus();
                B_BookID.Text = "";
            }
           
        }

        private void B_ReaderID_Leave(object sender, EventArgs e)
        {
            string Sql;
            if (B_ReaderID.Text.Trim() == "")
            {
                return;
            }
            Sql = "select * from Reader where readerid = '" + B_ReaderID.Text.Trim() + "';";
            DataSet ds = Operator.SelectSql(Sql);
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }
            else
            {
                MessageBox.Show("输入的读者编号有误,请仔细核对!","读者借阅");
                B_ReaderID.Focus();
                B_ReaderID.Text = "";
            }
        }

        private void R_BookID_Leave(object sender, EventArgs e)
        {
            string Sql;
            if (R_BookID.Text.Trim() == "")
            {
                return;
            }
            if (Value.Borrowreturn == "归还")
            {
                return;
            }
            Sql = "select isreturn,limitReturntime,spend from brinf where bookid = '" + R_BookID.Text.Trim() + "' and isreturn = '否';";
            DataSet ds = Operator.SelectSql(Sql);
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                System.TimeSpan  i = DateTime.Now.Date - Convert.ToDateTime(ds.Tables[0].Rows[0].ItemArray[1].ToString().Trim()).Date;
                if (i.Days > 0)
                {
                    MessageBox.Show("此图书已超期" + i.Days.ToString() + "天!", "读者还书");
                    Amerce_Num.Text = Convert.ToString(i.Days * Convert.ToDouble(ds.Tables[0].Rows[0].ItemArray[2].ToString().Trim()));
                }
                return;
            }
            else
            {
                MessageBox.Show("输入的图书编号有误或此图书没有借出,请仔细核对!", "读者借阅");
                R_BookID.Focus();
                R_BookID.Text = "";
            }
        }

        private void Return_Book_Click(object sender, EventArgs e)
        {
            string Sql,Money,Odays,Pid;
            if (R_BookID.Text.Trim() == "")
            {
                return;
            }
            if (Amerce_Num.Text.Trim() == "")
            {
                Money = "0";
            }
            else
            {
                Money = Amerce_Num.Text.Trim();
            }
            Sql = "select Published from bookinf where bookid = '"+R_BookID.Text.Trim()+"';";
            Pid  = Operator.SelectSql(Sql).Tables[0].Rows[0].ItemArray[0].ToString().Trim();
            Sql = "select isreturn,limitReturntime,spend from brinf where bookid = '" + R_BookID.Text.Trim() + "';";
            DataSet ds = Operator.SelectSql(Sql);
            System.TimeSpan i= DateTime.Now - Convert.ToDateTime(ds.Tables[0].Rows[0].ItemArray[1].ToString().Trim());
            if (i.Days <= 0)
            {
                Odays = "0";
            }
            else
            {
                Odays = i.Days.ToString();
            }
            Sql = "begin tran;update Brinf set returntime = getdate(),overtime = " + Odays + ",money = " + Money 
                + ",isreturn ='是',operater = '" + Value.CurrentLoger1 + "' where bookid = '"+R_BookID.Text.Trim()+"' and isreturn = '否';";
            Sql += "update booktable set bookstocks = bookstocks + 1 where Publishid = " + Pid  + ";";
            Sql += "update bookinf set Bookstate = '在库' where bookid ='"+R_BookID.Text.Trim()+"';commit tran;";
            if (Operator.ExecuteSql(Sql) <= 0)
            {
                MessageBox.Show("还书失败!", "读者还书");
            }
            BookInfoMag_Load(sender, e);
        }

    }
}

⌨️ 快捷键说明

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