/// <summary> /// 得到一个对象实体 /// </summary> public M_td_LoginInfo DataRowToModel(DataRow row) { M_td_LoginInfo model = new M_td_LoginInfo(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["AdminUserName"] != null) { model.AdminUserName = row["AdminUserName"].ToString(); } if (row["Pwd"] != null) { model.Pwd = row["Pwd"].ToString(); } if (row["LoginTime"] != null && row["LoginTime"].ToString() != "") { model.LoginTime = DateTime.Parse(row["LoginTime"].ToString()); } if (row["LoginIP"] != null) { model.LoginIP = row["LoginIP"].ToString(); } if (row["LoginSuccess"] != null && row["LoginSuccess"].ToString() != "") { model.LoginSuccess = int.Parse(row["LoginSuccess"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(M_td_LoginInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into hx_td_LoginInfo("); strSql.Append("AdminUserName,Pwd,LoginTime,LoginIP,LoginSuccess)"); strSql.Append(" values ("); strSql.Append("@AdminUserName,@Pwd,@LoginTime,@LoginIP,@LoginSuccess)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@AdminUserName", SqlDbType.VarChar, 50), new SqlParameter("@Pwd", SqlDbType.VarChar, 50), new SqlParameter("@LoginTime", SqlDbType.DateTime), new SqlParameter("@LoginIP", SqlDbType.VarChar, 20), new SqlParameter("@LoginSuccess", SqlDbType.Int, 4) }; parameters[0].Value = model.AdminUserName; parameters[1].Value = model.Pwd; parameters[2].Value = model.LoginTime; parameters[3].Value = model.LoginIP; parameters[4].Value = model.LoginSuccess; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(M_td_LoginInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update hx_td_LoginInfo set "); strSql.Append("AdminUserName=@AdminUserName,"); strSql.Append("Pwd=@Pwd,"); strSql.Append("LoginTime=@LoginTime,"); strSql.Append("LoginIP=@LoginIP,"); strSql.Append("LoginSuccess=@LoginSuccess"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@AdminUserName", SqlDbType.VarChar, 50), new SqlParameter("@Pwd", SqlDbType.VarChar, 50), new SqlParameter("@LoginTime", SqlDbType.DateTime), new SqlParameter("@LoginIP", SqlDbType.VarChar, 20), new SqlParameter("@LoginSuccess", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.AdminUserName; parameters[1].Value = model.Pwd; parameters[2].Value = model.LoginTime; parameters[3].Value = model.LoginIP; parameters[4].Value = model.LoginSuccess; parameters[5].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public M_td_LoginInfo GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,AdminUserName,Pwd,LoginTime,LoginIP,LoginSuccess from hx_td_LoginInfo "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; M_td_LoginInfo model = new M_td_LoginInfo(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
public ActionResult DoLogin(string txtUserName, string txtPassword, string txtCheckCode) { B_td_adminuser o = new B_td_adminuser(); M_td_adminuser p = new M_td_adminuser(); B_td_LoginInfo b1 = new B_td_LoginInfo(); M_td_LoginInfo m1 = new M_td_LoginInfo(); string username1 = null; string userpass1 = null; string code = null; if (Request.Form["txtUserName"] != null) { username1 = Utils.CheckSQLHtml(Request.Form["txtUserName"].ToString()); } if (Request.Form["txtPassword"] != null) { userpass1 = Utils.CheckSQLHtml(Request.Form["txtPassword"].ToString()); } if (Request.Form["txtCheckCode"] != null) { code = Utils.CheckSQLHtml(Request.Form["txtCheckCode"].ToString()); } userpass1 = Utils.MD5(userpass1); #region 检查验证码 if (Session["CheckCode"] != null) { if (code != Session["CheckCode"].ToString()) { //CommonOperate.Show_Msg("验证码不正确"); //Response.End(); return(Content(StringAlert.Alert("验证码不正确"), "text/html")); } else { } } else { //CommonOperate.Show_Msg("验证码过期"); //Response.End(); return(Content(StringAlert.Alert("验证码过期"), "text/html")); } #endregion string ip = Utils.GetRealIP(); int adminuserid = o.Check_userpass(username1, userpass1, ip); if (adminuserid > 0) { p = o.GetModel(adminuserid); Session["username"] = p.adminuser.ToString(); Session["userid_gpt"] = p.adminuserid.ToString(); //Session["area"] = p.Areacode.ToString(); //Session["purview"] = p.Purview.ToString(); Session["adminuserid"] = adminuserid.ToString(); ///添加登录日志 m1.AdminUserName = username1; m1.Pwd = "***"; m1.LoginSuccess = 1; m1.LoginIP = Request.UserHostAddress; b1.Add(m1); //Response.Redirect("Deflault.aspx"); return(RedirectToAction("Index", "default")); } else { ///添加登录日志 m1.AdminUserName = username1; m1.Pwd = userpass1; m1.LoginSuccess = 0; m1.LoginIP = Request.UserHostAddress; b1.Add(m1); //Response.Redirect("login.aspx"); return(RedirectToAction("Index", "Login")); } }