Ejemplo n.º 1
0
        private void borrow(CirculatedCopy cc, Copy c, Reservation r)
        {
            // Insert borrow record
            if (cc == null)
            {
                return;
            }
            if (CirculatedCopyDAO.Insert(cc))
            {
                txtDueDate.Text = Calendar1.SelectedDate.AddDays(14).ToString("dd/MM/yyyy");
                // update type = 'B' at Copy
                c = (Copy)Session["copy"];
                if (c == null)
                {
                    return;
                }
                c.Type = 'B';
                CopyDAO.Update(c);


                // update status = 'A' at Reservation
                r = (Reservation)Session["reser"];
                if (r == null)
                {
                    return;
                }
                r.Status = 'A';
                ReserveDAO.Update(r);
            }
            else
            {
                lblError.Text = cc.BorrowedDate.ToString("yyyy-MM-dd hh:mm:ss");
                lblError.Text = "Borrow Fail :< ";
            }
        }
Ejemplo n.º 2
0
        private void btnReturn_Click(object sender, EventArgs e)
        {
            CirculatedCopy cc = new CirculatedCopy();

            cc.CirculatedCopyId = Convert.ToInt32(dgvBorrowedBooks.Rows[rowIndex].Cells["circulatedCopyId"].Value);
            cc.ReturnedDate     = dtpReturnedDate.Value;
            cc.FineAmount       = double.Parse(txtFineAmount.Text);
            CirculatedCopyDAO.Update(cc);

            Copy c = CopyDAO.GetCopy(Convert.ToInt32(dgvBorrowedBooks.Rows[rowIndex].Cells["copyNumber"].Value));

            if (ReservationDAO.GetFirstReservation(c.BookNumber) != null)
            {
                c.Type = 2;
            }
            else
            {
                c.Type = 0;
            }
            CopyDAO.UpdateType(c);

            view(int.Parse(txtMemberCode.Text));
            MessageBox.Show("Return Successful.");
            btnReturn.Enabled      = false;
            txtFineAmount.Text     = "";
            btnConfirmFine.Enabled = false;
        }
Ejemplo n.º 3
0
        private void btnCopyAdd_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            if (btn.Text == "Add")
            {
                if (!isSelected())
                {
                    return;
                }
                txtCopyNumber.Text = dataGridView1.SelectedRows[0].Cells["bookNumber"].Value.ToString();
                c = new Copy(int.Parse(txtCopyNumber.Text), CopyDAO.GetCopyNumberMax() + 1, CopyDAO.GetSequenceNumberMax(int.Parse(txtCopyNumber.Text)) + 1, 'A', 0);
                displayCopy();

                displayCopyButtons(2);
            }
            else
            {
                c.Price = double.Parse(txtPrice.Text);
                CopyDAO.Insert(c);

                ViewCopies();

                displayCopyButtons(1);
            }
        }
Ejemplo n.º 4
0
        protected void btnCondition_Click(object sender, EventArgs e)
        {
            int bookNumber;

            try
            {
                bookNumber = int.Parse(txtBookNumber.Text);
            }
            catch
            {
                lblError.Text = "Borrower number must be a integer!";
                txtBorrowerNumber.Focus();
                return;
            }
            Book b = BookDAO.GetBook(bookNumber);

            if (b == null)
            {
                lblError.Text = String.Format("Booknumber {0} does't exist!", bookNumber);
                txtBorrowerNumber.Focus();
                return;
            }

            if (CopyDAO.GetCopyByBookNumber(bookNumber) == null)
            {
                displayButtons(3);
                txtTitle.Text = b.Title;
            }

            else
            {
                displayButtons(2);
            }
        }
Ejemplo n.º 5
0
        private bool checkCondition(int borrowerNumber, int bookNumber)
        {
            DataTable dt = new CopyDAO().GetAllCopyByBookNumber(bookNumber);

            if (dt.Rows.Count == 0)
            {
                MessageBox.Show("Book Number has not existed !!");
                txtBookNumber.Focus();
                return(false);
            }
            foreach (DataRow rd in dt.Rows)
            {
                if (rd["type"].ToString().Equals("A"))
                {
                    MessageBox.Show("The book is available !!!");
                    return(false);
                }
            }
            foreach (DataRow rd in dt.Rows)
            {
                if (rd["type"].ToString().Equals("B"))
                {
                    return(true);
                }
            }
            MessageBox.Show("All copy is reference !!!");
            return(false);
        }
