Пример #1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtSearch.Text != "")
                {
                    string search = txtSearch.Text;
                    // Search by ISBN
                    if (rdISBN.Checked)
                    {
                        Store store = new Store();
                        BookStoreDAL bookstoreDAL = new BookStoreDAL();
                        if (bookstoreDAL.GetBookStorebyISBN(search) != null)
                        {
                            store = bookstoreDAL.GetBookStorebyISBN(search);
                            List<Store> list = new List<Store>();
                            list.Add(store);
                            BookGridView.DataSource = list;
                            BookGridView.Refresh();
                        }
                        else
                        {
                            MessageBox.Show("Không tìm thấy kết quả. Vui lòng nhập chính xác ISBN!");
                        }
                    }
                    else
                    {
                        // search by BookName
                        if (rdBookName.Checked)
                        {
                            BookStoreDAL bookstoreDAL = new BookStoreDAL();
                            if (bookstoreDAL.GetBookStorebyName(search) != null)
                            {
                                List<Store> list = bookstoreDAL.GetBookStorebyName(search);
                                BookGridView.DataSource = list;
                                BookGridView.Refresh();
                            }
                            else
                            {
                                MessageBox.Show("Không tìm thấy kết quả. Vui lòng nhập chính xác tên sách!");
                            }
                        }
                        if (rdISBN.Checked == false && rdBookName.Checked == false)
                        {
                            MessageBox.Show("Hãy chọn mục tìm kiếm !");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Vui lòng nhập giá trị tìm kiếm !");
                }
            }
            catch (Exception ex)
            {

                logger.MyLogFile(DateTime.Now.ToString(), "' Error '" + ex.Message + "'");
            }
        }
Пример #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Bạn có muốn xóa ?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    //Restore book's quantity in Store when Delete Row
                    BookStore bookStore = new BookStore();
                    BookStoreDAL bookStoreDAL = new BookStoreDAL();
                    string ISBN = ieDetail.ISBNBook;
                    int Quantity = ieDetail.Quantity;
                    bookStore = bookStoreDAL.GetBookStorebyISBNBook(ISBN);
                    string error = "";
                    bool rs = true;
                    if (String.Compare(importExport.ImEx, "Xuất", true) == 0)
                    {
                        bookStore.Quantity += Quantity;
                    }
                    else
                    {
                        if (bookStore.Quantity >= Quantity)
                        {
                            bookStore.Quantity -= Quantity;
                        }
                        else
                        {
                            rs = false;
                            error = error + "Số lượng sách nhỏ hơn số sách cần xóa từ phiếu Nhập này";
                        }
                    }

                    rs = bookStoreDAL.UpdateBookStore(bookStore);
                    if (!rs)
                    {
                        error = error + "Không thể cập nhật sách.";
                        MessageBox.Show(error);
                    }
                    else
                    {
                        // Delete Book in IEDetail
                        ieDAL.DeleteOrderByCheckNoAndISBN(importExport.CheckNo, ieDetail.ISBNBook);
                    }

                }
                ClearAll();
                OrderLoadData();
            }
            catch (Exception ex)
            {

                logger.MyLogFile(DateTime.Now.ToString(), "' Error '" + ex.Message + "'");
            }
        }
Пример #3
0
        private bool UpdateStore(bool IsChangeQuantity)
        {
            try
            {
                bool rs = true;

                string error = "";

                BookStore bookStore = new BookStore();
                BookStoreDAL bookStoreDAL = new BookStoreDAL();
                string ISBN = ieDetail.ISBNBook;
                int Quantity = ieDetail.Quantity;
                bookStore = bookStoreDAL.GetBookStorebyISBNBook(ISBN);
                if (bookStore == null)
                {
                    if (String.Compare(importExport.ImEx, "Nhập", true) == 0)
                    {
                        BookStore bookStore1 = new BookStore();
                        bookStore1.ISBN = ISBN;
                        bookStore1.Quantity = Quantity;
                        rs = bookStoreDAL.CreateBookStore(bookStore1);
                        if (!rs)
                        {
                            error = "Không thể thêm sách vào kho.";
                        }
                    }
                    else
                    {
                        rs = false;
                        error = "Không thể xuất sách không có trong kho";
                    }
                }
                else
                {
                    if (String.Compare(importExport.ImEx, "Nhập", true) == 0)
                    {
                        if (IsChangeQuantity)
                        {
                            bookStore.Quantity += Quantity;
                        }
                        else
                        {
                            bookStore.Quantity = Quantity;
                        }
                    }
                    else
                    {
                        if (bookStore.Quantity >= Quantity)
                        {
                            if (IsChangeQuantity)
                            {
                                bookStore.Quantity -= Quantity;
                            }
                            else
                            {
                                bookStore.Quantity = Quantity;
                            }
                        }
                        else
                        {
                            rs = false;
                            error = "Số lượng sách lớn hơn số lượng có trong kho";
                        }
                    }
                    if (rs)
                    {
                        rs = bookStoreDAL.UpdateBookStore(bookStore);
                    }
                    if (!rs)
                    {
                        error = "Không thể cập nhật sách.";
                    }
                }

                if (!rs)
                {
                    MessageBox.Show(error + ". Vui lòng xem lại !");
                }
                return rs;
            }
            catch (Exception ex)
            {
                logger.MyLogFile(DateTime.Now.ToString(), "' Error '" + ex.Message + "'");
                return false;
            }
        }
Пример #4
0
 private void LoadAllData()
 {
     BookStoreDAL bookstoreDAL = new BookStoreDAL();
     List<Store> list = bookstoreDAL.GetAllStore();
     dataGridView1.DataSource = list;
 }