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_ProjectTypeInfo : 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["ptid"]))
        {
            DataSet ds = SqlHelper.GetDataSet("SELECT ProjectTypeName FROM dbo.tabA_Type_Project WHERE ProjectTypeId=" + ConvertHelper.GetInteger(Request["ptid"]) + "", "constring");
            if(ds.Tables[0].Rows.Count>0)
            {
                txtProjectTypeName.Text = ConvertHelper.GetString(ds.Tables[0].Rows[0]["ProjectTypeName"]);//项目名
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if(!string.IsNullOrEmpty(Request["ptid"]))//修改项目
        {
            int flag = SqlHelper.Operation("UPDATE dbo.tabA_Type_Project SET ProjectTypeName='" + txtProjectTypeName.Text.Trim() + "' WHERE ProjectTypeId=" + ConvertHelper.GetInteger(Request["ptid"]) + "", "constring");
            if(flag>0)
            {
                Response.Redirect("ProjectType.aspx");
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"","<script language='javascript' defer>alert('修改失败，请联系管理员！')</script>");
            }
        }
        else//添加项目
        {
            int flag = SqlHelper.Operation("INSERT INTO dbo.tabA_Type_Project(ProjectTypeName,CreateTime) VALUES('"+txtProjectTypeName.Text.Trim()+"','"+System.DateTime.Now+"')", "constring");
            if (flag > 0)
            {
                Response.Redirect("ProjectType.aspx");
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"","<script language='javascript' defer>alert('添加失败，请联系管理员！')</script>");
            }
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("ProjectType.aspx");
    }
}