Ejemplo n.º 6
0
 private void btnCheckCondition_Click(object sender, EventArgs e)
 {
     if (txtCopyNumber.Text != "")
     {
         if (CopyDAO.CheckCondition(int.Parse(txtCopyNumber.Text)) == 0)
         {
             MessageBox.Show("This book is available.");
             btnBorrow.Enabled = true;
         }
         else if (CopyDAO.CheckCondition(int.Parse(txtCopyNumber.Text)) == 2)
         {
             if (ReservationDAO.GetFirstReservation(CopyDAO.GetCopy(int.Parse(txtCopyNumber.Text)).BookNumber).MemberNumber
                 == int.Parse(txtMemberCode.Text))
             {
                 check = 1;
                 MessageBox.Show("This copy is available.");
                 btnBorrow.Enabled = true;
             }
             else
             {
                 MessageBox.Show("This copy is not available.");
             }
         }
         else
         {
             display(2);
             MessageBox.Show("Copy Number is invalid or This book is not available.");
         }
     }
     else
     {
         MessageBox.Show("Copy Code can not be blank.");
     }
 }
Ejemplo n.º 7
0
 protected void btnChkCondition_Click(object sender, EventArgs e)
 {
     if (txtBookNumber.Text == null || txtBookNumber.Text.Equals(""))
     {
         lblError.Text = "Book Number is not allow to be null";
         txtBookNumber.Focus();
     }
     else if (DAO.checkInt(txtBookNumber.Text) == false)
     {
         lblError.Text = "Book Number is numberic";
         txtBookNumber.Focus();
     }
     else
     {
         DataView dv = new DataView(BookDAO.GetDataTableBook());
         dv.RowFilter = "bookNumber = " + txtBookNumber.Text;
         if (dv.Count != 0)                                                               //book exist
         {
             int availableCopy = CopyDAO.getAvailableCopy(int.Parse(txtBookNumber.Text)); //số lượng bản copy A
             if (availableCopy > 0)
             {
                 lblError.Text = "This book having " + availableCopy + " copies available, you can borrow them";
             }
             else
             {
                 lblError.Text      = "";
                 btnReserve.Enabled = true;
             }
         }
         else
         {
             lblError.Text = "Oops! this book number is not exist!";
         }
     }
 }
Ejemplo n.º 8
0
        private void borrow(CirculatedCopy cc, Copy c, Reservation r)
        {
            // Insert borrow record
            if (cc == null)
            {
                return;
            }
            CirculatedCopyDAO.Insert(cc);

            // update type = 'B' at Copy
            if (c == null)
            {
                return;
            }
            c.Type = 'B';
            CopyDAO.Update(c);


            // update status = 'A' at Reservation
            if (r == null)
            {
                return;
            }
            r.Status = 'A';
            ReserveDAO.Update(r);
        }
Ejemplo n.º 9
0
        private errorBorrow checkCondition(int borrowerNumber, int copyNumber, out Copy c, out Reservation r)
        {
            c = null;
            r = null;


            c = CopyDAO.GetCopy(copyNumber);
            if (c == null)
            {
                return(errorBorrow.CopyNotExist);
            }
            if (c.Type == 'A')
            {
                return(errorBorrow.CopyReferenced);
            }
            if (c.Type == 'B')
            {
                return(errorBorrow.CopyBorrowed);
            }

            // Check if this book is reserved by others and you are not at the first of the reservation list
            int bookNumber = c.BookNumber;

            r = ReserveDAO.GetFirstReservation(bookNumber);
            if (r != null && r.BorrowerNumber != borrowerNumber)
            {
                return(errorBorrow.CopyReserved);
            }

            return(errorBorrow.OK);
        }
Ejemplo n.º 10
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int  add = (int)Session["add"];
            Copy c   = new Copy();

            c.BookNumber     = int.Parse(txtBookNumber.Text);
            c.SequenceNumber = CopyDAO.GetSequenceNumberMax(c.BookNumber) + 1;
            c.Type           = txtType.Text[0];
            if (txtPrice.Text == "")
            {
                c.Price = 0;
            }
            else
            {
                c.Price = int.Parse(txtPrice.Text);
            }
            if (add == 1)
            {
                c.CopyNumber = CopyDAO.GetCopyNumberMax() + 1;
                CopyDAO.Insert(c);
            }
            else
            {
                c.CopyNumber = (int)Session["copyNumber"];
                CopyDAO.Update(c);
            }

            ObjectDataSource1.Select();
            GridView1.DataBind();
            displayButtons(1);
        }
