Exemple #1
0
        private static NOTASERVICOEntity FillEntityObject(ref FbDataReader DataReader)
        {
            NOTASERVICOEntity entity = new NOTASERVICOEntity();

            FirebirdGetDbData getData = new FirebirdGetDbData();

            entity.IDNOTASERVICO         = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDNOTASERVICO"));
            entity.NPS                   = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("NPS"));
            entity.DATAEMISSAO           = getData.ConvertDBValueToDateTimeNullable(DataReader, DataReader.GetOrdinal("DATAEMISSAO"));
            entity.CODNATUREZA           = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("CODNATUREZA"));
            entity.REGIMETRIBUTACAO      = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("REGIMETRIBUTACAO"));
            entity.IDCLIENTE             = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDCLIENTE"));
            entity.DEDUCAO               = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("DEDUCAO"));
            entity.PIS                   = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("PIS"));
            entity.COFINS                = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("COFINS"));
            entity.INSS                  = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("INSS"));
            entity.IMPOSTORENDA          = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("IMPOSTORENDA"));
            entity.CONTRIBUICAOSOCIAL    = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("CONTRIBUICAOSOCIAL"));
            entity.ISS                   = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("ISS"));
            entity.ISSRETIDO             = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("ISSRETIDO"));
            entity.OUTRASRETENCOES       = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("OUTRASRETENCOES"));
            entity.BASECALCULO           = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("BASECALCULO"));
            entity.ALIQSERVICO           = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("ALIQSERVICO"));
            entity.DESCONTO              = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("DESCONTO"));
            entity.OBSERVACAO            = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("OBSERVACAO"));
            entity.DESCRICAODETALSERVICO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("DESCRICAODETALSERVICO"));
            entity.TOTALSERVICO          = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("TOTALSERVICO"));
            entity.IDCENTROCUSTO         = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDCENTROCUSTO"));
            entity.IDFORMAPAGTO          = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDFORMAPAGTO"));
            entity.IDLOCALCOBRANCA       = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDLOCALCOBRANCA"));


            return(entity);
        }
Exemple #2
0
        public NOTASERVICOEntity Read(int IDNOTASERVICO)
        {
            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_NOTASERVICO", dbCnn);
                    dbCommand.Transaction = ((FbTransaction)(dbTransaction));
                }
                else
                {
                    if (dbCnn == null)
                    {
                        dbCnn = ((FbConnection)GetConnectionDB());
                    }

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;

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


                reader = dbCommand.ExecuteReader();

                NOTASERVICOEntity 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;
            }
        }
Exemple #3
0
        public int Save(NOTASERVICOEntity 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_NOTASERVICO", dbCnn);
                    dbCommand.Transaction = ((FbTransaction)(dbTransaction));
                }
                else
                {
                    if (dbCnn == null)
                    {
                        dbCnn = ((FbConnection)GetConnectionDB());
                    }

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

                    dbCommand             = new FbCommand("Sav_NOTASERVICO", 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.IDNOTASERVICO == -1)
                {
                    dbCommand.Parameters.AddWithValue("@IDNOTASERVICO", DBNull.Value);
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDNOTASERVICO", Entity.IDNOTASERVICO);
                }

                dbCommand.Parameters.AddWithValue("@NPS", Entity.NPS);                           //Coluna
                dbCommand.Parameters.AddWithValue("@DATAEMISSAO", Entity.DATAEMISSAO);           //Coluna
                dbCommand.Parameters.AddWithValue("@CODNATUREZA", Entity.CODNATUREZA);           //Coluna
                dbCommand.Parameters.AddWithValue("@REGIMETRIBUTACAO", Entity.REGIMETRIBUTACAO); //Coluna

                if (Entity.IDCLIENTE != null)
                {
                    dbCommand.Parameters.AddWithValue("@IDCLIENTE", Entity.IDCLIENTE);                             //ForeignKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDCLIENTE", DBNull.Value);                         //ForeignKey 5
                }
                dbCommand.Parameters.AddWithValue("@DEDUCAO", Entity.DEDUCAO);                             //Coluna
                dbCommand.Parameters.AddWithValue("@PIS", Entity.PIS);                                     //Coluna
                dbCommand.Parameters.AddWithValue("@COFINS", Entity.COFINS);                               //Coluna
                dbCommand.Parameters.AddWithValue("@INSS", Entity.INSS);                                   //Coluna
                dbCommand.Parameters.AddWithValue("@IMPOSTORENDA", Entity.IMPOSTORENDA);                   //Coluna
                dbCommand.Parameters.AddWithValue("@CONTRIBUICAOSOCIAL", Entity.CONTRIBUICAOSOCIAL);       //Coluna
                dbCommand.Parameters.AddWithValue("@ISS", Entity.ISS);                                     //Coluna
                dbCommand.Parameters.AddWithValue("@ISSRETIDO", Entity.ISSRETIDO);                         //Coluna
                dbCommand.Parameters.AddWithValue("@OUTRASRETENCOES", Entity.OUTRASRETENCOES);             //Coluna
                dbCommand.Parameters.AddWithValue("@BASECALCULO", Entity.BASECALCULO);                     //Coluna
                dbCommand.Parameters.AddWithValue("@ALIQSERVICO", Entity.ALIQSERVICO);                     //Coluna
                dbCommand.Parameters.AddWithValue("@DESCONTO", Entity.DESCONTO);                           //Coluna
                dbCommand.Parameters.AddWithValue("@OBSERVACAO", Entity.OBSERVACAO);                       //Coluna
                dbCommand.Parameters.AddWithValue("@DESCRICAODETALSERVICO", Entity.DESCRICAODETALSERVICO); //Coluna
                dbCommand.Parameters.AddWithValue("@TOTALSERVICO", Entity.TOTALSERVICO);                   //Coluna

                if (Entity.IDCENTROCUSTO != null)
                {
                    dbCommand.Parameters.AddWithValue("@IDCENTROCUSTO", Entity.IDCENTROCUSTO);                             //ForeignKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDCENTROCUSTO", DBNull.Value);                             //ForeignKey 5
                }
                if (Entity.IDFORMAPAGTO != null)
                {
                    dbCommand.Parameters.AddWithValue("@IDFORMAPAGTO", Entity.IDFORMAPAGTO);                             //ForeignKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDFORMAPAGTO", DBNull.Value);                             //ForeignKey 5
                }
                if (Entity.IDLOCALCOBRANCA != null)
                {
                    dbCommand.Parameters.AddWithValue("@IDLOCALCOBRANCA", Entity.IDLOCALCOBRANCA);                             //ForeignKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDLOCALCOBRANCA", DBNull.Value);                             //ForeignKey 5
                }
                //Retorno da Procedure
                FbParameter returnValue;
                returnValue = dbCommand.CreateParameter();

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


                //Executando consulta
                dbCommand.ExecuteNonQuery();

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