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