Esempio n. 1
0
        protected void AddReader_Click(object sender, EventArgs e)
        {
            if (ProcessGUI.IsNumeric(this.txtReaderId.Text))
            {
                Int64 readerId = Int64.Parse(this.txtReaderId.Text);
                ReaderBLL readerBLL = new ReaderBLL();
                readerBLL = ReaderDAL.getReaderByReaderId(readerId);
                this._readerBLL = readerBLL;
                if (readerBLL != null)
                {
                    this.lblReaderName.Text = readerBLL.Name;
                    this.lblReaderId.Text = readerBLL.Code.ToString();
                    this.lblEmail.Text = readerBLL.Email;
                    this.lblAddress.Text = readerBLL.Address;
                    this.lblDayOfBirth.Text = readerBLL.Birthday.ToShortDateString();
                    this.lblPhone.Text = readerBLL.Phone;
                    this.lblQuantity.Text = "0";

                    int result = (DateTime.Compare(DateTime.Now, readerBLL.Enddate));
                    if (result > 0)
                    {
                        string script = "alert(\"This reader has expired!\");";
                        ScriptManager.RegisterStartupScript(this, GetType(),
                                              "ServerControlScript", script, true);
                        this.lblStatus.Text = "Expired";
                    }
                    else
                    {
                        BorrowBookBLL borrowBookBLL = new BorrowBookBLL();
                        if (borrowBookBLL.checkBookBorrowMax(readerBLL))
                        {
                            this.lblStatus.Text = "Good";
                            Session["readerName"]= readerBLL.Name;
                            Session["readerId"] = readerBLL.Code;
                            Session["quantity"] = borrowBookBLL.getBookQuantityCanBorrow(readerBLL);
                            this.lblQuantity.Text = borrowBookBLL.getBookQuantityCanBorrow(readerBLL).ToString();

                        }
                        else
                        {
                            string script = "alert(\"Reader has  borrowed maximum books!\");";
                            ScriptManager.RegisterStartupScript(this, GetType(),
                                                  "ServerControlScript", script, true);
                            this.lblStatus.Text = "Maximum";
                        }
                    }
                }
                else
                {
                    string script = "alert(\"Readers do not exist!\");";
                    ScriptManager.RegisterStartupScript(this, GetType(),
                                          "ServerControlScript", script, true);
                }
            }
        }
 protected void btnConfirm_Click(object sender, EventArgs e)
 {
     Int64 readerId = Int64.Parse(Session["ReaderId"].ToString());
     DateTime dateAdded = DateTime.Now;
     DateTime dateEnd = dateAdded.AddDays(10);
     List<Int32> bookList = new List<Int32>();
     if (Session["bookId1"] != null)
     {
         if (Session["bookId2"] != null)
         {
             if (Session["bookId3"] != null)
             {
                 bookList.Add(Int32.Parse(Session["bookId1"].ToString()));
                 bookList.Add(Int32.Parse(Session["bookId2"].ToString()));
                 bookList.Add(Int32.Parse(Session["bookId3"].ToString()));
             }
             else
             {
                 bookList.Add(Int32.Parse(Session["bookId1"].ToString()));
                 bookList.Add(Int32.Parse(Session["bookId2"].ToString()));
             }
         }
         else
         {
             bookList.Add(Int32.Parse(Session["bookId1"].ToString()));
         }
     }
     else
     {
         Response.Redirect("Book.aspx");
     }
     CertificateBLL certificateBLL = new CertificateBLL(1, readerId, dateAdded, dateEnd);
     BorrowBookBLL borrowBookBLL = new BorrowBookBLL();
     try
     {
         borrowBookBLL.Add(certificateBLL, bookList);
         string script = "alert(\"Success!\");";
         ScriptManager.RegisterStartupScript(this, GetType(),
                               "ServerControlScript", script, true);
         this.btnConfirm.Visible = false;
         this.btnCancel.Visible = false;
         Session.Abandon();
         //Response.Redirect("Reader.aspx");
     }
     catch (Exception ex)
     {
         string script = "alert(\"Error while add certificate: "+ex.Message+"\");";
         ScriptManager.RegisterStartupScript(this, GetType(),
                               "ServerControlScript", script, true);
     }
 }