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