Ejemplo n.º 11
0
        private void btnCopyEdit_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            if (btn.Text == "Edit")
            {
                if (!isCopySelected())
                {
                    return;
                }
                if (txtType.Text[0] == 'B')
                {
                    MessageBox.Show("Can't edit borrwed copy!");
                    return;
                }
                displayCopyButtons(3);
            }
            else
            {
                c = new Copy(int.Parse(txtCopyBookNumber.Text), int.Parse(txtCopyNumber.Text)
                             , int.Parse(txtSequenceNumber.Text), txtType.Text[0], double.Parse(txtPrice.Text));
                CopyDAO.Update(c);
                ViewCopies();
                displayCopyButtons(1);
            }
        }
Ejemplo n.º 12
0
        private bool checkCondition(int borrowerNumber, int bookNumber)
        {
            lbError.Visible = false;
            DataTable dt = CopyDAO.GetAllCopyByBookNumber(bookNumber);

            if (dt.Rows.Count == 0)
            {
                lbError.Visible = true;
                lbError.Text    = "Book Number has not existed !!";
                txtBookNumber.Focus();
                return(false);
            }
            foreach (DataRow rd in dt.Rows)
            {
                if (rd["type"].ToString().Equals("A"))
                {
                    lbError.Visible = true;
                    lbError.Text    = "The book is available !!!";
                    return(false);
                }
            }
            foreach (DataRow rd in dt.Rows)
            {
                if (rd["type"].ToString().Equals("B"))
                {
                    return(true);
                }
            }

            lbError.Text = "All copy is reference !!!";
            return(false);
        }
Ejemplo n.º 13
0
        private void ViewAllCopy()
        {
            DataTable dt = new CopyDAO().GetDataTable();

            dvc = new DataView(dt);
            dataGridView2.DataSource = dvc;
        }
Ejemplo n.º 14
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Copy c = new Copy();

            c.BookNumber     = int.Parse(txtBookNum.Text);
            c.SequenceNumber = CopyDAO.GetSeqNumMaxOfBook(c.BookNumber) + 1;

            ///Set Type
            if (!(txtType.Text[0].Equals('A')))
            {
                if (!(txtType.Text[0].Equals('R')))
                {
                    lblError.Text    = "Type must be A or R";
                    lblError.Visible = true;
                    return;
                }
            }
            c.Type = txtType.Text[0];

            //Set Price
            if (txtPrice.Text == "")
            {
                c.Price = 0;
            }
            else
            {
                if (DAO.checkFloat(txtPrice.Text))
                {
                    c.Price = float.Parse(txtPrice.Text);
                }
                else
                {
                    lblError.Text    = "Price must in range 0-999.999.999";
                    lblError.Visible = true;
                    return;
                }
            }



            if (check == 1)
            {
                CopyDAO.Insert(c);
                clear();
                displayButtons(1);
            }

            if (check == 2)
            {
                c.CopyNumber = (int)Session["copyNumber"];
                CopyDAO.Update(c);
                clear();
                displayButtons(1);
            }
            ObjectDataSource1.Select();
            GridView1.DataBind();
        }
Ejemplo n.º 15
0
 protected void GridViewCopy_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "DeleteRow")
     {
         int copyID = int.Parse(e.CommandArgument.ToString());
         CopyDAO.DeleteCopy(copyID);
         GridViewCopy.DataBind();
     }
 }
Ejemplo n.º 16
0
        private void Return(CirculatedCopy cc)
        {
            CirculatedCopyDAO.Update(cc);
            Copy c = CopyDAO.GetCopy(cc.CopyNumber);

            // update type = 'A' in copy
            c.Type = 'A';
            CopyDAO.Update(c);
        }
Ejemplo n.º 17
0
        private void dgvCopies_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            display(4);
            Copy c = CopyDAO.GetCopy(Convert.ToInt32(dgvCopies.Rows[e.RowIndex].Cells["copyNumber"].Value));

            txtCopyNumber.Text     = c.CopyNumber.ToString();
            txtSequenceNumber.Text = c.SequenceNumber.ToString();
            txtType.Text           = c.Type.ToString();
            txtPrice.Text          = c.Price.ToString();
        }
Ejemplo n.º 18
0
        private void btnDeleteCopy_Click(object sender, EventArgs e)
        {
            Copy c = new Copy();

            c.CopyNumber = Convert.ToInt32(txtCopyNumber.Text);
            CopyDAO.Delete(c);
            dgvCopies.DataSource = CopyDAO.GetDataTable(Convert.ToInt32(txtBookNumber1.Text));
            MessageBox.Show("Delete Successful");
            display(5);
        }
