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_LostBookList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData2();
        }
    }
    /*private void BindData()
    {
        N38_GetDataSet myDS = new N38_GetDataSet();
        anplost.RecordCount = myDS.GetLostCount();
        int pageindex = anplost.CurrentPageIndex - 1;
        int pagesize = 5;
        gvbook.DataSource = myDS.GetlostData(pageindex, pagesize);
        gvbook.DataKeyNames = new string[] { "n38_lost_id" };
        gvbook.DataBind();
    }*/
    private void BindData2()
    {
        N38_Book myBook = new N38_Book();
        anplost.RecordCount = myBook.SelectLostCount(tbbookname, tbusername);
        int pageindex = anplost.CurrentPageIndex - 1;
        int pagesize = 5;
        gvbook.DataSource = myBook.SelectLostData(tbbookname, tbusername, pageindex, pagesize);
        gvbook.DataKeyNames = new string[] { "n38_lost_id" };
        gvbook.DataBind();
    }
    protected void anpcatalog_PageChanged(object sender, EventArgs e)
    {
        /*if (tbbookname.Text == "" && tbusername.Text == "")
        {
            BindData();
        }
        else
        {*/
            BindData2();
        //}
    }
    protected void gvbook_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "find")
        {
            GridViewRow gvr = (GridViewRow)(((ImageButton)(e.CommandSource)).NamingContainer);
            N38_User myUser = new N38_User();
            N38_BookOperate myBookOP = new N38_BookOperate();
            string user = gvbook.Rows[gvr.RowIndex].Cells[1].Text.Trim();
            string username = myUser.GetName(user);
            string bookname = gvbook.Rows[gvr.RowIndex].Cells[0].Text.Trim();
            bool result = myBookOP.BookFind(username, bookname);
            if (result)
            {
                Response.Write("<script>alert('取消挂失成功')</script>");
                /*if (tbbookname.Text == "" && tbusername.Text == "")
                {
                    BindData();
                }
                else
                {*/
                    BindData2();
                //}
            }
            else
                Response.Write("<script>alert('取消挂失失败')</script>");
        }
    }
    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");
        }
    }
    protected void ibtnsel_Click(object sender, ImageClickEventArgs e)
    {
        /*if (tbbookname.Text == "" && tbusername.Text == "")
        {
            gvbook.Visible = true;
            BindData();
        }
        else
        {*/
            N38_User myUser = new N38_User();
            if (tbusername.Text != "")
            {
                if (myUser.UserExitByReal(tbusername.Text.Trim()))
                {
                    //gvbook.Visible = true;
                    BindData2();
                }
                else
                {
                    Response.Write("<script>alert('用户不存在')</script>");
                }
            }
            else
            {
                //gvbook.Visible = true;
                BindData2();
            }
        //}
    }
}
