private static PRODUTONFEntity FillEntityObject(ref FbDataReader DataReader) { PRODUTONFEntity entity = new PRODUTONFEntity(); FirebirdGetDbData getData = new FirebirdGetDbData(); entity.IDPRODUTONF = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDPRODUTONF")); entity.IDNOTAFISCAL = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDNOTAFISCAL")); entity.IDPRODUTO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDPRODUTO")); entity.QUANTIDADE = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("QUANTIDADE")); entity.VALORUNITARIO = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALORUNITARIO")); entity.VALORTOTAL = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALORTOTAL")); entity.COMISSAO = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("COMISSAO")); entity.ALICMS = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("ALICMS")); entity.REDICMS = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("REDICMS")); entity.VALORICMS = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALORICMS")); entity.ALIPI = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("ALIPI")); entity.VALORIPI = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALORIPI")); entity.IDCLASSFISCAL = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDCLASSFISCAL")); entity.IDCST = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDCST")); entity.BASEICMS = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("BASEICMS")); entity.IDUNIDADE = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDUNIDADE")); return(entity); }
public PRODUTONFEntity Read(int IDPRODUTONF) { 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_PRODUTONF", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Rea_PRODUTONF", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; dbCommand.Parameters.AddWithValue("@IDPRODUTONF", IDPRODUTONF); //PrimaryKey reader = dbCommand.ExecuteReader(); PRODUTONFEntity 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(PRODUTONFEntity 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_PRODUTONF", dbCnn); dbCommand.Transaction = ((FbTransaction)(dbTransaction)); } else { if (dbCnn == null) { dbCnn = ((FbConnection)GetConnectionDB()); } if (dbCnn.State == ConnectionState.Closed) { dbCnn.Open(); } dbCommand = new FbCommand("Sav_PRODUTONF", dbCnn); dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted); } dbCommand.CommandType = CommandType.StoredProcedure; if (Entity.IDPRODUTONF != -1) { dbCommand.Parameters.AddWithValue("@IDPRODUTONF", Entity.IDPRODUTONF); //PrimaryKey } else { dbCommand.Parameters.AddWithValue("@IDPRODUTONF", DBNull.Value); //PrimaryKey } dbCommand.Parameters.AddWithValue("@IDNOTAFISCAL", Entity.IDNOTAFISCAL); //Coluna dbCommand.Parameters.AddWithValue("@IDPRODUTO", Entity.IDPRODUTO); //Coluna dbCommand.Parameters.AddWithValue("@QUANTIDADE", Entity.QUANTIDADE); //Coluna dbCommand.Parameters.AddWithValue("@VALORUNITARIO", Entity.VALORUNITARIO); //Coluna dbCommand.Parameters.AddWithValue("@VALORTOTAL", Entity.VALORTOTAL); //Coluna dbCommand.Parameters.AddWithValue("@COMISSAO", Entity.COMISSAO); //Coluna dbCommand.Parameters.AddWithValue("@ALICMS", Entity.ALICMS); //Coluna dbCommand.Parameters.AddWithValue("@REDICMS", Entity.REDICMS); //Coluna dbCommand.Parameters.AddWithValue("@VALORICMS", Entity.VALORICMS); //Coluna dbCommand.Parameters.AddWithValue("@ALIPI", Entity.ALIPI); //Coluna dbCommand.Parameters.AddWithValue("@VALORIPI", Entity.VALORIPI); //Coluna dbCommand.Parameters.AddWithValue("@IDCLASSFISCAL", Entity.IDCLASSFISCAL); //Coluna dbCommand.Parameters.AddWithValue("@IDCST", Entity.IDCST); //Coluna dbCommand.Parameters.AddWithValue("@BASEICMS", Entity.BASEICMS); //Coluna dbCommand.Parameters.AddWithValue("@IDUNIDADE", Entity.IDUNIDADE); //Coluna //Retorno da Procedure FbParameter returnValue; returnValue = dbCommand.CreateParameter(); dbCommand.Parameters["@IDPRODUTONF"].Direction = ParameterDirection.InputOutput; //Executando consulta dbCommand.ExecuteNonQuery(); result = int.Parse(dbCommand.Parameters["@IDPRODUTONF"].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); }