using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
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.Xml.Linq;
using LZBS.Model;
using LZBS.BLL;
using LZBS.Common;

namespace LZBS.Web
{
    public partial class Login1 : System.Web.UI.Page
    {
        M_SysLog mLog = new M_SysLog();
        B_SysLog bLog = new B_SysLog();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.UrlReferrer != null)
                    ViewState["UrlReferrer"] = Request.UrlReferrer.ToString();
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            M_Member model = new M_Member();
            B_Member bll = new B_Member();
            string Interval = ddlInterval.SelectedValue;
            //string prevPageUrl=System.Web.HttpContext.Current.Request.ServerVariables["HTTP_REFERER"].ToString();
            model.MemberID = txtMemberID.Text.Trim();
            model.Password = txtPwd.Text.Trim();
            if (bll.CheckMember(model) == true)
            {
                Response.Cookies["MemberID"].Value = model.MemberID;
                mLog.UserIP = ClientInfo.GetUserIP();
                mLog.URL = Request.Url.AbsoluteUri.ToString();
                mLog.Account = txtMemberID.Text.Trim();
                mLog.UserType = 1;
                mLog.OPInfo = "登录";
                bLog.AddLog(mLog);
                if (Convert.ToInt32(Interval) > 0)
                {
                    Response.Cookies["MemberID"].Expires = DateTime.Now.AddDays(Convert.ToInt32(Interval));
                }
                //如果从其他页面跳转过来的，登录之后跳转到原来页面，否则跳转到首页
                if (ViewState["UrlReferrer"] == null)
                    Response.Redirect("Index.aspx", true);
                else
                    Response.Redirect(ViewState["UrlReferrer"].ToString(), true);
            }
            else
            {
                MyMessageBox.MessageBox("账号或密码错误，请重试", this.Page);
            }
        }
        /// <summary>
        /// 找回密码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbQuestion_Click(object sender, EventArgs e)
        {
            if (txtMemberID.Text == "")
                MyMessageBox.MessageBox("请输入账号", this.Page);
            else
                Response.Redirect("SecurityQuestion.aspx?MemberID="+txtMemberID.Text.Trim());
        }
    }
}
