using MESClassLibrary.BLL.Log; using MESClassLibrary.BLL.User; using MESClassLibrary.Model; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace MESWebSite { public partial class Login : System.Web.UI.Page { UserBLL userclass = new UserBLL(); UserModel md = new UserModel(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { } } /// /// 登录按钮 /// /// /// protected void btnLogin_Click(object sender, EventArgs e) { try { string _loginName = this.LoginName.Text.Trim(); string _loginpassword = this.LoginPassword.Text.Trim(); UserNameLogin(_loginName, _loginpassword); } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); } } /// /// 登录方法 /// /// /// public void UserNameLogin(string _loginName, string _loginpassword) { try { md.Username = _loginName; md.Password = _loginpassword; if (userclass.Login(md)) { DataTable dt_user = new DataTable(); dt_user = userclass.SearchUserInfoByUserName(md.Username); HttpCookie cookie = new HttpCookie("LoginUserInfo"); cookie["UserID"] = dt_user.Rows[0]["UserID"].ToString().Trim(); cookie["UserName"] = _loginName; cookie["PassWord"] = _loginpassword; cookie["RealName"] = HttpUtility.UrlEncode(dt_user.Rows[0]["RealName"].ToString().Trim(), System.Text.Encoding.UTF8); //cookie.Expires = DateTime.Now.AddDays(14); Response.Cookies.Add(cookie); Response.Redirect("Manage/index.aspx", false); } else { ClientScript.RegisterStartupScript(ClientScript.GetType(), "错误", ""); } #region 注销 //if (userclass.Login(md)) //{ // #region 下次自动登录-暂时注销 // //if (AutoLogin.Checked) // //{ // // HttpCookie cookie = new HttpCookie("LoginUserInfo"); // // cookie["UserName"] = _loginName; // // cookie["PassWord"] = _loginpassword; // // cookie.Expires = DateTime.Now.AddDays(14); // // Response.Cookies.Add(cookie); // //} // //Session.Add("LoginUserInfo", md); // #endregion // Response.Redirect("Manage/index.aspx", false); //} //else //{ // ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", ""); //} #endregion } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); } } } }