using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class N38_BorrowBookList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData2();
        }
    }
    protected void gvbook_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#d0e5f5'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'");
            e.Row.Attributes.Add("style", "height:22px;background-color:#ffffff");
        }
        if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Attributes.Add("style", "background-image:url('n38_image/ht_10.gif');height:22px");
        }
    }

    /*private void BindData()
    {
        N38_GetDataSet myDS = new N38_GetDataSet();
        anpborrow.RecordCount = myDS.GetBorrowCount();
        int pageindex = anpborrow.CurrentPageIndex - 1;
        int pagesize = 5;
        gvbook.DataSource = myDS.GetBorrowData(pageindex, pagesize);
        gvbook.DataKeyNames = new string[] { "n38_borrow_id" };
        gvbook.DataBind();
    }*/
    private void BindData2()
    {
        N38_Book myBook = new N38_Book();
        anpborrow.RecordCount = myBook.SelectBorrowCount(tbbookname, tbuser);
        int pageindex = anpborrow.CurrentPageIndex - 1;
        int pagesize = 5;
        gvbook.DataSource = myBook.SelectBorrowData(tbbookname, tbuser, pageindex, pagesize);
        gvbook.DataKeyNames = new string[] { "n38_borrow_id" };
        gvbook.DataBind();
    }
    protected void anpcatalog_PageChanged(object sender, EventArgs e)
    {
        /*if (!IsPostBack)
        {
            if (tbbookname.Text == "" && tbuser.Text == "")
            {
                BindData();
            }
            else
            {*/
                BindData2();
            /*}
        }*/
    }
    protected void gvbook_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "normal")
        {
            N38_User myUser=new N38_User();
            GridViewRow gvr = (GridViewRow)(((ImageButton)(e.CommandSource)).NamingContainer);
            int id = int.Parse(gvbook.DataKeys[gvr.RowIndex].Value.ToString());
            string bookname = gvbook.Rows[gvr.RowIndex].Cells[2].Text.Trim();
            string name=gvbook.Rows[gvr.RowIndex].Cells[1].Text.Trim();
            string username=myUser.GetName(name);
            N38_Book myBook = new N38_Book();
            myBook.NormalBorrowBook(bookname,username);
            /*if (tbbookname.Text == "" && tbuser.Text == "")
            {
                BindData();
            }
            else
            {*/
                BindData2();
            //}
        }
    }
    protected void ibtnsel_Click(object sender, ImageClickEventArgs e)
    {
        /*if (tbbookname.Text == "" && tbuser.Text == "")
        {
            gvbook.Visible = true;
            BindData();
        }
        else
        {*/
            N38_User myUser = new N38_User();
            if (tbuser.Text != "")
            {
                if (myUser.UserExitByReal(tbuser.Text.Trim()))
                {
                    //gvbook.Visible = true;
                    BindData2();
                }
                else
                {
                    Response.Write("<script>alert('用户不存在')</script>");
                }
            }
            else
            {
                //gvbook.Visible = true;
                BindData2();
            }
       // }
    }
}
