protected void LoginButton_Click(object sender, EventArgs e) { userBLL ubll = new userBLL(); string username = UserName.Text.Trim(), password = Password.Text.Trim(); System.Diagnostics.Debug.WriteLine("我是账户名" + username); HttpCookie oldcookie = Request.Cookies["preferences"]; if (oldcookie == null) { //测试登录功能 int[] result = ubll.login(username, password); if (result[0] >= 1) { info = "登陆成功"; HttpCookie cookie = new HttpCookie("Preferences"); cookie["username"] = username; cookie["userid"] = result[0].ToString(); cookie["role"] = result[1].ToString(); Session["userid"] = result[0].ToString(); Session["role"] = result[1].ToString(); Session["username"] = username; Response.Cookies.Add(cookie); //cookie有效1个月 cookie.Expires = DateTime.Now.AddMonths(1); //重定向到主页 Response.Redirect("~/Default.aspx"); } else if (result[0] == -1) { info = "密码错误"; Label1.Text = info; UpdatePanel1.Update(); } else { info = "账号不存在"; Label1.Text = info; UpdatePanel1.Update(); } System.Diagnostics.Debug.WriteLine(info); } }
protected void Button1_Click(object sender, EventArgs e) { string oldpsw = TextBox1.Text.Trim(); string newpsw = TextBox2.Text.Trim(); userBLL ubll = new userBLL(); string username = Session["username"].ToString().Trim(); int result = ubll.login(username, oldpsw)[0]; if (result >= 1) { int userID = Convert.ToInt32(Session["userid"]); if (ubll.changePsw(userID, newpsw) >=1) { Label4.Text = "修改成功"; UpdatePanel1.Update(); } } else { Label4.Text = "旧密码错误"; UpdatePanel1.Update(); } }
protected void CreateUserButton_Click(object sender, EventArgs e) { userBLL ubll = new userBLL(); string username = UserName.Text.Trim(); string password = Password.Text.Trim(); string name = Name.Text; string phone = Phone.Text; string email = Email.Text; string address = Address.Text; bool isCustomer = customerRadio.Checked; if (isCustomer) { if (ubll.registerAsCustonmer(username, password, name, phone, email, address) == 1) { HttpCookie cookie = new HttpCookie("Preferences"); cookie["username"] = username; userAccess ua = new userAccess(); User u = ua.SelectUserByName(username); cookie["userid"] = u.userID.ToString(); cookie["role"] = u.role.ToString(); Session["userid"] = u.userID.ToString(); Session["role"] = u.role.ToString(); Session["username"] = username; Response.Cookies.Add(cookie); //cookie有效1个月 cookie.Expires = DateTime.Now.AddMonths(1); //重定向到主页 Response.Redirect("~/Default.aspx"); } else { Label1.Text = "注册失败,请尝试使用另一个用户名注册"; UpdatePanel1.Update(); } } else { if (ubll.registerAsSeller(username, password, name, phone, email, address) == 1) { HttpCookie cookie = new HttpCookie("Preferences"); cookie["username"] = username; userAccess ua = new userAccess(); User u = ua.SelectUserByName(username); cookie["userid"] = u.userID.ToString(); cookie["role"] = u.role.ToString(); Session["userid"] = u.userID.ToString(); Session["role"] = u.role.ToString(); Session["username"] = username; Response.Cookies.Add(cookie); //cookie有效1个月 cookie.Expires = DateTime.Now.AddMonths(1); Directory.CreateDirectory(Server.MapPath("~/File/" + u.userID.ToString())); //重定向到主页 Response.Redirect("~/Default.aspx"); } else { Label1.Text = "注册失败,请尝试使用另一个用户名注册"; UpdatePanel1.Update(); } } }