using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class AccountType_IncomeTypeInfo : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!this.Page.IsPostBack)
        {
            BindPage();
        }
    }
    #region 功能列表
    protected void btnExpenditureType_Click(object sender, EventArgs e)//支出类型
    {
        Response.Redirect("ExpenditureType.aspx");
    }
    protected void btnIncomeType_Click(object sender, EventArgs e)//收入类型
    {
        Response.Redirect("IncomeType.aspx");
    }
    protected void btnProjectType_Click(object sender, EventArgs e)//项目
    {
        Response.Redirect("ProjectType.aspx");
    }
    protected void btnSeller_Click(object sender, EventArgs e)//商家/付款方
    {
        Response.Redirect("Seller.aspx");
    }
    #endregion
    /// <summary>
    /// 绑定页面信息
    /// </summary>
    public void BindPage()
    {
        if (!string.IsNullOrEmpty(Request["itid"]))
        {
            DataSet ds = SqlHelper.GetDataSet("SELECT IncomeTypeName FROM dbo.tabA_Type_Income WHERE IncomeTypeId="+ConvertHelper.GetInteger(Request["itid"])+" AND State=1", "constring");
            if(ds.Tables[0].Rows.Count>0)
            {
                txtIncome.Text = ConvertHelper.GetString(ds.Tables[0].Rows[0]["IncomeTypeName"]);//收入类型名
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if(!string.IsNullOrEmpty(Request["itid"]))//修改收入类型
        {
            int flag = SqlHelper.Operation("UPDATE dbo.tabA_Type_Income SET IncomeTypeName='" + txtIncome.Text.Trim() + "' WHERE IncomeTypeId="+ConvertHelper.GetInteger(Request["itid"])+"", "constring");
            if (flag > 0)
            {
                //Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"","<script language='javascript' defer>alert('修改成功！')</script>");
                Response.Redirect("IncomeType.aspx");
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"","<script language='javascript' defer>alert('修改失败，请联系管理员！')</script>");
            }
        }
        else//添加收入类型
        {
            int flag = SqlHelper.Operation("INSERT INTO dbo.tabA_Type_Income(IncomeTypeName,CreateTime) VALUES('"+txtIncome.Text.Trim()+"','"+System.DateTime.Now+"')","constring");
            if(flag>0)
            {
                Response.Redirect("IncomeType.aspx");
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"","<script language='javascript' defer>alert('修改失败，请联系管理员！')</script>");
            }
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("IncomeType.aspx");
    }
}
