protected void RegisterOnlineUser(Maticsoft.Model.tUsers user) { Maticsoft.BLL.S_Onlines bll = new Maticsoft.BLL.S_Onlines(); Maticsoft.Model.S_Onlines online = bll.GetModelByUseId(user.userId); DateTime now = DateTime.Now; // 如果不存在,就创建一条新的记录 if (online == null) { online = new Maticsoft.Model.S_Onlines(); online.UserId = user.userId; online.IpAdddress = Request.UserHostAddress; online.LoginTime = now; online.UpdateTime = now; bll.Add(online); } else { online.UserId = user.userId; online.IpAdddress = Request.UserHostAddress; online.LoginTime = now; online.UpdateTime = now; bll.Update(online); } }
public static void CheckLogin() { HttpContext.Current.Response.Clear(); if (HttpContext.Current.Session["adminUser"] == null && HttpContext.Current.Request.Cookies["adminUser"] == null) { HttpContext.Current.Response.Write("loginErr"); } else { if (HttpContext.Current.Session["adminUser"] == null) { var res = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["adminUser"].Value, Encoding.GetEncoding("UTF-8")); var resStu = JsonConvert.DeserializeObject <Maticsoft.Model.tUsers>(res); HttpContext.Current.Session["adminUser"] = resStu; HttpContext.Current.Session.Timeout = 120; } if (HttpContext.Current.Request.Cookies["adminUser"] == null) { Maticsoft.Model.tUsers resStu = HttpContext.Current.Session["adminUser"] as Maticsoft.Model.tUsers; var res = JsonConvert.SerializeObject(resStu); HttpCookie cookie = new HttpCookie("adminUser"); cookie.Expires = DateTime.Now.AddMinutes(120); cookie.Value = HttpUtility.UrlEncode(res, Encoding.GetEncoding("UTF-8")); HttpContext.Current.Response.Cookies.Add(cookie); } HttpContext.Current.Response.Write("loginOk"); } HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Maticsoft.Model.tUsers user = GetIdentityUser(); GetTask(user.dptId); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LoadData(); Maticsoft.Model.tUsers user = GetIdentityUser(); btnUserName.Text = user.usersName; btnUserName.ToolTip = dptbll.GetModel(user.dptId).dptName; Maticsoft.BLL.tSet bll = new Maticsoft.BLL.tSet(); model = bll.GetModel(1); GetTask(user.dptId); } }
/// <summary> /// 系统操作日志 /// </summary> /// <param name="doWhat"></param> protected void insertLog(string doWhat) { Maticsoft.BLL.tSysLog bll = new Maticsoft.BLL.tSysLog(); Maticsoft.Model.tSysLog m = new Maticsoft.Model.tSysLog(); m.DoWhat = doWhat; m.IP = Request.UserHostAddress; m.SysTime = DateTime.Now; Maticsoft.Model.tUsers user = GetIdentityUser(); m.UserId = user.userId; m.UserName = user.usersName; bll.Add(m); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.tUsers model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tUsers set "); strSql.Append("usersName=@usersName,"); strSql.Append("usersPwd=@usersPwd,"); strSql.Append("roleCode=@roleCode,"); strSql.Append("trueName=@trueName,"); strSql.Append("Flag=@Flag,"); strSql.Append("Tel=@Tel,"); strSql.Append("Address=@Address,"); strSql.Append("usersRemark=@usersRemark,"); strSql.Append("dptId=@dptId"); strSql.Append(" where userId=@userId"); SqlParameter[] parameters = { new SqlParameter("@usersName", SqlDbType.VarChar, 50), new SqlParameter("@usersPwd", SqlDbType.VarChar, 50), new SqlParameter("@roleCode", SqlDbType.Int, 4), new SqlParameter("@trueName", SqlDbType.VarChar, 50), new SqlParameter("@Flag", SqlDbType.Int, 4), new SqlParameter("@Tel", SqlDbType.VarChar, 50), new SqlParameter("@Address", SqlDbType.VarChar, 200), new SqlParameter("@usersRemark", SqlDbType.VarChar, 500), new SqlParameter("@userId", SqlDbType.Int, 4), new SqlParameter("@dptId", SqlDbType.Int, 4) }; parameters[0].Value = model.usersName; parameters[1].Value = model.usersPwd; parameters[2].Value = model.roleCode; parameters[3].Value = model.trueName; parameters[4].Value = model.Flag; parameters[5].Value = model.Tel; parameters[6].Value = model.Address; parameters[7].Value = model.usersRemark; parameters[8].Value = model.userId; parameters[9].Value = model.dptId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.tUsers DataRowToModel(DataRow row) { Maticsoft.Model.tUsers model = new Maticsoft.Model.tUsers(); if (row != null) { if (row["userId"] != null && row["userId"].ToString() != "") { model.userId = int.Parse(row["userId"].ToString()); } if (row["usersName"] != null) { model.usersName = row["usersName"].ToString(); } if (row["usersPwd"] != null) { model.usersPwd = row["usersPwd"].ToString(); } if (row["roleCode"] != null && row["roleCode"].ToString() != "") { model.roleCode = int.Parse(row["roleCode"].ToString()); } if (row["trueName"] != null) { model.trueName = row["trueName"].ToString(); } if (row["Flag"] != null && row["Flag"].ToString() != "") { model.Flag = int.Parse(row["Flag"].ToString()); } if (row["Tel"] != null) { model.Tel = row["Tel"].ToString(); } if (row["Address"] != null) { model.Address = row["Address"].ToString(); } if (row["usersRemark"] != null) { model.usersRemark = row["usersRemark"].ToString(); } if (row["dptId"] != null && row["dptId"].ToString() != "") { model.dptId = int.Parse(row["dptId"].ToString()); } } return(model); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LoadData(); Maticsoft.Model.tUsers user = GetIdentityUser(); btnUserName.Text = user.usersName; Maticsoft.BLL.tSet bll = new Maticsoft.BLL.tSet(); model = bll.GetModel(1); Maticsoft.BLL.S_Onlines bllOn = new Maticsoft.BLL.S_Onlines(); Maticsoft.Model.S_Onlines online = bllOn.GetModelByUseId(user.userId); CreateNotify("您上次登陆时间是:" + online.UpdateTime, "Self", "登录提示", 0, false); } }
/// <summary> /// 获取当前登录用户信息 /// </summary> /// <returns></returns> protected Maticsoft.Model.tUsers GetIdentityUser() { Maticsoft.Model.tUsers user = new Maticsoft.Model.tUsers(); if (Request.Cookies["adminUser"] == null) { Maticsoft.Model.tUsers resStu = Session["adminUser"] as Maticsoft.Model.tUsers; user = resStu; } else { var res = HttpUtility.UrlDecode(Request.Cookies["adminUser"].Value, Encoding.GetEncoding("UTF-8")); var resStu = JsonConvert.DeserializeObject <Maticsoft.Model.tUsers>(res); Maticsoft.Model.tUsers resStuCookie = resStu; user = resStu; } return(user); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.tUsers model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tUsers("); strSql.Append("usersName,usersPwd,roleCode,trueName,Flag,Tel,Address,usersRemark,dptId)"); strSql.Append(" values ("); strSql.Append("@usersName,@usersPwd,@roleCode,@trueName,@Flag,@Tel,@Address,@usersRemark,@dptId)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@usersName", SqlDbType.VarChar, 50), new SqlParameter("@usersPwd", SqlDbType.VarChar, 50), new SqlParameter("@roleCode", SqlDbType.Int, 4), new SqlParameter("@trueName", SqlDbType.VarChar, 50), new SqlParameter("@Flag", SqlDbType.Int, 4), new SqlParameter("@Tel", SqlDbType.VarChar, 50), new SqlParameter("@Address", SqlDbType.VarChar, 200), new SqlParameter("@usersRemark", SqlDbType.VarChar, 500), new SqlParameter("@dptId", SqlDbType.Int, 4) }; parameters[0].Value = model.usersName; parameters[1].Value = model.usersPwd; parameters[2].Value = model.roleCode; parameters[3].Value = model.trueName; parameters[4].Value = model.Flag; parameters[5].Value = model.Tel; parameters[6].Value = model.Address; parameters[7].Value = model.usersRemark; parameters[8].Value = model.dptId; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.tUsers GetModel(int userId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 userId,usersName,usersPwd,roleCode,trueName,Flag,Tel,Address,usersRemark,dptId from tUsers "); strSql.Append(" where userId=@userId"); SqlParameter[] parameters = { new SqlParameter("@userId", SqlDbType.Int, 4) }; parameters[0].Value = userId; Maticsoft.Model.tUsers model = new Maticsoft.Model.tUsers(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }