using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Account_LoanAccountInfo : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!this.Page.IsPostBack)
        {
            BindPage();
        }
    }
    #region 功能列表
    protected void btnAllAccount_Click(object sender, EventArgs e)//全部账户
    {
        Response.Redirect("Account.aspx");
    }
    protected void btnCashAccount_Click(object sender, EventArgs e)//现金账户
    {
        Response.Redirect("Account_Cash.aspx");
    }
    protected void btnCreditCard_Click(object sender, EventArgs e)//信用卡账户
    {
        Response.Redirect("Account_CreditCard.aspx");
    }
    protected void btnSavingsCard_Click(object sender, EventArgs e)//储蓄卡账户
    {
        Response.Redirect("Account_SavingsCard.aspx");
    }
    protected void btnOnlinPay_Click(object sender, EventArgs e)//网上支付
    {
        Response.Redirect("Account_OnlinePay.aspx");
    }
    protected void btnLoan_Click(object sender, EventArgs e)//借贷账户
    {
        Response.Redirect("Account_Loan.aspx");
    }
    #endregion
    /// <summary>
    /// 绑定借贷账户页面信息
    /// </summary>
    public void BindPage()
    {
        if (!string.IsNullOrEmpty(Request["laid"]))
        {
            DataSet ds = SqlHelper.GetDataSet("SELECT LoanAccountName,LoanAccountRemarks FROM dbo.tabA_Account_Loan WHERE State=1 AND LoanAccountId=" + ConvertHelper.GetInteger(Request["laid"]) + "", "constring");
            if(ds.Tables[0].Rows.Count>0)
            {
                txtLoanAccountName.Text = ConvertHelper.GetString(ds.Tables[0].Rows[0]["LoanAccountName"]);//借贷账户名称
                txtLoanAccountRemarks.Text = ConvertHelper.GetString(ds.Tables[0].Rows[0]["LoanAccountRemarks"]);//借贷账户备注
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request["laid"]))//编辑借贷账户
        {
            int flag = SqlHelper.Operation("UPDATE dbo.tabA_Account_Loan SET LoanAccountName='" + txtLoanAccountName.Text.Trim() + "',LoanAccountRemarks='" + txtLoanAccountRemarks.Text.Trim() + "',UpdateTime='" + System.DateTime.Now + "' WHERE LoanAccountId=" + ConvertHelper.GetInteger(Request["laid"]) + "", "constring");
            if (flag > 0)
            {
                Response.Redirect("Account_Loan.aspx");
            }
            else
            {
                ScriptHelper.AlertMessage(this.Page,"修改失败，请联系管理员！");
            }
        }
        else//添加借贷账户
        {
            int flag = SqlHelper.Operation("INSERT INTO dbo.tabA_Account_Loan(LoanAccountName,LoanAccountRemarks,UpdateTime) VALUES('"+txtLoanAccountName.Text.Trim()+"','"+txtLoanAccountRemarks.Text.Trim()+"','"+System.DateTime.Now+"')", "constring");
            if (flag > 0)
            {
                Response.Redirect("Account_Loan.aspx");
            }
            else
            {
                ScriptHelper.AlertMessage(this.Page,"添加失败，请联系管理员！");
            }
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Account_Loan.aspx");
    }
}