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 LeaseManage_LeaseManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
		ExpenseManage em=new ExpenseManage();
		if (Convert.ToString(Session["username"]) == "")
		{
			Response.Write("<script language=javascript>alert('请登录');location='../login.aspx'</script>");
			return;
		}
		if (!IsPostBack)
		{
			this.Button2_Click(sender, e);
		}
    }

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

	//public void Bind()
	//{
	//    Bll.ExpenseManage em = new Bll.ExpenseManage();
	//    DataSet ds = em.ReturnDataSet();
	//    Gridview1.DataSource = ds.Tables["Expense"];
	//    Gridview1.DataBind();
	//}

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

	protected void Gridview1_RowDeleting(object sender, GridViewDeleteEventArgs e)
	{
		string id = Gridview1.Rows[e.RowIndex].Cells[0].Text.ToString();
		ExpenseManage em =new ExpenseManage();
		em.Delete(id);
		this.Button2_Click(sender, e);
	}

	protected void Button2_Click(object sender, EventArgs e)
	{
		string day = Day.Text;
		string month = Month.Text;
		Bll.ExpenseManage em = new Bll.ExpenseManage();
		DataSet ds = em.ReturnDataSet(day, month);
		Gridview1.DataSource = ds.Tables["Expense"];
		Gridview1.DataBind();

		string daytime = Day.Text == "" ? "1900-1-1" : Day.Text.Trim();
		string monthtime = Month.Text == "" ? "1900-1-1" : Month.Text.Trim();
		Label1.Text = "";
		int amount = em.GetAllExpenses(Convert.ToDateTime(daytime), Convert.ToDateTime(monthtime));
		Label1.Text = amount.ToString();
		this.ClearTextBoxt();
	}

	private void ClearTextBoxt()
	{
		this.Day.Text = "";
		this.Month.Text = "";
	}
}
