BorrowInfo.aspx.cs
上传用户:gooyliu
上传日期:2018-09-29
资源大小:5816k
文件大小:3k
源码类别:

.net编程

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. using System.Xml.Linq;
  13. using System.Data.SqlClient;
  14. using BusinessLogicLayer;
  15. namespace Web.Reader
  16. {
  17.     public partial class BorrowInfo : System.Web.UI.Page
  18.     {
  19.         protected void Page_Load(object sender, EventArgs e)
  20.         {
  21.             if (!IsPostBack)
  22.             {
  23.                 BindData();
  24.             }
  25.         }
  26.         void BindData()
  27.         {
  28.             string userID = Session["userID"].ToString();
  29.             DataSet dsBorrowBook = new DataSet();
  30.             Users user = new Users();
  31.             dsBorrowBook = user.GetBorrowBook(userID);
  32.             if (dsBorrowBook.Tables[0].Rows.Count > 0)
  33.             {
  34.                 gvBorrowBookList.DataSource = dsBorrowBook;
  35.                 gvBorrowBookList.DataBind();
  36.                 this.TrMsg.Visible = false;       //有借阅记录则显示列表,并不显示提示
  37.             }
  38.             else                                  //没有借阅记录则不显示gridview,并给出提示信息
  39.             {
  40.                 this.TrGrid.Visible = false;               
  41.                 lblMsgNoBorrow.Text = "你好,你还没有借阅记录"; 
  42.             }
  43.         }
  44.         protected void gvBorrowBookList_RowDataBound(object sender, GridViewRowEventArgs e)
  45.         {
  46.             if (e.Row.RowType == DataControlRowType.DataRow)
  47.             {
  48.                 DateTime shouldEndDate = Convert.ToDateTime(e.Row.Cells[1].Text).AddDays(30);
  49.                 DateTime today=DateTime.Today;
  50.                 if (today.CompareTo(shouldEndDate) > 0)           //今天比应归还日期晚
  51.                 {
  52.                     e.Row.BackColor = System.Drawing.Color.Yellow;
  53.                     ClientScriptManager CSM = Page.ClientScript;  //加载页面时给出图书过期提示框
  54.                     string ScriptName = "showMsg";
  55.                     if (!CSM.IsClientScriptBlockRegistered(ScriptName))
  56.                     {
  57.                         string StrScript = "<script>";
  58.                         StrScript += "alert('您有过期的图书,请尽快归还');";
  59.                         StrScript += "</script>";
  60.                         CSM.RegisterStartupScript(this.GetType(), ScriptName, StrScript);
  61.                      }
  62.                     //Page.RegisterStartupScript("", "<script>alert('您有过期的图书,请尽快归还');</script>");
  63.                 }
  64.                 else
  65.                 { }
  66.                 ((Label)e.Row.Cells[2].FindControl("lblEndDate")).Text = (Convert.ToDateTime(e.Row.Cells[1].Text).AddDays(30)).ToString();
  67.             
  68.             }
  69.         }
  70.     }
  71. }