/// <summary> /// 得到一个对象实体 /// </summary> public DevicePushModel GetModel(string DeviceId, string PushType, string ReKey) { StringBuilder strSql = new StringBuilder(); strSql.Append("select DeviceId, PushType, ReKey, Memo "); strSql.Append(" from DBMSG.dbo.DevicePush "); strSql.Append(" where DeviceId=@DeviceId and PushType=@PushType and ReKey=@ReKey "); SqlParameter[] parameters = { new SqlParameter("@DeviceId", SqlDbType.VarChar, 50), new SqlParameter("@PushType", SqlDbType.VarChar, 50), new SqlParameter("@ReKey", SqlDbType.VarChar, 50) }; parameters[0].Value = DeviceId; parameters[1].Value = PushType; parameters[2].Value = ReKey; DevicePushModel model = new DevicePushModel(); DataSet ds = helper.ExecSqlReDs(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { model.DeviceId = ds.Tables[0].Rows[0]["DeviceId"].ToString(); model.PushType = ds.Tables[0].Rows[0]["PushType"].ToString(); model.ReKey = ds.Tables[0].Rows[0]["ReKey"].ToString(); model.Memo = ds.Tables[0].Rows[0]["Memo"].ToString(); return(model); } else { return(model); } }
private void RemoveDevicePush() { Model.DevicePushModel model = new DevicePushModel(); model.DeviceId = ReStr("DeviceId", ""); model.PushType = ReStr("PushType", ""); if (model.DeviceId == "") { throw new Exception("DeviceId不能为空!"); } if (model.PushType == "") { throw new Exception("PushType不能为空!"); } DAL.DevicePushDAL dal = new DAL.DevicePushDAL(); dal.DeleteList(" DeviceId='" + model.DeviceId + "' and PushType='" + model.PushType + "' "); ReTrue(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(DevicePushModel model) { bool reValue = true; int reCount = 0; StringBuilder strSql = new StringBuilder(); strSql.Append("update DBMSG.dbo.DevicePush set "); strSql.Append(" DeviceId = @DeviceId , "); strSql.Append(" PushType = @PushType , "); strSql.Append(" ReKey = @ReKey , "); strSql.Append(" Memo = @Memo "); strSql.Append(" where DeviceId=@DeviceId and PushType=@PushType and ReKey=@ReKey "); SqlParameter[] parameters = { new SqlParameter("@DeviceId", SqlDbType.VarChar, 50), new SqlParameter("@PushType", SqlDbType.VarChar, 50), new SqlParameter("@ReKey", SqlDbType.VarChar, 50), new SqlParameter("@Memo", SqlDbType.VarChar, 250) }; parameters[0].Value = model.DeviceId; parameters[1].Value = model.PushType; parameters[2].Value = model.ReKey; parameters[3].Value = model.Memo; 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(DevicePushModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into DBMSG.dbo.DevicePush ("); strSql.Append("DeviceId,PushType,ReKey,Memo"); strSql.Append(") values ("); strSql.Append("@DeviceId,@PushType,@ReKey,@Memo"); strSql.Append(") "); SqlParameter[] parameters = { new SqlParameter("@DeviceId", SqlDbType.VarChar, 50), new SqlParameter("@PushType", SqlDbType.VarChar, 50), new SqlParameter("@ReKey", SqlDbType.VarChar, 50), new SqlParameter("@Memo", SqlDbType.VarChar, 250) }; parameters[0].Value = model.DeviceId; parameters[1].Value = model.PushType; parameters[2].Value = model.ReKey; parameters[3].Value = model.Memo; bool result = false; try { helper.ExecSqlReInt(strSql.ToString(), parameters); result = true; } catch (Exception ex) { this.helper.Close(); throw ex; } finally { } return(result); }