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;
using Bll;

public partial class OrdersManage_LeaseManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		if (Convert.ToString(Session["username"]) == "")
		{
			Response.Write("<script language=javascript>alert('请登录');location='../login.aspx'</script>");
		}
		if(!IsPostBack)
		{
			this.Button2_Click(sender, e);
		}
    }

	protected void Button1_Click(object sender, EventArgs e)
	{
		Response.Write("<script>window.open('/OrdersManage/AddLeaseInfo.aspx','','width=550,height=450')</script>");
	}

	protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		GridView1.PageIndex = e.NewPageIndex;
		this.Button2_Click(sender, e);
	}

	protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
	{
		string id = GridView1.Rows[e.NewEditIndex].Cells[0].Text.ToString();
		OrdersBll ob = new OrdersBll();
		ob.QuitLease(id, Constext.Lease_In);
		this.Button2_Click(sender, e);
	}

	protected void Button2_Click(object sender, EventArgs e)
	{
		OrdersBll ob = new OrdersBll();
		if (Mobile.Text == "")
		{
			DataSet ds = ob.GetAllLeaseInfo();
			GridView1.DataSource = ds.Tables["LeaseInfo"];
			GridView1.DataBind();
		}
		else
		{
			string mobile = Request["Mobile"];
			if (Tools.validate(mobile))
			{
				Response.Write("<script>alert('请正确输入手机号！');histort.back()</script>");
			}
			DataSet ds = ob.GetSignLeaseInfo(mobile);
			GridView1.DataSource = ds.Tables["LeaseInfo"];
			GridView1.DataBind();
		}
	}

	protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
	{
		string id = GridView1.Rows[e.RowIndex].Cells[0].Text.ToString();
		OrdersBll ob = new OrdersBll();
		ob.DeleteLease(id);
		this.Button2_Click(sender, e);
	}
}
