/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.S_Onlines model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update S_Onlines set "); strSql.Append("IpAdddress=@IpAdddress,"); strSql.Append("LoginTime=@LoginTime,"); strSql.Append("UpdateTime=@UpdateTime,"); strSql.Append("UserId=@UserId"); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@IpAdddress", SqlDbType.NVarChar, 50), new SqlParameter("@LoginTime", SqlDbType.DateTime), new SqlParameter("@UpdateTime", SqlDbType.DateTime), new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.IpAdddress; parameters[1].Value = model.LoginTime; parameters[2].Value = model.UpdateTime; parameters[3].Value = model.UserId; parameters[4].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Maticsoft.Model.S_Onlines model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into S_Onlines("); strSql.Append("IpAdddress,LoginTime,UpdateTime,UserId)"); strSql.Append(" values ("); strSql.Append("@IpAdddress,@LoginTime,@UpdateTime,@UserId)"); SqlParameter[] parameters = { new SqlParameter("@IpAdddress", SqlDbType.NVarChar, 50), new SqlParameter("@LoginTime", SqlDbType.DateTime), new SqlParameter("@UpdateTime", SqlDbType.DateTime), new SqlParameter("@UserId", SqlDbType.Int, 4) }; parameters[0].Value = model.IpAdddress; parameters[1].Value = model.LoginTime; parameters[2].Value = model.UpdateTime; parameters[3].Value = model.UserId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.S_Onlines DataRowToModel(DataRow row) { Maticsoft.Model.S_Onlines model = new Maticsoft.Model.S_Onlines(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["IpAdddress"] != null) { model.IpAdddress = row["IpAdddress"].ToString(); } if (row["LoginTime"] != null && row["LoginTime"].ToString() != "") { model.LoginTime = DateTime.Parse(row["LoginTime"].ToString()); } if (row["UpdateTime"] != null && row["UpdateTime"].ToString() != "") { model.UpdateTime = DateTime.Parse(row["UpdateTime"].ToString()); } if (row["UserId"] != null && row["UserId"].ToString() != "") { model.UserId = int.Parse(row["UserId"].ToString()); } } return(model); }
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); } }
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> public Maticsoft.Model.S_Onlines GetModelByUseId(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,IpAdddress,LoginTime,UpdateTime,UserId from S_Onlines "); strSql.Append(" where UserId=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; Maticsoft.Model.S_Onlines model = new Maticsoft.Model.S_Onlines(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }