コード例 #1
0
ファイル: MainForm.cs プロジェクト: angelfeliz/BookShare
        private void listToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ListBook listBook = new ListBook();

            listBook.MdiParent = this;
            listBook.Show();
        }
コード例 #2
0
ファイル: AdminController.cs プロジェクト: SCIMTA/group-5
        // GET: Admin
        public ActionResult Book(int page = 1, string text = "", int cate = 0, int sort = 0, int pageSize = 16, int type = 0, int language = 0, int priceFrom = 0, int priceTo = 0)
        {
            ViewBag.ListCate     = dB.GetCategories();
            ViewBag.ListType     = dB.GetTypes();
            ViewBag.ListLanguage = dB.GetLanguages();
            ViewBag.Cate         = cate;
            ViewBag.Sort         = sort;
            ViewBag.Type         = type;
            if (priceFrom > priceTo)
            {
                priceTo = 0;
            }
            ViewBag.PriceFrom   = priceFrom;
            ViewBag.PriceTo     = priceTo;
            ViewBag.Language    = language;
            ViewBag.PageSize    = 16;
            ViewBag.CurrentPage = page;
            switch (sort)
            {
            case 0:
                ViewBag.TextSort = C.DROPDOWN_SORT.NEWEST;
                break;

            case 1:
                ViewBag.TextSort = C.DROPDOWN_SORT.OLDEST;
                break;

            case 2:
                ViewBag.TextSort = C.DROPDOWN_SORT.LOWEST_PRICE;
                break;

            case 3:
                ViewBag.TextSort = C.DROPDOWN_SORT.HIGHEST_PRICE;
                break;
            }

            if (pageSize != 16 && pageSize % 16 == 0 && pageSize <= 64)
            {
                ViewBag.PageSize = pageSize;
            }
            ListBook listBook = dB.GetListBook(page, text, cate, sort, pageSize, type, language, priceFrom, priceTo);

            ViewBag.ListPage   = HelperFunctions.getNumPage(page, listBook.pages);
            ViewBag.maxPage    = listBook.pages;
            ViewBag.TextSearch = text;
            ViewBag.list       = listBook.books;
            return(View());
        }
コード例 #3
0
        private void btn_Add_Click(object sender, RoutedEventArgs e)
        {
            if (tb_BookName.Text == "")
            {
                ErrorManager.Current.InfoIsNull.Call("Tên sách không được để trống!");
                return;
            }
            var selectedbook = tb_BookName.SelectedItem as Book;

            if (selectedbook != null)
            {
                AddedBook ab = new AddedBook()
                {
                    Book   = selectedbook,
                    Number = (int)num_UpDown.Value
                };
                var item = ListAddedBook.FirstOrDefault(x => x.Book.ID == ab.Book.ID);
                if (item != null)
                {
                    item.Number += (int)num_UpDown.Value;
                }
                else
                {
                    ListAddedBook.Add(ab);
                }
            }
            else
            {
                var       item = ListBook.FirstOrDefault(x => x.Name == tb_BookName.Text);
                AddedBook ab   = new AddedBook();
                if (item != null)
                {
                    ab.Book   = item;
                    ab.Number = (int)num_UpDown.Value;
                }
                else
                {
                    ab.Book               = new Book();
                    ab.Book.Name          = tb_BookName.Text;
                    ab.Book.AuthorsFormat = tb_Authors.Text;
                    ab.Book.GenresFormat  = tb_Genres.Text;
                    ab.Number             = (int)num_UpDown.Value;
                }
                ListAddedBook.Add(ab);
            }
        }
コード例 #4
0
        /// <summary>
        /// UpdateItem
        /// </summary>
        public void UpdateItem()
        {
            if (string.IsNullOrEmpty(this.TitleBook) || string.IsNullOrEmpty(this.DescriptionBook) || CbbAuthor == null)
            {
                MessageBox.Show(Utils.Localization.Instance.GetString(Constant.Constant.Book_001));
                return;
            }
            if (Globals.RoleUser == (int)Roles.Contributor && !ListBook.Where(w => w.ID == Id && w.Creator == Globals.NameUser).Any())
            {
                MessageBox.Show(Utils.Localization.Instance.GetString(Constant.Constant.Book_002));
                return;
            }

            int isSuccess = this.BD.UpdateBook(Id, TitleBook, DescriptionBook, CbbAuthor[SelectitemAuthor].Index, CbbCategory[SelectitemCategory].Index, nameIname, ContentBook);

            if (!string.IsNullOrEmpty(nameIname))
            {
                CopyFiles(FileImage, path);
            }
            this.nameIname = string.Empty;
            this.FileImage = string.Empty;
            Initialize();
            MessageBox.Show(Utils.Localization.Instance.GetString(Constant.Constant.Book_004));
        }
コード例 #5
0
        private void button5_Click(object sender, EventArgs e)
        {
            ListBook lsb = new ListBook();

            lsb.Show();
        }
コード例 #6
0
        public BookMngViewVM()
        {
            IsEnabledListView = true;
            IsAdding          = true;

            AddCommand = new RelayCommand <Button>((p) => { return(true); }, (p) =>
            {
                ID = DataProvider.Ins.DB.Database.SqlQuery <string>("MASACHTIEPTHEO").First();
                IsEnabledListView  = false;
                IsEnabledTextBox   = true;
                IsEnabledIDTextBox = true;
            });
            SaveCommand = new RelayCommand <Button>((p) =>
            {
                if (!string.IsNullOrEmpty(ID) &&
                    !string.IsNullOrEmpty(BookName) &&
                    !string.IsNullOrEmpty(Author) &&
                    !string.IsNullOrEmpty(BookType) &&
                    !string.IsNullOrEmpty(ID))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }, (p) =>
            {
                IsEnabledListView  = true;
                IsEnabledTextBox   = false;
                IsEnabledIDTextBox = false;
                if (!IsAdding)
                {
                    var book = DataProvider.Ins.DB.SACHes.Where(x => x.MASACH == SelectedItem.MASACH).SingleOrDefault();
                    if (book == null)
                    {
                        MessageBoxWindow mess2 = new MessageBoxWindow();
                        mess2.Tag = "Không tìm thấy cuôn sách này";
                        mess2.ShowDialog();

                        //MessageBox.Show("Không tìm thấy cuôn sách này", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    if (Img != null)
                    {
                        Image        = ByteToImageConverter.Ins.ImageToByte(Img);
                        book.HINHANH = Image;
                    }
                    else
                    {
                        book.HINHANH = null;
                    }
                    book.TENSACH        = BookName;
                    book.MALOAISACH     = BookType;
                    book.TACGIA         = Author;
                    book.MANXB          = PublishingHouse;
                    book.SOLUONGHIENTAI = NumOfBook;
                    book.GIANHAP        = InputPrice;
                    book.GIABAN         = BuyingPrice;
                    DataProvider.Ins.DB.SaveChanges();
                    IsAdding = true;

                    ListBook = new ObservableCollection <SACH>(DataProvider.Ins.DB.Database.SqlQuery <SACH>("GET_SACH").OrderByDescending(x => x.MASACH == ID));
                }
                else
                {
                    if (Img != null)
                    {
                        Image = ByteToImageConverter.Ins.ImageToByte(Img);
                        DataProvider.Ins.DB.Database.ExecuteSqlCommand("USP_THEMSACH @MASACH, @TENSACH, @MALOAISACH, @TACGIA, @MANXB, @GIABAN, @GIANHAP, @HINHANH",
                                                                       new SqlParameter("@MASACH", ID),
                                                                       new SqlParameter("@TENSACH", BookName),
                                                                       new SqlParameter("@MALOAISACH", BookType),
                                                                       new SqlParameter("@TACGIA", Author),
                                                                       new SqlParameter("@MANXB", PublishingHouse),
                                                                       new SqlParameter("@GIABAN", BuyingPrice),
                                                                       new SqlParameter("@GIANHAP", InputPrice),
                                                                       new SqlParameter("@HINHANH", Image)
                                                                       );

                        ListBook = new ObservableCollection <SACH>(DataProvider.Ins.DB.Database.SqlQuery <SACH>("GET_SACH").OrderByDescending(x => x.MASACH == ID));
                    }
                    else
                    {
                        MessageBoxWindow window = new MessageBoxWindow();
                        window.Tag = "Bạn chưa thêm hình ảnh";
                        window.ShowDialog();
                    }

                    //var book = new SACH() { MASACH = ID, TENSACH = BookName, MALOAISACH = BookType, TACGIA = Author, MANXB = PublishingHouse, GIABAN = BuyingPrice, GIANHAP = InputPrice, HINHANH = Image };
                    //if (DataProvider.Ins.DB.SACHes.Where(x => x.MASACH == BookID.ToString()).Count() > 0)
                    //{
                    //    MessageBox.Show("Mã Sách đã tồn tại!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                    //}
                    //else
                    //{



                    //}
                }
            });
            EditCommand = new RelayCommand <Button>((p) => { return(true); }, (p) =>
            {
                IsAdding           = false;
                IsEnabledListView  = false;
                IsEnabledTextBox   = true;
                IsEnabledIDTextBox = false;
            });
            DeleteCommand = new RelayCommand <Button>((p) => { return(true); }, (p) =>
            {
                var book = DataProvider.Ins.DB.SACHes.Where(x => x.MASACH == SelectedItem.MASACH).SingleOrDefault();
                DataProvider.Ins.DB.SACHes.Remove(book);
                try
                {
                    DataProvider.Ins.DB.SaveChanges();

                    ListBook.Remove(SelectedItem);
                }
                catch (Exception)
                {
                    MessageBoxWindow mess2 = new MessageBoxWindow();
                    mess2.Tag = "Không thể xóa cuốn sách này";
                    mess2.ShowDialog();

                    //MessageBox.Show("Không thể xóa cuốn sách này", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            });
            SearchCmd = new RelayCommand <TextBox>((p) => { return(true); }, (p) =>
            {
                if (p.Text != "")
                {
                    var newList = new ObservableCollection <SACH>(DataProvider.Ins.DB.Database.SqlQuery <SACH>("USP_TIMSACHTHEOTEN @TEN", new SqlParameter("TEN", p.Text)));
                    ListBook    = newList;
                }
                else
                {
                    var newList = new ObservableCollection <SACH>(DataProvider.Ins.DB.SACHes);
                    ListBook    = newList;
                }
            });
            ListBook            = new ObservableCollection <SACH>(DataProvider.Ins.DB.SACHes);
            ListPublishingHouse = new ObservableCollection <NHAXUATBAN>(DataProvider.Ins.DB.NHAXUATBANs);
            ListBookType        = new ObservableCollection <LOAISACH>(DataProvider.Ins.DB.LOAISACHes);
        }
コード例 #7
0
        /// <summary>
        /// 查询图书信息
        /// </summary>
        /// <param name="book"></param>
        public void SearchBookInfo(Books book)
        {
            ListBook.Clear();

            Fistpage     = "0";//0代表false 1代表true
            Nextpage     = "0";
            Previewpage  = "0";
            LastPage     = "0";
            Redirttopage = "0";


            foreach (var item in txtboxlist)
            {
                if (item.Name == "pagesize")
                {
                    book.PageSize = Convert.ToInt32(item.Text);
                }
                if (item.Name == "pageindex")
                {
                    book.PageIndex = Convert.ToInt32(item.Text);
                }
            }

            List <Books> bookslist = new List <Books>();

            new BLL.BookMaintain.BookMaintainBLL().SearchBookinfoList <Books>(DAL.SQLID.BookMaintain.BookMaintain.selelct_book_bycontation, book, bookslist);


            if (bookslist.Count != 0)
            {
                foreach (var item in bookslist)
                {
                    ListBook.Add(item);
                }
            }

            if (ListBook.Count != 0)
            {
                int Total = ListBook[0].PageCount;

                int PageSize = 0;

                foreach (var item in txtboxlist)
                {
                    if (item.Name == "pagesize")
                    {
                        PageSize = Convert.ToInt32(item.Text);
                    }
                }

                int pc = Total / PageSize;
                if (Total % PageSize == 0)
                {
                    PageCount = pc.ToString();

                    if (Convert.ToInt32(PageCount) > 1)
                    {
                        Fistpage     = "1";//0代表false 1代表true
                        Nextpage     = "1";
                        Previewpage  = "1";
                        LastPage     = "1";
                        Redirttopage = "1";
                    }
                    //else
                    //{
                    //    Fistpage = "0";//0代表false 1代表true
                    //    Nextpage = "0";
                    //    Previewpage = "0";
                    //    LastPage = "0";
                    //    Redirttopage = "0";
                    //}
                }
                else
                {
                    PageCount = (pc + 1).ToString();

                    if (Convert.ToInt32(PageCount) > 1)
                    {
                        Fistpage     = "0";//0代表false 1代表true
                        Nextpage     = "1";
                        Previewpage  = "0";
                        LastPage     = "1";
                        Redirttopage = "1";
                    }
                    //else
                    //{
                    //    Fistpage = "0";//0代表false 1代表true
                    //    Nextpage = "0";
                    //    Previewpage = "0";
                    //    LastPage = "0";
                    //    Redirttopage = "0";
                    //}
                }
            }
            else
            {
                PageCount    = "0";
                Fistpage     = "0";//0代表false 1代表true
                Nextpage     = "0";
                Previewpage  = "0";
                LastPage     = "0";
                Redirttopage = "0";
            }
        }