/// <summary> /// 增加一条数据 /// </summary> public bool Add(MessageRecordME model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into messageRecord("); strSql.Append("happenTime,messageID,dynamicContent)"); strSql.Append(" values ("); strSql.Append("@happenTime,@messageID,@dynamicContent)"); SqlParameter[] parameters = { new SqlParameter("@happenTime", SqlDbType.DateTime), new SqlParameter("@messageID", SqlDbType.Int,4), new SqlParameter("@dynamicContent", SqlDbType.NVarChar,255)}; parameters[0].Value = model.happenTime; parameters[1].Value = model.messageID; parameters[2].Value = model.dynamicContent; int rows = _dbAssist.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 增加一条消息记录 /// </summary> /// <param name="mesID"></param> /// <param name="dynamicContent"></param> /// <returns></returns> public bool RecordMessage(int mesID,string dynamicContent) { if(_mesDefDAL.Exists(mesID)) { MessageRecordME m = new MessageRecordME(); m.messageID = mesID; m.happenTime = System.DateTime.Now; m.dynamicContent = dynamicContent; if(_mesRecordDAL.Exists(m.happenTime)) { Thread.Sleep(100); m.happenTime = System.DateTime.Now; return _mesRecordDAL.Add(m); } return _mesRecordDAL.Add(m); } else { return false; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(MessageRecordME model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update messageRecord set "); strSql.Append("messageID=@messageID,"); strSql.Append("dynamicContent=@dynamicContent"); strSql.Append(" where happenTime=@happenTime "); SqlParameter[] parameters = { new SqlParameter("@messageID", SqlDbType.Int,4), new SqlParameter("@dynamicContent", SqlDbType.NVarChar,255), new SqlParameter("@happenTime", SqlDbType.DateTime)}; parameters[0].Value = model.messageID; parameters[1].Value = model.dynamicContent; parameters[2].Value = model.happenTime; int rows = _dbAssist.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 得到一个对象实体 /// </summary> public MessageRecordME GetModel(DateTime happenTime) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 happenTime,messageID,dynamicContent from messageRecord "); strSql.Append(" where happenTime=@happenTime "); SqlParameter[] parameters = { new SqlParameter("@happenTime", SqlDbType.DateTime) }; parameters[0].Value = happenTime; MessageRecordME model = new MessageRecordME(); DataSet ds = _dbAssist.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["happenTime"] != null && ds.Tables[0].Rows[0]["happenTime"].ToString() != "") { model.happenTime = DateTime.Parse(ds.Tables[0].Rows[0]["happenTime"].ToString()); } if (ds.Tables[0].Rows[0]["messageID"] != null && ds.Tables[0].Rows[0]["messageID"].ToString() != "") { model.messageID = int.Parse(ds.Tables[0].Rows[0]["messageID"].ToString()); } if (ds.Tables[0].Rows[0]["dynamicContent"] != null && ds.Tables[0].Rows[0]["dynamicContent"].ToString() != "") { model.dynamicContent = ds.Tables[0].Rows[0]["dynamicContent"].ToString(); } return model; } else { return null; } }