Beispiel #1
0
        private static SERVICOPEDOTICAEntity FillEntityObject(ref FbDataReader DataReader)
        {
            SERVICOPEDOTICAEntity entity = new SERVICOPEDOTICAEntity();

            FirebirdGetDbData getData = new FirebirdGetDbData();

            entity.IDPRODPEDOTICA = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDPRODPEDOTICA"));
            entity.IDPEDIDOOTICA  = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDPEDIDOOTICA"));
            entity.IDSERVICO      = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDSERVICO"));
            entity.QUANTIDADE     = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("QUANTIDADE"));
            entity.VALORUNITARIO  = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALORUNITARIO"));
            entity.VALORTOTAL     = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALORTOTAL"));


            return(entity);
        }
Beispiel #2
0
        public SERVICOPEDOTICAEntity Read(int IDPRODPEDOTICA)
        {
            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_SERVICOPEDOTICA", dbCnn);
                    dbCommand.Transaction = ((FbTransaction)(dbTransaction));
                }
                else
                {
                    if (dbCnn == null)
                    {
                        dbCnn = ((FbConnection)GetConnectionDB());
                    }

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;

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


                reader = dbCommand.ExecuteReader();

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

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;


                if (Entity.IDPRODPEDOTICA != -1)
                {
                    dbCommand.Parameters.AddWithValue("@IDPRODPEDOTICA", Entity.IDPRODPEDOTICA); //PrimaryKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDPRODPEDOTICA", DBNull.Value);    //PrimaryKey
                }
                dbCommand.Parameters.AddWithValue("@IDPEDIDOOTICA", Entity.IDPEDIDOOTICA); //Coluna
                dbCommand.Parameters.AddWithValue("@IDSERVICO", Entity.IDSERVICO);         //Coluna
                dbCommand.Parameters.AddWithValue("@QUANTIDADE", Entity.QUANTIDADE);       //Coluna
                dbCommand.Parameters.AddWithValue("@VALORUNITARIO", Entity.VALORUNITARIO); //Coluna
                dbCommand.Parameters.AddWithValue("@VALORTOTAL", Entity.VALORTOTAL);       //Coluna



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

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


                //Executando consulta
                dbCommand.ExecuteNonQuery();

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