Ejemplo n.º 19
0
        // get books and display
        private void View()
        {
            DataTable dt = new CopyDAO().GetDataTable();

            dvc = new DataView(dt);
            dataGridView2.DataSource = dvc;

            dt = new BookDAO().GetDataTable();
            dv = new DataView(dt);
            dataGridView1.DataSource = dv;
        }
Ejemplo n.º 20
0
        private void dgvBooks_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            display(1);
            Book b = BookDAO.GetBook(Convert.ToInt32(dgvBooks.Rows[e.RowIndex].Cells["bookNumber"].Value));

            txtBookNumber.Text   = b.BookNumber.ToString();
            txtTitle.Text        = b.Title;
            txtAuthors.Text      = b.Authors;
            txtPublisher.Text    = b.Publisher;
            dgvCopies.DataSource = CopyDAO.GetDataTable(b.BookNumber);
            txtBookNumber1.Text  = b.BookNumber.ToString();
        }
Ejemplo n.º 21
0
        private void ViewCopies()
        {
            if (dataGridView1.SelectedRows.Count == 0)
            {
                return;
            }
            int bookNumber = (int)dataGridView1.SelectedRows[0].Cells["bookNumber"].Value;

            txtCopyBookNumber.Text = bookNumber.ToString();
            dvc                      = new DataView(CopyDAO.GetDataTable());
            dvc.RowFilter            = "bookNumber = " + bookNumber;
            dataGridView2.DataSource = dvc;
        }
Ejemplo n.º 22
0
        protected void btnBorrow_Click(object sender, EventArgs e)
        {
            DateTime receiveDate = Calendar1.SelectedDate;
            DateTime dueDate     = Calendar1.SelectedDate.AddDays(14);

            CirculatedCopy cc = new CirculatedCopy(int.Parse(txtCopyNumber.Text), int.Parse(txtBorrowerNumber.Text),
                                                   receiveDate, dueDate);

            c = CopyDAO.GetCopy(int.Parse(txtCopyNumber.Text));
            r = r = ReserveDAO.GetFirstReservation(c.BookNumber);
            borrow(cc, c, r);

            showData();
            displayButtons(1);
        }
Ejemplo n.º 23
0
        private void Return(CirculatedCopy cc)
        {
            CirculatedCopyDAO.Update(cc);

            Copy c = CopyDAO.GetCopy(cc.CopyNumber);

            // if copy is reference
            if (c.Type == 'R')
            {
                return;
            }
            // update type = 'A' in copy
            c.Type = 'A';
            CopyDAO.Update(c);
        }
Ejemplo n.º 24
0
        private void btnCopyDelete_Click(object sender, EventArgs e)
        {
            if (!isSelected())
            {
                return;
            }
            int          copyNumber = (int)dataGridView2.Rows[0].Cells["copyNumber"].Value;
            DialogResult dr         = MessageBox.Show(String.Format("Do you want to delete this copy number {0}?", copyNumber), "Confirm deleting", MessageBoxButtons.YesNo);

            if (dr == DialogResult.No)
            {
                return;
            }
            CopyDAO.Delete(copyNumber);
            ViewCopies();
        }
Ejemplo n.º 25
0
        //reload each action change grid view
        protected void reload()
        {
            // reload first path with book
            if (copyExist == false)
            {
                DataTable dt;
                if (Session["sortdata1"] == null)
                {
                    dt = BookDAO.GetDataTable();
                }
                else
                {
                    // set session from dataview so must to parse to dataview first
                    dt = (Session["sortdata1"] as DataView).ToTable();
                }
                GridView1.DataSource = dt;
                ViewState["data1"]   = dt;
                GridView1.DataBind();
                int maxBook = dt.Rows.Count;
                Label2.Text = maxBook.ToString();

                //ViewState["sortExp"] = "ASC";
            }
            //copy path
            else
            {
                DataTable dt;
                if (Session["sortdata2"] == null)
                {
                    dt = CopyDAO.GetAllCopyByBookNumber(bo.BookNumber);
                }
                else
                {
                    dt = (Session["sortdata2"] as DataView).ToTable();
                }

                GridView2.DataSource = dt;
                ViewState["data2"]   = dt;
                GridView2.DataBind();
                int maxCopy = dt.Rows.Count;
                Label7.Text = maxCopy.ToString();
                //ViewState["sortExp"] = "ASC";
            }

            lbErrorBook.Visible   = false;
            lbErrorCopies.Visible = false;
        }
Ejemplo n.º 26
0
        private void Return(CirculatedCopy cc)
        {
            if (CirculatedCopyDAO.Update(cc))
            {
                showMessageError("Return completed <3");

                Copy c = CopyDAO.GetCopy(cc.CopyNumber);

                // update type = 'A' in copy
                c.Type = 'A';
                CopyDAO.Update(c);
            }
            else
            {
                showMessageError("Return Fail :<");
            }
        }
