private static MANUTESQUIPAMENTOEntity FillEntityObject(ref FbDataReader DataReader) { MANUTESQUIPAMENTOEntity entity = new MANUTESQUIPAMENTOEntity(); FirebirdGetDbData getData = new FirebirdGetDbData(); entity.IDMANUTEESQUIPAMENTO = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDMANUTEESQUIPAMENTO")); entity.DATAMANUT = getData.ConvertDBValueToDateTimeNullable(DataReader, DataReader.GetOrdinal("DATAMANUT")); entity.DATAPROXIMAMANUT = getData.ConvertDBValueToDateTimeNullable(DataReader, DataReader.GetOrdinal("DATAPROXIMAMANUT")); entity.IDTIPOMANUTENCAO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDTIPOMANUTENCAO")); entity.IDSITUACAO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDSITUACAO")); entity.IDFUNCSOLICITANTE = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDFUNCSOLICITANTE")); entity.IDFUNCEXECUTOR = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDFUNCEXECUTOR")); entity.IDFORNECEDOR = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDFORNECEDOR")); entity.VALORMANUTENCAO = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALORMANUTENCAO")); entity.KMMANUTENCAO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("KMMANUTENCAO")); entity.KMPROXMANUT = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("KMPROXMANUT")); entity.OBSERVACAO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("OBSERVACAO")); entity.IDEQUIPAMENTO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDEQUIPAMENTO")); entity.IDCENTROCUSTO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDCENTROCUSTO")); entity.CODREFERENCIA = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("CODREFERENCIA")); entity.KMATUAL = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("KMATUAL")); return(entity); }
public MANUTESQUIPAMENTOEntity Read(int IDMANUTEESQUIPAMENTO) { 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_MANUTESQUIPAMENTO", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Rea_MANUTESQUIPAMENTO", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; dbCommand.Parameters.AddWithValue("@IDMANUTEESQUIPAMENTO", IDMANUTEESQUIPAMENTO); //PrimaryKey reader = dbCommand.ExecuteReader(); MANUTESQUIPAMENTOEntity 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(MANUTESQUIPAMENTOEntity 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_MANUTESQUIPAMENTO", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Sav_MANUTESQUIPAMENTO", 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.IDMANUTEESQUIPAMENTO == -1) { dbCommand.Parameters.AddWithValue("@IDMANUTEESQUIPAMENTO", DBNull.Value); } else { dbCommand.Parameters.AddWithValue("@IDMANUTEESQUIPAMENTO", Entity.IDMANUTEESQUIPAMENTO); } dbCommand.Parameters.AddWithValue("@DATAMANUT", Entity.DATAMANUT); //Coluna dbCommand.Parameters.AddWithValue("@DATAPROXIMAMANUT", Entity.DATAPROXIMAMANUT); //Coluna if (Entity.IDTIPOMANUTENCAO != null) { dbCommand.Parameters.AddWithValue("@IDTIPOMANUTENCAO", Entity.IDTIPOMANUTENCAO); //ForeignKey } else { dbCommand.Parameters.AddWithValue("@IDTIPOMANUTENCAO", DBNull.Value); //ForeignKey 5 } if (Entity.IDSITUACAO != null) { dbCommand.Parameters.AddWithValue("@IDSITUACAO", Entity.IDSITUACAO); //ForeignKey } else { dbCommand.Parameters.AddWithValue("@IDSITUACAO", DBNull.Value); //ForeignKey 5 } if (Entity.IDFUNCSOLICITANTE != null) { dbCommand.Parameters.AddWithValue("@IDFUNCSOLICITANTE", Entity.IDFUNCSOLICITANTE); //ForeignKey } else { dbCommand.Parameters.AddWithValue("@IDFUNCSOLICITANTE", DBNull.Value); //ForeignKey 5 } if (Entity.IDFUNCEXECUTOR != null) { dbCommand.Parameters.AddWithValue("@IDFUNCEXECUTOR", Entity.IDFUNCEXECUTOR); //ForeignKey } else { dbCommand.Parameters.AddWithValue("@IDFUNCEXECUTOR", DBNull.Value); //ForeignKey 5 } if (Entity.IDFORNECEDOR != null) { dbCommand.Parameters.AddWithValue("@IDFORNECEDOR", Entity.IDFORNECEDOR); //ForeignKey } else { dbCommand.Parameters.AddWithValue("@IDFORNECEDOR", DBNull.Value); //ForeignKey 5 } dbCommand.Parameters.AddWithValue("@VALORMANUTENCAO", Entity.VALORMANUTENCAO); //Coluna dbCommand.Parameters.AddWithValue("@KMMANUTENCAO", Entity.KMMANUTENCAO); //Coluna dbCommand.Parameters.AddWithValue("@KMPROXMANUT", Entity.KMPROXMANUT); //Coluna dbCommand.Parameters.AddWithValue("@OBSERVACAO", Entity.OBSERVACAO); //Coluna if (Entity.IDEQUIPAMENTO != null) { dbCommand.Parameters.AddWithValue("@IDEQUIPAMENTO", Entity.IDEQUIPAMENTO); //ForeignKey } else { dbCommand.Parameters.AddWithValue("@IDEQUIPAMENTO", DBNull.Value); //ForeignKey 5 } if (Entity.IDCENTROCUSTO != null) { dbCommand.Parameters.AddWithValue("@IDCENTROCUSTO", Entity.IDCENTROCUSTO); //ForeignKey } else { dbCommand.Parameters.AddWithValue("@IDCENTROCUSTO", DBNull.Value); //ForeignKey 5 } dbCommand.Parameters.AddWithValue("@CODREFERENCIA", Entity.CODREFERENCIA); //Coluna dbCommand.Parameters.AddWithValue("@KMATUAL", Entity.KMATUAL); //Coluna //Retorno da Procedure FbParameter returnValue; returnValue = dbCommand.CreateParameter(); dbCommand.Parameters["@IDMANUTEESQUIPAMENTO"].Direction = ParameterDirection.InputOutput; //Executando consulta dbCommand.ExecuteNonQuery(); result = int.Parse(dbCommand.Parameters["@IDMANUTEESQUIPAMENTO"].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); }