Example #1
0
 private void recommendButton_Click(object sender, EventArgs e)//推荐,推荐数+1
 {
     currentBook.Recommend = currentBook.Recommend + 1;
     BookShelfService.UpdateBook(currentBook);
     this.recommendButton.Enabled = false;
     this.recommendButton.Visible = false;
 }
Example #2
0
 private void addButton_Click(object sender, EventArgs e)//增加图书
 {
     if (nameTextBox.Text != null && authorTextBox.Text != null && sortTextBox.Text != null && introductionTextBox.Text != null)
     {
         int    k           = Convert.ToInt32(BookShelfService.AllBooks().Max(i => i.BookId)) + 1;
         string bookId      = k + "";
         string name        = this.nameTextBox.Text;
         string author      = this.authorTextBox.Text;
         string bookShelfId = currentShelf.BookShelfId;
         string lendTime    = null;
         string clientName  = null;
         string sort        = this.sortTextBox.Text;
         string appointers  = "";
         string description = this.introductionTextBox.Text;
         Book   newBook     = new Book(bookId, name, bookShelfId, author, description, lendTime, clientName, sort, appointers)
         {
             State = "可正常使用"
         };
         if (path != null)
         {
             File.Copy(path, resPath + @"\" + newBook.Name + ".jpg");
             newBook.imagePath = path;
         }
         currentShelf.AddBook(newBook);
         BookShelfService.UpdateShelf(currentShelf);
         MessageBox.Show("已添加新书!");
         this.addButton.Enabled = false;
         this.addButton.Visible = false;
     }
     else
     {
         MessageBox.Show("没有输入完整的信息!");
     }
 }
Example #3
0
        private void deleteShelfButton_Click(object sender, EventArgs e)//删除书架
        {
            BookShelf shelf = shelfBindingSource.Current as BookShelf;

            BookShelfService.RemoveBookShelf(shelf.BookShelfId);
            shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
        }
Example #4
0
        private void signInButton_Click(object sender, EventArgs e)//登录,完成
        {
            FormRegisterandSignin formRegisterandSignin = new FormRegisterandSignin(1);

            if (formRegisterandSignin.ShowDialog() == DialogResult.OK)
            {
                currentClient = formRegisterandSignin.currentClient;
                if (currentClient != null)
                {
                    nameTextBox.ReadOnly        = false;
                    nameTextBox.Text            = currentClient.Name;
                    nameTextBox.ReadOnly        = true;
                    this.signOutButton.Visible  = true;
                    this.signOutButton.Enabled  = true;
                    this.signInButton.Visible   = false;
                    this.signInButton.Enabled   = false;
                    this.registerButton.Visible = false;
                    this.registerButton.Enabled = false;
                    if (currentClient.Name == "管理员")
                    {
                        this.manageButton.Visible = true;
                        this.manageButton.Enabled = true;
                    }
                    appointBooks = BookShelfService.GetAllAppointedBooks(currentClient);
                    lendBooks    = BookShelfService.GetAllLentBooks(currentClient);
                    appointBindingSource.DataSource = appointBooks;
                    lendBindingSource.DataSource    = lendBooks;
                }
            }
        }
Example #5
0
 private void refreshButton_Click(object sender, EventArgs e)//将管理方式改为按书架
 {
     isNormal = true;
     shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
     bookBindingSource.DataSource  = shelfBindingSource;
     bookBindingSource.DataMember  = "Books";
 }
Example #6
0
 private void managebySortButton_Click(object sender, EventArgs e)//改为按分类管理图书
 {
     isNormal = false;
     shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
     bookBindingSource.DataMember  = null;
     bookBindingSource.DataSource  = BookShelfService.AllBooks();
 }
Example #7
0
        private void addShelfButton_Click(object sender, EventArgs e)//添加书架,直接添加一个新的空书架
        {
            int k = Convert.ToInt32(BookShelfService.GetAllShelfs().Max(i => i.BookShelfId)) + 1;

            BookShelfService.AddBookShelf(new BookShelf()
            {
                BookShelfId = k + ""
            });
            shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
        }
Example #8
0
        private void deleteButton_Click(object sender, EventArgs e)//删除图书,同上
        {
            Book book = bookBindingSource.Current as Book;

            if (book == null)
            {
                MessageBox.Show("请选择一本书进行操作!");
                return;
            }
            BookShelfService.RemoveBooks(book.BookId);
            shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
        }
Example #9
0
        private void addButton_Click(object sender, EventArgs e)//添加图书,必须选取一个书架才能添加
        {
            BookShelf      shelf          = shelfBindingSource.Current as BookShelf;
            FormBookDetail formBookDetail = new FormBookDetail(shelf);

            if (formBookDetail.ShowDialog() == DialogResult.OK)
            {
                shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
                bookBindingSource.DataSource  = shelfBindingSource;
                bookBindingSource.DataMember  = "Books";
            }
        }
Example #10
0
        private void manageButton_Click(object sender, EventArgs e)//图书管理,完成
        {
            FormShelf formShelf = new FormShelf(currentClient);

            if (formShelf.ShowDialog() == DialogResult.OK)
            {
                Query(1);
                appointBooks = BookShelfService.GetAllAppointedBooks(currentClient);
                lendBooks    = BookShelfService.GetAllLentBooks(currentClient);
                appointBindingSource.DataSource = appointBooks;
                lendBindingSource.DataSource    = lendBooks;
            }
        }
Example #11
0
        private void changeDetailButton_Click(object sender, EventArgs e)//修改图书细节
        {
            BookShelf      shelf          = shelfBindingSource.Current as BookShelf;
            Book           book           = bookBindingSource.Current as Book;
            FormBookDetail formBookDetail = new FormBookDetail(book, currentClient, 2);

            if (formBookDetail.ShowDialog() == DialogResult.OK)
            {
                shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
                bookBindingSource.DataSource  = shelfBindingSource;
                bookBindingSource.DataMember  = "Books";
            }
        }
Example #12
0
 private void lendButton_Click(object sender, EventArgs e)//借阅,当图书可用时将图书的状态改为借阅
 {
     if (yearComboBox.Text != "" && monthComboBox.Text != "" && dayComboBox.Text != "")
     {
         string year  = yearComboBox.Text;
         string month = monthComboBox.Text;
         string day   = dayComboBox.Text;
         BookShelfService.LendBook(currentBook, currentClient, year, month, day);
     }
     else
     {
         MessageBox.Show("没有输入正确的日期!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #13
0
        public static void Test1()
        {
            //MessageBox.Show(administrator1);
            //MessageBox.Show(administrator2);
            BookShelf test1 = new BookShelf();
            Book      book1 = new Book("1", "毛泽东选集", "1", "毛泽东", "毛泽东所写的一本书。", null, null, "政治", "")
            {
                State     = "可正常使用",
                Recommend = 10,
                imagePath = @"C:\Users\tjw20\source\repos\Library\Resources\毛泽东选集.jpg"
            };
            Book book2 = new Book("2", "论持久战", "1", "毛泽东", "毛泽东所写的一本书。", "2020年8月1日", "涂珈玮", "政治", "")
            {
                State     = "已被借阅",
                Recommend = 15,
                imagePath = @"C:\Users\tjw20\source\repos\Library\Resources\论持久战.jpg"
            };
            //book2.Appointer = ClientService.transferIntoAppointer(administrator2, book2);
            //book2.Appointers.Add(administrator2);
            Book book3 = new Book("3", "钢铁是怎样炼成的", "1", "奥斯特洛夫斯基", "奥斯特洛夫斯基所写的一本书。", "2020年8月1日", "涂珈玮", "文学", user2 + " ")
            {
                State     = "已被借阅",
                Recommend = 15,
                imagePath = @"C:\Users\tjw20\source\repos\Library\Resources\钢铁是怎样炼成的.jpg"
            };
            //book3.Appointer = ClientService.transferIntoAppointer(administrator2, book3);
            //book3.Appointers.Add(administrator2);
            Book book4 = new Book("4", "西游记", "1", "吴承恩", "吴承恩所写的一本书。", "2020年8月1日", "康盛尧", "文学", user3 + " ")
            {
                State     = "已被借阅",
                Recommend = 13,
                imagePath = @"C:\Users\tjw20\source\repos\Library\Resources\西游记.jpg"
            };
            //book4.Appointer = ClientService.transferIntoAppointer(administrator2, book4);
            //book4.Appointers.Add(administrator2);
            List <Book> Books1 = new List <Book>()
            {
                book1, book2, book3, book4
            };

            foreach (var book in Books1)
            {
                //MessageBox.Show(book.Name+book.Appointer.Count()+"");
                //book.setAppoint();
                test1.AddBook(book);
            }
            test1.BookShelfId = "1";
            BookShelfService.AddBookShelf(test1);
        }
Example #14
0
        private void Search(int i, string key)//查询方法,i表示具体的排序规则,完成
        {
            List <Book> searchBooks = new List <Book>();

            using (var db = new BookShelfContext())
            {
                switch (i)
                {
                case 1:    //按书号查询
                    foreach (var book in BookShelfService.AllBooks().Where(o => o.BookId.Contains(key) == true))
                    {
                        searchBooks.Add(book);
                    }
                    break;

                case 2:    //书名
                    foreach (var book in BookShelfService.AllBooks().Where(o => o.Name.Contains(key) == true))
                    {
                        searchBooks.Add(book);
                    }
                    break;

                case 3:    //作者
                    foreach (var book in BookShelfService.AllBooks().Where(o => o.Author.Contains(key) == true))
                    {
                        searchBooks.Add(book);
                    }
                    break;

                case 4:    //分类
                    foreach (var book in BookShelfService.AllBooks().Where(o => o.Sort == key))
                    {
                        searchBooks.Add(book);
                    }
                    break;

                case 5:    //书架号
                    foreach (var book in BookShelfService.AllBooks().Where(o => o.BookShelfId == key))
                    {
                        searchBooks.Add(book);
                    }
                    break;
                }
                booksBindingSource.DataSource = new List <Book>();
                booksBindingSource.ResetBindings(false);
                booksBindingSource.DataSource = searchBooks;
            }
        }
Example #15
0
        private void intoDetailButton_Click(object sender, EventArgs e)//查看细节,完成
        {
            if (currentClient == null)
            {
                MessageBox.Show("请登录后再进行此操作!");
                return;
            }
            Book           book           = booksBindingSource.Current as Book;
            FormBookDetail formBookDetail = new FormBookDetail(book, currentClient, 1);

            if (formBookDetail.ShowDialog() == DialogResult.OK)
            {
                Query(1);
                appointBooks = BookShelfService.GetAllAppointedBooks(currentClient);
                lendBooks    = BookShelfService.GetAllLentBooks(currentClient);
                appointBindingSource.DataSource = appointBooks;
                lendBindingSource.DataSource    = lendBooks;
            }
        }
Example #16
0
        private void Query(int i)//排序方法,i表示具体的排序规则,完成
        {
            List <Book> queryBooks = new List <Book>();

            using (var db = new BookShelfContext())
            {
                switch (i)
                {
                case 1:    //默认的按推荐数排序
                    var query1 = BookShelfService.AllBooks();
                    var list1  = from t in query1 orderby t.Recommend descending select t;
                    queryBooks = list1.ToList();
                    break;

                case 2:    //书号
                    var query2 = BookShelfService.AllBooks();
                    var list2  = from t in query2 orderby t.BookId ascending select t;
                    queryBooks = list2.ToList();
                    break;

                case 3:    //作者
                    var query3 = BookShelfService.AllBooks();
                    var list3  = from t in query3 orderby t.Author ascending select t;
                    queryBooks = list3.ToList();
                    break;

                case 4:    //分类
                    var query4 = BookShelfService.AllBooks();
                    var list4  = from t in query4 orderby t.BookId ascending select t;
                    queryBooks = list4.ToList();
                    break;

                case 5:    //书架号
                    var query5 = BookShelfService.AllBooks();
                    var list5  = from t in query5 orderby t.BookId ascending select t;
                    queryBooks = list5.ToList();
                    break;
                }
                booksBindingSource.DataSource = new List <Book>();
                booksBindingSource.ResetBindings(false);
                booksBindingSource.DataSource = queryBooks;
            }
        }
Example #17
0
        private void renewButton_Click(object sender, EventArgs e)//续借,完成
        {
            Book book = lendBindingSource.Current as Book;

            if (book == null)
            {
                MessageBox.Show("请选择一本书进行操作!");
                return;
            }
            else
            {
                if (yearComboBox.Text != "" && monthComboBox.Text != "" && dayComboBox.Text != "")//monthComboBox之前打快了打成了monthhComboBox
                {
                    string year  = yearComboBox.Text;
                    string month = monthComboBox.Text;
                    string day   = dayComboBox.Text;
                    if (book.reNewNum < 3)
                    {
                        BookShelfService.ReNewLending(book, currentClient, year, month, day);
                    }
                    else
                    {
                        MessageBox.Show("该书续借次数太多,不允许继续续借!");
                    }
                }
                else
                {
                    MessageBox.Show("没有输入正确的日期!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            lendBooks = new List <Book>();
            lendBindingSource.DataSource = lendBooks;
            lendBooks = BookShelfService.GetAllLentBooks(currentClient);
            lendBindingSource.ResetBindings(false);
            lendBindingSource.DataSource = lendBooks;
            Books = new List <Book>();
            booksBindingSource.DataSource = Books;
            Books = BookShelfService.AllBooks();
            booksBindingSource.ResetBindings(false);
            booksBindingSource.DataSource = Books;
            Query(1);
        }
Example #18
0
        public FormMain()
        {
            InitializeComponent();
            administrator.Id = "1";
            user1.Id         = "2";
            user2.Id         = "3";
            user3.Id         = "4";
            if (currentClient == null)
            {
                this.signOutButton.Visible = false;
                this.signOutButton.Enabled = false;
            }
            if (ClientService.AllClients().Count == 0)
            {
                ClientService.AddAdministrator(administrator);
                ClientService.AddAdministrator(user1);
                ClientService.AddAdministrator(user2);
                ClientService.AddAdministrator(user3);
            }
            this.managePictureBox.Visible = false;
            this.managePictureBox.Enabled = false;
            this.manageLabel.Visible      = false;
            this.manageLabel.Enabled      = false;
            if (BookShelfService.AllBooks().Count == 0)//设置初始值
            {
                Test.Test1();
                Test.Test2();
            }
            //MessageBox.Show("1");
            Year  = DateTime.Now.Year;
            Month = DateTime.Now.Month;
            String time = DateTime.Now.ToLongDateString().ToString();
            int    m    = time.IndexOf("月");
            int    d    = time.IndexOf("日");

            Day = DateTime.Now.Day;
            BookShelfService.Check(Year, Month, Day);
            Books = BookShelfService.AllBooks();
            booksBindingSource.DataSource = Books;
            Query(1);
            //MessageBox.Show(Year+"年"+Month+"月"+Day+"日");
        }
Example #19
0
 private void finishButton_Click(object sender, EventArgs e)//完成
 {
     if (Flag == 2)
     {
         currentBook.Name        = this.nameTextBox.Text;
         currentBook.Author      = this.authorTextBox.Text;
         currentBook.Sort        = this.sortTextBox.Text;
         currentBook.Description = this.introductionTextBox.Text;
         if (path != null)
         {
             if (File.Exists(resPath + @"\" + currentBook.Name + ".jpg")) //判断文件是否存在
             {
                 File.Delete(resPath + @"\" + currentBook.Name + ".jpg");
             }
             File.Copy(path, resPath + @"\" + currentBook.Name + ".jpg");
             currentBook.imagePath = path;
         }
         BookShelfService.UpdateBook(currentBook);
     }
     this.Close();
 }
Example #20
0
        private void cancellButton_Click(object sender, EventArgs e)//取消预约,完成
        {
            Book book = appointBindingSource.Current as Book;

            if (book == null)
            {
                MessageBox.Show("请选择一本书进行操作!");
                return;
            }
            BookShelfService.CancellAppoint(book, currentClient);
            appointBooks = new List <Book>();
            appointBindingSource.DataSource = appointBooks;
            appointBooks = BookShelfService.GetAllAppointedBooks(currentClient);
            appointBindingSource.ResetBindings(false);
            appointBindingSource.DataSource = appointBooks;
            Books = new List <Book>();
            booksBindingSource.DataSource = Books;
            Books = BookShelfService.AllBooks();
            booksBindingSource.ResetBindings(false);
            booksBindingSource.DataSource = Books;
            Query(1);
        }
Example #21
0
        private void returnButton_Click(object sender, EventArgs e)//还书,完成
        {
            Book book = lendBindingSource.Current as Book;

            if (book == null)
            {
                MessageBox.Show("请选择一本书进行操作!");
                return;
            }
            BookShelfService.ReturnBooks(book, currentClient);//问题
            lendBooks = new List <Book>();
            lendBindingSource.DataSource = lendBooks;
            lendBooks = BookShelfService.GetAllLentBooks(currentClient);
            lendBindingSource.ResetBindings(false);
            lendBindingSource.DataSource = lendBooks;
            Books = new List <Book>();
            booksBindingSource.DataSource = Books;
            Books = BookShelfService.AllBooks();
            booksBindingSource.ResetBindings(false);
            booksBindingSource.DataSource = Books;
            Query(1);
        }
Example #22
0
        public static void Test2()
        {
            BookShelf test2 = new BookShelf();
            Book      book1 = new Book("5", "C#程序设计语言", "2", "Peter Golde", "C#编程指南。", null, null, "编程", "")
            {
                State     = "可正常使用",
                Recommend = 14,
                imagePath = @"C:\Users\tjw20\source\repos\Library\Resources\C#程序设计语言.jpg"
            };

            Book book2 = new Book("6", "JAVA语言程序设计", "2", "佚名", "JAVA编程指南。", "2020年5月1日", "李梦凡", "编程", user1 + " ")
            {
                State     = "已被借阅",
                Recommend = 12,
                imagePath = @"C:\Users\tjw20\source\repos\Library\Resources\JAVA语言程序设计.jpg"
            };
            //book2.Appointer = ClientService.transferIntoAppointer(administrator1, book2);
            //book2.Appointers.Add(administrator2);
            Book book3 = new Book("7", "三国演义", "2", "罗贯中", "罗贯中所写的一本书。", "2020年9月1日", "康盛尧", "文学", user1 + " " + user3 + " ")
            {
                State     = "已被借阅",
                Recommend = 13,
                imagePath = @"C:\Users\tjw20\source\repos\Library\Resources\三国演义.jpg"
            };
            //book3.Appointer = ClientService.transferIntoAppointer(administrator1, book3);
            List <Book> Books2 = new List <Book>()
            {
                book1, book2, book3
            };

            foreach (var book in Books2)
            {
                test2.AddBook(book);
            }
            test2.BookShelfId = "2";
            BookShelfService.AddBookShelf(test2);
        }
Example #23
0
 private void appointButton_Click(object sender, EventArgs e)//预约
 {
     BookShelfService.AppointBook(currentBook, currentClient);
     this.appointButton.Enabled = false;
     this.appointButton.Visible = false;
 }
Example #24
0
 public FormShelf(Client client)
 {
     InitializeComponent();
     shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
     currentClient = client;
 }
Example #25
0
 private void appointButton_Click(object sender, EventArgs e)//预约,预约时间必须后于当前时间(可能要涉及DateTime),并同时改动预约情况
 {
     BookShelfService.AppointBook(currentBook, currentClient);
     this.appointButton.Enabled = false;
     this.appointButton.Visible = false;
 }
Example #26
0
        private void searchButton_Click(object sender, EventArgs e)//查询图书
        {
            if (searchTextBox.Text == null)
            {
                MessageBox.Show("没有输入用于查询的关键词!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                String      key         = searchTextBox.Text;
                List <Book> searchBooks = new List <Book>();
                switch (searchComboBox.Text)
                {
                case "书号":
                    if (!isNormal)
                    {
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.BookId.Contains(key) == true))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    else
                    {
                        BookShelf shelf = shelfBindingSource.Current as BookShelf;
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.BookId.Contains(key) == true).Where(i => i.BookShelfId == shelf.BookShelfId))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    break;

                case "书名":
                    if (!isNormal)
                    {
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.Name.Contains(key) == true))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    else
                    {
                        BookShelf shelf = shelfBindingSource.Current as BookShelf;
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.Name.Contains(key) == true).Where(i => i.BookShelfId == shelf.BookShelfId))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    break;

                case "作者":
                    if (!isNormal)
                    {
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.Author.Contains(key) == true))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    else
                    {
                        BookShelf shelf = shelfBindingSource.Current as BookShelf;
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.Author.Contains(key) == true).Where(i => i.BookShelfId == shelf.BookShelfId))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    break;

                case "分类":
                    if (!isNormal)
                    {
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.Sort.Contains(key) == true))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    else
                    {
                        BookShelf shelf = shelfBindingSource.Current as BookShelf;
                        foreach (var book in BookShelfService.AllBooks().Where(o => o.Sort.Contains(key) == true).Where(i => i.BookShelfId == shelf.BookShelfId))
                        {
                            searchBooks.Add(book);
                        }
                    }
                    break;

                default:
                    MessageBox.Show("没有选择正确的查询方式!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                }
                bookBindingSource.DataMember = null;
                bookBindingSource.DataSource = searchBooks;
            }
        }