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

            FirebirdGetDbData getData = new FirebirdGetDbData();

            entity.IDCHEQUE          = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDCHEQUE"));
            entity.NUMERO            = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("NUMERO"));
            entity.AGENCIA           = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("AGENCIA"));
            entity.CONTA             = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("CONTA"));
            entity.DIGCONTA          = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("DIGCONTA"));
            entity.VALOR             = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALOR"));
            entity.ENTRADA           = getData.ConvertDBValueToDateTimeNullable(DataReader, DataReader.GetOrdinal("ENTRADA"));
            entity.BOMPARA           = getData.ConvertDBValueToDateTimeNullable(DataReader, DataReader.GetOrdinal("BOMPARA"));
            entity.IDCENTROCUSTO     = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDCENTROCUSTO"));
            entity.IDBANCO           = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDBANCO"));
            entity.IDSTATUS          = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDSTATUS"));
            entity.IDFUNCIONARIO     = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDFUNCIONARIO"));
            entity.TIPORECEBIMENTO   = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("TIPORECEBIMENTO"));
            entity.NOMECLIENTEFORNEC = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("NOMECLIENTEFORNEC"));
            entity.IDCLIENTE         = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDCLIENTE"));
            entity.IDFORNECEDOR      = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDFORNECEDOR"));
            entity.TITULAR           = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("TITULAR"));
            entity.OBSERVACAO        = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("OBSERVACAO"));


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

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;

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


                reader = dbCommand.ExecuteReader();

                CHEQUEEntity 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(CHEQUEEntity 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_CHEQUE", dbCnn);
                    dbCommand.Transaction = ((FbTransaction)(dbTransaction));
                }
                else
                {
                    if (dbCnn == null)
                    {
                        dbCnn = ((FbConnection)GetConnectionDB());
                    }

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;


                if (Entity.IDCHEQUE != -1)
                {
                    dbCommand.Parameters.AddWithValue("@IDCHEQUE", Entity.IDCHEQUE); //PrimaryKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDCHEQUE", DBNull.Value);                  //PrimaryKey
                }
                dbCommand.Parameters.AddWithValue("@NUMERO", Entity.NUMERO);                       //Coluna
                dbCommand.Parameters.AddWithValue("@AGENCIA", Entity.AGENCIA);                     //Coluna
                dbCommand.Parameters.AddWithValue("@CONTA", Entity.CONTA);                         //Coluna
                dbCommand.Parameters.AddWithValue("@DIGCONTA", Entity.DIGCONTA);                   //Coluna
                dbCommand.Parameters.AddWithValue("@VALOR", Entity.VALOR);                         //Coluna
                dbCommand.Parameters.AddWithValue("@ENTRADA", Entity.ENTRADA);                     //Coluna
                dbCommand.Parameters.AddWithValue("@BOMPARA", Entity.BOMPARA);                     //Coluna
                dbCommand.Parameters.AddWithValue("@IDCENTROCUSTO", Entity.IDCENTROCUSTO);         //Coluna
                dbCommand.Parameters.AddWithValue("@IDBANCO", Entity.IDBANCO);                     //Coluna
                dbCommand.Parameters.AddWithValue("@IDSTATUS", Entity.IDSTATUS);                   //Coluna
                dbCommand.Parameters.AddWithValue("@IDFUNCIONARIO", Entity.IDFUNCIONARIO);         //Coluna
                dbCommand.Parameters.AddWithValue("@TIPORECEBIMENTO", Entity.TIPORECEBIMENTO);     //Coluna
                dbCommand.Parameters.AddWithValue("@NOMECLIENTEFORNEC", Entity.NOMECLIENTEFORNEC); //Coluna
                dbCommand.Parameters.AddWithValue("@IDCLIENTE", Entity.IDCLIENTE);                 //Coluna
                dbCommand.Parameters.AddWithValue("@IDFORNECEDOR", Entity.IDFORNECEDOR);           //Coluna
                dbCommand.Parameters.AddWithValue("@TITULAR", Entity.TITULAR);                     //Coluna
                dbCommand.Parameters.AddWithValue("@OBSERVACAO", Entity.OBSERVACAO);               //Coluna



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

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


                //Executando consulta
                dbCommand.ExecuteNonQuery();

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