using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNet.FrameWork.Data;
using DotNet.FrameWork.Common.Web;
using DotNet.FrameWork.Utils;
using System.Data.SqlClient;
using System.Data;

namespace HteamDd.Web.Web.Dd_Eamil_active
{
    public partial class Dd_reg_is_active : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //ActiveUser("11", "/Dd_login.aspx", "2011-08-23 08:57:56.130");
                if (Fetch.Get("action") != "tdc%BDF%lhhy%ghdifs%dfgr" && Fetch.Get("userguid") != "")
                {
                    ActiveUser(Fetch.Get("userguid"), "/Dd_login.aspx", Fetch.Get("time"));
                }
                if (Fetch.Get("userguid") != "")
                {
                    ActiveUser(Fetch.Get("userguid"), "/Dd_login.aspx", Fetch.Get("time"));
                }
            }
        }

        public void ActiveUser(string user_id, string url,string time)
        {
            //SqlParameter ID = new SqlParameter("@ID",SqlDbType.Int);
            // SqlParameter create_time= new SqlParameter("@time",SqlDbType.DateTime);
            // ID.Value = user_id;
            // create_time.Value = time;
            // IDataParameter[] par = new IDataParameter[] { ID, create_time};
            //SqlDataReader sdr = DbHelperSQL.RunProcedure("SP_time", par);
            //string mes = string.Empty;
            //while (sdr.Read())
            //{
            //    mes = sdr.GetValue(0).ToString();
            //}

            int active_state =Convert.ToInt32( DbHelperSQL.GetSingle("select User_ActivCondition from Dd_User where User_ID=" + user_id + ""));
            if (active_state ==1)
            {
                Jscript.ShowAndRedirect(this, "您已使用过该链接或激活链接已过期！", url);
                return;
            }
            else
            {
                string strsql = "update Dd_User set User_ActivCondition=1 where User_ID=" + user_id + "";
                DbHelperSQL.ExecuteSql(strsql);
                Jscript.AlertAndRedirect("激活成功！",url);
            }
           
        }

        private bool Get_Uerguid(string ID)
        {
            string sql_guid = "select User_Guid from Dd_User where User_Email=@email";
            SqlParameter Parms = new SqlParameter("@email", SqlDbType.NVarChar, 50);
            Parms.Value = ID;
            return DbHelperSQL.GetExists(sql_guid, Parms);
        }

    }
}