private static DIAGMEDIOPEDIDOEntity FillEntityObject(ref FbDataReader DataReader) { DIAGMEDIOPEDIDOEntity entity = new DIAGMEDIOPEDIDOEntity(); FirebirdGetDbData getData = new FirebirdGetDbData(); entity.IDDIAGMEDIOPEDIDO = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDDIAGMEDIOPEDIDO")); entity.IDPEDIDO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDPEDIDO")); entity.DIRESFERICO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("DIRESFERICO")); entity.DIRCILINDRICO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("DIRCILINDRICO")); entity.DIREIXO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("DIREIXO")); entity.DIRADICAO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("DIRADICAO")); entity.DIRDNP = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("DIRDNP")); entity.DIRACO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("DIRACO")); entity.ESQESFERICO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("ESQESFERICO")); entity.ESQCILINDRICO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("ESQCILINDRICO")); entity.ESQEIXO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("ESQEIXO")); entity.ESQADICAO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("ESQADICAO")); entity.ESQDNP = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("ESQDNP")); entity.ESQACO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("ESQACO")); entity.LENTES = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("LENTES")); entity.ARMACAO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("ARMACAO")); entity.DISTANCIAPUPILAR = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("DISTANCIAPUPILAR")); entity.DIREITO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("DIREITO")); entity.ESQUERDO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("ESQUERDO")); entity.DPA = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("DPA")); entity.MD = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("MD")); entity.MV = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("MV")); return(entity); }
public DIAGMEDIOPEDIDOEntity Read(int IDDIAGMEDIOPEDIDO) { 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_DIAGMEDIOPEDIDO", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Rea_DIAGMEDIOPEDIDO", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; dbCommand.Parameters.AddWithValue("@IDDIAGMEDIOPEDIDO", IDDIAGMEDIOPEDIDO); //PrimaryKey reader = dbCommand.ExecuteReader(); DIAGMEDIOPEDIDOEntity 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(DIAGMEDIOPEDIDOEntity 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_DIAGMEDIOPEDIDO", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Sav_DIAGMEDIOPEDIDO", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; if (Entity.IDDIAGMEDIOPEDIDO != -1) { dbCommand.Parameters.AddWithValue("@IDDIAGMEDIOPEDIDO", Entity.IDDIAGMEDIOPEDIDO); //PrimaryKey } else { dbCommand.Parameters.AddWithValue("@IDDIAGMEDIOPEDIDO", DBNull.Value); //PrimaryKey } dbCommand.Parameters.AddWithValue("@IDPEDIDO", Entity.IDPEDIDO); //Coluna dbCommand.Parameters.AddWithValue("@DIRESFERICO", Entity.DIRESFERICO); //Coluna dbCommand.Parameters.AddWithValue("@DIRCILINDRICO", Entity.DIRCILINDRICO); //Coluna dbCommand.Parameters.AddWithValue("@DIREIXO", Entity.DIREIXO); //Coluna dbCommand.Parameters.AddWithValue("@DIRADICAO", Entity.DIRADICAO); //Coluna dbCommand.Parameters.AddWithValue("@DIRDNP", Entity.DIRDNP); //Coluna dbCommand.Parameters.AddWithValue("@DIRACO", Entity.DIRACO); //Coluna dbCommand.Parameters.AddWithValue("@ESQESFERICO", Entity.ESQESFERICO); //Coluna dbCommand.Parameters.AddWithValue("@ESQCILINDRICO", Entity.ESQCILINDRICO); //Coluna dbCommand.Parameters.AddWithValue("@ESQEIXO", Entity.ESQEIXO); //Coluna dbCommand.Parameters.AddWithValue("@ESQADICAO", Entity.ESQADICAO); //Coluna dbCommand.Parameters.AddWithValue("@ESQDNP", Entity.ESQDNP); //Coluna dbCommand.Parameters.AddWithValue("@ESQACO", Entity.ESQACO); //Coluna dbCommand.Parameters.AddWithValue("@LENTES", Entity.LENTES); //Coluna dbCommand.Parameters.AddWithValue("@ARMACAO", Entity.ARMACAO); //Coluna dbCommand.Parameters.AddWithValue("@DISTANCIAPUPILAR", Entity.DISTANCIAPUPILAR); //Coluna dbCommand.Parameters.AddWithValue("@DIREITO", Entity.DIREITO); //Coluna dbCommand.Parameters.AddWithValue("@ESQUERDO", Entity.ESQUERDO); //Coluna dbCommand.Parameters.AddWithValue("@DPA", Entity.DPA); //Coluna dbCommand.Parameters.AddWithValue("@MD", Entity.MD); //Coluna dbCommand.Parameters.AddWithValue("@MV", Entity.MV); //Coluna //Retorno da Procedure FbParameter returnValue; returnValue = dbCommand.CreateParameter(); dbCommand.Parameters["@IDDIAGMEDIOPEDIDO"].Direction = ParameterDirection.InputOutput; //Executando consulta dbCommand.ExecuteNonQuery(); result = int.Parse(dbCommand.Parameters["@IDDIAGMEDIOPEDIDO"].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); }