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 CRM.BLL;
using CRM.Model;
using CRM.Common;
using CRM.DBUtility;
using System.Data.SqlClient;

public partial class Pages_sxt_Moneys4 : System.Web.UI.Page
{
    protected void Bind()
    {
        string sql = "select * from 客户余额表  order by 日期 desc";
        GridView1.DataSource = SqlHelper.ExecuteDataSet(SqlHelper.connstr, CommandType.Text, sql, null);
        GridView1.DataKeyNames = new string[] { "id" };
        GridView1.DataBind();

        string sql2 = "select * from 短信价格表";
        DataTable dt = SqlHelper.ExecuteDataSet(SqlHelper.connstr, CommandType.Text, sql2, null).Tables[0];
        if (dt.Rows.Count > 0)
        {
            Label1.Text = dt.Rows[0]["price"].ToString();
        }

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        Bind();
    }
    protected void Button2_Click(object o, EventArgs e)
    {
        string sql = "update 短信价格表 set price=@price where id=1";
        try
        {
            SqlParameter para = new SqlParameter("price", decimal.Parse(TextBox1.Text.Trim()));
            SqlHelper.ExecuteNonQuery(SqlHelper.connstr, CommandType.Text, sql, para);

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

    public string GetClientMobile(string eid)
    {
        string sql = "select 手机 from 员工表 where eid=" + eid;
        object obj = SqlHelper.ExecuteScalar(SqlHelper.connstr, CommandType.Text, sql, null);
        if (null == obj)
        {
            return "";
        }
        return obj.ToString();
    }

    public string GetTotleMoney(string eid)
    {
        string sql = "select sum(充值) from 客户余额表 where 充值状态='1' and eid=" + eid;
        object obj = SqlHelper.ExecuteScalar(SqlHelper.connstr, CommandType.Text, sql, null);
        if (null == obj)
        {
            return "";
        }
        return obj.ToString();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        CRM.Common.Login.IsLogin();
        if (!IsPostBack)
        {
            Bind();
        }
    }
}
