//插入 登录记录 public bool save(LoginMarks lm) { string sql = "insert into t_LoginMarks(userId,userName,loginTime) values(" + lm.userId + ",'" + lm.userName + "','" + lm.loginTime + "')"; int flag = DBHelper.ExecuteSQL(sql); if (flag == 1) { return true; } else { return false; } }
protected void btnLogin_Click(object sender, EventArgs e) { //验证登陆 string txtName = txtUserName.Text; string txtPwd = txtUserPwd.Text; if (txtName == null || txtName.Trim().Equals("")) { labInfo.Text = "友情提示:用户名不能为空"; return; } if (txtPwd == null || txtPwd.Trim().Length < 6) { labInfo.Text = "友情提示:密码长度不能小于6位"; return; } UserBLL userbll = new UserBLL(); User u = userbll.Login(txtName, txtPwd); if (u == null) { labInfo.Text = "友情提示:用户名或密码错误"; } else { //Loginmark LoginMarksBLL lmb = new LoginMarksBLL(); LoginMarks lm = new LoginMarks(); lm.userId = u.userId; lm.userName = u.userName; lm.loginTime = DateTime.Now; if (lmb.save(lm)) { Session["user"] = u; Response.Redirect("MainForm.aspx"); } } }
//插入 登录记录 public bool save(LoginMarks lm) { return(dll.save(lm)); }
//根据sql查询登录信息 IList<LoginMarks> GetLoginMarksBySql(string sql) { SqlDataReader reader = DBHelper.ExecuteReader(sql); IList<LoginMarks> LoginMarks = new List<LoginMarks>(); try { while (reader.Read()) { LoginMarks lm = new LoginMarks(); lm.markId= Convert.ToInt32(reader["markId"]); lm.userId = Convert.ToInt32(reader["userId "]); lm.userName = reader["userName"].ToString(); lm.loginTime = (DateTime)reader["loginTime"]; LoginMarks.Add(lm); } } catch (Exception) { throw; } finally { if (reader != null) { reader.Close(); } } return LoginMarks; }