Exemplo n.º 1
0
        private static SERVICONFEEntity FillEntityObject(ref FbDataReader DataReader)
        {
            SERVICONFEEntity entity = new SERVICONFEEntity();

            FirebirdGetDbData getData = new FirebirdGetDbData();

            entity.IDSERVICONFE  = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDSERVICONFE"));
            entity.IDSERVICO     = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDSERVICO"));
            entity.IDNOTAFISCALE = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDNOTAFISCALE"));
            entity.QUANTIDADE    = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("QUANTIDADE"));
            entity.VALORUNITARIO = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALORUNITARIO"));
            entity.VALORTOTAL    = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALORTOTAL"));
            entity.ALIQISSQN     = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("ALIQISSQN"));
            entity.VALORISSQN    = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALORISSQN"));


            return(entity);
        }
Exemplo n.º 2
0
        public SERVICONFEEntity Read(int IDSERVICONFE)
        {
            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_SERVICONFE", dbCnn);
                    dbCommand.Transaction = ((FbTransaction)(dbTransaction));
                }
                else
                {
                    if (dbCnn == null)
                    {
                        dbCnn = ((FbConnection)GetConnectionDB());
                    }

                    if (dbCnn.State == ConnectionState.Closed)
                    {
                        dbCnn.Open();
                    }

                    dbCommand             = new FbCommand("Rea_SERVICONFE", dbCnn);
                    dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted);
                }

                dbCommand.CommandType = CommandType.StoredProcedure;

                dbCommand.Parameters.AddWithValue("@IDSERVICONFE", IDSERVICONFE);                //PrimaryKey


                reader = dbCommand.ExecuteReader();

                SERVICONFEEntity 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;
            }
        }
Exemplo n.º 3
0
        public int Save(SERVICONFEEntity 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_SERVICONFE", dbCnn);
                    dbCommand.Transaction = ((FbTransaction)(dbTransaction));
                }
                else
                {
                    if (dbCnn == null)
                    {
                        dbCnn = ((FbConnection)GetConnectionDB());
                    }

                    if (dbCnn.State == ConnectionState.Closed)
                    {
                        dbCnn.Open();
                    }

                    dbCommand             = new FbCommand("Sav_SERVICONFE", dbCnn);
                    dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted);
                }

                dbCommand.CommandType = CommandType.StoredProcedure;


                if (Entity.IDSERVICONFE != -1)
                {
                    dbCommand.Parameters.AddWithValue("@IDSERVICONFE", Entity.IDSERVICONFE);            //PrimaryKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDSERVICONFE", DBNull.Value);      //PrimaryKey
                }
                dbCommand.Parameters.AddWithValue("@IDSERVICO", Entity.IDSERVICO);         //Coluna
                dbCommand.Parameters.AddWithValue("@IDNOTAFISCALE", Entity.IDNOTAFISCALE); //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("@ALIQISSQN", Entity.ALIQISSQN);         //Coluna
                dbCommand.Parameters.AddWithValue("@VALORISSQN", Entity.VALORISSQN);       //Coluna



                //Retorno da Procedure
                FbParameter returnValue;
                returnValue = dbCommand.CreateParameter();

                dbCommand.Parameters["@IDSERVICONFE"].Direction = ParameterDirection.InputOutput;


                //Executando consulta
                dbCommand.ExecuteNonQuery();

                result = int.Parse(dbCommand.Parameters["@IDSERVICONFE"].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);
        }