コード例 #1
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;
            }
        }
コード例 #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 + "'");
            }
        }