/// <summary> /// 得到一个实体 /// </summary> /// <param name="id"></param> /// <returns></returns> public ShowShop.Model.Member.Message GetModelByID(int id) { ShowShop.Model.Member.Message model = new ShowShop.Model.Member.Message(); StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 [id],[uid],[userid],[title],[content],[adminid],[sendtime],[state],[isread] from yxs_message "); strSql.Append(" where [id]=@id "); SqlParameter[] parameters = (SqlParameter[])this.ValueIDPara(id); using (SqlDataReader reader = ChangeHope.DataBase.SQLServerHelper.ExecuteReader(strSql.ToString(), parameters)) { if (reader.Read()) { model.ID = reader.GetInt32(0); model.UID = reader.GetInt32(1); model.UserId = reader.GetString(2); model.Title = reader.GetString(3); model.Content = reader.GetString(4); model.AdminId = reader.GetString(5); model.SendTime = reader.GetDateTime(6); model.State = reader.GetInt32(7); model.IsRead = reader.GetInt32(8); } } return model; }
/// <summary> /// 得到指定条件的所有短消息 不加 where /// </summary> /// <param name="uid"></param> /// <returns></returns> public List<ShowShop.Model.Member.Message> GetAll(string strWhere) { List<ShowShop.Model.Member.Message> list = new List<ShowShop.Model.Member.Message>(); StringBuilder strSql = new StringBuilder(); strSql.Append("select [id],[uid],[userid],[title],[content],[adminid],[sendtime],[state],[isread] from yxs_message "); if (strWhere != null && strWhere != "") { strSql.Append("where " + strWhere + " "); } using (SqlDataReader reader = ChangeHope.DataBase.SQLServerHelper.ExecuteReader(strSql.ToString())) { while (reader.Read()) { ShowShop.Model.Member.Message model = new ShowShop.Model.Member.Message(); model.ID = reader.GetInt32(0); model.UID = reader.GetInt32(1); model.UserId = reader.GetString(2); model.Title = reader.GetString(3); model.Content = reader.GetString(4); model.AdminId = reader.GetString(5); model.SendTime = reader.GetDateTime(6); model.State = reader.GetInt32(7); model.IsRead = reader.GetInt32(8); list.Add(model); } } return list; }