// ReSharper disable once MemberCanBePrivate.Global
        public async Task BindData()
        {
            try
            {
                var data = await _api.GetBooksInfo();

                Gc_BooksInfo.DataSource = data;
            }
            catch (Exception e)
            {
                PopupProvider.Error("获取书籍信息异常!", e);
            }
        }
        private async Task BindBookInfo()
        {
            try
            {
                var searchPara = Te_SearchPara.Text.Trim();
                //获取模糊查询书籍信息
                _handle = OverlayScreenForm.ShowProgressPanel(this);
                var bookInfos = await _bookInfoApi.GetBooksInfo(false);

                bookInfos = bookInfos
                            .Where(m => m.Id.ToString().Contains(searchPara) || m.BookName.Contains(searchPara)).ToList();
                OverlayScreenForm.CloseProgressPanel(_handle);
                if (bookInfos.Count == 0)
                {
                    PopupProvider.Warning("未检索到信息!");
                    return;
                }

                //找到对应的书籍信息的已上架书籍
                var books = new List <Book>();


                foreach (var info in bookInfos)
                {
                    books.AddRange(await _bookApi.GetBooks(new Dictionary <string, object>
                    {
                        { "BookInfoId", info.Id }
                    }));
                }


                foreach (var item in books)
                {
                    switch (item.BookState)
                    {
                    case 0:
                        item.BookStateName = "正常";
                        break;

                    case 1:
                        item.BookStateName = "已借阅";
                        break;

                    case 2:
                        item.BookStateName = "已预约";
                        break;
                    }
                }

                //如果存在多个数据,采用列表显示,操作员自行选择.
                if (books.Count > 1)
                {
                    Gc_Books.DataSource = books;
                    Gc_Books.Visible    = true;
                    Gv_Books.Focus();
                    return;
                }
                if (books.Count == 0)
                {
                    PopupProvider.Warning("未找到可借阅的相应书籍!");
                    return;
                }

                //如果只有一条数据则进行数据赋值展示
                var book        = books.First();
                var reservation = await _reservationApi.GetReservations(new Dictionary <string, object>
                {
                    { "BookId", book.Id },
                    { "IsRemove", false },
                    { "StudentId", Te_StudentId.Text }
                });

                if (reservation.Count <= 0 && book.BookStateName.Equals("已预约"))
                {
                    PopupProvider.Warning($"{book.BookStateName}书籍不可借阅!");
                    return;
                }
                if (book.BookStateName.Equals("已借阅"))
                {
                    PopupProvider.Warning($"{book.BookStateName}书籍不可借阅!");
                    return;
                }
                Te_BookName.Text         = book.BookName;
                Te_Author.Text           = book.Author;
                Te_ReleaseTime.EditValue = book.ReleaseDate;
                Te_PublishingHouse.Text  = book.PublishingName;
                Te_Category.Text         = book.CategoryName;
                Pe_BookPhoto.Image       = Image.FromFile(book.BookPhoto);
                Te_BookId.Text           = book.Id.ToString();
                Te_ISBN.Text             = book.ISBN;
                Te_ReleaseTime.Text      = book.ReleaseDate.ToString("yyyy-MM-dd");
                Te_Price.Text            = book.Price.ToString("F");
            }
            catch (Exception e)
            {
                PopupProvider.Error("获取数据信息异常!", e);
            }
        }
Beispiel #3
0
        private async Task BindBookInfo()
        {
            try
            {
                var searchPara = Te_SearchPara.Text.Trim();
                //获取模糊查询书籍信息
                var bookInfos = await _bookInfoApi.GetBooksInfo(new Dictionary <string, object>()
                {
                    { "%BookName", $"%{searchPara}%" },
                    { "IsRemove", false }
                });

                if (bookInfos.Count == 0)
                {
                    PopupProvider.Warning("未检索到信息!");
                    return;
                }
                if (bookInfos.Count > 1)
                {
                    Gc_Books.DataSource = bookInfos;
                    Gc_Books.Visible    = true;
                    Gv_Books.Focus();
                    return;
                }
                //找到对应的书籍信息的已上架书籍
                var books = await _bookApi.GetBooks(new Dictionary <string, object>
                {
                    { "BookInfoId", bookInfos[0].Id },
                    { "IsRemove", false }
                });

                if (books.Count == 0)
                {
                    PopupProvider.Warning("该书籍还未登记上架!");
                    return;
                }
                var reservationBooks = books.Where(m => m.BookState == 1).ToList();
                var normalBooks      = books.Where(m => m.BookState == 0).ToList();
                if (normalBooks.Count > 0)
                {
                    PopupProvider.Warning("该书籍还可借阅!");
                    return;
                }

                if (reservationBooks.Count == 0)
                {
                    PopupProvider.Warning("该书籍没有可预约项!");
                    return;
                }
                var book = books.First();
                var isReservationBook = await _reservationApi.GetReservationBooks();

                if (isReservationBook.Any(item => item.Equals(book.Id)))
                {
                    PopupProvider.Warning("该书籍没有可预约项!");
                    return;
                }

                //如果只有一条数据则进行数据赋值展示
                Te_BookName.Text         = book.BookName;
                Te_Author.Text           = book.Author;
                Te_ReleaseTime.EditValue = book.ReleaseDate;
                Te_PublishingHouse.Text  = book.PublishingName;
                Te_Category.Text         = book.CategoryName;
                Te_Id.Text         = book.Id.ToString();
                Pe_BookPhoto.Image = Image.FromFile(book.BookPhoto);
                Sb_Input.Enabled   = true;
                Te_ISBN.Text       = book.ISBN;
                Te_Price.Text      = book.Price.ToString("F");
            }
            catch (Exception e)
            {
                PopupProvider.Error("获取数据信息异常!", e);
            }
        }