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 System.Data.SqlClient;
using Bll;

public partial class OrdersManage_AddLeaseInfo : 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>");
		}
		DropDownList1.Attributes.Add("OnClick", "Values()");
    }


	protected void query_Click(object sender, EventArgs e)
	{
		string moblie = Request["TextBox4"].ToString();
		if (moblie == "")
		{
			Response.Write("<script>alert('请输入客户电话!')</script>");
			return;
		}
		if (Tools.validate(moblie))
		{
			Response.Write("<script>alert('手机号中不能有非法字符')</script>");
		}
		OrdersBll ob = new OrdersBll();
		SqlDataReader sr = ob.GetReader(moblie);
		int essclr = ob.GetExcuteScal(moblie);
		if (essclr > 0)
		{
			if(sr.Read())
			{
				this.Clear();
				clientno.Text = sr["id"].ToString();
				name.Text = sr[3].ToString();
				type.Text = sr[1].ToString();
				area.Text = sr[0].ToString();
				mobile.Text = sr["mobile"].ToString();
				address.Text = sr["address"].ToString();
			}
			ob.Close();
		}
		else
		{
			Response.Write("<script>window.open('/SystemManage/AddClientInfo.aspx','','width=450,height=250')</script>");
		}
	}


	protected void Button3_Click(object sender, EventArgs e)
	{
		OrdersBll ob = new OrdersBll();
		string productName = Request["productName"];//产品名
		int Amount = Request["Amount"] == "" ? 0 : Convert.ToInt32(Request["Amount"]);//数量
		decimal foregift = Request["foregift"] == "" ? 0 : Convert.ToDecimal(Request["foregift"]);//押金
		decimal monthPrice = Request["monthPrice"] == "" ? 0 : Convert.ToDecimal(Request["monthPrice"]);//月租
		string Mome = Request["Mome"];//备注
		int id = clientno.Text == "" ? 0 : Convert.ToInt32(clientno.Text);//用户ID
		if(id == 0)
		{
			Response.Write("<script>alert('请先选择客户!');history.back()</script>");
			return;
		}
		try
		{
			ob.AddLeaseInfo(id, productName, Amount, foregift, monthPrice, DateTime.Now, Constext.Lease_Out, Mome);
            Response.Write("<script>alert('保存成功!');opener.location='LeaseManage.aspx';window.close()</script>");
		}
		catch
		{
			Response.Write("<script>alert('出错了!');history.back()</script>");
		}
	}

	public void Clear()
	{
		clientno.Text = "";
		name.Text = "";
		type.Text = "";
		area.Text = "";
		mobile.Text = "";
		address.Text = "";
	}
}
