Beispiel #1
0
 private void managebySortButton_Click(object sender, EventArgs e)//改为按分类管理图书
 {
     isNormal = false;
     shelfBindingSource.DataSource = BookShelfService.GetAllShelfs();
     bookBindingSource.DataMember  = null;
     bookBindingSource.DataSource  = BookShelfService.AllBooks();
 }
Beispiel #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("没有输入完整的信息!");
     }
 }
        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;
            }
        }
        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;
            }
        }
        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);
        }
Beispiel #6
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+"日");
        }
        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);
        }
        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);
        }
Beispiel #9
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;
            }
        }