Ejemplo n.º 27
0
        private void btnBorrow_Click(object sender, EventArgs e)
        {
            if (dtpBorrowed.Value < dtpDue.Value)
            {
                CirculatedCopy cc = new CirculatedCopy();
                cc.CopyNumber   = int.Parse(txtCopyNumber.Text);
                cc.MemberNumber = int.Parse(txtMemberCode.Text);
                cc.BorrowedDate = dtpBorrowed.Value;
                cc.DueDate      = dtpDue.Value;

                if (CirculatedCopyDAO.Add(cc))
                {
                    Copy c = CopyDAO.GetCopy(int.Parse(txtCopyNumber.Text));
                    c.Type = 1;
                    CopyDAO.UpdateType(c);
                    display(2);
                    view(int.Parse(txtMemberCode.Text));
                    MessageBox.Show("Add Successful.");

                    if (check == 1)
                    {
                        Reservation r = ReservationDAO.GetFirstReservation(c.BookNumber);
                        r.Status = true;
                        ReservationDAO.UpdateStatus(r);
                    }

                    if (dgvBorrowedBooks.Rows.Count >= 5)
                    {
                        display(0);
                        MessageBox.Show("The number of borrowed books is 5. You can not borrow anymore book.");
                    }
                }
                else
                {
                    MessageBox.Show("Error.");
                }
            }
            else
            {
                MessageBox.Show("Borrowed date has to be smaller than Due date.");
            }
        }
Ejemplo n.º 28
0
 private void btnCRC_Click(object sender, EventArgs e)
 {
     if (txtBookNumber.Text != "")
     {
         if (!CopyDAO.CheckAvailableCopy(int.Parse(txtBookNumber.Text)))
         {
             MessageBox.Show("You can reserve this book.");
             btnReserve.Enabled = true;
         }
         else
         {
             txtBookNumber.Text = "";
             btnReserve.Enabled = false;
             MessageBox.Show("This book still have available copy.");
         }
     }
     else
     {
         MessageBox.Show("Book Code can not be blank.");
     }
 }
Ejemplo n.º 29
0
        protected void ButtonAddCopy_Click(object sender, EventArgs e)
        {
            int    bookCode = int.Parse(TextBoxBookCode.Text.Trim());
            int    copyNum, sequenceNum, price;
            string type = TextBoxType.Text.Trim();

            if (!int.TryParse(TextBoxCopyNumber.Text.Trim(), out copyNum))
            {
                return;
            }
            else if (!int.TryParse(TextBoxSequenceNumber.Text.Trim(), out sequenceNum))
            {
                return;
            }
            else if (!int.TryParse(TextBoxPrice.Text.Trim(), out price))
            {
                return;
            }
            CopyDAO.InsertCopy(bookCode, copyNum, sequenceNum, type, price);
            GridViewCopy.DataBind();
        }
Ejemplo n.º 30
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (check1 == 1)
     {
         if (CopyDAO.ValidateCopy(txtSequenceNumber.Text, txtPrice.Text))
         {
             Copy c = new Copy();
             c.BookNumber     = Convert.ToInt32(txtBookNumber1.Text);
             c.SequenceNumber = Convert.ToInt32(txtSequenceNumber.Text);
             c.Type           = Convert.ToInt32(txtType.Text);
             c.Price          = Convert.ToDouble(txtPrice.Text);
             CopyDAO.Add(c);
             dgvCopies.DataSource = CopyDAO.GetDataTable(c.BookNumber);
             MessageBox.Show("Add Successful");
             display(5);
             btnSave.Visible = false;
             check1          = 0;
         }
     }
     else if (check1 == 2)
     {
         if (CopyDAO.ValidateCopy(txtSequenceNumber.Text, txtPrice.Text))
         {
             Copy c = new Copy();
             c.CopyNumber     = Convert.ToInt32(txtCopyNumber.Text);
             c.BookNumber     = Convert.ToInt32(txtBookNumber1.Text);
             c.SequenceNumber = Convert.ToInt32(txtSequenceNumber.Text);
             c.Type           = Convert.ToInt32(txtType.Text);
             c.Price          = Convert.ToDouble(txtPrice.Text);
             CopyDAO.Edit(c);
             dgvCopies.DataSource = CopyDAO.GetDataTable(c.BookNumber);
             MessageBox.Show("Edit Successful");
             display(5);
             btnSave.Visible = false;
             check1          = 0;
         }
     }
 }