using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Picascx_Login : System.Web.UI.UserControl
{
    DataBaseLayer db = new DataBaseLayer();
    protected void Page_Load(object sender, EventArgs e)
    { 
        if (!IsPostBack)
        {
            msgshow.Visible = false;
            if (Session["UserID"] == null)
            {
                UserLogin.Visible = true;
                UserShow.Visible = false;
            }
            else
            {
                UserLogin.Visible =false;
                UserShow.Visible = true;
            }
           
        }

    }
    protected void Register_Click(object sender, EventArgs e)
    {
        Response.Redirect("register.aspx");

    }
    protected void Login1_Click(object sender, EventArgs e)
    {
        string userName = UserName.Text.Trim();
        string password = PassWord.Text.Trim();

        SqlParameter[] prams ={db.ParamBuilder("@USERNAME",userName,SqlDbType.VarChar),
            db.ParamBuilder("@PASSWORD",md5Password(password),SqlDbType.VarChar)
        };
        SqlDataReader dr = db.DataReader("Pr_Mp4_CheckUser", prams);
        if (dr.Read())
        {
            Session["UserID"] = dr["UserID"];
            Session["UserName"] = dr["UserName"];
            Session["Point"] = dr["Point"];
            UserLogin.Visible = false;
            UserShow.Visible = true;
            dr.Dispose();
        }
        else
        {
            msgshow.Visible = true;
            ShowMsg.Text = "<font color=red>用户名或密码错误!</font>";
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        UserLogin.Visible = true;
        UserShow.Visible = false;
        Session["UserName"] = "";
        UserName.Text = "";
        msgshow.Visible = false;
    }
    public string md5Password(string password)
    {
        string sPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");
        return sPassword;
    }
}
