private static TABELAIBPTEntity FillEntityObject(ref FbDataReader DataReader) { TABELAIBPTEntity entity = new TABELAIBPTEntity(); FirebirdGetDbData getData = new FirebirdGetDbData(); entity.IDTABELAIBPT = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDTABELAIBPT")); entity.IDNCM = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDNCM")); entity.ALNACIONAL = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("ALNACIONAL")); entity.ALIMPORTACAO = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("ALIMPORTACAO")); entity.ALESTADUAL = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("ALESTADUAL")); entity.ALMUNICIPAL = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("ALMUNICIPAL")); entity.DTINICIO = getData.ConvertDBValueToDateTimeNullable(DataReader, DataReader.GetOrdinal("DTINICIO")); entity.DTFIM = getData.ConvertDBValueToDateTimeNullable(DataReader, DataReader.GetOrdinal("DTFIM")); entity.CHAVE = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("CHAVE")); entity.VERSAO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("VERSAO")); entity.FONTE = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("FONTE")); entity.IDCODUFIBGE = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDCODUFIBGE")); entity.TIPO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("TIPO")); entity.EX = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("EX")); return(entity); }
public TABELAIBPTEntity Read(int IDTABELAIBPT) { FbDataReader reader = null; try { //Verificando a existência de um transação aberta if (dbTransaction != null) { if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Rea_TABELAIBPT", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Rea_TABELAIBPT", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; dbCommand.Parameters.AddWithValue("@IDTABELAIBPT", IDTABELAIBPT); //PrimaryKey reader = dbCommand.ExecuteReader(); TABELAIBPTEntity entity = null; if (reader.HasRows) { while (reader.Read()) { entity = FillEntityObject(ref reader); } } // Deleta reader if (reader != null) { reader.Close(); reader.Dispose(); } // Fecha conexão if (dbTransaction == null) { dbCommand.Transaction.Commit(); if (dbCnn.State == ConnectionState.Open) { dbCnn.Close(); } } return(entity); } catch (Exception ex) { // Deleta reader if (reader != null) { reader.Close(); reader.Dispose(); } if (dbTransaction != null) { this.RollbackTransaction(); } else { if (dbCommand.Transaction != null) { dbCommand.Transaction.Rollback(); } if (dbCnn.State == ConnectionState.Open) { dbCnn.Close(); } } throw ex; } }
public int Save(TABELAIBPTEntity Entity) { int result = 0; try { //Verificando a existência de um transação aberta if (dbTransaction != null) { if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Sav_TABELAIBPT", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Sav_TABELAIBPT", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; //PrimaryKey com valor igual a null, indica um novo registro, //o valor da chave será fornecido pelo banco. Qualquer outro valor indicará edição do registro. if (Entity.IDTABELAIBPT == -1) { dbCommand.Parameters.AddWithValue("@IDTABELAIBPT", DBNull.Value); } else { dbCommand.Parameters.AddWithValue("@IDTABELAIBPT", Entity.IDTABELAIBPT); } if (Entity.IDNCM != null) { dbCommand.Parameters.AddWithValue("@IDNCM", Entity.IDNCM); //ForeignKey } else { dbCommand.Parameters.AddWithValue("@IDNCM", DBNull.Value); //ForeignKey 5 } dbCommand.Parameters.AddWithValue("@ALNACIONAL", Entity.ALNACIONAL); //Coluna dbCommand.Parameters.AddWithValue("@ALIMPORTACAO", Entity.ALIMPORTACAO); //Coluna dbCommand.Parameters.AddWithValue("@ALESTADUAL", Entity.ALESTADUAL); //Coluna dbCommand.Parameters.AddWithValue("@ALMUNICIPAL", Entity.ALMUNICIPAL); //Coluna dbCommand.Parameters.AddWithValue("@DTINICIO", Entity.DTINICIO); //Coluna dbCommand.Parameters.AddWithValue("@DTFIM", Entity.DTFIM); //Coluna dbCommand.Parameters.AddWithValue("@CHAVE", Entity.CHAVE); //Coluna dbCommand.Parameters.AddWithValue("@VERSAO", Entity.VERSAO); //Coluna dbCommand.Parameters.AddWithValue("@FONTE", Entity.FONTE); //Coluna if (Entity.IDCODUFIBGE != null) { dbCommand.Parameters.AddWithValue("@IDCODUFIBGE", Entity.IDCODUFIBGE); //ForeignKey } else { dbCommand.Parameters.AddWithValue("@IDCODUFIBGE", DBNull.Value); //ForeignKey 5 } dbCommand.Parameters.AddWithValue("@TIPO", Entity.TIPO); //Coluna dbCommand.Parameters.AddWithValue("@EX", Entity.EX); //Coluna //Retorno da Procedure FbParameter returnValue; returnValue = dbCommand.CreateParameter(); dbCommand.Parameters["@IDTABELAIBPT"].Direction = ParameterDirection.InputOutput; //Executando consulta dbCommand.ExecuteNonQuery(); result = int.Parse(dbCommand.Parameters["@IDTABELAIBPT"].Value.ToString()); if (dbTransaction == null) { dbCommand.Transaction.Commit(); dbCnn.Close(); } } catch (Exception ex) { if (dbTransaction != null) { this.RollbackTransaction(); } else { if (dbCommand.Transaction != null) { dbCommand.Transaction.Rollback(); } if (dbCnn.State == ConnectionState.Open) { dbCnn.Close(); } } throw ex; } return(result); }