/// <summary> /// 得到一个对象实体 /// </summary> public UserOnLineModel GetModel(string UserId, decimal MerId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select UserId, MerId, UserOnlineStatusId, PushTypeId, LastTime "); strSql.Append(" from YYHD.dbo.UserOnLine "); strSql.Append(" where UserId=@UserId and MerId=@MerId "); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.VarChar, 50), new SqlParameter("@MerId", SqlDbType.Decimal, 9) }; parameters[0].Value = UserId; parameters[1].Value = MerId; UserOnLineModel model = new UserOnLineModel(); DataSet ds = helper.ExecSqlReDs(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { model.UserId = ds.Tables[0].Rows[0]["UserId"].ToString(); if (ds.Tables[0].Rows[0]["MerId"].ToString() != "") { model.MerId = decimal.Parse(ds.Tables[0].Rows[0]["MerId"].ToString()); } if (ds.Tables[0].Rows[0]["UserOnlineStatusId"].ToString() != "") { model.UserOnlineStatusId = int.Parse(ds.Tables[0].Rows[0]["UserOnlineStatusId"].ToString()); } if (ds.Tables[0].Rows[0]["PushTypeId"].ToString() != "") { model.PushTypeId = int.Parse(ds.Tables[0].Rows[0]["PushTypeId"].ToString()); } if (ds.Tables[0].Rows[0]["LastTime"].ToString() != "") { model.LastTime = DateTime.Parse(ds.Tables[0].Rows[0]["LastTime"].ToString()); } return(model); } else { return(model); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(UserOnLineModel model) { bool reValue = true; int reCount = 0; StringBuilder strSql = new StringBuilder(); strSql.Append("update YYHD.dbo.UserOnLine set "); strSql.Append(" UserId = @UserId , "); strSql.Append(" MerId = @MerId , "); strSql.Append(" UserOnlineStatusId = @UserOnlineStatusId , "); strSql.Append(" PushTypeId = @PushTypeId , "); strSql.Append(" LastTime = @LastTime "); strSql.Append(" where UserId=@UserId and MerId=@MerId "); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.VarChar, 50), new SqlParameter("@MerId", SqlDbType.Decimal, 9), new SqlParameter("@UserOnlineStatusId", SqlDbType.Int, 4), new SqlParameter("@PushTypeId", SqlDbType.Int, 4), new SqlParameter("@LastTime", SqlDbType.DateTime) }; parameters[0].Value = model.UserId; parameters[1].Value = model.MerId; parameters[2].Value = model.UserOnlineStatusId; parameters[3].Value = model.PushTypeId; parameters[4].Value = model.LastTime; try {//异常处理 reCount = this.helper.ExecSqlReInt(strSql.ToString(), parameters); } catch (Exception ex) { this.helper.Close(); throw ex; } if (reCount <= 0) { reValue = false; } return(reValue); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(UserOnLineModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into YYHD.dbo.UserOnLine ("); strSql.Append("UserId,MerId,UserOnlineStatusId,PushTypeId,LastTime"); strSql.Append(") values ("); strSql.Append("@UserId,@MerId,@UserOnlineStatusId,@PushTypeId,@LastTime"); strSql.Append(") "); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.VarChar, 50), new SqlParameter("@MerId", SqlDbType.Decimal, 9), new SqlParameter("@UserOnlineStatusId", SqlDbType.Int, 4), new SqlParameter("@PushTypeId", SqlDbType.Int, 4), new SqlParameter("@LastTime", SqlDbType.DateTime) }; parameters[0].Value = model.UserId; parameters[1].Value = model.MerId; parameters[2].Value = model.UserOnlineStatusId; parameters[3].Value = model.PushTypeId; parameters[4].Value = model.LastTime; bool result = false; try { helper.ExecSqlReInt(strSql.ToString(), parameters); result = true; } catch (Exception ex) { this.helper.Close(); throw ex; } finally { } return(result); }