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

            FirebirdGetDbData getData = new FirebirdGetDbData();

            entity.CODIGO_VENDEDOR = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("CODIGO_VENDEDOR"));
            entity.NOME_VENDEDOR   = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("NOME_VENDEDOR"));



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

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;

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


                reader = dbCommand.ExecuteReader();

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

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;


                if (Entity.CODIGO_VENDEDOR != -1)
                {
                    dbCommand.Parameters.AddWithValue("@CODIGO_VENDEDOR", Entity.CODIGO_VENDEDOR); //PrimaryKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@CODIGO_VENDEDOR", DBNull.Value); //PrimaryKey
                }
                if (Entity.NOME_VENDEDOR != null)
                {
                    dbCommand.Parameters.AddWithValue("@NOME_VENDEDOR", Entity.NOME_VENDEDOR); //Coluna
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@NOME_VENDEDOR", DBNull.Value); //Coluna 3
                }
                //Retorno da Procedure
                FbParameter returnValue;
                returnValue = dbCommand.CreateParameter();

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


                //Executando consulta
                dbCommand.ExecuteNonQuery();

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