C# 图书馆项目实例

图书馆管理系统

第一部分BLL文件

C# 图书馆项目实例_第1张图片

在这里插入图片描述

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("BLL")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("BLL")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。  如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("56508829-94db-4184-bb70-fcd4e4c5238c")]

// 程序集的版本信息由下面四个值组成: 
//
//      主版本
//      次版本 
//      生成号
//      修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: 
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using DAL;
using System.Data;

namespace BLL
{
    public class Admin_BLL
    {
        Admin_DAL aa = new Admin_DAL();

        //删除管理员
        public int deleteAdmin(String LoginId)
        {
            return aa.deleteAdmin(LoginId);
        }
        //修改管理员
        public int ExitAdmin(Admin a)
        {
            return aa.ExitAdmin(a);
        }
        //添加管理员
        public int AddAdmin(Admin a)
        {
            return aa.AddAdmin(a);
        }
        public DataSet selectAdmin()
        {
            return aa.selectAdmin();
        }


        public int Scalar(Admin a)
        {
            return aa.Scalar(a);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using DAL;
using System.Data;

namespace BLL
{
    public class BookInfo_BLL
    {
        BookInfo_DAL b = new BookInfo_DAL();

        /// 
        /// 查询BookInfo表
        /// 
        /// 
        public List selectBookInfo()
        {
            return b.selectBookInfo();
        }
        /// 
        /// 查询BookInfo表
        /// 
        /// 
        /// 
        public List selectBookInfo(string BookId)
        {
            return b.selectBookInfo(BookId);
        }
        /// 
        /// 查询BookInfo表
        /// 
        /// 
        public DataSet selectBookInfo1()
        {
            return b.selectBookInfo1();
        }
        /// 
        /// 查询BookInfo表带条件
        /// 
        /// 
        /// 
        public DataSet selectBookInfo1(int index)
        {
            return b.selectBookInfo1(index);
        }
        /// 
        /// 查询BookInfo表带条件
        /// 
        /// 
        /// 
        /// 
        public DataSet selectBookInfo1(string A, string B)
        {
            return b.selectBookInfo1(A, B);
        }

        //查询BookInfo表带条件 全部
        public DataSet selectBookInfo1(List list, string B)
        {
            return b.selectBookInfo1(list, B);
        }

        /// 
        /// 查询BookInfo表 目前可以借阅的图书
        /// 
        /// 
        /// 
        public DataSet selectBookInfo2(string BookId)
        {
            return b.selectBookInfo2(BookId);
        }
        //修改图书信息
        public int ExitBookInfo(BookInfo book)
        {
            return b.ExitBookInfo(book);
        }

        //添加图书信息
        public int AddBookInfo(BookInfo book)
        {
            return b.AddBookInfo(book);
        }

        //删除图书信息
        public int DeleteBookInfo(string BookId)
        {
            return b.DeleteBookInfo(BookId);
        }
    }
}

using DAL;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class BookType_BLL
    {
        BookType_DAL bookType_dal = new BookType_DAL();
        public List selectBookType()
        {
            return bookType_dal.selectBookType();
        }

        public DataSet selectBookType1()
        {
            return bookType_dal.selectBookType1();
        }

        public int AddBookTypeInfo(BookType type)
        {
            return bookType_dal.AddBookTypeInfo(type);
        }

        //删除图书类型
        public int deleteBookType(int BookTypeId)
        {
            return bookType_dal.deleteBookType(BookTypeId);
        }

        //修改图书类型
        public int updateBookType(BookType type)
        {
            return bookType_dal.updateBookType(type);
        }
    }
}

using DAL;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class BorrowReturn_BLL
    {
        BorrowReturn_DAL borrowReturn_dal = new BorrowReturn_DAL();

        //查询借还表信息
        public DataSet selectHostory(BorrowReturn b, string radioName, String cboBorrowTimeType, Boolean checkTime)
        {
            return borrowReturn_dal.selectHostory(b, radioName, cboBorrowTimeType, checkTime);
        }
        //借还表全部信息 包括现在借阅的和历史借阅的
        public DataSet AllBorrowReturn()
        {
            return borrowReturn_dal.AllBorrowReturn();
        }
        //查询图书借还表
        public DataSet selectBorrowReturn(string BookId)
        {
            return borrowReturn_dal.selectBorrowReturn(BookId);
        }

        //读者借阅记录
        public DataSet ReaderBorrowReturn(string ReaderId)
        {
            return borrowReturn_dal.ReaderBorrowReturn(ReaderId);
        }

        //读者历史借阅记录
        public DataSet ReaderBorrowReturn1(string ReaderId)
        {
            return borrowReturn_dal.ReaderBorrowReturn1(ReaderId);
        }

        //还书
        public int ReturnBook(int BorrowReturnId)
        {
            return borrowReturn_dal.ReturnBook(BorrowReturnId);
        }

        //借书
        public int BorrowBook(BorrowReturn b)
        {
            return borrowReturn_dal.BorrowBook(b);
        }

        //续借
        public int RenewBook(BorrowReturn b)
        {
            return borrowReturn_dal.RenewBook(b);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using Model;
using System.Data;

namespace BLL
{
    public class Class_BLL
    {
        Class_DAL class_dal = new Class_DAL();
        public List selectClass()
        {
            return class_dal.selectClass();
        }

        public DataSet selectClass1()
        {
            return class_dal.selectClass1();
        }

        public int AddClass(Class c)
        {
            return class_dal.AddClass(c);
        }

        //删除班级
        public int deleteClass(int ClassId)
        {
            return class_dal.deleteClass(ClassId);
        }

        //修改班级
        public int updateClass(Class c)
        {
            return class_dal.updateClass(c);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using Model;
using System.Data;

namespace BLL
{
    public class Department_BLL
    {
        Department_DAL department_dal = new Department_DAL();
        public List selectDepartment()
        {
            return department_dal.selectDepartment();
        }

        public DataSet selectDepartment1()
        {
            return department_dal.selectDepartment1();
        }

        public int addDepartment(Department d)
        {
            return department_dal.addDepartment(d);
        }

        //删除院系
        public int deleteDepartment(int DepartmentId)
        {
            return department_dal.deleteDepartment(DepartmentId);
        }

        //修改院系
        public int updateDepartment(Department d)
        {
            return department_dal.updateDepartment(d);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using Model;
using System.Data;


namespace BLL
{
    public class Reader_BLL
    {
        Reader_DAL reader_dal = new Reader_DAL();
        //无条件查询读者信息
        public DataSet selectReader()
        {
            return reader_dal.selectReader();
        }

        //根据ID查询全部的读者信息
        public DataSet selectReader(int ReaderTypeId)
        {
            return reader_dal.selectReader(ReaderTypeId);
        }

        //根据查询内容和条件查询的读者信息
        public DataSet selectReader(string A, string B)
        {
            return reader_dal.selectReader(A, B);
        }

        //根据查询条件查询的读者信息
        public DataSet selectReader(List list, string B)
        {
            return reader_dal.selectReader(list, B);
        }

        //删除读者信息
        public int deleteReader(string ReaderId)
        {
            return reader_dal.deleteReader(ReaderId);
        }

        //根据ID查询的读者信息
        public List selectReader1(string ReaderId)
        {
            return reader_dal.selectReader1(ReaderId);
        }

        //修改读者信息
        public int updateReader(Reader reader)
        {
            return reader_dal.updateReader(reader);
        }

        //添加读者信息
        public int addReader(Reader r)
        {
            return reader_dal.addReader(r);
        }

        //返回读者编号,读者姓名
        public List selectReaderId(string ReaderId)
        {
            return reader_dal.selectReaderId(ReaderId);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using Model;
using System.Data;
namespace BLL
{
    public class ReaderType_BLL
    {
        ReaderType_DAL reader_dal = new ReaderType_DAL();
        //查询全部的读者类型
        public List selectReaderType()
        {
            return reader_dal.selectReaderType();
        }

        //查询全部的读者类型
        public DataSet selectReaderType1()
        {
            return reader_dal.selectReaderType1();
        }


        //添加读者类型
        public int addReaderType(ReaderType r)
        {
            return reader_dal.addReaderType(r);
        }

        //删除读者类型
        public int deleteReader(int ReaderTypeId)
        {
            return reader_dal.deleteReader(ReaderTypeId);
        }

        //修改读者类型
        public int updateReaderType(ReaderType r)
        {
            return reader_dal.updateReaderType(r);
        }
    }
}

第二部分:Common

C# 图书馆项目实例_第2张图片

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Common")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Common")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。  如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("14c13f05-90ff-4cf8-9f0d-fc68ef309436")]

// 程序集的版本信息由下面四个值组成: 
//
//      主版本
//      次版本 
//      生成号
//      修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: 
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Reflection;
using System.Drawing;

namespace Common
{
    public class Com
    {
        public void thread()
        {
        
        }
        /// 
        /// DataGridView的样式
        /// 
        /// 
        public void ExitGridView(DataGridView GridView)
        {
            GridView.AllowDrop = false;
            GridView.AllowUserToAddRows = false;
            GridView.AllowUserToDeleteRows = false;
            GridView.AllowUserToOrderColumns = false;
            GridView.AllowUserToResizeColumns = false;
        }
        /// 
        /// 生成一列有功能的按钮
        /// 
        /// 
        /// 
        public void AddColumn(string name, DataGridView GridView)
        {
            //添加修改按钮
            DataGridViewButtonColumn c = new DataGridViewButtonColumn();
            //设置列标题单元格的名称
            c.Text = name;
            //单元格的背景色
            c.DefaultCellStyle.BackColor = Color.LightGray;
            //单元格选定时的背景色
            c.DefaultCellStyle.SelectionBackColor = Color.DarkGray;
            //单元格的默认文本
            c.UseColumnTextForButtonValue = true;
            //单元格宽
            c.Width = 60;
            //添加新的一列对象
            //选中时背景色为灰色
            c.DefaultCellStyle.SelectionBackColor = Color.LightGray;
            c.DefaultCellStyle.SelectionForeColor = Color.Black;
            c.FillWeight = 50;
            GridView.Columns.Add(c);
        }
        /// 
        /// 自动生成columns 没有修改和删除
        /// 
        /// 
        /// 
        /// 
        public void AutoColumn(string HeaderText, string DataPropertyNames, DataGridView GrdiView)
        {
            //去掉自动生成的列
            GrdiView.AutoGenerateColumns = false;
            GrdiView.RowHeadersDefaultCellStyle.SelectionBackColor = Color.DarkGray;
            //生成行标题标号的方法
            GrdiView.DataSource = System.Drawing.Imaging.ImageCodecInfo.GetImageDecoders();
            // 禁止用户改变DataGridView1的所有列的列宽
            GrdiView.AllowUserToResizeColumns = false;
            //禁止用户改变DataGridView1の所有行的行高 
            GrdiView.AllowUserToResizeRows = false;
            //选择整行
            GrdiView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            GrdiView.AllowDrop = false;
            //不可以添加行
            GrdiView.AllowUserToAddRows = false;
            //不可以删除行
            GrdiView.AllowUserToDeleteRows = false;
            //不可以手动对列重新定位
            GrdiView.AllowUserToOrderColumns = false;
            //不可以调整列的大小
            GrdiView.AllowUserToResizeColumns = false;
            //不可以调整行的大小
            GrdiView.AllowUserToResizeRows = false;
            //行标题行的宽度
            GrdiView.RowHeadersWidth = 32;
            //不能多选
            GrdiView.MultiSelect = false;
            //获取标题样式
            GrdiView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            string[] arrayHeaderText = HeaderText.Split(',');
            string[] arrayDataPropertyNames = DataPropertyNames.Split(',');
            for (int i = 0; i < arrayHeaderText.Length; i++)
            {
                DataGridViewTextBoxColumn d = new DataGridViewTextBoxColumn();
                //绑定数据库列名称
                d.DataPropertyName = arrayDataPropertyNames[i];
                //设置列标题的名称
                d.HeaderText = arrayHeaderText[i];
                //单元格选定时的背景色
                d.DefaultCellStyle.SelectionBackColor = Color.Gainsboro;
                d.DefaultCellStyle.SelectionForeColor = Color.Black;
                //单元格的内容居中
                d.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                GrdiView.Columns.Add(d);
            }
            GrdiView.DataSource = null;
        }
        /// 
        /// 找到刚刚添加成功的数据行s
        /// 
        /// 
        /// 
        public void AutoFindRow(string A, DataGridView GridView) 
        {
            //获取DataGridView中的总行数
            int rows = GridView.RowCount;

            //找到刚刚添加成功的数据行
            for (int i = 0; i < rows; i++)
            {
                string a = GridView.Rows[i].Cells[0].Value.ToString();
                if (a == A)
                {
                    //选中整行
                    GridView.Rows[i].Selected = true;
                    //垂直滚动条,滚动到当前行索引位置
                    GridView.FirstDisplayedScrollingRowIndex = i;
                }
                else
                {
                    //清楚整行选中
                    GridView.Rows[i].Selected = false;
                }
            }
        }

        /// 
        /// 找到刚刚添加成功的数据行
        /// 
        /// 
        /// 
        public void AutoFindRow(int A, DataGridView GridView)
        {
            //获取DataGridView中的总行数
            int rows = GridView.RowCount;

            //找到刚刚添加成功的数据行
            for (int i = 0; i < rows; i++)
            {
                int a = (int)GridView.Rows[i].Cells[0].Value;
                if (a == A)
                {
                    //选中整行
                    GridView.Rows[i].Selected = true;
                    //垂直滚动条,滚动到当前行索引位置
                    GridView.FirstDisplayedScrollingRowIndex = i;
                }
                else
                {
                    //清楚整行选中
                    GridView.Rows[i].Selected = false;
                }
            }
        }
    }
}

第三部分:DAL

C# 图书馆项目实例_第3张图片

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("DAL")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("DAL")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。  如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("aa1f6ea9-d7f8-4ac5-9b21-813cc209d14c")]

// 程序集的版本信息由下面四个值组成: 
//
//      主版本
//      次版本 
//      生成号
//      修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: 
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class Admin_DAL
    {
        /// 
        /// 查询全部
        /// 
        /// 
        public DataSet selectAdmin()
        {
            string sql = @"select * from Admin";
            return DBhelp.Create().ExecuteAdater(sql);
        }
        /// 
        /// 删除管理员
        /// 
        /// 
        /// 
        public int deleteAdmin(string LoginId)
        {
            string sql = "delete from Admin where LoginId=@LoginId";
            SqlParameter[] sp ={
                                  new SqlParameter("@LoginId",LoginId)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }
        /// 
        /// 修改管理员
        /// 
        /// 
        /// 
        public int ExitAdmin(Admin a)
        {
            string sql = "update Admin set LoginId=@LoginId,LoginPwd=@LoginPwd,LoginType=@LoginType,LoginRemark=@LoginRemark where LoginId=@LoginId";
            SqlParameter[] sp = { 
                                new SqlParameter("LoginId",a.LoginId),
                                new SqlParameter("LoginPwd",a.LoginPwd),
                                new SqlParameter("LoginType",a.LoginType),
                                new SqlParameter("LoginRemark",a.LoginRemark)
                                };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }
        /// 
        /// 添加管理员
        /// 
        /// 
        /// 
        public int AddAdmin(Admin a)
        {
            string sql = "insert into Admin select @LoginId,@LoginPwd,@LoginType,@LoginRemark";
            SqlParameter[] sp ={
                                new SqlParameter("LoginId",a.LoginId),
                                new SqlParameter("LoginPwd",a.LoginPwd),
                                new SqlParameter("LoginType",a.LoginType),
                                new SqlParameter("LoginRemark",a.LoginRemark)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }

        /// 
        /// 查询相同用户
        /// 
        /// 
        /// 
        public int Scalar(Admin a)
        {
            string sql = "select COUNT(*) from Admin where LoginId=@LoginId and LoginPwd=@LoginPwd and LoginType=@LoginType";
            SqlParameter[] sp ={
                                new SqlParameter("@LoginId",a.LoginId),
                                new SqlParameter("@LoginPwd",a.LoginPwd),
                                new SqlParameter("@LoginType",a.LoginType)
                              };
            return DBhelp.Create().ExecuteScalar(sql, sp);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public class BookInfo_DAL
    {
        /// 
        /// 查询BookInfo表
        /// 
        /// 
        public List selectBookInfo()
        {
            string sql = @"select BookId,BookName,TimeIn,BookTypeName,Author,PinYinCode,Translator,Language,
                            BookNumber,Price,Layout,Address,ISBS,Versions,BookRemark from BookInfo
                            inner join BookType on BookType.BookTypeId=BookInfo.BookTypeId";
            List list = new List();
            SqlDataReader reader = DBhelp.Create().ExecuteReader(sql);
            while (reader.Read())
            {
                BookInfo b = new BookInfo();
                b.BookId = reader.GetString(0);
                b.BookName = reader.GetString(1);
                b.TimeIn = reader.GetDateTime(2);
                b.BookType = new BookType();
                b.BookType.BookTypeName = reader.GetString(3);
                b.Author = reader.GetString(4);
                b.PinYinCode = reader.GetString(5);
                b.Translator = reader.GetString(6);
                b.Language = reader.GetString(7);
                b.BookNumber = reader.GetString(8);
                b.Price = reader.GetString(9);
                b.Layout = reader.GetString(10);
                b.Address = reader.GetString(11);
                b.ISBS = reader.GetString(12);
                b.Versions = reader.GetString(13);
                b.BookRemark = reader.GetString(14);
                list.Add(b);
            }
            reader.Close();
            return list;
        }
        /// 
        /// 根据ID查询bookinfo表
        /// 
        /// 
        /// 
        public List selectBookInfo(string BookId)
        {
            string sql = @"select BookId,BookName,TimeIn,BookTypeId,Author,PinYinCode,Translator,Language,BookNumber, Price,Layout,Address,ISBS,Versions,BookRemark from BookInfo where BookId=@BookId";
            SqlParameter[] sp ={
                                new SqlParameter("@BookId",BookId)
                              };
            SqlDataReader reader = DBhelp.Create().ExecuteReader(sql, sp);
            List list = new List();
            while (reader.Read())
            {
                BookInfo b = new BookInfo();
                b.BookId = reader.GetString(0);
                b.BookName = reader.GetString(1);
                b.TimeIn = reader.GetDateTime(2);
                b.BookTypeId = reader.GetInt32(3);
                b.Author = reader.GetString(4);
                b.PinYinCode = reader.GetString(5);
                b.Translator = reader.GetString(6);
                b.Language = reader.GetString(7);
                b.BookNumber = reader.GetString(8);
                b.Price = reader.GetString(9);
                b.Layout = reader.GetString(10);
                b.Address = reader.GetString(11);
                b.ISBS = reader.GetString(12);
                b.Versions = reader.GetString(13);
                b.BookRemark = reader.GetString(14);
                list.Add(b);
            }
            reader.Close();
            return list;
        }


        /// 
        /// 查询BookInfo表
        /// 
        /// 
        public DataSet selectBookInfo1()
        {
            string sql = @"select BookId,BookName,TimeIn,BookTypeName,Author,PinYinCode,Translator,Language,BookNumber,Price,Layout,Address,ISBS,Versions,BookRemark from BookInfo inner join BookType on BookType.BookTypeId=BookInfo.BookTypeId";
            return DBhelp.Create().ExecuteAdater(sql);
        }
        public DataSet selectBook;

        /// 
        /// 查询BookInfo表 目前可以借阅的图书
        /// 
        /// 
        /// 
        public DataSet selectBookInfo2(string BookId)
        {
            string sql = @"select BookInfo.BookId as 'BookId',BookName,TimeIn,BookTypeName,Author,PinYinCode,Translator,Language,
                    BookNumber,Price,Layout,Address,ISBS,Versions,BookRemark from BookInfo
                    inner join BookType on BookType.BookTypeId=BookInfo.BookTypeId
                   
                    where BookInfo.BookId like '%'+@BookId+'%' and BookInfo.BookId not in(select BookId from BorrowReturn where FactReturnTime is null )";
            SqlParameter[] sp ={
                                   new SqlParameter("@BookId",BookId)
                              };
            return DBhelp.Create().ExecuteAdater(sql, sp: sp);
        }
        /// 
        /// 根据条件查询bookinfo表
        /// 
        /// 
        /// 
        public DataSet selectBookInfo1(int index)
        {
            string sql = @"select BookId,BookName,TimeIn,BookTypeName,Author,PinYinCode,Translator,Language,
                            BookNumber,Price,Layout,Address,ISBS,Versions,BookRemark from BookInfo
                            inner join BookType on BookType.BookTypeId=BookInfo.BookTypeId
                            where BookType.BookTypeId=@BookTypeId";
            SqlParameter[] sp ={
                                   new SqlParameter("@BookTypeId",index)
                              };
            return DBhelp.Create().ExecuteAdater(sql, sp);
        }

        /// 
        /// 根据条件查询bookinfo表
        /// 
        /// 
        /// 
        /// 
        public DataSet selectBookInfo1(string A, string B)
        {
            string sql = string.Format(@"select BookId,BookName,TimeIn,BookTypeName,Author,PinYinCode,Translator,Language,
                            BookNumber,Price,Layout,Address,ISBS,Versions,BookRemark from BookInfo
                            inner join BookType on BookType.BookTypeId=BookInfo.BookTypeId
                            where {0} like '%{1}%'", A, B);
            return DBhelp.Create().ExecuteAdater(sql);
        }
        /// 
        /// 查询BookInfo表 带全部查询(表中所有相关的字段)
        /// 
        /// 
        /// 
        /// 
        public DataSet selectBookInfo1(List list, string B)
        {
            string sql = "";
            for (int i = 0; i < list.Count; i++)
            {
                if (i != list.Count - 1)
                {
                    sql += string.Format(@"select BookId,BookName,TimeIn,BookTypeName,Author,PinYinCode,Translator,Language,
                            BookNumber,Price,Layout,Address,ISBS,Versions,BookRemark from BookInfo
                            inner join BookType on BookType.BookTypeId=BookInfo.BookTypeId
                            where {0} like '%{1}%' union  ", list[i], B);
                }
                else
                {
                    sql += string.Format(@"select BookId,BookName,TimeIn,BookTypeName,Author,PinYinCode,Translator,Language,
                            BookNumber,Price,Layout,Address,ISBS,Versions,BookRemark from BookInfo
                            inner join BookType on BookType.BookTypeId=BookInfo.BookTypeId
                            where {0} like '%{1}%' ", list[i], B);
                }

            }

            return DBhelp.Create().ExecuteAdater(sql);
        }
        /// 
        /// 添加图书信息
        /// 
        /// 
        /// 
        public int AddBookInfo(BookInfo book)
        {
            string sql = @"insert into BookInfo select @BookId,@BookName,@TimeIn,@BookTypeId,@Author,
                    @PinYinCode,@Translator,@Language,@BookNumber,@Price,@Layout,@Address,@ISBS,@Versions,@BookRemark";
            SqlParameter[] sp ={
                                   new SqlParameter("@BookId",book.BookId),
                                   new SqlParameter("@BookName",book.BookName),
                                   new SqlParameter("@TimeIn",book.TimeIn),
                                   new SqlParameter("@BookTypeId",book.BookTypeId),
                                   new SqlParameter("@Author",book.Author),
                                   new SqlParameter("@PinYinCode",book.PinYinCode),
                                   new SqlParameter("@Translator",book.Translator),
                                   new SqlParameter("@Language",book.Language),
                                   new SqlParameter("@BookNumber",book.BookNumber),
                                   new SqlParameter("@Price",book.Price),
                                   new SqlParameter("@Layout",book.Layout),
                                   new SqlParameter("@Address",book.Address),
                                   new SqlParameter("@ISBS",book.ISBS),
                                   new SqlParameter("@Versions",book.Versions),
                                   new SqlParameter("@BookRemark",book.BookRemark),
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }
        /// 
        /// 修改图书信息
        /// 
        /// 
        /// 
        public int ExitBookInfo(BookInfo book)
        {
            string sql = @"update BookInfo set BookName=@BookName,TimeIn=@TimeIn,BookTypeId=@BookTypeId,
            Author=@Author,PinYinCode=@PinYinCode,Translator=@Translator,Language=@Language,BookNumber=@BookNumber,
            Price=@Price,Layout=@Layout,Address=@Address,ISBS=@ISBS,Versions=@Versions,BookRemark=@BookRemark
            where BookId=@BookId";
            SqlParameter[] sp ={
                                    new SqlParameter("@BookName",book.BookName),
                                    new SqlParameter("@TimeIn",book.TimeIn),
                                    new SqlParameter("@BookTypeId",book.BookTypeId),
                                    new SqlParameter("@Author",book.Author),
                                    new SqlParameter("@PinYinCode",book.PinYinCode),
                                    new SqlParameter("@Translator",book.Translator),
                                    new SqlParameter("@Language",book.Language),
                                    new SqlParameter("@BookNumber",book.BookNumber),
                                    new SqlParameter("@Price",book.Price),
                                    new SqlParameter("@Layout",book.Layout),
                                    new SqlParameter("@Address",book.Address),
                                    new SqlParameter("@ISBS",book.ISBS),
                                    new SqlParameter("@Versions",book.Versions),
                                    new SqlParameter("@BookRemark",book.BookRemark),
                                    new SqlParameter("@BookId",book.BookId)
                              };

            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }
        /// 
        /// 根据Id删除
        /// 
        /// 
        /// 
        public int DeleteBookInfo(string BookId)
        {
            string sql = @"
                            delete from BorrowReturn where BookId=@BookId
                            delete from BookInfo where BookId=@BookId";
            SqlParameter[] sp ={
                                   new SqlParameter("@BookId",BookId)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }
    }
}

using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class BookType_DAL
    {
        public List selectBookType()
        {
            string sql = "select *  from BookType";
            List list = new List();
            SqlDataReader reader = DBhelp.Create().ExecuteReader(sql);
            while (reader.Read())
            {
                BookType b = new BookType();
                b.BookTypeId = reader.GetInt32(0);
                b.BookTypeName = reader.GetString(1);
                list.Add(b);
            }
            reader.Close();
            return list;
        }
        public DataSet selectBookType1()
        {
            string sql = "select BookTypeId,BookTypeName from BookType";
            return DBhelp.Create().ExecuteAdater(sql);
        }

        public int AddBookTypeInfo(BookType type)
        {
            string sql = "proc_AddBookTypeInfo";
            SqlParameter[] sp ={
                                   new SqlParameter("@BookTypeId",SqlDbType.Int),
                                   new SqlParameter("@BookTypeName",type.BookTypeName),
                                   new SqlParameter("@ReturnValue",SqlDbType.Int)
                              };
            sp[0].Direction = ParameterDirection.Output;
            sp[2].Direction = ParameterDirection.ReturnValue;
            DBhelp.Create().ExecuteNonQuery(sql,CommandType.StoredProcedure, sp);

            type.BookTypeId = (int)sp[0].Value;
            return (int)sp[2].Value;
        }

        //删除图书类型
        public int deleteBookType(int BookTypeId)
        {
            string sql = @"delete from BorrowReturn where BookId in(select BookId from BookInfo where BookTypeId=@BookTypeId)
                            delete from BookInfo where BookTypeId=@BookTypeId
                            delete from BookType where BookTypeId=@BookTypeId";
            SqlParameter[] sp ={
                                   new SqlParameter("@BookTypeId",BookTypeId)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp:sp);
        }


        //修改图书类型
        public int updateBookType(BookType type)
        {
            string sql = "update BookType set BookTypeName=@BookTypeName where BookTypeId=@BookTypeId";
            SqlParameter[] sp ={
                                   new SqlParameter("@BookTypeId",type.BookTypeId),
                                   new SqlParameter("@BookTypeName",type.BookTypeName)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }
    }
}

using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class BorrowReturn_DAL
    {
        //查询借还表信息
        public DataSet selectHostory(BorrowReturn b, string radioName, String cboBorrowTimeType, Boolean checkTime)
        {
            string sql = string.Format(@"select BookInfo.BookId as 'BookId',Reader.ReaderId as 'ReaderId',BookName,ReaderName,
                            BookTypeName,ReaderTypeName,Gender,IdentityCard,
                            BorrowTime,ReturnTime,FactReturnTime,Fine,RenewCount
                            from BorrowReturn
                            inner join BookInfo on BookInfo.BookId=BorrowReturn.BookId
                            inner join Reader on Reader.ReaderId=BorrowReturn.ReaderId
                            inner join BookType on BookType.BookTypeId=BookInfo.BookTypeId
                            inner join ReaderType on ReaderType.ReaderTypeId=Reader.ReaderTypeId
                            where BookInfo.BookId like '%{0}%' and 
                            Reader.ReaderId like '%{1}%' ", b.BookId, b.ReaderId);
            if (radioName == "全部")
            {

            }
            else if (radioName == "已借")
            {
                sql += " and FactReturnTime	is  null ";
            }
            else if (radioName == "已还")
            {
                sql += " and FactReturnTime	is not null ";
            }
            if (checkTime)
            {
                if (cboBorrowTimeType == "日期")
                {
                    sql += string.Format(@" and BorrowId in(
                                        select BorrowId from BorrowReturn where BorrowTime between '{0}' and '{1}' union
                                        select BorrowId from BorrowReturn where ReturnTime between '{0}' and '{1}' union
                                        select BorrowId from BorrowReturn where FactReturnTime between '{0}' and '{1}'
                                        ) ", b.TimeIn, b.TimeOut);
                }
                else if (cboBorrowTimeType == "借书日期")
                {
                    sql += @" and BorrowTime between '" + b.TimeIn + "' and '" + b.TimeOut + "' ";
                }
                else if (cboBorrowTimeType == "应还书日期")
                {
                    sql += @" and ReturnTime between '" + b.TimeIn + "' and  '" + b.TimeOut + "' ";
                }
                else if (cboBorrowTimeType == "实际还书日期")
                {
                    sql += @" and FactReturnTime between '" + b.TimeIn + "' and '" + b.TimeOut + "' ";
                }
            }

            return DBhelp.Create().ExecuteAdater(sql);
        }

        //借还表全部信息 包括现在借阅的和历史借阅的
        public DataSet AllBorrowReturn()
        {
            string sql = @"select BookInfo.BookId as 'BookId',Reader.ReaderId as 'ReaderId',BookName,ReaderName,
                            BookTypeName,ReaderTypeName,Gender,IdentityCard,
                            BorrowTime,ReturnTime,FactReturnTime,Fine,RenewCount
                            from BorrowReturn
                            inner join BookInfo on BookInfo.BookId=BorrowReturn.BookId
                            inner join Reader on Reader.ReaderId=BorrowReturn.ReaderId
                            inner join BookType on BookType.BookTypeId=BookInfo.BookTypeId
                            inner join ReaderType on ReaderType.ReaderTypeId=Reader.ReaderTypeId";
            return DBhelp.Create().ExecuteAdater(sql);
        }

        //查询图书借还表(表连接)
        public DataSet selectBorrowReturn(string BookId)
        {
            string sql = @"select BookInfo.BookId,BookName,Reader.ReaderId,ReaderName,BorrowTime,ReturnTime,FactReturnTime,Fine,RenewCount,BorrowRemark from BookInfo
                    inner join BorrowReturn on BorrowReturn.BookId=BookInfo.BookId
                    inner join Reader on Reader.ReaderId=BorrowReturn.ReaderId 
                    where BookInfo.BookId=@BookId ";
            SqlParameter[] sp ={
                                   new SqlParameter("@BookId",BookId)
                              };

            return DBhelp.Create().ExecuteAdater(sql, sp);
        }


        //读者借阅记录
        public DataSet ReaderBorrowReturn(string ReaderId)
        {
            string sql = @"select BorrowId,Reader.ReaderId as 'ReaderId',ReaderName,BookInfo.BookId as 'BookId',BookName,BorrowTime,ReturnTime,FactReturnTime,Fine,RenewCount,BorrowRemark from Reader
                            inner join BorrowReturn on BorrowReturn.ReaderId=Reader.ReaderId
                            inner join BookInfo on BookInfo.BookId=BorrowReturn.BookId
                            where Reader.ReaderId=@ReaderId and FactReturnTime is null ";
            SqlParameter[] sp ={
                                   new SqlParameter("@ReaderId",ReaderId)
                              };
            return DBhelp.Create().ExecuteAdater(sql, sp);
        }

        //读者历史借阅记录
        public DataSet ReaderBorrowReturn1(string ReaderId)
        {
            string sql = @"select BorrowId,Reader.ReaderId as 'ReaderId',ReaderName,BookInfo.BookId as 'BookId',BookName,BorrowTime,ReturnTime,FactReturnTime,Fine,RenewCount,BorrowRemark from Reader
                            inner join BorrowReturn on BorrowReturn.ReaderId=Reader.ReaderId
                            inner join BookInfo on BookInfo.BookId=BorrowReturn.BookId
                            where Reader.ReaderId=@ReaderId and FactReturnTime is not null ";
            SqlParameter[] sp ={
                                   new SqlParameter("@ReaderId",ReaderId)
                              };
            return DBhelp.Create().ExecuteAdater(sql, sp);
        }

        //还书
        public int ReturnBook(int BorrowReturnId)
        {
            string sql = @"update BorrowReturn set FactReturnTime=@FactReturnTime,RenewCount=0 where BorrowId=@BorrowId";
            SqlParameter[] sp ={
                                   new SqlParameter("@FactReturnTime",DateTime.Now),
                                   new SqlParameter("@BorrowId",BorrowReturnId)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }

        //借书
        public int BorrowBook(BorrowReturn b)
        {
            string sql = "proc_BorrowBook";
            SqlParameter[] sp ={
                                   new SqlParameter("@BorrowId",DbType.Int32),
                                   new SqlParameter("@BookId",b.BookId),
                                   new SqlParameter("@ReaderId",b.ReaderId),
                                   new SqlParameter("@BorrowTime",b.BorrowTime),
                                   new SqlParameter("@ReturnTime",b.ReturnTime),
                                   new SqlParameter("@Fine",b.Fine),
                                   new SqlParameter("@RenewCount",b.RenewCount),
                                   new SqlParameter("@BorrowRemark",b.BorrowRemark),
                                   new SqlParameter("@ReturnValue",DbType.Int32)
                              };
            sp[0].Direction = ParameterDirection.Output;
            sp[sp.Length - 1].Direction = ParameterDirection.ReturnValue;
            DBhelp.Create().ExecuteNonQuery(sql, CommandType.StoredProcedure, sp);
            b.BorrowId = (int)sp[0].Value;
            return (int)sp[sp.Length - 1].Value;
        }

        //续借
        public int RenewBook(BorrowReturn b)
        {
            string sql = @"update BorrowReturn set ReturnTime=dateadd(month,3,ReturnTime),RenewCount=RenewCount+1 where BorrowId=@BorrowId";
            SqlParameter[] sp ={
                                   new SqlParameter("@BorrowId",b.BorrowId)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class Class_DAL
    {
        public List selectClass()
        {
            string sql = "select * from Class";
            List list = new List();
            SqlDataReader reader = DBhelp.Create().ExecuteReader(sql);
            while (reader.Read())
            {
                Class c = new Class();
                c.ClassId = reader.GetInt32(0);
                c.ClassName = reader.GetString(1);
                list.Add(c);
            }
            reader.Close();
            return list;
        }


        public DataSet selectClass1()
        {
            string sql = "select * from Class";
            return DBhelp.Create().ExecuteAdater(sql);
        }

        public int AddClass(Class c)
        {
            string sql = "proc_addClass";
            SqlParameter[] sp ={
                                   new SqlParameter("@ClassId",DbType.Int32),
                                   new SqlParameter("@ClassName",c.ClassName),
                                   new SqlParameter("@ReturnValue",DbType.Int32)
                              };
            sp[0].Direction = ParameterDirection.Output;
            sp[2].Direction = ParameterDirection.ReturnValue;
            DBhelp.Create().ExecuteNonQuery(sql, CommandType.StoredProcedure, sp);
            c.ClassId = (int)sp[0].Value;
            return (int)sp[2].Value;
        }

        //删除班级
        public int deleteClass(int ClassId)
        {
            string sql = @"delete from Reader where ClassId=@ClassId
                            delete from Class where ClassId=@ClassId";
            SqlParameter[] sp ={
                                   new SqlParameter("@ClassId",ClassId)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);

        }

        //修改班级
        public int updateClass(Class c)
        {
            string sql = "update Class set ClassName=@ClassName where ClassId=@ClassId";
            SqlParameter[] sp ={
                                   new SqlParameter("@ClassId",c.ClassId),
                                   new SqlParameter("@ClassName",c.ClassName)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace DAL
{
    public class DBhelp
    {
        private DBhelp() { }
        private static DBhelp dbhelp = null;
        public static DBhelp Create()
        {
            if (dbhelp == null)
                dbhelp = new DBhelp();
            return dbhelp;
        }

        string conString = ConfigurationManager.ConnectionStrings["a"].ConnectionString;

        //返回一行一列
        public int ExecuteScalar(string sql, params SqlParameter[] sp)
        {
            SqlConnection con = new SqlConnection(conString);

            try
            {
                con.Open();
                SqlCommand com = new SqlCommand(sql, con);
                com.Parameters.AddRange(sp);
                return (int)com.ExecuteScalar();
            }
            catch (Exception)
            {
                con.Close();
                throw;
            }
            finally
            {
                con.Close();
            }
            
        }

        //返回读取器对象
        public SqlDataReader ExecuteReader(string sql, params SqlParameter[] sp)
        {
            SqlConnection con = new SqlConnection(conString);
            try
            {
                con.Open();
                SqlCommand com = new SqlCommand(sql, con);
                com.Parameters.AddRange(sp);
                return com.ExecuteReader(CommandBehavior.CloseConnection);
            }
            catch (Exception ex)
            {
                con.Close();
                throw ex;
            }
        }

        //返回数据集,
        public DataSet ExecuteAdater(string sql, params SqlParameter[] sp)
        {
            SqlConnection con = new SqlConnection(conString);

            try
            {
                SqlCommand com = new SqlCommand(sql, con);
                com.Parameters.AddRange(sp);
                SqlDataAdapter adapter = new SqlDataAdapter(com);
                DataSet ds = new DataSet();
                adapter.Fill(ds, "a");
                return ds;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                con.Close();
            }


        }

        //返回受影响行数
        public int ExecuteNonQuery(string sql, CommandType type = CommandType.Text, params SqlParameter[] sp)
        {
            SqlConnection con = new SqlConnection(conString);
            try
            {
                con.Open();
                SqlCommand com = new SqlCommand(sql, con);
                com.Parameters.AddRange(sp);
                com.CommandType = type;
                return com.ExecuteNonQuery();
            }
            catch (Exception)
            {
                con.Close();
                throw;
            }
            finally
            {
                con.Close();
            }




        }


    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class Department_DAL
    {
        public List selectDepartment()
        {
            string sql = "select * from Department";
            List list = new List();
            SqlDataReader reader = DBhelp.Create().ExecuteReader(sql);
            while (reader.Read())
            {
                Department d = new Department();
                d.DepartmentId = (int)reader["DepartmentId"];
                d.DepartmentName = reader["DepartmentName"].ToString();
                list.Add(d);
            }
            reader.Close();
            return list;
        }
        public DataSet selectDepartment1()
        {
            string sql = "select * from Department";

            return DBhelp.Create().ExecuteAdater(sql); ;
        }

        public int addDepartment(Department d)
        {
            string sql = "proc_addDepartment";
            SqlParameter[] sp ={
                                   new SqlParameter("@DepartmentId",DbType.Int32),
                                   new SqlParameter("@DepartmentName",d.DepartmentName),
                                   new SqlParameter("@ReturnValue",DbType.Int32)
                              };
            sp[0].Direction = ParameterDirection.Output;
            sp[2].Direction = ParameterDirection.ReturnValue;
            DBhelp.Create().ExecuteNonQuery(sql, CommandType.StoredProcedure, sp);
            d.DepartmentId = (int)sp[0].Value;
            return (int)sp[2].Value;

        }
        //删除院系
        public int deleteDepartment(int DepartmentId)
        {
            string sql = @"delete from Reader where DepartmentId=@DepartmentId
                            delete from Department where DepartmentId=@DepartmentId";
            SqlParameter[] sp ={
                                   new SqlParameter("@DepartmentId",DepartmentId)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }

        //修改院系
        public int updateDepartment(Department d)
        {
            string sql = "update Department set DepartmentName=@DepartmentName where DepartmentId=@DepartmentId";
            SqlParameter[] sp ={
                                   new SqlParameter("@DepartmentId",d.DepartmentId),
                                   new SqlParameter("@DepartmentName",d.DepartmentName)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public class Reader_DAL
    {
        //无条件查询读者信息
        public DataSet selectReader()
        {
            string sql = @"select ReaderId,ReaderName,TimeIn,TimeOut,ReaderTypeName,DepartmentName,ClassName,IdentityCard,Gender,Special,Phone,Email,Address,ReaderRemark from Reader 
                            inner join ReaderType on ReaderType.ReaderTypeId=Reader.ReaderTypeId
                            inner join Department on Department.DepartmentId=Reader.DepartmentId
                            inner join Class on Class.ClassId=Reader.ClassId";
            return DBhelp.Create().ExecuteAdater(sql);
        }

        //根据读者类型ID查询的读者信息
        public DataSet selectReader(int ReaderTypeId)
        {

            string sql = @"select ReaderId,ReaderName,TimeIn,TimeOut,ReaderTypeName,DepartmentName,ClassName,IdentityCard,Gender,Special,Phone,Email,Address,ReaderRemark from Reader 
                            inner join ReaderType on ReaderType.ReaderTypeId=Reader.ReaderTypeId
                            inner join Department on Department.DepartmentId=Reader.DepartmentId
                            inner join Class on Class.ClassId=Reader.ClassId
                            where ReaderType.ReaderTypeId=@ReaderTypeId ";
            SqlParameter[] sp ={
                                   new SqlParameter("@ReaderTypeId",ReaderTypeId)
                              };
            return DBhelp.Create().ExecuteAdater(sql, sp);
        }

        //根据ID查询的读者信息
        public List selectReader1(string ReaderId)
        {

            string sql = @"select ReaderId,ReaderName,TimeIn,TimeOut,ReaderTypeId,DepartmentId,ClassId,IdentityCard,
                            Gender,Special,Phone,Email,Address,ReaderRemark from Reader";
            SqlParameter[] sp ={
                                   new SqlParameter("@ReaderId",ReaderId)
                              };
            List list = new List();
            SqlDataReader reader = DBhelp.Create().ExecuteReader(sql, sp);
            while (reader.Read())
            {
                Reader r = new Reader();
                r.ReaderId = reader.GetString(0);
                r.ReaderName = reader.GetString(1);
                r.TimeIn = reader.GetDateTime(2);
                r.TimeOut = reader.GetDateTime(3);
                r.ReaderTypeId = reader.GetInt32(4);
                r.DepartmentId = reader.GetInt32(5);
                r.ClassId = reader.GetInt32(6);
                r.IdentityCard = reader.GetString(7);
                r.Gender = reader.GetString(8);
                r.Special = reader.GetString(9);
                r.Phone = reader.GetString(10);
                r.Email = reader.GetString(11);
                r.Address = reader.GetString(12);
                r.ReaderRemark = reader.GetString(13);
                list.Add(r);
            }
            reader.Close();
            return list;

        }

        //根据查询内容和条件查询的读者信息
        public DataSet selectReader(string A, string B)
        {

            string sql = string.Format(@"select ReaderId,ReaderName,TimeIn,TimeOut,ReaderTypeName,DepartmentName,ClassName,IdentityCard,Gender,Special,Phone,Email,Address,ReaderRemark from Reader 
                            inner join ReaderType on ReaderType.ReaderTypeId=Reader.ReaderTypeId
                            inner join Department on Department.DepartmentId=Reader.DepartmentId
                            inner join Class on Class.ClassId=Reader.ClassId
                            where {0} like '%{1}%'", A, B);
            return DBhelp.Create().ExecuteAdater(sql);
        }


        //根据查询条件查询的读者信息
        public DataSet selectReader(List list, string B)
        {
            string sql = "";
            for (int i = 0; i < list.Count; i++)
            {
                if (i != list.Count - 1)
                {
                    sql += string.Format(@"select ReaderId,ReaderName,TimeIn,TimeOut,ReaderTypeName,DepartmentName,ClassName,IdentityCard,Gender,Special,Phone,Email,Address,ReaderRemark from Reader 
                            inner join ReaderType on ReaderType.ReaderTypeId=Reader.ReaderTypeId
                            inner join Department on Department.DepartmentId=Reader.DepartmentId
                            inner join Class on Class.ClassId=Reader.ClassId
                            where {0} like '%{1}%' union  ", list[i], B);
                }
                else
                {
                    sql += string.Format(@"select ReaderId,ReaderName,TimeIn,TimeOut,ReaderTypeName,DepartmentName,ClassName,IdentityCard,Gender,Special,Phone,Email,Address,ReaderRemark from Reader 
                            inner join ReaderType on ReaderType.ReaderTypeId=Reader.ReaderTypeId
                            inner join Department on Department.DepartmentId=Reader.DepartmentId
                            inner join Class on Class.ClassId=Reader.ClassId
                            where {0} like '%{1}%' ", list[i], B);
                }

            }

            return DBhelp.Create().ExecuteAdater(sql);
        }

        //删除读者信息
        public int deleteReader(string ReaderId)
        {
            string sql = @"
                            delete from BorrowReturn where ReaderId=@ReaderId
                            delete from Reader where ReaderId=@ReaderId";
            SqlParameter[] sp ={
                                   new SqlParameter("@ReaderId",ReaderId)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }

        //修改读者信息
        public int updateReader(Reader reader)
        {
            string sql = @"update Reader set ReaderName=@ReaderName,TimeIn=@TimeIn,TimeOut=@TimeOut,ReaderTypeId=@ReaderTypeId,
                            DepartmentId=@DepartmentId,ClassId=@ClassId,IdentityCard=@IdentityCard,Gender=@Gender,Special=@Special,
                            Phone=@Phone,Email=@Email,Address=@Address,ReaderRemark=@ReaderRemark where ReaderId=@ReaderId";
            SqlParameter[] sp ={
                                   new SqlParameter("@ReaderName",reader.ReaderName),
                                   new SqlParameter("@TimeIn",reader.TimeIn),
                                   new SqlParameter("@TimeOut",reader.TimeOut),
                                   new SqlParameter("@ReaderTypeId",reader.ReaderTypeId),
                                   new SqlParameter("@DepartmentId",reader.DepartmentId),
                                   new SqlParameter("@ClassId",reader.ClassId),
                                   new SqlParameter("@IdentityCard",reader.IdentityCard),
                                   new SqlParameter("@Gender",reader.Gender),
                                   new SqlParameter("@Special",reader.Special),
                                   new SqlParameter("@Phone",reader.Phone),
                                   new SqlParameter("@Email",reader.Email),
                                   new SqlParameter("@Address",reader.Address),
                                   new SqlParameter("@ReaderRemark",reader.ReaderRemark),
                                   new SqlParameter("@ReaderId",reader.ReaderId)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }


        //添加读者信息
        public int addReader(Reader r)
        {
            string sql = "proc_AddReader";
            SqlParameter[] sp ={
                                   new SqlParameter("@ReaderId",r.ReaderId),
                                   new SqlParameter("@ReaderName",r.ReaderName),
                                   new SqlParameter("@TimeIn",r.TimeIn),
                                   new SqlParameter("@TimeOut",r.TimeOut),
                                   new SqlParameter("@ReaderTypeId",r.ReaderTypeId),
                                   new SqlParameter("@DepartmentId",r.DepartmentId),
                                   new SqlParameter("@ClassId",r.ClassId),
                                   new SqlParameter("@IdentityCard",r.IdentityCard),
                                   new SqlParameter("@Gender",r.Gender),
                                   new SqlParameter("@Special",r.Special),
                                   new SqlParameter("@Phone",r.Phone),
                                   new SqlParameter("@Email",r.Email),
                                   new SqlParameter("@Address",r.Address),
                                   new SqlParameter("@ReaderRemark",r.ReaderRemark),
                                   new SqlParameter("@ReturnValue",DbType.Int32)
                              };
            sp[sp.Length - 1].Direction = ParameterDirection.ReturnValue;
            DBhelp.Create().ExecuteNonQuery(sql, CommandType.StoredProcedure, sp);
            return (int)sp[sp.Length - 1].Value;
        }

        //返回读者编号,读者姓名
        public List selectReaderId(string ReaderId)
        {
            string sql = "select ReaderId,ReaderName from Reader where ReaderId like '%'+@ReaderId+'%' ";
            SqlParameter[] sp ={
                                   new SqlParameter("@ReaderId",ReaderId)
                              };
            SqlDataReader reader = DBhelp.Create().ExecuteReader(sql, sp: sp);
            List list = new List();
            while (reader.Read())
            {
                Reader r = new Reader();
                r.ReaderId = reader["ReaderId"].ToString();
                r.ReaderName = reader["ReaderName"].ToString();
                list.Add(r);
            }
            reader.Close();
            return list;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public class ReaderType_DAL
    {
        //查询全部的读者类型
        public List selectReaderType()
        {
            List list = new List();
            string sql = @"select * from ReaderType";
            SqlDataReader reader = DBhelp.Create().ExecuteReader(sql);
            while (reader.Read())
            {
                ReaderType type = new ReaderType();
                type.ReaderTypeId = reader.GetInt32(0);
                type.ReaderTypeName = reader.GetString(1);
                list.Add(type);
            }
            reader.Close();
            return list;
        }
        //查询全部的读者类型
        public DataSet selectReaderType1()
        {
            string sql = @"select * from ReaderType";
            return DBhelp.Create().ExecuteAdater(sql);
        }

        //添加读者类型
        public int addReaderType(ReaderType r)
        {
            string sql = "proc_addReaderType";
            SqlParameter[] sp ={
                                   new SqlParameter("@ReaderTypeId",DbType.Int32),
                                   new SqlParameter("@ReaderTypeName",r.ReaderTypeName),
                                   new SqlParameter("@ReturnValue",DbType.Int32)
                              };
            sp[0].Direction = ParameterDirection.Output;
            sp[2].Direction = ParameterDirection.ReturnValue;
            DBhelp.Create().ExecuteNonQuery(sql, CommandType.StoredProcedure, sp);
            r.ReaderTypeId = (int)sp[0].Value;
            return (int)sp[2].Value;
        }
        //删除读者类型
        public int deleteReader(int ReaderTypeId)
        {
            string sql = @"delete from BorrowReturn where ReaderId in(select ReaderId from Reader where ReaderTypeId=@ReaderTypeId)
                            delete from Reader where ReaderTypeId=@ReaderTypeId
                            delete from ReaderType where ReaderTypeId=@ReaderTypeId";
            SqlParameter[] sp ={
                                   new SqlParameter("@ReaderTypeId",ReaderTypeId)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }

        //修改读者类型
        public int updateReaderType(ReaderType r)
        {
            string sql = "update ReaderType set ReaderTypeName=@ReaderTypeName where ReaderTypeId=@ReaderTypeId";
            SqlParameter[] sp ={
                                   new SqlParameter("@ReaderTypeId",r.ReaderTypeId),
                                   new SqlParameter("@ReaderTypeName",r.ReaderTypeName)
                              };
            return DBhelp.Create().ExecuteNonQuery(sql, sp: sp);
        }
    }
}

C# 图书馆项目实例_第4张图片

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Model")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Model")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。  如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("9e29104f-b24e-4136-bc0d-8206d819e4c4")]

// 程序集的版本信息由下面四个值组成: 
//
//      主版本
//      次版本 
//      生成号
//      修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: 
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    public class Admin
    {
        public string LoginId { get; set; }
        public string LoginPwd { get; set; }
        public string LoginType { get; set; }
        public string LoginRemark { get; set; }


    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    public class BookInfo
    {
        public string BookId { get; set; }
        public string BookName { get; set; }
        public DateTime TimeIn { get; set; }
        private int bookTypeId;
        public int BookTypeId
        {
            get { return bookTypeId; }
            set { bookTypeId = value; }
        }
        public string Author { get; set; }
        public string PinYinCode { get; set; }
        public string Translator { get; set; }
        public string Language { get; set; }
        public string BookNumber { get; set; }
        public string Price { get; set; }
        public string Layout { get; set; }
        public string Address { get; set; }
        public string ISBS { get; set; }
        public string Versions { get; set; }
        public string BookRemark { get; set; }

        public BookType BookType { get; set; }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    public class BookType
    {
        public int BookTypeId { get; set; }
        public string BookTypeName { get; set; }

        public override string ToString()
        {
            return this.BookTypeName;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    public class BorrowReturn
    {
        public int BorrowId { get; set; }
        public string BookId { get; set; }
        public string  ReaderId { get; set; }
        public DateTime BorrowTime { get; set; }
        public DateTime ReturnTime { get; set; }
        public DateTime FactReturnTime { get; set; }
        public double Fine { get; set; }
        public int RenewCount { get; set; }
        public string BorrowRemark { get; set; }

        //方便
        public DateTime  TimeIn { get; set; } //开始日期
        public DateTime  TimeOut { get; set; } //结束日期
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    public class Class
    {
        public int ClassId { get; set; }
        public string ClassName { get; set; }

        public override string ToString()
        {
            return this.ClassName; 
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    public class Department
    {
        public int DepartmentId { get; set; }
        public string DepartmentName { get; set; }

        public override string ToString()
        {
            return this.DepartmentName;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    public class Reader
    {
        public string ReaderId { get; set; }
        public string ReaderName { get; set; }
        public DateTime TimeIn { get; set; }
        public DateTime TimeOut { get; set; }
        public int ReaderTypeId { get; set; }
        public int DepartmentId { get; set; }
        public int ClassId { get; set; }
        public string IdentityCard { get; set; }
        public string Gender { get; set; }
        public string Special { get; set; }
        public string Phone { get; set; }
        public string Email { get; set; }
        public string Address { get; set; }
        public string ReaderRemark { get; set; }


    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    public class ReaderType
    {
        public int ReaderTypeId { get; set; }
        public string ReaderTypeName { get; set; }

        public override string ToString()
        {
            return this.ReaderTypeName;
        }
    }
}

C# 图书馆项目实例_第5张图片
C# 图书馆项目实例_第6张图片
C# 图书馆项目实例_第7张图片

``

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BLL;
using Model;
using Common;

namespace Web
{
    public partial class Add : Form
    {
        public Add()
        {
            InitializeComponent();
        }
        public BookInfoManager_UI Manager = null;
        public BookInfoExit_UI bookInfoExit = null;
        public BookInfoAdd_UI bookInfoAdd = null;

        public ReaderManager_UI readerManager = null;
        public ReaderExit_UI readerExit = null;
        public ReaderAdd_UI readerAdd = null;

        public BookType_BLL booktype = new BookType_BLL();
        public ReaderType_BLL readerType_bll = new ReaderType_BLL();
        public Department_BLL department_bll = new Department_BLL();
        public Class_BLL class_bll = new Class_BLL();
        Com auto = new Com();

        public string tabName = null;

        private void Add_Load(object sender, EventArgs e)
        {
            TabControl.TabPageCollection tabs = this.tabControl1.TabPages;
            for (int i = 0; i < tabs.Count; i++)
            {
                if (tabs[i].Text == tabName)
                {
                    this.tabControl1.SelectedIndex = i;
                    break;
                }
            }


            #region 图书类型表的绑定

            string HeaderText = "ID,图书类型";
            string DataPropertyNames = "BookTypeId,BookTypeName";
            //this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            //自动生成列
            auto.AutoColumn(HeaderText, DataPropertyNames, this.dataGridView1);
            auto.AddColumn("修改", this.dataGridView1);
            auto.AddColumn("删除", this.dataGridView1);

            this.dataGridView1.DataSource = booktype.selectBookType1().Tables[0];
            this.dataGridView1.Columns[0].Visible = false;

            #endregion

            #region 读者类型表的绑定

            string HeaderText1 = "ID,读者类型";
            string DataPropertyNames1 = "ReaderTypeId,ReaderTypeName";
            //this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            //自动生成列
            auto.AutoColumn(HeaderText1, DataPropertyNames1, this.dataGridView2);
            auto.AddColumn("修改", this.dataGridView2);
            auto.AddColumn("删除", this.dataGridView2);

            this.dataGridView2.DataSource = readerType_bll.selectReaderType1().Tables[0];
            this.dataGridView2.Columns[0].Visible = false;

            #endregion

            #region 院系表的绑定

            string HeaderText2 = "ID,院系";
            string DataPropertyNames2 = "DepartmentId,DepartmentName";
            //this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            //自动生成列
            auto.AutoColumn(HeaderText2, DataPropertyNames2, this.dataGridView3);
            auto.AddColumn("修改", this.dataGridView3);
            auto.AddColumn("删除", this.dataGridView3);

            this.dataGridView3.DataSource = department_bll.selectDepartment1().Tables[0];
            this.dataGridView3.Columns[0].Visible = false;

            #endregion

            #region 班级表的绑定

            string HeaderText3 = "ID,班级";
            string DataPropertyNames3 = "ClassId,ClassName";
            //this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            //自动生成列
            auto.AutoColumn(HeaderText3, DataPropertyNames3, this.dataGridView4);
            auto.AddColumn("修改", this.dataGridView4);
            auto.AddColumn("删除", this.dataGridView4);

            this.dataGridView4.DataSource = class_bll.selectClass1().Tables[0];
            this.dataGridView4.Columns[0].Visible = false;

            #endregion
        }
        Com com = new Com();

        //添加图书类型
        private void button1_Click(object sender, EventArgs e)
        {
            BookType type = new BookType();
            type.BookTypeName = textBox1.Text.Trim();
            if (booktype.AddBookTypeInfo(type) == 0)
            {
                MessageBox.Show("添加成功!");
                this.dataGridView1.DataSource = booktype.selectBookType1().Tables[0];

                //自动找到刚刚添加成功的新行,并选中
                com.AutoFindRow(type.BookTypeId.ToString(), this.dataGridView1);
            }
            else
            {
                MessageBox.Show("添加失败!");
            }
        }

        //添加读者类型
        private void button2_Click(object sender, EventArgs e)
        {
            ReaderType r = new ReaderType();
            r.ReaderTypeName = textBox2.Text.Trim();
            if (readerType_bll.addReaderType(r) == 0)
            {
                MessageBox.Show("添加成功!");
                this.dataGridView2.DataSource = readerType_bll.selectReaderType1().Tables[0];

                //自动找到刚刚添加成功的新行,并选中
                com.AutoFindRow(r.ReaderTypeId.ToString(), this.dataGridView2);
            }
            else
            {
                MessageBox.Show("添加失败!");
            }
        }

        //添加院系
        private void button3_Click(object sender, EventArgs e)
        {
            Department d = new Department();
            d.DepartmentName = textBox3.Text.Trim();
            if (department_bll.addDepartment(d) == 0)
            {
                MessageBox.Show("添加成功!");
                this.dataGridView3.DataSource = department_bll.selectDepartment1().Tables[0];

                //自动找到刚刚添加成功的新行,并选中
                com.AutoFindRow(d.DepartmentId.ToString(), this.dataGridView3);
            }
            else
            {
                MessageBox.Show("添加失败!");
            }
        }

        //添加班级
        private void button4_Click(object sender, EventArgs e)
        {
            Class c = new Class();
            c.ClassName = textBox4.Text.Trim();
            if (class_bll.AddClass(c) == 0)
            {
                MessageBox.Show("添加成功!");
                this.dataGridView4.DataSource = class_bll.selectClass1().Tables[0];

                //自动找到刚刚添加成功的新行,并选中
                com.AutoFindRow(c.ClassId.ToString(), this.dataGridView4);
            }
            else
            {
                MessageBox.Show("添加失败!");
            }
        }

        //当编辑绑定完 DataGridView所有单元格之后,执行绘制引发的事件
        private void dataGridView2_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X,
               e.RowBounds.Location.Y,
               dataGridView1.RowHeadersWidth - 4,
               e.RowBounds.Height);

            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                dataGridView1.RowHeadersDefaultCellStyle.Font,
                rectangle,
                dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }

        //图书类型表的单元格单击事件
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //选中行的图书编号
            int str = -1;
            try
            {
                str = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value;
            }
            catch (Exception) { }

            //DataGridView的总列数
            int rows = dataGridView1.Columns.Count;

            if (e.ColumnIndex == rows - 2)//修改
            {
                BookType t = new BookType();
                t.BookTypeId = str;
                t.BookTypeName = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                Exit exit = new Exit();
                exit.aa = this;
                exit.t = t;
                exit.Text = "修改图书类型";
                exit.ShowDialog();
            }
            else if (e.ColumnIndex == rows - 1)//删除
            {
                DialogResult result = MessageBox.Show("确定删除吗?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (result == DialogResult.OK)
                {
                    if (booktype.deleteBookType(str) > 0)
                    {
                        this.dataGridView1.DataSource = booktype.selectBookType1().Tables[0];
                    }
                    else
                    {
                        MessageBox.Show("删除失败!");
                    }
                }
            }
        }

        //读者类型表的单元格单击事件
        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //选中行的图书编号
            int str = -1;
            try
            {
                str = (int)dataGridView2.Rows[e.RowIndex].Cells[0].Value;
            }
            catch (Exception) { }

            //DataGridView的总列数
            int rows = dataGridView2.Columns.Count;

            if (e.ColumnIndex == rows - 2)//修改
            {
                ReaderType r = new ReaderType();
                r.ReaderTypeId = str;
                r.ReaderTypeName = dataGridView2.Rows[e.RowIndex].Cells[1].Value.ToString();
                Exit exit = new Exit();
                exit.aa = this;
                exit.r = r;
                exit.Text = "修改读者类型";
                exit.ShowDialog();
            }
            else if (e.ColumnIndex == rows - 1)//删除
            {
                DialogResult result = MessageBox.Show("确定删除吗?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (result == DialogResult.OK)
                {
                    if (readerType_bll.deleteReader(str) > 0)
                    {
                        this.dataGridView2.DataSource = readerType_bll.selectReaderType1().Tables[0];
                    }
                    else
                    {
                        MessageBox.Show("删除失败!");
                    }
                }
            }
        }

        //院系表的单元格单击事件
        private void dataGridView3_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //选中行的图书编号
            int str = -1;
            try
            {
                str = (int)dataGridView3.Rows[e.RowIndex].Cells[0].Value;
            }
            catch (Exception) { }

            //DataGridView的总列数
            int rows = dataGridView3.Columns.Count;

            if (e.ColumnIndex == rows - 2)//修改
            {
                Department d = new Department();
                d.DepartmentId = str;
                d.DepartmentName = dataGridView3.Rows[e.RowIndex].Cells[1].Value.ToString();
                Exit exit = new Exit();
                exit.aa = this;
                exit.d = d;
                exit.Text = "修改院系";
                exit.ShowDialog();
            }
            else if (e.ColumnIndex == rows - 1)//删除
            {
                DialogResult result = MessageBox.Show("确定删除吗?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (result == DialogResult.OK)
                {
                    if (department_bll.deleteDepartment(str) > 0)
                    {
                        this.dataGridView3.DataSource = department_bll.selectDepartment1().Tables[0];
                    }
                    else
                    {
                        MessageBox.Show("删除失败!");
                    }
                }
            }
        }

        //班级表的单元格单击事件
        private void dataGridView4_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //选中行的图书编号
            int str = -1;
            try
            {
                str = (int)dataGridView4.Rows[e.RowIndex].Cells[0].Value;
            }
            catch (Exception) { }

            //DataGridView的总列数
            int rows = dataGridView4.Columns.Count;

            if (e.ColumnIndex == rows - 2)//修改
            {
                Class c = new Class();
                c.ClassId = str;
                c.ClassName = dataGridView4.Rows[e.RowIndex].Cells[1].Value.ToString();
                Exit exit = new Exit();
                exit.aa = this;
                exit.c = c;
                exit.Text = "修改班级";
                exit.ShowDialog();
            }
            else if (e.ColumnIndex == rows - 1)//删除
            {
                DialogResult result = MessageBox.Show("确定删除吗?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (result == DialogResult.OK)
                {
                    if (class_bll.deleteClass(str) > 0)
                    {
                        this.dataGridView4.DataSource = class_bll.selectClass1().Tables[0];
                    }
                    else
                    {
                        MessageBox.Show("删除失败!");
                    }
                }
            }
        }

        //窗口关闭时为了刷新前一个窗体的下拉菜单
        private void Add_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (bookInfoExit != null)
            {
                bookInfoExit.BookInfoExit_UI_Load(null, null);
            }
            if (readerExit != null)
            {
                readerExit.ReaderExit_UI_Load(null, null);
            }
            if (Manager != null)
            {
                Manager.treeView1.Nodes.Clear();
                Manager.TreeViewBand();
                Manager.btnSelect_Click(null, null);
            }
            if (bookInfoAdd != null)
            {
                bookInfoAdd.BookInfoAdd_UI_Load(null, null);
            }
            if (readerManager != null)
            {
                readerManager.treeView1.Nodes.Clear();
                readerManager.TreeViewBand();
                readerManager.btnSelect_Click(null, null);
            }
        }
    }
}

在这里插入图片描述`

``` ### BookInfoAdd_UI.cs ![BookInfoAdd_UI.cs](https://img-blog.csdnimg.cn/20181106225958714.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzU4MjEyMw==,size_16,color_FFFFFF,t_70)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Model;
using BLL;
using Common;

namespace Web
{
    public partial class BookInfoAdd_UI : Form
    {
        public BookInfoAdd_UI()
        {
            InitializeComponent();
        }
        public BookInfoManager_UI manager = null;
        Com com = new Com();

        private void button3_MouseEnter(object sender, EventArgs e)
        {
            ((Button)sender).FlatStyle = FlatStyle.Standard;
        }

        private void button3_MouseLeave(object sender, EventArgs e)
        {
            ((Button)sender).FlatStyle = FlatStyle.Flat;
        }
        BookInfo_BLL bookInfo = new BookInfo_BLL();
        BookType_BLL bookType = new BookType_BLL();

        public void BookInfoAdd_UI_Load(object sender, EventArgs e)
        {
            this.cboBookTypeId.DataSource = bookType.selectBookType();
            this.cboBookTypeId.DisplayMember = "BookTypeName";
            this.cboBookTypeId.ValueMember = "BookTypeId";
        }
        /// 
        /// 添加图书信息
        /// 
        /// 
        /// 
        private void button1_Click(object sender, EventArgs e)
        {
            //图书编号必须唯一
            int rows = this.manager.dataGridView1.RowCount;
            lab.Text = "";
            for (int i = 0; i < rows; i++)
            {
                string Columns1 = this.manager.dataGridView1.Rows[i].Cells[0].Value.ToString();
                if (Columns1 == txtBookId.Text.Trim())
                {
                    lab.Text = "图书编号已存在!";
                    return;
                }
            }

            //创建添加的对象
            BookInfo book = new BookInfo();
            book.BookId = txtBookId.Text.Trim();
            book.BookName = txtBookName.Text.Trim();
            book.TimeIn = TimeIn.Value;
            book.BookTypeId = (int)cboBookTypeId.SelectedValue;
            book.Author = txtAuthor.Text.Trim();
            book.PinYinCode = txtPinYinCode.Text.Trim();
            book.Translator = txtTranslator.Text.Trim();
            book.Language = txtLanguge.Text.Trim();
            book.BookNumber = txtBookNumber.Text.Trim();
            book.Price = txtPrice.Text.Trim();
            book.Layout = txtLayout.Text.Trim();
            book.Address = txtAddress.Text.Trim();
            book.ISBS = txtISBS.Text.Trim();
            book.Versions = txtVersions.Text.Trim();
            book.BookRemark = txtBookRemark.Text.Trim();

            if (bookInfo.AddBookInfo(book) > 0)
            {
                MessageBox.Show("添加信息成功!");
                //图书类型信息的绑定
                manager.dataGridView1.DataSource = manager.bookInfo_bll.selectBookInfo1().Tables[0];

                //自动找到刚刚添加成功的新行,并选中
                com.AutoFindRow(txtBookId.Text.Trim(), this.manager.dataGridView1);
            }
            else
            {
                MessageBox.Show("添加信息失败!");
            }
        }

        /// 
        /// 添加图书分类
        /// 
        /// 
        /// 
        private void button4_Click(object sender, EventArgs e)
        {
            Add a = new Add();
            a.tabName = "图书类型";
            a.bookInfoAdd = this;
            a.Manager = this.manager;
            a.ShowDialog();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void cboBookTypeId_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}

BookInfoExit_UI.cs

C# 图书馆项目实例_第8张图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DAL;
using Model;
using Common;
using BLL;


namespace Web
{
    public partial class BookInfoExit_UI : Form
    {
        public BookInfoExit_UI()
        {
            InitializeComponent();
        }
        public string BookId = null;
        public BookInfoManager_UI manager = null;
        Com com = new Com();

        private void button3_MouseEnter(object sender, EventArgs e)
        {
            ((Button)sender).FlatStyle = FlatStyle.Standard;
        }

        private void button3_MouseLeave(object sender, EventArgs e)
        {
            ((Button)sender).FlatStyle = FlatStyle.Flat;
        }
        BookInfo_BLL bookInfo = new BookInfo_BLL();
        BookType_BLL bookType = new BookType_BLL();

        public void BookInfoExit_UI_Load(object sender, EventArgs e)
        {
            this.cboBookTypeId.DataSource = bookType.selectBookType();
            this.cboBookTypeId.DisplayMember = "BookTypeName";
            this.cboBookTypeId.ValueMember = "BookTypeId";

            List list = bookInfo.selectBookInfo(this.BookId);
            txtBookId.Text = list[0].BookId;
            txtBookName.Text = list[0].BookName;
            TimeIn.Value = list[0].TimeIn;
            cboBookTypeId.SelectedValue = list[0].BookTypeId;
            txtAuthor.Text = list[0].Author;
            txtPinYinCode.Text = list[0].PinYinCode;
            txtTranslator.Text = list[0].Translator;
            txtLanguge.Text = list[0].Language;
            txtBookNumber.Text = list[0].BookNumber;
            txtPrice.Text = list[0].Price;
            txtLayout.Text = list[0].Layout;
            txtAddress.Text = list[0].Address;
            txtISBS.Text = list[0].ISBS;
            txtVersions.Text = list[0].Versions;
            txtBookRemark.Text = list[0].BookRemark;
        }
        /// 
        /// 添加图书分类
        /// 
        /// 
        /// 
        private void button4_Click(object sender, EventArgs e)
        {
            Add a = new Add();
            a.tabName = "图书类型";
            a.bookInfoExit = this;
            a.Manager = this.manager;
            a.ShowDialog();
        }
        /// 
        /// 保存修改信息
        /// 
        /// 
        /// 
        private void btnSave_Click(object sender, EventArgs e)
        {
            //创建添加的对象
            BookInfo book = new BookInfo();
            book.BookId = txtBookId.Text.Trim();
            book.BookName = txtBookName.Text.Trim();
            book.TimeIn = TimeIn.Value;
            book.BookTypeId = (int)cboBookTypeId.SelectedValue;
            book.Author = txtAuthor.Text.Trim();
            book.PinYinCode = txtPinYinCode.Text.Trim();
            book.Translator = txtTranslator.Text.Trim();
            book.Language = txtLanguge.Text.Trim();
            book.BookNumber = txtBookNumber.Text.Trim();
            book.Price = txtPrice.Text.Trim();
            book.Layout = txtLayout.Text.Trim();
            book.Address = txtAddress.Text.Trim();
            book.ISBS = txtISBS.Text.Trim();
            book.Versions = txtVersions.Text.Trim();
            book.BookRemark = txtBookRemark.Text.Trim();

            if (bookInfo.ExitBookInfo(book) > 0)
            {
                MessageBox.Show("修改信息成功!");
                //单击查询
                manager.btnSelect_Click(null, null);

                //自动找到刚刚修改成功的行,并选中
                com.AutoFindRow(txtBookId.Text.Trim(), this.manager.dataGridView1);
            }
            else
            {
                MessageBox.Show("修改信息失败!");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

BookInfoExitRows_UI.cs

C# 图书馆项目实例_第9张图片
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Web
{
public partial class BookInfoExitRows_UI : Form
{
public BookInfoExitRows_UI()
{
InitializeComponent();
}
public BookInfoManager_UI Book = null;
public ReaderManager_UI Reader = null;

    DataGridViewColumnCollection columns;

    private void BookInfoExitRows_UI_Load(object sender, EventArgs e)
    {
        if (Book != null)
        {
            columns = Book.dataGridView1.Columns;
        }
        else if (Reader != null)
        {
            columns = Reader.dgvHeaderInfo.Columns;
        }
        for (int i = 0; i < columns.Count - 2; i++)
        {
            if (columns[i].Visible == true)
            {
                listBox1.Items.Add(columns[i].HeaderText);
            }
            else
            {
                listBox2.Items.Add(columns[i].HeaderText);
            }
        }
    }
    //左移
    private void btnLeft_Click(object sender, EventArgs e)
    {
        ListBox.SelectedObjectCollection selectListBox2 = listBox2.SelectedItems;
        for (int i = 0; i < selectListBox2.Count; i++)
        {
            listBox1.Items.Add(selectListBox2[i]);
            for (int j = 0; j < columns.Count - 2; j++)
            {
                if (columns[j].HeaderText == selectListBox2[i].ToString())
                {
                    columns[j].Visible = true;
                }
            }
        }

        ListBox.SelectedIndexCollection indices = listBox2.SelectedIndices;

        for (int i = indices.Count - 1; i >= 0; i--)
        {
            int index = indices[i];
            listBox2.Items.RemoveAt(index);
        }
    }
    //右移
    private void btnRight_Click(object sender, EventArgs e)
    {
        ListBox.SelectedObjectCollection selectListBox1 = listBox1.SelectedItems;
        for (int i = 0; i < selectListBox1.Count; i++)
        {
            listBox2.Items.Add(selectListBox1[i]);
            for (int j = 0; j < columns.Count - 2; j++)
            {
                if (columns[j].HeaderText == selectListBox1[i].ToString())
                {
                    columns[j].Visible = false;
                }
            }
        }


        ListBox.SelectedIndexCollection indices = listBox1.SelectedIndices;
        for (int i = indices.Count - 1; i >= 0; i--)
        {
            int index = indices[i];
            listBox1.Items.RemoveAt(index);

        }
    }

    private void btnClose_Click(object sender, EventArgs e)
    {
        this.Close();
    }

}

}

BookInfoManager_UI.cs

C# 图书馆项目实例_第10张图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BLL;
using Common;
using Model;
using System.Reflection;
using System.Data.SqlClient;

namespace Web
{
    public partial class BookInfoManager_UI : Form
    {
        public BookInfoManager_UI()
        {
            InitializeComponent();
        }
        public BookInfo_BLL bookInfo_bll = new BookInfo_BLL();
        BookType_BLL bookType_bll = new BookType_BLL();
        Com autocoumns = new Com();
        public BorrowReturn_BLL borrowReturn_bll = new BorrowReturn_BLL();

        //树绑定
        public void TreeViewBand()
        {
            //图书类型的集合
            List list1 = bookType_bll.selectBookType();
            TreeNode nod = new TreeNode();
            nod.Text = "图书类型";
            nod.ImageIndex = 0;
            treeView1.Nodes.Add(nod);

            foreach (BookType k in list1)
            {
                TreeNode node = new TreeNode();
                node.Text = k.BookTypeName;
                node.Tag = k.BookTypeId;
                node.ImageIndex = 0;
                nod.Nodes.Add(node);
            }

            treeView1.ExpandAll();
        }

        private void BookInfoManager_UI_Load(object sender, EventArgs e)
        {
            #region DataGridView1绑定
            //需要添加列的列标题字符串
            string arraysHeaderText = @"图书编号,图书名称,登记时间,图书类型,作者,拼音码,翻译,语言,页数,价格,印刷版面,存放位置,ISBS码,版本,描述";
            //需要绑定数据库列名称的字符串
            string arraysName = @"BookId,BookName,TimeIn,BookTypeName,Author,PinYinCode,Translator,Language,BookNumber,Price,Layout,Address,ISBS,Versions,BookRemark";


            //自动生成columns
            autocoumns.AutoColumn(arraysHeaderText, arraysName, dataGridView1);
            dataGridView1.DataSource = bookInfo_bll.selectBookInfo1().Tables[0];
            autocoumns.AddColumn("修改", dataGridView1);
            autocoumns.AddColumn("删除", dataGridView1);

            //DataGridView1数据集绑定
            this.dataGridView1.DataSource = bookInfo_bll.selectBookInfo1().Tables[0];
            //窗体加载时默认隐藏的列
            this.dataGridView1.Columns[14].Visible = false;
            this.dataGridView1.Columns[13].Visible = false;
            this.dataGridView1.Columns[12].Visible = false;
            this.dataGridView1.Columns[11].Visible = false;
            this.dataGridView1.Columns[10].Visible = false;
            #endregion

            #region 下拉框绑定

            DataGridViewColumnCollection columns = dataGridView1.Columns;

            for (int i = 0; i < columns.Count - 2; i++)
            {
                comboBox1.Items.Add(columns[i].HeaderText);
            }
            comboBox1.Items.Insert(0, "全部");
            comboBox1.SelectedIndex = 0;

            #endregion

            #region 树状图的绑定

            TreeViewBand();

            #endregion

            #region DgvHostory绑定

            string Header1 = @"图书编号,图书名称,读者编号,读者名称,借出时间,书应归还时间,实际归还时间,应付罚金,续借次数,借还描述";
            string PropertyNames1 = @"BookId,BookName,ReaderId,ReaderName,BorrowTime,ReturnTime,FactReturnTime,Fine,RenewCount,BorrowRemark";
            //自动生成columns
            autocoumns.AutoColumn(Header1, PropertyNames1, dgvHostory);

            #endregion
        }
        /// 
        /// 树控件更改选定内容的事件
        /// 
        /// 
        /// 
        private void treeView1_AfterSelect_1(object sender, TreeViewEventArgs e)
        {
            if (treeView1.SelectedNode.Level == 0)
            {
                dataGridView1.DataSource = bookInfo_bll.selectBookInfo1().Tables[0];
            }
            else if (treeView1.SelectedNode.Level == 1)
            {
                int index = (int)treeView1.SelectedNode.Tag;
                dataGridView1.DataSource = bookInfo_bll.selectBookInfo1(index).Tables[0];
            }
            //如果读者信息表中查不到一条数据,相关表的数据也清空
            if (dataGridView1.Rows.Count == 0)
            {
                dgvHostory.DataSource = null;
                return;
            }
        }

        /// 
        /// 当编辑绑定完 DataGridView所有单元格之后,执行绘制引发的事件
        /// 
        /// 
        /// 
        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X,
               e.RowBounds.Location.Y,
               dataGridView1.RowHeadersWidth - 4,
               e.RowBounds.Height);

            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                dataGridView1.RowHeadersDefaultCellStyle.Font,
                rectangle,
                dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            BookInfoExitRows_UI b = new BookInfoExitRows_UI();
            b.Book = this;
            b.ShowDialog();
        }
        public string BookId = "";

        /// 
        /// 单击DataGridView单元格事件
        /// 
        /// 
        /// 
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                //选中行的图书编号
                BookId = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();

            }
            catch (Exception) { }

            //单击某行 历史记录表就显示相关的数据
            this.dgvHostory.DataSource = borrowReturn_bll.selectBorrowReturn(BookId).Tables[0];


            //DataGridView的总列数
            int rows = dataGridView1.Columns.Count;

            if (e.ColumnIndex == rows - 2)//修改
            {
                BookInfoExit_UI b = new BookInfoExit_UI();
                b.manager = this;
                b.BookId = BookId;
                b.ShowDialog();
            }
            else if (e.ColumnIndex == rows - 1)//删除
            {
                DialogResult result = MessageBox.Show("确定删除吗?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (result == DialogResult.OK)
                {
                    if (bookInfo_bll.DeleteBookInfo(BookId) > 0)
                    {
                        //调用查询按钮刷新图书信息表
                        btnSelect_Click(null, null);
                        //历史记录表中的数据引用着图书信息表的数据,删除图书信息应该刷新历史记录表
                        this.dgvHostory.DataSource = borrowReturn_bll.selectBorrowReturn(BookId).Tables[0];
                    }
                    else
                    {
                        MessageBox.Show("删除失败!");
                    }
                }
            }
        }
        /// 
        /// 点击查询按钮
        /// 
        /// 
        /// 
        public void btnSelect_Click(object sender, EventArgs e)
        {
            DataGridViewColumnCollection columns = dataGridView1.Columns;
            if (comboBox1.SelectedIndex == 0)//全部
            {
                List list = new List();
                for (int i = 0; i < columns.Count - 2; i++)
                {
                    list.Add(columns[i].DataPropertyName);
                }
                string B = textBox1.Text.Trim();
                dataGridView1.DataSource = bookInfo_bll.selectBookInfo1(list, B).Tables[0];
            }
            else
            {

                for (int i = 0; i < columns.Count - 2; i++)
                {
                    if (comboBox1.SelectedItem.ToString() == columns[i].HeaderText)
                    {
                        string A = columns[i].DataPropertyName;
                        string B = textBox1.Text.Trim();
                        dataGridView1.DataSource = bookInfo_bll.selectBookInfo1(A, B).Tables[0];
                        break;
                    }
                }
            }

            //如果读者信息表中查不到一条数据,相关表的数据也清空
            if (dataGridView1.Rows.Count == 0)
            {
                dgvHostory.DataSource = null;
                return;
            }
        }
        public BookInfoAdd_UI bookInfoAdd;
        public void btnAddBookInfo_Click(object sender, EventArgs e)
        {
            bookInfoAdd = new BookInfoAdd_UI();
            bookInfoAdd.manager = this;
            bookInfoAdd.ShowDialog();
        }
    }
}

BorrowHostory_UI

C# 图书馆项目实例_第11张图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Common;
using BLL;
using Model;

namespace Web
{
    public partial class BorrowHostory_UI : Form
    {
        public BorrowHostory_UI()
        {
            InitializeComponent();
        }

        private void button5_MouseEnter(object sender, EventArgs e)
        {
            ((Button)sender).FlatStyle = FlatStyle.Standard;
        }

        private void button5_MouseLeave(object sender, EventArgs e)
        {
            ((Button)sender).FlatStyle = FlatStyle.Flat;
        }
        Com com = new Com();
        BorrowReturn_BLL borrowReturn_bll = new BorrowReturn_BLL();

        private void btnReaderId_Click(object sender, EventArgs e)
        {
            Info_UI i = new Info_UI();
            i.txtName = "读者信息";
            i.BorrowHostory = this;
            i.ShowDialog();
        }

        private void btnBookId_Click(object sender, EventArgs e)
        {
            Info_UI i = new Info_UI();
            i.txtName = "图书信息";
            i.BorrowHostory = this;
            i.ShowDialog();
        }

        private void BorrowHostory_UI_Load(object sender, EventArgs e)
        {
            cboBorrowTimeType.SelectedIndex = 0;
            #region dgvHostory列表生成

            string ColumnHeaderText = "图书编号,读者编号,图书名称,读者名称,图书类型,读者类型,读者性别,身份证号,借阅时间,应还时间,实际还书时间,罚金,续借次数";
            string ColumnHeaderName = @"BookId,ReaderId,BookName,ReaderName,BookTypeName,ReaderTypeName,Gender,IdentityCard,BorrowTime,ReturnTime,FactReturnTime,Fine,RenewCount";
            com.AutoColumn(ColumnHeaderText, ColumnHeaderName, dgvHostory);
            dgvHostory.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgvHostory.DataSource = borrowReturn_bll.AllBorrowReturn().Tables[0];
            #endregion
        }

        //当编辑绑定完 DataGridView所有单元格之后,执行绘制引发的事件
        private void dgvHostory_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X,
               e.RowBounds.Location.Y,
               dgvHostory.RowHeadersWidth - 4,
               e.RowBounds.Height);

            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                dgvHostory.RowHeadersDefaultCellStyle.Font,
                rectangle,
                dgvHostory.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }
        //CheckBox是否选中打钩 事件
        private void checkTime_CheckedChanged(object sender, EventArgs e)
        {
            if (checkTime.Checked)
            {
                dtIn.Enabled = true;
                dtOut.Enabled = true;
                cboBorrowTimeType.Enabled = true;
            }
            else
            {
                dtIn.Enabled = false;
                dtOut.Enabled = false;
                cboBorrowTimeType.Enabled = false;
            }
        }
        //单击查询
        private void btnSelect_Click(object sender, EventArgs e)
        {
            BorrowReturn b = new BorrowReturn();
            b.BookId = txtBookId.Text.Trim();
            b.ReaderId = txtReaderId.Text.Trim();
            b.TimeIn = dtIn.Value;
            b.TimeOut = dtOut.Value;
            String rdoName = rdoAll.Text;
            if (rdoBorrow.Checked)
                rdoName = rdoBorrow.Text;
            else if (rdoReturn.Checked)
                rdoName = rdoReturn.Text;
            String cboBorrowTimeType = this.cboBorrowTimeType.SelectedItem.ToString();
            bool checkTime = this.checkTime.Checked;
            dgvHostory.DataSource = borrowReturn_bll.selectHostory(b, rdoName, cboBorrowTimeType, checkTime).Tables[0];
        }

        private void dgvHostory_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}

BorrowManager_UI

C# 图书馆项目实例_第12张图片


    using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Common;
using BLL;
using Model;

namespace Web
{
    public partial class BorrowManager_UI : Form
    {
        public BorrowManager_UI()
        {
            InitializeComponent();
        }

        private void BorrowManager_UI_Load(object sender, EventArgs e)
        {
            #region dgvReaderInfo自动生成列

            //需要添加列的列标题字符串
            string arraysHeaderText = @"读者编号,读者名称,登记时间,有效时间,图书类型,所在院系,所在班级,省份证号,性别,电话,手机,Email,联系地址,描述信息";
            //需要绑定数据库列名称的字符串
            string arraysName = @"ReaderId,ReaderName,TimeIn,TimeOut,ReaderTypeName,DepartmentName,ClassName,IdentityCard,Gender,Special,Phone,Email,Address,ReaderRemark";

            //自动生成columns
            autocoumns.AutoColumn(arraysHeaderText, arraysName, dgvReaderInfo);

            //DataGridView1数据集绑定
            //this.dgvReaderInfo.DataSource = reader_bll.selectReader().Tables[0];
            this.dgvReaderInfo.Columns[13].Visible = false;
            this.dgvReaderInfo.Columns[12].Visible = false;
            this.dgvReaderInfo.Columns[11].Visible = false;
            dgvReaderInfo.DataSource = null;

            #endregion


            #region dgvBorrow表的自动生成列

            //dataGridView3.AutoGenerateColumns = false;
            //需要添加列的列标题字符串
            string arraysHeaderText1 = @"借还ID,读者编号,读者名称,图书编号,图书名称,借出时间,书应归还时间,实际归还时间,应付罚金,续借次数,借还描述";
            //需要绑定数据库列名称的字符串
            string arraysName1 = @"BorrowId,ReaderId,ReaderName,BookId,BookName,BorrowTime,ReturnTime,FactReturnTime,Fine,RenewCount,BorrowRemark";

            //自动生成columns
            autocoumns.AutoColumn(arraysHeaderText1, arraysName1, dgvBorrowed);
            autocoumns.AddColumn("续借", dgvBorrowed);
            autocoumns.AddColumn("还书", dgvBorrowed);

            //dgvBorrowed.Columns[2].Frozen = true;
            //dgvBorrowed.Columns[1].Frozen = true;
            //自动铺满的列宽
            dgvBorrowed.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgvBorrowed.Columns[0].Visible = false;
            dgvBorrowed.Columns[1].Visible = false;
            dgvBorrowed.Columns[2].Visible = false;
            dgvBorrowed.Columns[7].Visible = false;
            dgvBorrowed.Columns[dgvBorrowed.Columns.Count - 3].Visible = false;
            dgvBorrowed.DataSource = null;
            #endregion


            #region dgvBookInfo的自动生成列

            //需要添加列的列标题字符串
            string arraysHeaderText2 = @"图书编号,图书名称,登记时间,图书类型,作者,拼音码,翻译,语言,页数,价格,印刷版面,存放位置,ISBS码,版本,描述";
            //需要绑定数据库列名称的字符串
            string arraysName2 = @"BookId,BookName,TimeIn,BookTypeName,Author,PinYinCode,Translator,Language,BookNumber,Price,Layout,Address,ISBS,Versions,BookRemark";

            //自动生成columns
            autocoumns.AutoColumn(arraysHeaderText2, arraysName2, dgvBookInfo);
            autocoumns.AddColumn("借书", dgvBookInfo);

            dgvBookInfo.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgvBookInfo.DataSource = null;

            dgvBookInfo.Columns[dgvBookInfo.Columns.Count - 2].Visible = false;
            dgvBookInfo.Columns[dgvBookInfo.Columns.Count - 3].Visible = false;
            dgvBookInfo.Columns[dgvBookInfo.Columns.Count - 4].Visible = false;
            dgvBookInfo.Columns[dgvBookInfo.Columns.Count - 5].Visible = false;
            dgvBookInfo.Columns[dgvBookInfo.Columns.Count - 6].Visible = false;
            dgvBookInfo.Columns[dgvBookInfo.Columns.Count - 7].Visible = false;
            dgvBookInfo.Columns[dgvBookInfo.Columns.Count - 8].Visible = false;
            #endregion
        }
        private void button5_MouseEnter(object sender, EventArgs e)
        {
            ((Button)sender).FlatStyle = FlatStyle.Standard;
        }

        private void button5_MouseLeave(object sender, EventArgs e)
        {
            ((Button)sender).FlatStyle = FlatStyle.Flat;
        }
        Com autocoumns = new Com();
        Reader_BLL reader_bll = new Reader_BLL();
        BorrowReturn_BLL borrowReturn_bll = new BorrowReturn_BLL();
        BookInfo_BLL bookInfo_bll = new BookInfo_BLL();

        //读者信息与读者借还表的联动
        private void txtReaderId_TextChanged(object sender, EventArgs e)
        {
            string ReaderId = txtReaderId.Text.Trim();
            dgvReaderInfo.DataSource = reader_bll.selectReader("ReaderId", ReaderId).Tables[0];
        }
        //重新绑定数据是发生
        private void dgvReaderInfo_DataSourceChanged(object sender, EventArgs e)
        {
            if (dgvReaderInfo.Rows.Count > 0)
            {
                string ReaderId = dgvReaderInfo.Rows[0].Cells[0].Value.ToString();
                dgvBorrowed.DataSource = borrowReturn_bll.ReaderBorrowReturn(ReaderId).Tables[0];

                labBorrowBook.Text = "读者编号为:" + ReaderId + " 正在借阅的以下图书";
            }
            else
            {
                dgvBorrowed.DataSource = null;
                labBorrowBook.Text = ".....正在借阅的图书";
            }
        }
        //根据图书编号改变事件
        private void txtBookId_TextChanged(object sender, EventArgs e)
        {
            string BookId = txtBookId.Text.Trim();
            dgvBookInfo.DataSource = bookInfo_bll.selectBookInfo2(BookId).Tables[0];
        }

        private void dgvBorrowed_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int BorrowReturnId = -1;
            try
            {
                //选中行的借阅编号
                BorrowReturnId = (int)dgvBorrowed.Rows[e.RowIndex].Cells[0].Value;

            }
            catch (Exception) { }

            //DataGridView的总列数
            int rows = dgvBorrowed.Columns.Count;

            if (e.ColumnIndex == rows - 2)//修改
            {
                DialogResult result = MessageBox.Show("确定续借吗?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (result == DialogResult.OK)
                {
                    BorrowReturn b = new BorrowReturn();
                    b.BorrowId = BorrowReturnId;
                    if (borrowReturn_bll.RenewBook(b) > 0)
                    {
                        MessageBox.Show("续借成功!");
                        dgvReaderInfo_DataSourceChanged(null, null);
                        autocoumns.AutoFindRow(b.BorrowId, dgvBorrowed);
                    }
                    else
                    {
                        MessageBox.Show("续借失败!");
                    }
                }
            }
            else if (e.ColumnIndex == rows - 1)//还书
            {
                DialogResult result = MessageBox.Show("确定还书吗?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (result == DialogResult.OK)
                {
                    if (borrowReturn_bll.ReturnBook(BorrowReturnId) > 0)
                    {
                        dgvReaderInfo_DataSourceChanged(null, null);
                        MessageBox.Show("还书成功!");
                        txtBookId_TextChanged(null, null);
                    }
                    else
                    {
                        MessageBox.Show("还书失败!");
                    }
                }
            }
        }
        //借书
        private void dgvBookInfo_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string BookId = "";
            try
            {
                //选中行的图书编号
                BookId = dgvBookInfo.Rows[e.RowIndex].Cells[0].Value.ToString();

            }
            catch (Exception) { }

            //DataGridView的总列数
            int rows = dgvBookInfo.Columns.Count;

            if (e.ColumnIndex == rows - 1)//借书
            {
                if (dgvReaderInfo.Rows.Count < 1)
                {
                    MessageBox.Show("没有读者信息!");
                    return;
                }
                BorrowReturn b = new BorrowReturn();
                b.BookId = BookId;
                b.ReaderId = dgvReaderInfo.Rows[0].Cells[0].Value.ToString();
                b.BorrowTime = DateTime.Now;
                b.ReturnTime = DateTime.Now;//数据库中存储过程根据借书时间自动计算应还书日期
                b.Fine = 0;
                b.RenewCount = 0;
                b.BorrowRemark = "";


                DialogResult result = MessageBox.Show("确定借书吗?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (result == DialogResult.OK)
                {
                    if (borrowReturn_bll.BorrowBook(b) == 0)
                    {


                        MessageBox.Show("借书成功!");
                        //刷新图书借还表
                        dgvReaderInfo_DataSourceChanged(null, null);
                        //选中添加成功的新行
                        autocoumns.AutoFindRow(b.BorrowId, dgvBorrowed);
                        //刷新 //读者信息与读者借还表的联动
                        txtBookId_TextChanged(null, null);
                    }
                    else
                    {
                        MessageBox.Show("借书失败!");
                    }
                }

            }
        }
        //查询读者
        private void btnSelctReader_Click(object sender, EventArgs e)
        {
            Info_UI i = new Info_UI();
            i.txtName = "读者信息";
            i.borrowManager = this;
            i.ShowDialog();
        }

        private void btnSelectBook_Click(object sender, EventArgs e)
        {
            Info_UI i = new Info_UI();
            i.txtName = "图书信息";
            i.borrowManager = this;
            i.ShowDialog();
        }

        private void dgvBorrowed_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X,
               e.RowBounds.Location.Y,
               dgvBorrowed.RowHeadersWidth - 4,
               e.RowBounds.Height);

            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                dgvBorrowed.RowHeadersDefaultCellStyle.Font,
                rectangle,
                dgvBorrowed.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }


    }
}


Exit

C# 图书馆项目实例_第13张图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Model;
using Common;
using BLL;

namespace Web
{
    public partial class Exit : Form
    {
        public Exit()
        {
            InitializeComponent();
        }
        public Class c = null;
        public Department d = null;
        public ReaderType r = null;
        public Add aa = null;
        public BookType t = null;
        Com com = new Com();

        private void Exit_Load(object sender, EventArgs e)
        {
            if (t != null)
            {
                this.textBox1.Text = t.BookTypeName;
            }
            else if (r != null)
            {
                this.textBox1.Text = r.ReaderTypeName;
            }
            else if (d != null)
            {
                this.textBox1.Text = d.DepartmentName;
            }
            else if (c != null)
            {
                this.textBox1.Text = c.ClassName;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (t != null)
            {
                t.BookTypeName = textBox1.Text.Trim();
                if (aa.booktype.updateBookType(t) > 0)
                {
                    aa.dataGridView1.DataSource = aa.booktype.selectBookType1().Tables[0];
                    //自动找到刚刚修改成功的行,并选中
                    com.AutoFindRow(t.BookTypeId.ToString(), aa.dataGridView1);
                }
                else { MessageBox.Show("修改失败!"); }
            }
            if (r != null)
            {
                r.ReaderTypeName = textBox1.Text.Trim();
                if (aa.readerType_bll.updateReaderType(r) > 0)
                {
                    aa.dataGridView2.DataSource = aa.readerType_bll.selectReaderType1().Tables[0];
                    //自动找到刚刚修改成功的行,并选中
                    com.AutoFindRow(r.ReaderTypeId.ToString(), aa.dataGridView2);
                }
                else { MessageBox.Show("修改失败!"); }
            }
            if (d != null)
            {
                d.DepartmentName = textBox1.Text.Trim();
                if (aa.department_bll.updateDepartment(d) > 0)
                {
                    aa.dataGridView3.DataSource = aa.department_bll.selectDepartment1().Tables[0];
                    //自动找到刚刚修改成功的行,并选中
                    com.AutoFindRow(d.DepartmentId.ToString(), aa.dataGridView3);
                }
                else { MessageBox.Show("修改失败!"); }
            }
            if (c != null)
            {
                c.ClassName = textBox1.Text.Trim();
                if (aa.class_bll.updateClass(c) > 0)
                {
                    aa.dataGridView4.DataSource = aa.class_bll.selectClass1().Tables[0];
                    //自动找到刚刚修改成功的行,并选中
                    com.AutoFindRow(c.ClassId.ToString(), aa.dataGridView4);
                }
                else { MessageBox.Show("修改失败!"); }
            }
            this.Close();
        }
    }
}

FrmMain

C# 图书馆项目实例_第14张图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Model;
using System.Threading;

namespace Web
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }
        public Admin admin = null;
        BookInfoManager_UI book;
        ReaderManager_UI reader;
        Thread t;
        private void FrmMain_Load(object sender, EventArgs e)
        {
            this.toolStripStatusLabel.Text = "状态:" + admin.LoginType + "\"" + admin.LoginId + "\"已登录.";
            //图书管理窗体的绑定
            book = new BookInfoManager_UI();
            Control.CheckForIllegalCrossThreadCalls = false;
            //t = new Thread(delegate() { banding(book, tabPage1); });
            //t.IsBackground = true;
            //t.Start();
            banding(book, tabPage1);

            //读者管理窗体的绑定
            reader = new ReaderManager_UI();
            reader.book = book;
            banding(reader, tabPage2);

            //借还历史记录窗体的绑定
            banding(new BorrowHostory_UI(), tabPage3);
        }

        //TabControl的TabPage绑定窗体的公共方法
        public void banding(Form form, TabPage page)
        {
            page.Controls.Clear();
            form.FormBorderStyle = FormBorderStyle.None;
            form.StartPosition = FormStartPosition.Manual;
            form.Size = page.Size;
            form.TopLevel = false;
            page.Controls.Add(form);
            form.Show();

        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();  
        }

        //menuStrip新增图书
        private void menuStripAddBookInfo_Click(object sender, EventArgs e)
        {
            book.btnAddBookInfo_Click(null, null);
        }

        private void toolStripBorrow_Click(object sender, EventArgs e)
        {
            BorrowManager_UI b = new BorrowManager_UI();
            b.ShowDialog();
        }
        private void menuStripAddReaderInfo_Click(object sender, EventArgs e)
        {
            reader.btnAddReaderInfo_Click(null, null);
        }

        private void 图书类别管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Add a = new Add();
            a.tabName = "图书类型";
            a.Manager = this.book;
            a.ShowDialog();
        }
        private void 读者类型管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Add a = new Add();
            a.tabName = "读者类型";
            a.readerManager = this.reader;
            a.ShowDialog();
        }

        //图书管理
        private void toolStripButtonBookManager_Click(object sender, EventArgs e)
        {
            this.tabControl.SelectedIndex = 0;
        }
        //读者管理
        private void toolStripButtonReaderManager_Click(object sender, EventArgs e)
        {
            this.tabControl.SelectedIndex = 1;
        }
        //借还管理
        private void toolStripButtonBorrowReturn_Click(object sender, EventArgs e)
        {
            this.tabControl.SelectedIndex = 2;
        }

        private void 画图工具ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("mspaint.exe");
        }

        private void 计算器ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("calc.exe");
        }




        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("确认退出", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.OK)
            {
                Application.Exit();
            }
        }

        private void 操作员管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (admin.LoginType == "超级管理员")
            {
                //AdminManager_UI a = new AdminManager_UI();
                //a.ShowDialog();
            }
            else
            {
                MessageBox.Show("只有超级管理员能使用此功能");
            }
        }

        

        private void menuStripBorrow_Click(object sender, EventArgs e)
        {
            BorrowManager_UI b = new BorrowManager_UI();
            b.ShowDialog();
        }

        private void 图书借还记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.tabControl.SelectedIndex = 2;
        }




    }
}

C# 图书馆项目实例_第15张图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Common;
using BLL;
using Model;

namespace Web
{
    public partial class Info_UI : Form
    {
        public Info_UI()
        {
            InitializeComponent();
        }
        public BorrowHostory_UI BorrowHostory = null;
        public string txtName = "";
        public BorrowManager_UI borrowManager = null;
        Com com = new Com();
        Reader_BLL reader_bll = new Reader_BLL();
        BookInfo_BLL bookInfo_bll = new BookInfo_BLL();

        private void Info_UI_Load(object sender, EventArgs e)
        {
            if (txtName.Equals("读者信息"))
            {
                this.Text = "读者信息类表";
                //需要添加列的列标题字符串
                string arraysHeaderText = @"读者编号,读者名称,登记时间,有效时间,图书类型,所在院系,所在班级,省份证号,性别,电话,手机,Email,联系地址,描述信息";
                //需要绑定数据库列名称的字符串
                string arraysName = @"ReaderId,ReaderName,TimeIn,TimeOut,ReaderTypeName,DepartmentName,ClassName,IdentityCard,Gender,Special,Phone,Email,Address,ReaderRemark";

                //自动生成columns
                com.AutoColumn(arraysHeaderText, arraysName, dgvInfo);
                for (int i = 0; i < dgvInfo.Columns.Count; i++)
                {
                    if (i > 5)
                        dgvInfo.Columns[i].Visible = false;
                }
                dgvInfo.DataSource = reader_bll.selectReader().Tables[0];
                dgvInfo.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            }
            else if (txtName == "图书信息")
            {
                this.Text = "图书信系列表";
                //需要添加列的列标题字符串
                string arraysHeaderText = @"图书编号,图书名称,登记时间,图书类型,作者,拼音码,翻译,语言,页数,价格,印刷版面,存放位置,ISBS码,版本,描述";
                //需要绑定数据库列名称的字符串
                string arraysName = @"BookId,BookName,TimeIn,BookTypeName,Author,PinYinCode,Translator,Language,BookNumber,Price,Layout,Address,ISBS,Versions,BookRemark";

                //自动生成columns
                com.AutoColumn(arraysHeaderText, arraysName, dgvInfo);
                for (int i = 0; i < dgvInfo.Columns.Count; i++)
                {
                    if (i > 5)
                        dgvInfo.Columns[i].Visible = false;
                }
                if (BorrowHostory != null)
                {
                    dgvInfo.DataSource = bookInfo_bll.selectBookInfo1().Tables[0];
                }
                else if (borrowManager != null)
                {
                    dgvInfo.DataSource = bookInfo_bll.selectBookInfo2("").Tables[0];
                }

                dgvInfo.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            }

            com.AddColumn("选取", dgvInfo);
        }

        private void dgvInfo_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string name = "";
            try
            {
                //选中行的编号
                name = dgvInfo.Rows[e.RowIndex].Cells[0].Value.ToString();

            }
            catch (Exception) { }


            if (e.ColumnIndex == dgvInfo.Columns.Count - 1)
            {
                if (borrowManager != null)
                {
                    if (txtName == "读者信息")
                    {
                        borrowManager.txtReaderId.Text = name;
                    }
                    else if (txtName == "图书信息")
                    {
                        borrowManager.txtBookId.Text = name;
                    }
                }
                else if (BorrowHostory != null)
                {
                    if (txtName == "读者信息")
                    {
                        BorrowHostory.txtReaderId.Text = name;
                    }
                    else if (txtName == "图书信息")
                    {
                        BorrowHostory.txtBookId.Text = name;
                    }
                }
                this.Close();
            }
        }

        //当编辑绑定完 DataGridView所有单元格之后,执行绘制引发的事件
        private void dgvInfo_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X,
               e.RowBounds.Location.Y,
               dgvInfo.RowHeadersWidth - 4,
               e.RowBounds.Height);

            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                dgvInfo.RowHeadersDefaultCellStyle.Font,
                rectangle,
                dgvInfo.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }
    }
}

C# 图书馆项目实例_第16张图片

using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace Web
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }
        Admin_BLL aa = new Admin_BLL();
        //窗体加载
        private void Login_Load(object sender, EventArgs e)
        {
            cboType.Items.Add("超级管理员");
            cboType.Items.Add("普通管理员");
            this.cboType.SelectedIndex = 0;
        }
        //取消
        private void btnClose_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("确定取消吗!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.OK)
                Application.Exit();      
        }
        //登录
        private void btnLongin_Click(object sender, EventArgs e)
        {
            Admin a = new Admin();
            a.LoginId = txtLoginId.Text.Trim();
            a.LoginPwd = txtPwd.Text.Trim();
            a.LoginType = cboType.Text.Trim();
            if (aa.Scalar(a)>0)
            {
                FrmMain f = new FrmMain();
                f.admin = a;
                f.Show();
                this.Hide();
                this.Visible = false;
            }
            else
            {
                MessageBox.Show("登录失败");
            }
        }
    }
}

C# 图书馆项目实例_第17张图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BLL;
using Model;
using Common;

namespace Web
{
    public partial class ReaderAdd_UI : Form
    {
        public ReaderAdd_UI()
        {
            InitializeComponent();
        }
        private void button3_MouseEnter(object sender, EventArgs e)
        {
            ((Button)sender).FlatStyle = FlatStyle.Standard;
        }

        private void button3_MouseLeave(object sender, EventArgs e)
        {
            ((Button)sender).FlatStyle = FlatStyle.Flat;
        }
        public ReaderManager_UI reader = null;

        Reader_BLL reader_bll = new Reader_BLL();
        ReaderType_BLL readerType_bll = new ReaderType_BLL();
        Department_BLL department_bll = new Department_BLL();
        Class_BLL class_bll = new Class_BLL();
        Com com = new Com();

        //加载
        private void ReaderAdd_UI_Load(object sender, EventArgs e)
        {
            //读者类型的下拉框绑定
            cboReaderType.DataSource = readerType_bll.selectReaderType();
            cboReaderType.DisplayMember = "ReaderTypeName";
            cboReaderType.ValueMember = "ReaderTypeId";

            //院系的下拉框绑定
            cboDepartment.DataSource = department_bll.selectDepartment();
            cboDepartment.DisplayMember = "DepartmentName";
            cboDepartment.ValueMember = "DepartmentId";

            //班级的下拉框绑定
            cboClass.DataSource = class_bll.selectClass();
            cboClass.DisplayMember = "ClassName";
            cboClass.ValueMember = "ClassId";
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }
        //添加读者类型
        private void btnReaderType_Click(object sender, EventArgs e)
        {
            Add a = new Add();
            a.tabName = "读者类型";
            a.readerManager = this.reader;
            a.readerAdd = this;
            a.ShowDialog();
        }
        //添加院系
        private void btnDepartment_Click(object sender, EventArgs e)
        {
            Add a = new Add();
            a.tabName = "院系";
            a.readerManager = this.reader;
            a.readerAdd = this;
            a.ShowDialog();
        }
        //添加班级
        private void btnClass_Click(object sender, EventArgs e)
        {
            Add a = new Add();
            a.tabName = "班级";
            a.readerManager = this.reader;
            a.readerAdd = this;
            a.ShowDialog();
        }
        //新增读者信息
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //图书编号必须唯一
            int rows = reader.dgvHeaderInfo.RowCount;
            lab.Text = "";
            for (int i = 0; i < rows; i++)
            {
                string Columns1 = reader.dgvHeaderInfo.Rows[i].Cells[0].Value.ToString();
                if (Columns1 == txtReaderId.Text.Trim())
                {
                    lab.Text = "读者编号已存在!";
                    return;
                }
            }
            Reader r = new Reader();
            r.ReaderId = txtReaderId.Text.Trim();
            r.ReaderName = txtReaderName.Text.Trim();
            r.TimeIn = dtTimeIn.Value;
            r.TimeOut = dtTimeOut.Value;
            r.ReaderTypeId = (int)cboReaderType.SelectedValue;
            r.DepartmentId = (int)cboDepartment.SelectedValue;
            r.ClassId = (int)cboClass.SelectedValue;
            r.IdentityCard = txtIdentityCard.Text.Trim();
            r.Gender = txtGender.Text.Trim();
            r.Phone = txtPhone.Text.Trim();
            r.Special = txtSpecial.Text.Trim();
            r.Email = txtEmail.Text.Trim();
            r.Address = txtAddress.Text.Trim();
            r.ReaderRemark = txtRemark.Text.Trim();

            if (reader_bll.addReader(r) == 0)
            {
                MessageBox.Show("新增成功!");
                //单击查询 刷新读者信息表
                reader.btnSelect_Click(null, null);

                //自动找到刚刚添加成功的新行,并选中
                com.AutoFindRow(txtReaderId.Text.Trim(), reader.dgvHeaderInfo);
            }
            else
            {
                MessageBox.Show("新增失败!");
            }
        }

    }
}

C# 图书馆项目实例_第18张图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BLL;
using Model;
using Common;

namespace Web
{
    public partial class ReaderExit_UI : Form
    {
        public ReaderExit_UI()
        {
            InitializeComponent();
        }
        private void button3_MouseEnter(object sender, EventArgs e)
        {
            ((Button)sender).FlatStyle = FlatStyle.Standard;
        }

        private void button3_MouseLeave(object sender, EventArgs e)
        {
            ((Button)sender).FlatStyle = FlatStyle.Flat;
        }

        public ReaderManager_UI reader = null;
        public string ReaderId = null;

        Reader_BLL reader_bll = new Reader_BLL();
        ReaderType_BLL readerType_bll = new ReaderType_BLL();
        Department_BLL department_bll = new Department_BLL();
        Class_BLL class_bll = new Class_BLL();
        Com com = new Com();

        public void ReaderExit_UI_Load(object sender, EventArgs e)
        {
            //读者类型的下拉框绑定
            cboReaderType.DataSource = readerType_bll.selectReaderType();
            cboReaderType.DisplayMember = "ReaderTypeName";
            cboReaderType.ValueMember = "ReaderTypeId";

            //院系的下拉框绑定
            cboDepartment.DataSource = department_bll.selectDepartment();
            cboDepartment.DisplayMember = "DepartmentName";
            cboDepartment.ValueMember = "DepartmentId";
            //班级的下拉框绑定
            cboClass.DataSource = class_bll.selectClass();
            cboClass.DisplayMember = "ClassName";
            cboClass.ValueMember = "ClassId";

            List list = reader_bll.selectReader1(ReaderId);
            txtReaderId.Text = list[0].ReaderId;
            txtReaderName.Text = list[0].ReaderName;
            dtTimeIn.Value = list[0].TimeIn;
            dtTimeOut.Value = list[0].TimeOut;
            cboReaderType.SelectedValue = list[0].ReaderTypeId;
            cboDepartment.SelectedValue = list[0].DepartmentId;
            cboClass.SelectedValue = list[0].ClassId;
            txtIdentityCard.Text = list[0].IdentityCard;
            txtGender.Text = list[0].Gender;
            txtSpecial.Text = list[0].Special;
            txtPhone.Text = list[0].Phone;
            txtEmail.Text = list[0].Email;
            txtAddress.Text = list[0].Address;
            txtRemark.Text = list[0].ReaderRemark;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            Reader r = new Reader();
            r.ReaderId = txtReaderId.Text.Trim();
            r.ReaderName = txtReaderName.Text.Trim();
            r.TimeIn = dtTimeIn.Value;
            r.TimeOut = dtTimeOut.Value;
            r.ReaderTypeId = (int)cboReaderType.SelectedValue;
            r.DepartmentId = (int)cboDepartment.SelectedValue;
            r.ClassId = (int)cboClass.SelectedValue;
            r.IdentityCard = txtIdentityCard.Text.Trim();
            r.Gender = txtGender.Text.Trim();
            r.Special = txtSpecial.Text.Trim();
            r.Phone = txtPhone.Text.Trim();
            r.Email = txtEmail.Text.Trim();
            r.Address = txtAddress.Text.Trim();
            r.ReaderRemark = txtRemark.Text.Trim();

            if (reader_bll.updateReader(r) > 0)
            {
                MessageBox.Show("修改成功!");
                //单价查询
                reader.btnSelect_Click(null, null);

                //自动找到刚刚修改成功的行,并选中
                com.AutoFindRow(txtReaderId.Text.Trim(), reader.dgvHeaderInfo);
            }
            else
            {
                MessageBox.Show("修改失败!");
            }
        }
        //读者类型编辑
        private void button4_Click(object sender, EventArgs e)
        {
            Add a = new Add();
            a.tabName = "读者类型";
            a.readerExit = this;
            a.readerManager = this.reader;
            a.ShowDialog();
        }
        //院系编辑
        private void button3_Click(object sender, EventArgs e)
        {
            Add a = new Add();
            a.tabName = "院系";
            a.readerExit = this;
            a.readerManager = this.reader;
            a.ShowDialog();
        }
        //班级编辑
        private void button5_Click(object sender, EventArgs e)
        {
            Add a = new Add();
            a.tabName = "班级";
            a.readerExit = this;
            a.readerManager = this.reader;
            a.ShowDialog();
        }

    }
}

C# 图书馆项目实例_第19张图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BLL;
using Model;
using Common;

namespace Web
{
    public partial class ReaderManager_UI : Form
    {
        public ReaderManager_UI()
        {
            InitializeComponent();
        }
        public BookInfoManager_UI book = null;
        Com autocoumns = new Com();
        public Reader_BLL reader_bll = new Reader_BLL();
        ReaderType_BLL readerType_bll = new ReaderType_BLL();
        BorrowReturn_BLL borrowReturn_bll = new BorrowReturn_BLL();

        //树状图的绑定
        public void TreeViewBand()
        {
            //图书类型的集合
            List list = readerType_bll.selectReaderType();
            TreeNode node = new TreeNode();
            node.Text = "读者类型";
            node.ImageIndex = 0;
            treeView1.Nodes.Add(node);

            foreach (ReaderType k in list)
            {
                TreeNode n = new TreeNode();
                n.Text = k.ReaderTypeName;
                n.Tag = k.ReaderTypeId;
                n.ImageIndex = 0;
                node.Nodes.Add(n);
            }
            treeView1.ExpandAll();
        }
        //读者管理窗体的加载事件
        private void ReaderManager_UI_Load(object sender, EventArgs e)
        {
            //需要添加列的列标题字符串
            string arraysHeaderText = @"读者编号,读者名称,登记时间,有效时间,读者类型,所在院系,所在班级,省份证号,性别,电话,手机,Email,联系地址,描述信息";
            //需要绑定数据库列名称的字符串
            string arraysName = @"ReaderId,ReaderName,TimeIn,TimeOut,ReaderTypeName,DepartmentName,ClassName,IdentityCard,Gender,Special,Phone,Email,Address,ReaderRemark";

            //自动生成columns
            autocoumns.AutoColumn(arraysHeaderText, arraysName, dgvHeaderInfo);
            autocoumns.AddColumn("修改", dgvHeaderInfo);
            autocoumns.AddColumn("删除", dgvHeaderInfo);

            //dgvHeaderInfo数据集绑定
            this.dgvHeaderInfo.DataSource = reader_bll.selectReader().Tables[0];
            this.dgvHeaderInfo.Columns[13].Visible = false;
            this.dgvHeaderInfo.Columns[12].Visible = false;
            this.dgvHeaderInfo.Columns[11].Visible = false;
            this.dgvHeaderInfo.Columns[10].Visible = false;

            #region 下拉框绑定

            DataGridViewColumnCollection columns = dgvHeaderInfo.Columns;

            for (int i = 0; i < columns.Count - 2; i++)
            {
                comboBox1.Items.Add(columns[i].HeaderText);
            }
            comboBox1.Items.Insert(0, "全部");
            comboBox1.SelectedIndex = 0;

            #endregion


            //树状图的绑定

            TreeViewBand();

            #region DataGridView3的绑定 已借阅的图书信息表

            //dataGridView3.AutoGenerateColumns = false;
            //需要添加列的列标题字符串
            string arraysHeaderText1 = @"读者编号,读者名称,图书编号,图书名称,借出时间,书应归还时间,实际归还时间,应付罚金,续借次数,借还描述";
            //需要绑定数据库列名称的字符串
            string arraysName1 = @"ReaderId,ReaderName,BookId,BookName,BorrowTime,ReturnTime,FactReturnTime,Fine,RenewCount,BorrowRemark";

            //自动生成columns
            autocoumns.AutoColumn(arraysHeaderText1, arraysName1, dgvReaderBorrowBook);

            //string index = dgvHeaderInfo.Rows[0].Cells[0].Value.ToString();
            //DataGridView1数据集绑定
            //this.dgvReaderBorrowBook.DataSource = borrowReturn_bll.ReaderBorrowReturn(index).Tables[0];

            #endregion

            #region DataGridView2的绑定 历史借阅记录表

            //dataGridView2.AutoGenerateColumns = false;
            //需要添加列的列标题字符串
            string arraysHeaderText2 = @"读者编号,读者名称,图书编号,图书名称,借出时间,书应归还时间,实际归还时间,应付罚金,续借次数,借还描述";
            //需要绑定数据库列名称的字符串
            string arraysName2 = @"ReaderId,ReaderName,BookId,BookName,BorrowTime,ReturnTime,FactReturnTime,Fine,RenewCount,BorrowRemark";

            //自动生成columns
            autocoumns.AutoColumn(arraysHeaderText2, arraysName2, dgvReaderBorrowBookInfoed);

            string index1 = dgvHeaderInfo.Rows[0].Cells[0].Value.ToString();
            //DataGridView1数据集绑定
            this.dgvReaderBorrowBookInfoed.DataSource = borrowReturn_bll.ReaderBorrowReturn1(index1).Tables[0];
            dgvReaderBorrowBookInfoed.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            #endregion
        }
        //TreeView节点选项改变事件
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (treeView1.SelectedNode.Level == 0)
            {
                dgvHeaderInfo.DataSource = reader_bll.selectReader().Tables[0];
            }
            else if (treeView1.SelectedNode.Level == 1)
            {
                int index = (int)treeView1.SelectedNode.Tag;
                dgvHeaderInfo.DataSource = reader_bll.selectReader(index).Tables[0];
            }

            //如果读者信息表中查不到一条数据,相关表的数据也清空
            if (dgvHeaderInfo.Rows.Count == 0)
            {
                dgvReaderBorrowBookInfoed.DataSource = null;
                dgvReaderBorrowBook.DataSource = null;
                return;
            }
        }

        
        private void btnExitColumn_Click(object sender, EventArgs e)
        {
            BookInfoExitRows_UI b = new BookInfoExitRows_UI();
            b.Reader = this;
            b.ShowDialog();
        }

        //当编辑绑定完 DataGridView所有单元格之后,执行绘制引发的事件
        //private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        //{

        //}
        //当编辑绑定完 DataGridView所有单元格之后,执行绘制引发的事件
        private void dgvHeaderInfo_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string ReaderId = "";
            try
            {
                //选中行的图书编号
                ReaderId = dgvHeaderInfo.Rows[e.RowIndex].Cells[0].Value.ToString();

            }
            catch (Exception) { }

            //单击某行 读者借阅表就显示相关的数据
            dgvReaderBorrowBook.DataSource = borrowReturn_bll.ReaderBorrowReturn(ReaderId).Tables[0];

            //单击某行 读者历史借阅表就显示相关的数据
            dgvReaderBorrowBookInfoed.DataSource = borrowReturn_bll.ReaderBorrowReturn1(ReaderId).Tables[0];

            //DataGridView的总列数
            int rows = dgvHeaderInfo.Columns.Count;

            if (e.ColumnIndex == rows - 2)//修改
            {
                ReaderExit_UI b = new ReaderExit_UI();
                b.reader = this;
                b.ReaderId = ReaderId;
                b.ShowDialog();
            }
            else if (e.ColumnIndex == rows - 1)//删除
            {
                DialogResult result = MessageBox.Show("确定删除吗?", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (result == DialogResult.OK)
                {
                    if (reader_bll.deleteReader(ReaderId) > 0)
                    {
                        btnSelect_Click(null, null);
                        //历史记录表中的数据引用着读者信息表的数据,删除读者信息应该刷新历史记录表
                        book.dgvHostory.DataSource = book.borrowReturn_bll.selectBorrowReturn(book.BookId).Tables[0];
                    }
                    else
                    {
                        MessageBox.Show("删除失败!");
                    }
                }
            }
        }

        //当编辑绑定完 DataGridView所有单元格之后,执行绘制引发的事件
        private void dgvHeaderInfo_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X,
               e.RowBounds.Location.Y,
               dgvHeaderInfo.RowHeadersWidth - 4,
               e.RowBounds.Height);

            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                dgvHeaderInfo.RowHeadersDefaultCellStyle.Font,
                rectangle,
                dgvHeaderInfo.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }

        //单击查询按钮
        public void btnSelect_Click(object sender, EventArgs e)
        {
            DataGridViewColumnCollection columns = dgvHeaderInfo.Columns;
            if (comboBox1.SelectedIndex == 0)//全部
            {
                List list = new List();
                for (int i = 0; i < columns.Count - 2; i++)
                {
                    list.Add(columns[i].DataPropertyName);
                }
                string B = textBox1.Text.Trim();
                dgvHeaderInfo.DataSource = reader_bll.selectReader(list, B).Tables[0];
            }
            else
            {

                for (int i = 0; i < columns.Count - 2; i++)
                {
                    if (comboBox1.SelectedItem.ToString() == columns[i].HeaderText)
                    {
                        string A = columns[i].DataPropertyName;
                        string B = textBox1.Text.Trim();
                        dgvHeaderInfo.DataSource = reader_bll.selectReader(A, B).Tables[0];
                        break;
                    }
                }
            }

            //如果读者信息表中查不到一条数据,相关表的数据也清空
            if (dgvHeaderInfo.Rows.Count == 0)
            {
                dgvReaderBorrowBookInfoed.DataSource = null;
                dgvReaderBorrowBook.DataSource = null;
                return;
            }
        }


        public ReaderAdd_UI readerAdd;
        public void btnAddReaderInfo_Click(object sender, EventArgs e)
        {
            readerAdd = new ReaderAdd_UI();
            readerAdd.reader = this;
            readerAdd.ShowDialog();
        }
    }
}

你可能感兴趣的:(C#,图书馆管理)