예제 #1
0
        private static ARQUIVOPEDIDOEntity FillEntityObject(ref FbDataReader DataReader)
        {
            ARQUIVOPEDIDOEntity entity = new ARQUIVOPEDIDOEntity();

            FirebirdGetDbData getData = new FirebirdGetDbData();

            entity.IDARQUIVOPEDIDO = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDARQUIVOPEDIDO"));
            entity.IDPEDIDO        = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDPEDIDO"));
            entity.NOME            = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("NOME"));
            entity.TIPO            = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("TIPO"));
            entity.FOTO            = getData.ConvertDBValueToBytes(DataReader, DataReader.GetOrdinal("FOTO"));


            return(entity);
        }
예제 #2
0
        public ARQUIVOPEDIDOEntity Read(int IDARQUIVOPEDIDO)
        {
            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_ARQUIVOPEDIDO", dbCnn);
                    dbCommand.Transaction = ((FbTransaction)(dbTransaction));
                }
                else
                {
                    if (dbCnn == null)
                    {
                        dbCnn = ((FbConnection)GetConnectionDB());
                    }

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;

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


                reader = dbCommand.ExecuteReader();

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

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

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


                if (Entity.IDPEDIDO != null)
                {
                    dbCommand.Parameters.AddWithValue("@IDPEDIDO", Entity.IDPEDIDO);                             //ForeignKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDPEDIDO", DBNull.Value);                //ForeignKey 5
                }
                dbCommand.Parameters.AddWithValue("@NOME", Entity.NOME);                         //Coluna
                dbCommand.Parameters.AddWithValue("@TIPO", Entity.TIPO);                         //Coluna
                dbCommand.Parameters.AddWithValue("@FOTO", Entity.FOTO);                         //Coluna



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

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


                //Executando consulta
                dbCommand.ExecuteNonQuery();

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