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

            FirebirdGetDbData getData = new FirebirdGetDbData();

            entity.IDORCAMENTO    = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDORCAMENTO"));
            entity.IDCLIENTE      = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDCLIENTE"));
            entity.DTEMISSAO      = getData.ConvertDBValueToDateTimeNullable(DataReader, DataReader.GetOrdinal("DTEMISSAO"));
            entity.DTVALIDADE     = getData.ConvertDBValueToDateTimeNullable(DataReader, DataReader.GetOrdinal("DTVALIDADE"));
            entity.IDSTATUS       = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDSTATUS"));
            entity.PRAZOENTREGA   = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("PRAZOENTREGA"));
            entity.IDFORMAPAGTO   = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDFORMAPAGTO"));
            entity.IDFUNCIONARIO  = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDFUNCIONARIO"));
            entity.IDTRANSPORTES  = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDTRANSPORTES"));
            entity.OBSERVACAO     = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("OBSERVACAO"));
            entity.TOTALIPI       = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("TOTALIPI"));
            entity.PORCDESCONTO   = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("PORCDESCONTO"));
            entity.TOTALDESCONTO  = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("TOTALDESCONTO"));
            entity.PORCACRESCIMO  = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("PORCACRESCIMO"));
            entity.TOTALACRESCIMO = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("TOTALACRESCIMO"));
            entity.TOTAORCAMENTO  = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("TOTAORCAMENTO"));


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

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;

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


                reader = dbCommand.ExecuteReader();

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

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;


                if (Entity.IDORCAMENTO != -1)
                {
                    dbCommand.Parameters.AddWithValue("@IDORCAMENTO", Entity.IDORCAMENTO); //PrimaryKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDORCAMENTO", DBNull.Value);         //PrimaryKey
                }
                dbCommand.Parameters.AddWithValue("@IDCLIENTE", Entity.IDCLIENTE);           //Coluna
                dbCommand.Parameters.AddWithValue("@DTEMISSAO", Entity.DTEMISSAO);           //Coluna
                dbCommand.Parameters.AddWithValue("@DTVALIDADE", Entity.DTVALIDADE);         //Coluna
                dbCommand.Parameters.AddWithValue("@IDSTATUS", Entity.IDSTATUS);             //Coluna
                dbCommand.Parameters.AddWithValue("@PRAZOENTREGA", Entity.PRAZOENTREGA);     //Coluna
                dbCommand.Parameters.AddWithValue("@IDFORMAPAGTO", Entity.IDFORMAPAGTO);     //Coluna
                dbCommand.Parameters.AddWithValue("@IDFUNCIONARIO", Entity.IDFUNCIONARIO);   //Coluna
                dbCommand.Parameters.AddWithValue("@IDTRANSPORTES", Entity.IDTRANSPORTES);   //Coluna
                dbCommand.Parameters.AddWithValue("@OBSERVACAO", Entity.OBSERVACAO);         //Coluna
                dbCommand.Parameters.AddWithValue("@TOTALIPI", Entity.TOTALIPI);             //Coluna
                dbCommand.Parameters.AddWithValue("@PORCDESCONTO", Entity.PORCDESCONTO);     //Coluna
                dbCommand.Parameters.AddWithValue("@TOTALDESCONTO", Entity.TOTALDESCONTO);   //Coluna
                dbCommand.Parameters.AddWithValue("@PORCACRESCIMO", Entity.PORCACRESCIMO);   //Coluna
                dbCommand.Parameters.AddWithValue("@TOTALACRESCIMO", Entity.TOTALACRESCIMO); //Coluna
                dbCommand.Parameters.AddWithValue("@TOTAORCAMENTO", Entity.TOTAORCAMENTO);   //Coluna



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

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


                //Executando consulta
                dbCommand.ExecuteNonQuery();

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