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

            FirebirdGetDbData getData = new FirebirdGetDbData();

            entity.IDITPECASFECHOS = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDITPECASFECHOS"));
            entity.IDPRODUTO       = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDPRODUTO"));
            entity.QUANTIDADE      = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("QUANTIDADE"));
            entity.VALORUNITARIO   = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALORUNITARIO"));
            entity.VALORTOTAL      = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALORTOTAL"));
            entity.IDFECHOSERVICO  = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDFECHOSERVICO"));
            entity.IDORDEMSERVICO  = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDORDEMSERVICO"));


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

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;

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


                reader = dbCommand.ExecuteReader();

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

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;


                if (Entity.IDITPECASFECHOS != -1)
                {
                    dbCommand.Parameters.AddWithValue("@IDITPECASFECHOS", Entity.IDITPECASFECHOS); //PrimaryKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDITPECASFECHOS", DBNull.Value);     //PrimaryKey
                }
                dbCommand.Parameters.AddWithValue("@IDPRODUTO", Entity.IDPRODUTO);           //Coluna
                dbCommand.Parameters.AddWithValue("@QUANTIDADE", Entity.QUANTIDADE);         //Coluna
                dbCommand.Parameters.AddWithValue("@VALORUNITARIO", Entity.VALORUNITARIO);   //Coluna
                dbCommand.Parameters.AddWithValue("@VALORTOTAL", Entity.VALORTOTAL);         //Coluna
                dbCommand.Parameters.AddWithValue("@IDFECHOSERVICO", Entity.IDFECHOSERVICO); //Coluna
                dbCommand.Parameters.AddWithValue("@IDORDEMSERVICO", Entity.IDORDEMSERVICO); //Coluna



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

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


                //Executando consulta
                dbCommand.ExecuteNonQuery();

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