private static PLANOCORTEEntity FillEntityObject(ref FbDataReader DataReader) { PLANOCORTEEntity entity = new PLANOCORTEEntity(); FirebirdGetDbData getData = new FirebirdGetDbData(); entity.IDPLANOCORTE = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDPLANOCORTE")); entity.COMPCHAPA = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("COMPCHAPA")); entity.LARGURACHAPA = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("LARGURACHAPA")); entity.LARGLAMINA = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("LARGLAMINA")); entity.NIVELOTIMIZACAO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("NIVELOTIMIZACAO")); entity.IDPRODUTO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDPRODUTO")); entity.DESCRICAO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("DESCRICAO")); entity.EXIBIRDADOS = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("EXIBIRDADOS")); entity.EXIBIRMEDIDAS = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("EXIBIRMEDIDAS")); entity.DATACORTE = getData.ConvertDBValueToDateTimeNullable(DataReader, DataReader.GetOrdinal("DATACORTE")); entity.TAMZOOM = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("TAMZOOM")); return(entity); }
public PLANOCORTEEntity Read(int IDPLANOCORTE) { 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_PLANOCORTE", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Rea_PLANOCORTE", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; dbCommand.Parameters.AddWithValue("@IDPLANOCORTE", IDPLANOCORTE); //PrimaryKey reader = dbCommand.ExecuteReader(); PLANOCORTEEntity 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(PLANOCORTEEntity 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_PLANOCORTE", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Sav_PLANOCORTE", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; if (Entity.IDPLANOCORTE != -1) { dbCommand.Parameters.AddWithValue("@IDPLANOCORTE", Entity.IDPLANOCORTE); //PrimaryKey } else { dbCommand.Parameters.AddWithValue("@IDPLANOCORTE", DBNull.Value); //PrimaryKey } dbCommand.Parameters.AddWithValue("@COMPCHAPA", Entity.COMPCHAPA); //Coluna dbCommand.Parameters.AddWithValue("@LARGURACHAPA", Entity.LARGURACHAPA); //Coluna dbCommand.Parameters.AddWithValue("@LARGLAMINA", Entity.LARGLAMINA); //Coluna dbCommand.Parameters.AddWithValue("@NIVELOTIMIZACAO", Entity.NIVELOTIMIZACAO); //Coluna dbCommand.Parameters.AddWithValue("@IDPRODUTO", Entity.IDPRODUTO); //Coluna dbCommand.Parameters.AddWithValue("@DESCRICAO", Entity.DESCRICAO); //Coluna dbCommand.Parameters.AddWithValue("@EXIBIRDADOS", Entity.EXIBIRDADOS); //Coluna dbCommand.Parameters.AddWithValue("@EXIBIRMEDIDAS", Entity.EXIBIRMEDIDAS); //Coluna dbCommand.Parameters.AddWithValue("@DATACORTE", Entity.DATACORTE); //Coluna dbCommand.Parameters.AddWithValue("@TAMZOOM", Entity.TAMZOOM); //Coluna //Retorno da Procedure FbParameter returnValue; returnValue = dbCommand.CreateParameter(); dbCommand.Parameters["@IDPLANOCORTE"].Direction = ParameterDirection.InputOutput; //Executando consulta dbCommand.ExecuteNonQuery(); result = int.Parse(dbCommand.Parameters["@IDPLANOCORTE"].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); }