public void ProcessRequest(HttpContext context) { BLL.HKSJ_USERS userServices = new BLL.HKSJ_USERS(); context.Response.ContentType = "text/plain"; //获取参数实现用户的添加 Model.HKSJ_USERS users = new Model.HKSJ_USERS(); //UserName,LoginName,Password,Plane,Phone,Email,CardNo; users.UserName = context.Request["UserName"]; users.LoginName = context.Request["LoginName"]; users.PassWord = context.Request["Password"]; users.Plane = context.Request["Plane"]; users.phone = context.Request["Phone"]; users.Mail = context.Request["Email"]; users.cardNo = context.Request["CardNo"]; //实现给数据库中添加数据 if (userServices.Add(users) > 0) { context.Response.Write("OK"); } else { context.Response.Write("error"); } }
/// <summary> /// 本来想写从服务端获取数据显示在前台上面的,但是没有实现功能 /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //获取ID信息 int ID = context.Request["ID"] == null ? 0 : Convert.ToInt32(context.Request["ID"]); //获取为ID的实体对象 BLL.HKSJ_USERS userServices = new BLL.HKSJ_USERS(); var data = userServices.GetModel(ID); //将Json集合转换成字符串 JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); var jsonlist = javaScriptSerializer.Serialize(data); context.Response.Write(jsonlist); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //首先判断用户是否已经登陆 if (context.Session["user"] == null) { context.Response.Write("请您正常操作"); return; } //构造出使用easyUI显示的用户信息的Json数据 //首先计算出User用户的集合 BLL.HKSJ_USERS userServices = new BLL.HKSJ_USERS(); //var list = userServices.GetModelList(string.Empty); //获取easyUI分页的参数page:1,rows:30 int pageIndex = context.Request["page"] == null ? 1 : Convert.ToInt32(context.Request["page"]); int pageSize = context.Request["rows"] == null ? 10 : Convert.ToInt32(context.Request["rows"]); //计算出总的数量为了给easyUI控件实现分页 int total = userServices.GetRecordCount(string.Empty); var list = userServices.GetPageSizeNav(pageIndex, pageSize, out total); //{ // "total":239, // "rows":[ // {"code":"001","name":"Name 1","addr":"Address 11","col4":"col4 data"}, // ] //} //计算出分页的总数 //使用匿名类来实现前台要求的Json格式,序列化为此格式 var data = new { total = total, rows = list }; //将data集合构造成Json字符串 JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); string json = javaScriptSerializer.Serialize(data); context.Response.Write(json); }
//登入后保存用户名,第二次自动显示 protected void Page_Load(object sender, EventArgs e) { //第一次访问是地址栏访问 //第二次是表单提交访问,即下面的if //如果是表单提交 if (IsPostBack) { //能到这里说明,是第二次访问,而不是第三第四次,因为如果已经登入在Page_Init处理过了 string userName = Context.Request["account"]; string passWord=Context.Request["pwd"]; #region 处理Cookie //把用户名保存到Cookie //解决中文乱码 Context.Response.Cookies["UserName"].Value = Server.UrlDecode(userName); //设置生命周期 Context.Response.Cookies["UserName"].Expires = DateTime.Now.AddSeconds(10); UserName = userName; #endregion #region 校验验证码 string validateCode = Request["captcha"]; //如果验证码错误 if (validateCode != Session["Validate"].ToString()) { ScriptString = @"<script type=""text/javascript"">alert('验证码错误')</script>"; //不能写Response.End(),否则什么都不会显示到页面上 return; } #endregion #region 校验用户名密码 BLL.HKSJ_USERS userBll = new BLL.HKSJ_USERS(); string strwhere = "LoginName='" + userName + "' and PassWord='******'"; List<Model.HKSJ_USERS> userModeList=userBll.GetModelList(strwhere); //如果找不到用户名密码 if (userModeList.Count<=0) { ScriptString=@"<script type=""text/javascript"">alert('用户名密码错误')</script>"; return; } #endregion #region 登入成功后,写入Session,其目的是为了不让所有人都能访问第二个页面 Session["UserInfo"] = userModeList.First(); #endregion //跳转 Response.Redirect("../MyCRUD/AdminForm.aspx"); } else { //如果是页面跳转!!,注意是页面跳转,不只是第一次访问 //拿到Cookie中的用户名,保存到私有字段 UserName = Server.UrlDecode(Request["UserName"] ?? "");//这种方式能拿到Cookie } }
protected void btnLogin_Click(object sender, ImageClickEventArgs e) { #region 验证码判断 //先取得验证码,判断验证码是否正确,如果不正确就不用到数据库中查找内容了 string code = Session["ValidateCode"] == null ? string.Empty : Session["ValidateCode"].ToString(); string fromCode = Request["txtCode"]; if (code != fromCode) { //名字保留 userName = Request["txtClientID"]; //提醒用户 ErrorMsg = "验证码有误!"; return; } #endregion #region 获取提交过来的用户信息,到数据库查询 string strLoginName = Request["txtClientID"].Trim(); string strUserPwd = Request["txtPassword"]; BLL.HKSJ_USERS userInfoService = new BLL.HKSJ_USERS(); Model.HKSJ_USERS user = new Model.HKSJ_USERS(); LoginResult result = userInfoService.GetUserLoginUserModel(strLoginName, strUserPwd); //判断返回结果 if (result == LoginResult.userIsNull) { Js = "<script>alert('用户名不能为空!')</script>"; return; } else if (result == LoginResult.pwdIsNull) { Js = "<script>alert('密码不能为空!')</script>"; return; } else if (result == LoginResult.userNotExist) { Js = "<script>alert('用户名不存在!')</script>"; //名字保留 userName = Request["txtClientID"]; return; } else if (result == LoginResult.pwdError) { Js = "<script>alert('密码错误!')</script>"; //名字保留 userName = Request["txtClientID"]; return; } else if (result == LoginResult.OK) { //验证通过后把用户名保存到session里面 Session["user"] = user; //把登录成功的用户名保存到cookie中 if (!String.IsNullOrEmpty(strLoginName)) { Response.Cookies["userName"].Value = strLoginName; Response.Cookies["userName"].Expires = DateTime.Now.AddDays(5); } //验证都通过,转到后台页面 Response.Redirect("~/admin/users/adminUser.html"); } else { Js = "<script>alert('未知错误!')</script>"; return; } #endregion }
protected void Page_Load(object sender, EventArgs e) { BLL.HKSJ_USERS userService = new BLL.HKSJ_USERS(); users = userService.GetModelList(string.Empty); }