Esempio n. 1
0
        private void btnReserveBook_Click(object sender, EventArgs e)
        {
            DateTime rDate = Convert.ToDateTime(lvIssuesList.SelectedItems[0].SubItems[1].Text);

            MessageBox.Show(dtpReserveDate.Value.Date.ToString());
            ReserveBook reserve = new ReserveBook();

            //if (dtpReserveDate.Value.Date < date)
            //{
            //    MessageBox.Show("The book will still be loaned at this date.\n"
            //      + "Please select a date after the due date");
            //}
            if ((reserve.StudentID = int.Parse(cbStudentID.Text)) == 0)
            {
                MessageBox.Show("Student ID must be an integer");
                cbStudentID.Focus();
                return;
            }
            else if (reserve.StudentID < 1)
            {
                MessageBox.Show("Student ID must be a positive number");
                cbStudentID.Focus();
                return;
            }
            reserve.BookID      = int.Parse(lvIssuesList.SelectedItems[0].SubItems[2].Text);
            reserve.LibrarianID = int.Parse(Environment.GetEnvironmentVariable("librarianID"));
            reserve.ReturnDate  = dtpReserveDate.Value.Date;
            string resDate = reserve.ReserveDate.ToString("MM-DD-YY");

            MessageBox.Show(resDate);
            if ((reserve.Reserve()) != 0)
            {
                MessageBox.Show("Book successfully reserved");
            }
            else
            {
                MessageBox.Show("Book was not reserved, please check details and try again");
            }
        }
Esempio n. 2
0
        private void btnReserve_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateInputs() == false)
                {
                    return;
                }
                Book ToReserveBook = new Book();
                ToReserveBook.BookID = int.Parse(txtBookID.Text);

                string ConditionQuery;

                ConditionQuery = "select noOfAvailableBooks from Book where bookID=(" + int.Parse(txtBookID.Text) + ")";



                SqlConnection conn = ConnectionManager.DBConnection();
                SqlDataReader rdr  = null;
                try
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand(ConditionQuery, conn);
                    rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        ToReserveBook.AvailableBooks = int.Parse(rdr["noOfAvailableBooks"].ToString());

                        if (ToReserveBook.AvailableBooks <= 0)
                        {
                            ReserveBook ReserveBook = new ReserveBook();
                            ReserveBook.BookID      = int.Parse(txtBookID.Text);
                            ReserveBook.StudentID   = int.Parse(txtStudentID.Text);
                            ReserveBook.RSD         = DateTime.Parse(txtRSD.Text);
                            ReserveBook.LibrarianID = int.Parse(txtLibrarianID.Text);
                            ReserveBook.AddNewReserve();
                            MessageBox.Show(" Book Reservation Complete.", "Reserve");
                        }
                        else
                        {
                            DialogResult dialogResult = MessageBox.Show("Book Requested is available at moment." + Environment.NewLine + "Do you want Issue this book now?", "Hey The Book is Available.", MessageBoxButtons.YesNo);
                            if (dialogResult == DialogResult.Yes)
                            {
                                this.Hide();
                                IssueForm Procede = new IssueForm();
                                Procede.Show();
                            }
                            else if (dialogResult == DialogResult.No)
                            {
                                MessageBox.Show(" It's not allowed to reserve book , unless they are not Available.", "Sorry NOT ALLOWED");
                                txtBookID.Text      = "";
                                txtStudentID.Text   = "";
                                txtRSD.Text         = "";
                                txtLibrarianID.Text = "";
                                txtBookID.Focus();
                            }
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Please make sure the follow details are inserted in the right format as in this example:" + Environment.NewLine + "BookiD : 1" + Environment.NewLine + "Student ID : 1001" + Environment.NewLine + "Date of Reserve: MM-DD-YYYY" + Environment.NewLine + "LibrarianID : 2");
                }
            }
            catch
            {
                MessageBox.Show("Please make sure the follow details are inserted in the right format as in this example:" + Environment.NewLine + "BookiD : 1" + Environment.NewLine + "Student ID : 1001" + Environment.NewLine + "Date of Reserve: MM-DD-YYYY" + Environment.NewLine + "LibrarianID : 2");
            }
        }