protected void BtnLogin_Click(object sender, EventArgs e) { //FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, "yankun", DateTime.Now, DateTime.Now.AddDays(1), false, "1"); //string strE = FormsAuthentication.Encrypt(ticket); //HttpCookie cookieAuthen = new HttpCookie(FormsAuthentication.FormsCookieName); //cookieAuthen.Value = strE; //Response.Cookies.Add(cookieAuthen); HttpCookie cookieInfo = new HttpCookie("AdminInfo"); cookieInfo.Values["OrgCode"] = "default"; cookieInfo.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookieInfo); string UserName = TbUserName.Value.Trim(); string Userpwd = TbUserPwd.Value.ToEncryptStr(); if (Session["VerifyCode"] == null) { LbTooltip.Text = "验证失效,请点击重新获取!"; return; } if (Session["VerifyCode"].ToStr() != TBYanZheng.Value.Trim()) { LbTooltip.Text = "验证码错误,请重新输入!"; return; } List <Expression> express = new List <Expression>(); express.Add(new Expression("UserName", "=", UserName)); express.Add(new Expression("Userpwd", "=", Userpwd)); TB_Admin_User model = AdminService.UserService.Get(express); if (model.ID > 0) { HttpCookie cookie = new HttpCookie("AdminInfo"); cookie.Values["ID"] = model.ID.ToStr(); cookie.Values["UserName"] = UserName; cookie.Values["UserPwd"] = Userpwd; cookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookie); //操作日志 AdminService.LogService.Insert(OperationType.用户操作, model.ID, "用户" + model.UserName + "后台登录", UserName); Response.Redirect("Default.aspx"); } else { LbTooltip.Text = "用户名或密码错误!"; } }
protected void BtnSubmit_Click(object sender, EventArgs e) { TB_Admin_User model = new TB_Admin_User(); model.UserName = TbUserName.Text; model.UserPwd = TbPwd.Text; model.UserState = 0; model.LastLoginTime = DateTime.Now; YK.Service.FactoryCommon <TB_Admin_User> .Common.Insert(model); loadDataBind(); }
protected void BtnUpdate_Click(object sender, EventArgs e) { TB_Admin_User model = new TB_Admin_User(); model.UserName = TbUserName.Text; model.UserPwd = TbPwd.Text; model.UserState = 0; model.LastLoginTime = DateTime.Now; List <Expression> express = new List <Expression>(); express.Add(new Expression("ID", "=", "14")); YK.Service.FactoryCommon <TB_Admin_User> .Common.Update(model, express); loadDataBind(); }
//加载 public void LoadDataBind() { int id = CommonClass.ReturnRequestInt("id", 0); if (id > 0) { TB_Admin_User model = AdminService.UserService.Get(id); TbUserName.Text = model.UserName; TbUserName.Enabled = false; TbUserPwd.Text = model.UserPwd; CheckBoxState.Checked = model.UserState == 1 ? true : false; ViewState["id"] = model.ID; TbUserName.Enabled = false; } }
protected void Page_Load(object sender, EventArgs e) { //性能测试结果:10000条数据3469毫秒,1000条数据350毫秒 YK.Common.PerformanceHelper performanceHelper = new YK.Common.PerformanceHelper(); performanceHelper.Start("开始"); var list = new List <TB_Admin_User>(); for (int i = 0; i < 10000; i++) { YK.Model.TB_Admin_User user = new TB_Admin_User(); user.UserName = "******" + i; user.UserPwd = i.ToString(); list.Add(user); } YK.Service.AdminService.UserService.BatchInsert(list); performanceHelper.Stop(); }
//状态设置 protected void BtnStateSet_Click(object sender, EventArgs e) { foreach (RepeaterItem ri in RepList.Items) { CheckBox cb = ((CheckBox)ri.FindControl("CheckBoxChoose")); int ID = Convert.ToInt32(((HiddenField)ri.FindControl("HiddenFieldID")).Value); if (cb.Checked == true) { List <Expression> express = new List <Expression>(); express.Add(new Expression("ID", "=", ID.ToStr())); TB_Admin_User model = AdminService.UserService.Get(express); model.UserState = DDLState.SelectedValue.ToInt(); AdminService.UserService.Update(model); } } //重新加载 LoadDataBind(); }
public void loadDataBind() { int i = 0; GridView1.DataSource = YK.Service.FactoryCommon <TB_Admin_User> .Common.Search(100, 1, new List <Expression>(), "ID asc", ref i); GridView1.DataBind(); List <Expression> express = new List <Expression>(); express.Add(new Expression("ID", "=", "15")); TB_Admin_User model = YK.Service.FactoryCommon <TB_Admin_User> .Common.Get(express); TbUserName.Text = model.UserName; TbPwd.Text = model.UserPwd; express.Clear(); express.Add(new Expression("ID", "=", "9")); YK.Service.FactoryCommon <TB_Admin_User> .Common.Delete(express); }
//保存 protected void BtnSave_Click(object sender, EventArgs e) { TB_Admin_User model = new TB_Admin_User(); if (ViewState["id"] != null) { model = AdminService.UserService.Get(ViewState["id"]); } else { List <Expression> expression = new List <Expression>(); expression.Add(new Expression("UserName", "=", TbUserName.Text.TrimEnd())); if (AdminService.UserService.Search(expression).Count > 0) { MessageDiv.InnerHtml = CommonClass.Alert("此用户已存在,请重新输入"); return; } } if (TbUserPwd.Text.TrimEnd().Length < 6) { MessageDiv.InnerHtml = CommonClass.Alert("密码长度必须大于6位数"); return; } model.UserName = TbUserName.Text.Trim(); model.UserPwd = TbUserPwd.Text.Trim().ToEncryptStr(); model.UserState = CheckBoxState.Checked == false ? 0 : 1; model.LastLoginTime = DateTime.Now; model.Creater = AdminUserName; model.AddDate = DateTime.Now; IAdmin_User AdminUser = AdminService.UserService; if (ViewState["id"] == null) { if (AdminUser.Insert(model) == 1) { //操作日志 AdminService.LogService.Insert(OperationType.用户操作, 0, "添加用户" + model.UserName); MessageDiv.InnerHtml = CommonClass.Reload("数据添加成功"); } else { MessageDiv.InnerHtml = CommonClass.Alert("数据添加失败"); } } else { if (AdminUser.Update(model) == 1) { //操作日志 AdminService.LogService.Insert(OperationType.用户操作, 0, "修改用户" + model.UserName); MessageDiv.InnerHtml = CommonClass.Reload("数据修改成功"); } else { MessageDiv.InnerHtml = CommonClass.Alert("数据修改失败"); } } }