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;

public partial class member_login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    /// <summary>
    /// 会员登录
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Fm.Bussiness.Fm_Admin_Login login = new Fm.Bussiness.Fm_Admin_Login();
        Fm.Bussiness.member member = new Fm.Bussiness.member();

        //将获取的密码进行加密
        string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(password.Text.Trim(), "MD5");
        //验证用户名的正误
        DataView ds = login.Admin_Login(username.Text.Trim(), pass) as DataView;
        if (ds.Count > 0)
        {
            //把用户名和用户名存储到Session会话中
            Session["membername"] = username.Text.Trim();
            Session["memberid"] = ds[0]["u_id"].ToString();
            //保存用户登录信息
            Fm.EntityClass.Login lo = new Fm.EntityClass.Login();
            lo.lo_user = username.Text.Trim();
            lo.lo_ip = Request.UserHostAddress.ToString();
            lo.lo_time = DateTime.Now;
            login.Login_Ip(lo);
            //查询所属角色组
            DataView dv = member.member_role(int.Parse(Session["memberid"].ToString()));
            if (dv.Count > 0)
            {
                //判断所属角色ID是否为管理组
                if (dv[0]["g_id"].ToString() == "1")
                {
                    //把角色ID存储到Session会话中
                    Session["rid"] = 0;
                }
                else
                {
                    Session["rid"] = dv[0]["r_id"].ToString();
                }
                Response.Redirect("main.aspx");
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('您无权登陆会员中心,请您联系网站管理员赋予您权限!');</script>");
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请输入正确的用户名和密码!');</script>");
        }
    }
}
