Esempio n. 1
0
        private static FOTOPRODUTOEntity FillEntityObject(ref FbDataReader DataReader)
        {
            FOTOPRODUTOEntity entity = new FOTOPRODUTOEntity();

            FirebirdGetDbData getData = new FirebirdGetDbData();

            entity.IDFOTO     = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDFOTO"));
            entity.NOME       = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("NOME"));
            entity.TIPO       = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("TIPO"));
            entity.OBSERVACAO = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("OBSERVACAO"));
            entity.IDPRODUTO  = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDPRODUTO"));
            entity.FOTO       = getData.ConvertDBValueToBytes(DataReader, DataReader.GetOrdinal("FOTO"));


            return(entity);
        }
Esempio n. 2
0
        public FOTOPRODUTOEntity Read(int IDFOTO)
        {
            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_FOTOPRODUTO", dbCnn);
                    dbCommand.Transaction = ((FbTransaction)(dbTransaction));
                }
                else
                {
                    if (dbCnn == null)
                    {
                        dbCnn = ((FbConnection)GetConnectionDB());
                    }

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;

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


                reader = dbCommand.ExecuteReader();

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

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;


                if (Entity.IDFOTO != -1)
                {
                    dbCommand.Parameters.AddWithValue("@IDFOTO", Entity.IDFOTO); //PrimaryKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDFOTO", DBNull.Value);      //PrimaryKey
                }
                dbCommand.Parameters.AddWithValue("@NOME", Entity.NOME);             //Coluna
                dbCommand.Parameters.AddWithValue("@TIPO", Entity.TIPO);             //Coluna
                dbCommand.Parameters.AddWithValue("@OBSERVACAO", Entity.OBSERVACAO); //Coluna
                dbCommand.Parameters.AddWithValue("@IDPRODUTO", Entity.IDPRODUTO);   //Coluna
                dbCommand.Parameters.AddWithValue("@FOTO", Entity.FOTO);             //Coluna



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

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


                //Executando consulta
                dbCommand.ExecuteNonQuery();

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