using System;
using System.Collections;
using System.Configuration;
using System.Data;
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.Web.UI.WebControls.WebParts;
using CRM.BLL;
using CRM.Model;
using CRM.Common;
using CRM.DBUtility;
using System.Data.SqlClient;


public partial class Pages_sxt_Moneys : System.Web.UI.Page
{
    protected void Bind()
    {
        string sql = "select * from 客户余额表 where 充值状态=1 and eid=" + Session["LoginID"].ToString();
        GridView1.DataSource = SqlHelper.ExecuteDataSet(SqlHelper.connstr, CommandType.Text, sql, null);
        GridView1.DataKeyNames = new string[] { "id"};
        GridView1.DataBind();

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        Bind();
    }
    protected void Button2_Click(object o, EventArgs e)
    {
        //string sql = "select top 1 * from 客户余额表 where eid=" + Session["LoginID"].ToString()+" order by id desc";
        //DataTable dt = SqlHelper.ExecuteDataSet(SqlHelper.connstr,CommandType.Text,sql,null).Tables[0];
        //if (dt.Rows.Count > 0)
        //{
        //    sql = "insert into 客户余额表(eid,充值,余额,可用余额) values(@eid,@充值,@余额,@可用余额)";
        //    try
        //    {
        //        SqlParameter[] paras = new SqlParameter[4];
        //        paras[0] = new SqlParameter("eid", Session["LoginID"].ToString());
        //        paras[1] = new SqlParameter("充值", decimal.Parse(TextBox1.Text.Trim()));
        //        paras[2] = new SqlParameter("余额", decimal.Parse(dt.Rows[0]["余额"].ToString()) + decimal.Parse(TextBox1.Text.Trim()));
        //        paras[3] = new SqlParameter("可用余额", decimal.Parse(dt.Rows[0]["可用余额"].ToString()) + decimal.Parse(TextBox1.Text.Trim()));
        //        SqlHelper.ExecuteNonQuery(SqlHelper.connstr, CommandType.Text, sql, paras);

        //        Bind();
        //    }
        //    catch
        //    {
        //        RegisterClientScriptBlock("", "<script language=javascript>alert('只允许输入数值，请检查!');</script>");
        //    }
        //}
        //else {
        //    sql = "insert into 客户余额表(eid,充值,余额,可用余额) values(@eid,@充值,@余额,@可用余额)";
        //    try
        //    {
        //        SqlParameter[] paras = new SqlParameter[4];
        //        paras[0] = new SqlParameter("eid", Session["LoginID"].ToString());
        //        paras[1] = new SqlParameter("充值", decimal.Parse(TextBox1.Text.Trim()));
        //        paras[2] = new SqlParameter("余额", decimal.Parse(TextBox1.Text.Trim()));
        //        paras[3] = new SqlParameter("可用余额", decimal.Parse(TextBox1.Text.Trim()));
        //        SqlHelper.ExecuteNonQuery(SqlHelper.connstr, CommandType.Text, sql, paras);

        //        Bind();
        //    }
        //    catch
        //    {
        //        RegisterClientScriptBlock("", "<script language=javascript>alert('只允许输入数值，请检查!');</script>");
        //    }
        //}

        string sql = "insert into 客户余额表(eid,充值) values(@eid,@充值)";
        try
        {
            SqlParameter[] paras = new SqlParameter[2];
            paras[0] = new SqlParameter("eid", Session["LoginID"].ToString());
            paras[1] = new SqlParameter("充值", decimal.Parse(TextBox1.Text.Trim()));
            SqlHelper.ExecuteNonQuery(SqlHelper.connstr, CommandType.Text, sql, paras);

            RegisterClientScriptBlock("", "<script language=javascript>alert('充值申请已提交，请等待处理!');</script>");

            Bind();
        }
        catch
        {
            RegisterClientScriptBlock("", "<script language=javascript>alert('只允许输入数值，请检查!');</script>");
        }
    
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        CRM.Common.Login.IsLogin();
        if (!IsPostBack)
        {
            Bind();
        }
    }
}
