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_FindBook : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private void BindData()
    {
        N38_User myUser = new N38_User();
        N38_Book myBook = new N38_Book();
        N38_GetDataSet myDS = new N38_GetDataSet();
        string username = myUser.GetUserName(int.Parse(tbuserid.Text.Trim()));
        string bookname = myBook.GetBookName(int.Parse(tbbookid.Text.Trim()));
        gvbook.DataSource = myDS.GetFindBookData(username, bookname);
        gvbook.DataKeyNames = new string[] { "n38_lost_id" };
        gvbook.DataBind();
    }
    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 ibtnok_Click(object sender, ImageClickEventArgs e)
    {
        if (tbuserid.Text == "")
        {
            Response.Write("<script>alert('请输入读者编号')</script>");
        }
        else
        {
            if (tbbookid.Text == "")
            {
                Response.Write("<script>alert('请输入图书编号')</script>");
            }
            else
            {
                N38_User myUser = new N38_User();
                N38_Book myBook = new N38_Book();
                N38_Config myConfig = new N38_Config();
                bool exit = myUser.UserExitByID(int.Parse(tbuserid.Text.Trim()));
                if (exit)
                {
                    string type = myUser.GetUserType(int.Parse(tbuserid.Text.Trim()));
                    int day = myConfig.GetBookDay(type);
                    gvbook.Visible = true;
                    BindData();
                }
                else
                {
                    Response.Write("<script>alert('用户不存在')</script>");
                }
            }
        }
    }
    protected void gvbook_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "find")
        {
            N38_User myUser = new N38_User();
            N38_Book myBook = new N38_Book();
            N38_BookOperate myBookOP = new N38_BookOperate();
            string username = myUser.GetUserName(int.Parse(tbuserid.Text.Trim()));
            string bookname = myBook.GetBookName(int.Parse(tbbookid.Text.Trim()));
            bool result=myBookOP.BookFind(username, bookname);
            if (result)
            {
                Response.Write("<script>alert('取消挂失成功')</script>");
                BindData();
            }
            else
                Response.Write("<script>alert('取消挂失失败')</script>");
        }
    }
}
