日期:2014-05-17 浏览次数:20466 次
/// <summary> /// 用户登录时查询 /// </summary> /// <param name="uname"></param> /// <param name="pwd"></param> /// <returns></returns> public string[] Login_Sel(string uname, string pwd) { try { SqlParameter[] parm = { SqlHelper.CreateCommandParameter("@uname",SqlDbType.NVarChar,uname), SqlHelper.CreateCommandParameter("@pwd",SqlDbType.NVarChar,pwd) }; string str = "select * from Users where uname=@uname and pwd=@pwd"; cmd = SqlHelper.CreateDbCommand(str, conn); cmd.Parameters.AddRange(parm); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); string[] result = new string[5]; if (dr.Read()) { result[0] = dr["uname"].ToString(); result[1] = dr["truename"].ToString(); result[2] = dr["qx"].ToString(); result[4] = dr["dptid"].ToString(); return result; } else { return null; } } catch (Exception e) { throw e; } finally { conn.Close(); } } //登录按钮,取的用户信息相当详细 protected void IBLogin_Click(object sender, ImageClickEventArgs e) { Users u = new Users(); string uname =TextUname.Text.Trim(); string pwd = TextUpwd.Text.Trim(); string lasttime = u.LastLoginTime(); string nowtime = DateTime.Now.ToString("yyyy-MM-dd"); string last2time = u.Last2Time(); if (DateTime.Parse(lasttime) <= DateTime.Parse(nowtime)&&DateTime.Parse(lasttime)>=DateTime.Parse(last2time)) { if (DateTime.Parse(nowtime) < DateTime.Parse("2012-08-1")) { if (u.Login_Sel(uname, pwd) != null) { string logintime = DateTime.Now.ToString("yyyy-MM-dd"); u.Add_LoginTime(logintime); string[] result = new string[3]; result = u.Login_Sel(uname, pwd); Session["truename"] = result[1].ToString(); Session["uname"] = result[0].ToString(); Session["qx"] = result[2].ToString(); Session["dptid"] = result[4].ToString(); Response.Redirect("Index.aspx"); } else { Common.ShowMessage.Show(Page, "seuss", "用户名或密码不正确", "Login.aspx"); TextUname.Text = ""; TextUpwd.Text = ""; } } else { Common.ShowMessage.Show(Page, "s