Exemplo n.º 1
0
        public bool insertLending(Lending lending)
        {
            try
            {
                conn.Open();
                OleDbCommand cmd = new OleDbCommand(insertBorrowSQL, conn);
                cmd.Parameters.AddWithValue("@isbn", lending.ISBN);
                cmd.Parameters.AddWithValue("@borrowtime", GetDateWithoutMilliseconds(DateTime.Now));
                cmd.Parameters.AddWithValue("@borrowerid", lending.BorrowerID);
                cmd.Parameters.AddWithValue("@borrowername", lending.BorrowerName);

                cmd.ExecuteNonQuery();
                return(true);
            }
            catch (OleDbException ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                conn.Close();
            }

            return(false);
        }
Exemplo n.º 2
0
        public int returnBook(Lending lending)
        {
            try
            {
                conn.Open();
                OleDbCommand cmd = new OleDbCommand(returnBookSQL, conn);
                cmd.Parameters.AddWithValue("@returntime", GetDateWithoutMilliseconds(DateTime.Now));
                cmd.Parameters.AddWithValue("@isbn", lending.ISBN);
                cmd.Parameters.AddWithValue("@borrowername", lending.BorrowerName);
                cmd.Parameters.AddWithValue("@borrowerid", lending.BorrowerID);

                int rowsAffected = cmd.ExecuteNonQuery();
                return(rowsAffected);
            }
            catch (OleDbException ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                conn.Close();
            }

            return(0);
        }
Exemplo n.º 3
0
        public bool checkStudentBookUnreturnExist(Lending lending)
        {
            try
            {
                conn.Open();
                OleDbCommand cmd = new OleDbCommand(selectStudentBookUnreturnedCountSQL, conn);
                cmd.Parameters.AddWithValue("@isbn", lending.ISBN);
                cmd.Parameters.AddWithValue("@borrowername", lending.BorrowerName);
                cmd.Parameters.AddWithValue("@borrowerid", lending.BorrowerID);

                OleDbDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows || reader != null)
                {
                    while (reader.Read())
                    {
                        return(true);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (OleDbException ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                conn.Close();
            }

            return(false);
        }
Exemplo n.º 4
0
        private void continue_btn_Click(object sender, EventArgs e)
        {
            ArrayList lendingList = new ArrayList();

            string[] allTextBoxes = { book1ISBN_textbox.Text, book2ISBN_textbox.Text, book3ISBN_textbox.Text, book4ISBN_textbox.Text };
            // book id list for duplicate checking only
            List <string> isbnListForDC = new List <string>();

            int emptyTextboxCount = 0;

            foreach (string ISBN in allTextBoxes)
            {
                if (!String.IsNullOrEmpty(ISBN))
                {
                    Lending lending = new Lending();
                    lending.ISBN = ISBN.ToUpper();
                    lendingList.Add(lending);
                    isbnListForDC.Add(ISBN.ToUpper());
                }
                else
                {
                    emptyTextboxCount++;
                }
            }

            if (emptyTextboxCount == allTextBoxes.Count())
            {
                MessageBox.Show("Please scan a book's barcode.", "Empty Field", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!checkDuplicateBook(isbnListForDC))
            {
                if (actionType.Equals("Borrow"))
                {
                    MessageBox.Show("You cannot borrow the same book.", "Duplicate Book", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (actionType.Equals("Return"))
                {
                    MessageBox.Show("You are trying to return many same books.", "Duplicate Book", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            // check if book id is valid
            foreach (Lending lending in lendingList)
            {
                if (dbManager.isbnExists(lending.ISBN) == false)
                {
                    MessageBox.Show("The book ID " + lending.ISBN + " does not exist, no such book.", "Invalid Book ID", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            if (actionType.Equals("Borrow"))
            {
                foreach (Lending lending in lendingList)
                {
                    int  unreturnedQuantity = dbManager.selectUnreturnQuantity(lending.ISBN);
                    int  totalQuantity      = dbManager.selectBook(lending.ISBN).Quantity;
                    bool bookAvailable      = totalQuantity > unreturnedQuantity;
                    if (bookAvailable == false)
                    {
                        MessageBox.Show("Please return the book ID " + lending.ISBN + " before trying to borrow.", "Book Not Available", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                Action frmAction = new Action(actionType, lendingList);
                frmAction.Show();
                this.Owner = frmAction;
                this.Hide();
            }

            else if (actionType.Equals("Return")) //return book
            {
                Action frmAction = new Action(actionType, lendingList);
                frmAction.Show();
                this.Owner = frmAction;
                this.Hide();
            }
        }