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

📄 librarysystem.cs

📁 一个基于.NETFramework架构的图书管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace LibraryWinUI
{
    public partial class LibrarySystem : Form
    {
        private LibraryBusiness.WinLogic logic;
        private string borrower;
        private string borbook;
        private string deletebook;
        private string adminno;


        public LibrarySystem(string a)
        {
            logic = new LibraryBusiness.WinLogic();
            adminno = a;
            InitializeComponent();

            DataSet ds1 = logic.GetAllBookBooktype();
            cbBookTypeD1.DataSource = ds1.Tables[0];
            cbBookTypeD1.DisplayMember = "booktypename";
            cbBookTypeD1.ValueMember = "booktypeno";

            DataSet ds2 = logic.GetAllBookBooktype();
            cbBookTypeD2.DataSource = ds2.Tables[0];
            cbBookTypeD2.DisplayMember = "booktypename";
            cbBookTypeD2.ValueMember = "booktypeno";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(Configuration.ApplicationConfiguration.ConnectionString);
            //Exception ex1 = new Exception();

            //DataAccess.DBException ex = new DataAccess.DBException(ex1);
            //MessageBox.Show(ex.Message);

            //DataAccess.NoRecordException ex2 = new DataAccess.NoRecordException();
            //MessageBox.Show(ex2.Message);

            //DataAccess.NoRecordException ex3 = new DataAccess.NoRecordException("aa");
            //MessageBox.Show(ex3.Message);

            //SqlCommand  cmd=new SqlCommand ("delete from [user] where userno='2005'");
            //int n=DataAccess .DBAccess .ExecuteSQL (cmd);
            //MessageBox.Show (n.ToString ());

            //SqlCommand cmd = new SqlCommand("select username from [user] where userno='20060402057'");
            //object o = DataAccess.DBAccess.GetScalar(cmd);
            //MessageBox.Show(o.ToString());

            //SqlCommand com = new SqlCommand("select * from [user]");
            //DataSet ds = DataAccess.DBAccess.QueryData(com);
            //dataGridView3.DataSource = ds.Tables[0];

            //DataAccess.User u1 = new DataAccess.User();
            //DataSet s1 = u1.GetUserInfo("20060101183");
            //dataGridView3.DataSource = s1.Tables[0];

            //DataAccess.User u1 = new DataAccess.User();
            //bool b1 = u1.Login("20060101001", "123456");
            //MessageBox.Show(b1.ToString());

            //DataAccess.User u1 = new DataAccess.User();
            //bool b2 = u1.InsertUser("20050101001", "a", "123", 0, "123@163.com", "1");
            //MessageBox.Show(b2.ToString());

            //DataAccess.BookInfo b = new DataAccess.BookInfo();
            //DataSet ds = b.GetBookInfo("工程", "");
            //dataGridView3.DataSource = ds.Tables[0];

            //DataAccess.BookInfo b = new DataAccess.BookInfo();
            //DataSet ds = b.GetAllBookBooktype();
            //dataGridView3.DataSource = ds.Tables[0];

            //DataAccess.BookInfo b = new DataAccess.BookInfo();
            //DataSet ds = b.GetBookStatisticInfo();
            //dataGridView3.DataSource = ds.Tables[0];

            //DataAccess.BookInfo b = new DataAccess.BookInfo();
            //bool a = b.InsertNewBook("1", "1", "1", "1", Convert.ToDateTime("2005-1-5"), "1", 23000, 200, "a", "T");
            //MessageBox.Show(a.ToString());

            //DataAccess.BookInfo b = new DataAccess.BookInfo();
            //bool a = b.UpdateBookInfo("1", "2", "2", "2", Convert.ToDateTime("2005-1-5"), "2", 23000, 200, "2", "T");
            //MessageBox.Show(a.ToString());

            //DataAccess.BookInfo b = new DataAccess.BookInfo();
            //bool a = b.DeleteBook("1");
            //MessageBox.Show(a.ToString());

            //DataAccess.BorrowInfo b = new DataAccess.BorrowInfo();
            //DataSet ds = b.GetBorrowInfoByUserNO ("20060209013");
            //dataGridView3.DataSource = ds.Tables[0];

            //DataAccess.BorrowInfo b = new DataAccess.BorrowInfo();
            //DataSet ds = b.GetBorrowInfoByBookNO("R33/10");
            //dataGridView3.DataSource = ds.Tables[0];

            //DataAccess.BorrowInfo b = new DataAccess.BorrowInfo();
            //bool a = b.HasBook("4566");
            //MessageBox.Show(a.ToString());


            //DataAccess.BorrowInfo b = new DataAccess.BorrowInfo();
            //bool a = b.IsBorrowed("TB12/4");
            //MessageBox.Show(a.ToString());

            //DataAccess.BorrowInfo b = new DataAccess.BorrowInfo();
            //bool a = b.BorrowBook("TB12/4", "20060402057");
            ////MessageBox.Show(a.ToString());

            //DataAccess.BorrowInfo b = new DataAccess.BorrowInfo();
            //bool a = b.ReBorrow("TB12/4");
            //MessageBox.Show(a.ToString());

            //DataAccess.BorrowInfo b = new DataAccess.BorrowInfo();
            //bool a = b.ReturnBook("TB12/4");
            //MessageBox.Show(a.ToString());

            //LibraryBusiness.WinLogic w = new LibraryBusiness.WinLogic();
            //DataSet ds = w.GetBookInfo("工程", "T");
            //dataGridView3.DataSource = ds.Tables[0];         
            //DataAccess.Admin a = new DataAccess.Admin();
            //bool b = a.InsertAdmin("1", "1", "100", "aa");
            //MessageBox.Show(b.ToString());

        }

        private void btnConfirmA1_Click(object sender, EventArgs e)
        {
            borrower = txtIDA.Text.Trim();
            if (borrower == "")
            {
                MessageBox.Show("读者编号不能为空");
                return;
            }

            try
            {

                
                DataRow userRow = logic.GetUserInfo(borrower).Tables[0].Rows[0];

                txtNameA.Text = userRow["Username"].ToString();
                if ((bool)userRow["sex"])
                {
                    rbFemaleA.Select();
                }
                else
                {

                    rbMaleA.Select();
                }
                txtClassA.Text = userRow["class"].ToString();
                dgBorrowInfoA.DataSource = logic.GetBorrowInfoByUserNO(borrower).Tables[0];
                btnConfirmA2.Enabled = true;
                txtIDA.Enabled = false;

            }


            catch
            {
                txtNameA.Text = "";
                txtClassA.Text = "";
                rbFemaleA.Checked = false;
                rbMaleA.Checked = false;
                btnConfirmA2.Enabled = false;
                MessageBox.Show("没有这个用户!");
                
            }
        }

        private void btnCancelA1_Click(object sender, EventArgs e)
        {
            foreach (Control co1 in groupBox1.Controls)
            {
                System.Windows.Forms.TextBox tb = co1 as System.Windows.Forms.TextBox;
                if (tb != null)
                {
                    tb.Text = "";
                }  
            }
           rbFemaleA.Checked = false;
           rbMaleA.Checked = false;
           txtIDA.Enabled = true;
        }

        private void btnBorrow_Click(object sender, EventArgs e)
        {
            
            borbook = txtBookIDB.Text.Trim();
            if (borbook == "")
            {
                MessageBox.Show("图书编号不能为空");
                return;
            }
            lblAlertMessageB.Visible = false;
            try
            {
                if (btnBorrow.Text == "检索")
                {
                    DataSet ds=logic.GetBorrowInfoByBookNO(borbook);
                    if (ds.Tables [0].Rows.Count ==0)
                    {
                        lblAlertMessageB.Visible = true;
                        return;
                    }
                    DataRow userRow = ds.Tables[0].Rows[0];
                    if (Convert.ToBoolean(userRow["isreturned"]))
                    {
                        MessageBox.Show("该书已归还");
                        return;
                    }
                    btnBorrow.Text = "还书";
                    txtBookIDB.Enabled = false;
                    txtISBNB.Text = userRow["ISBN"].ToString();
                    txtBookNameB.Text = userRow["BookName"].ToString();
                    txtPublisherB.Text = userRow["Publisher"].ToString();
                    txtAuthorB.Text = userRow["Author"].ToString();
                    txtNameB.Text = userRow["UserName"].ToString();
                    txtClassB.Text = userRow["class"].ToString();
                    if ((bool)userRow["sex"])
                    {
                        rbFemaleB.Select();
                    }
                    else
                    {
                        rbMaleB.Select();
                    }
                    borrower = userRow["Userno"].ToString();
                    dgBorrowInfoB.DataSource = logic.GetBorrowInfoByUserNO(borrower).Tables[0];
                }
                else
                {
                    logic.ReturnBook(borbook);
                    MessageBox.Show("还书成功!");
                    dgBorrowInfoB.DataSource = logic.GetBorrowInfoByUserNO(borrower).Tables[0];
                    btnCancelB_Click(sender, e);
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }

        private void btnConfirmA2_Click(object sender, EventArgs e)
        {
            string bookno = txtBookIDA.Text.Trim();
            if (bookno == "")
            {
                MessageBox.Show("图书编号不能为空");
                return;

            }

            try
            {
                if (logic.BorrowBook(bookno, borrower))
                {
                    MessageBox.Show("借书成功");
                    txtBookIDA.Text = "";
                    dgBorrowInfoA.DataSource = logic.GetBorrowInfoByUserNO(borrower).Tables[0];

                }
                else
                {
                    MessageBox.Show("借书失败");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
        }

        private void btnCancelA2_Click(object sender, EventArgs e)
        {
            txtBookIDA.Text = "";
        }

        private void btnCancelB_Click(object sender, EventArgs e)
        {
            btnBorrow.Text = "检索";
            txtBookIDB.Enabled = true;
            foreach (Control co1 in groupBox3.Controls)
            {
                System.Windows.Forms.TextBox tb = co1 as System.Windows.Forms.TextBox;
                if (tb != null)
                {
                    tb.Text = "";
                }              
            }
            foreach (Control co1 in groupBox4.Controls)
            {
                System.Windows.Forms.TextBox tb = co1 as System.Windows.Forms.TextBox;
                if (tb != null)
                {
                    tb.Text = "";
                }
            }
            foreach (Control co1 in groupBox5.Controls)
            {
                System.Windows.Forms.TextBox tb = co1 as System.Windows.Forms.TextBox;
                if (tb != null)
                {

⌨️ 快捷键说明

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