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_OrdersManage : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		DropDownList1.Attributes.Add("OnClick", "bind()");
		DropDownList2.Attributes.Add("OnClick","bind1()");
		if (Convert.ToString(Session["username"]) == "")
		{
			Response.Write("<script language=javascript>alert('请登录');location='../login.aspx'</script>");
		}
		if(!IsPostBack)
		{
			this.Button5_Click(sender,e);
			this.Inistans();
			//OrdersBll ob=new OrdersBll();
			//Label1.Text = ob.ToDayOrder().ToString();
			//Label2.Text = ob.ToDayDeliveryOrder().ToString();
			//int aa = ob.ToDayOrder() - ob.ToDayDeliveryOrder();
			//Label3.Text = aa.ToString();
			//Label4.Text =  ob.ToDayGathering().ToString();
			//int bb = ob.ToDayCopeMoney() - ob.ToDayGathering();
			//Label5.Text = bb.ToString();
		}
	}

	/// <summary>
	/// 页面初始化
	/// </summary>
    //public void Bind()
    //{
    //    DataSet ds = new DataSet();
    //    OrdersBll ob=new OrdersBll();
    //    ds = ob.GetOrdersInfo();
    //    GridView1.DataSource = ds.Tables["Orders"];
    //    GridView1.DataBind();
    //}

	/// <summary>
	/// 页面初始化数据
	/// </summary>
	public void Inistans()
	{
		AreaBusniss ab = new AreaBusniss();
		DataSet ds = ab.GetAllArea();
		DropDownList1.DataSource = ds.Tables[0];
		DropDownList1.DataTextField = "NAME";
		DropDownList1.DataBind();
	}

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

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

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

	protected void Button5_Click(object sender, EventArgs e)
	{
		string area = Area.Text.ToString() == "" ? "" : Area.Text.ToString();
		string mobile = Mobile.Text.ToString() == "" ? "" : Mobile.Text.ToString();
		string day = Day.Text == "" ? "1900-1-1" : Day.Text;
		string month = Month.Text == "" ? "1900-1-1" : Month.Text;
		string startTime = StartTime.Text == "" ? "1900-1-1" : StartTime.Text;
		string overTime = OverTime.Text == "" ? "1900-1-1" : OverTime.Text;
		int number = DayNumber.Text == "" ? Convert.ToInt32("0") : Convert.ToInt32(DayNumber.Text);
		string address = Address.Text == "" ? "" : Address.Text;
        bool notDelivery = NotDelivery.Checked;
		bool NotMoney = CheckBox1.Checked;
        bool qian_money = CheckBox2.Checked;
        bool qian_bottle = CheckBox3.Checked;

		OrdersBll ob = new OrdersBll();
		DataSet ds = new DataSet();
        ds = ob.GetOrdersInfo(Convert.ToDateTime(day), Convert.ToDateTime(month), Convert.ToDateTime(startTime), Convert.ToDateTime(overTime), mobile, area, number, address, notDelivery, NotMoney, qian_money, qian_bottle);
		GridView1.DataSource = ds.Tables["Orders"];
		GridView1.DataBind();

		Label1.Text = ob.OrderNumber(Convert.ToDateTime(day), Convert.ToDateTime(month), Convert.ToDateTime(startTime), Convert.ToDateTime(overTime)).ToString();
		Label3.Text = ob.DeliveryOrder(Convert.ToDateTime(day), Convert.ToDateTime(month), Convert.ToDateTime(startTime), Convert.ToDateTime(overTime)).ToString();
		int i = ob.OrderNumber(Convert.ToDateTime(day), Convert.ToDateTime(month), Convert.ToDateTime(startTime), Convert.ToDateTime(overTime)) - ob.DeliveryOrder(Convert.ToDateTime(day), Convert.ToDateTime(month), Convert.ToDateTime(startTime), Convert.ToDateTime(overTime));
		Label2.Text = i.ToString();
		Label4.Text = ob.Gathering(Convert.ToDateTime(day), Convert.ToDateTime(month), Convert.ToDateTime(startTime), Convert.ToDateTime(overTime)).ToString();

		//this.ClearTextBoxContext();
	} 

	public void ClearTextBoxContext()
	{
		Area.Text = "";
		Mobile.Text = "";
		Day.Text = "";
		Month.Text = "";
		StartTime.Text = "";
		OverTime.Text = "";
		DayNumber.Text = "";
		Address.Text = "";
        //NotDelivery.Checked = false;

	}
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("PrintOrderBill.aspx");
    }
}
