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_ClientManage : 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);
		}
	}

	/// <summary>
	/// 加载数据
	/// </summary>
	public void Bind()
	{ 
		OrdersBll ob=new OrdersBll();
		DataSet ds = ob.GetAllClientInfo();
		GridView1.DataSource = ds.Tables["Client"];
		GridView1.DataBind();
	}

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

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

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

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


    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        OrdersBll ob = new OrdersBll();
        string id = GridView1.Rows[e.NewEditIndex].Cells[0].Text.ToString();
        Response.Write("<script>window.open('client_open.aspx?id=" + id + "','','width=450,height=250')</script>");
        Response.Write("<script>location='javascript:history.go(-1)'</script>");
    }
}
