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

            FirebirdGetDbData getData = new FirebirdGetDbData();

            entity.IDEQUIPAMENTOOSFECH = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDEQUIPAMENTOOSFECH"));
            entity.IDEQUIPAMENTO       = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDEQUIPAMENTO"));
            entity.QUANTIDADE          = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("QUANTIDADE"));
            entity.VALORUNITARIO       = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALORUNITARIO"));
            entity.VALORTOTAL          = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("VALORTOTAL"));
            entity.IDORDEMSERVICO      = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDORDEMSERVICO"));
            entity.TIPOLOCACAO         = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("TIPOLOCACAO"));
            entity.DATAINICIAL         = getData.ConvertDBValueToDateTimeNullable(DataReader, DataReader.GetOrdinal("DATAINICIAL"));
            entity.DATAFINAL           = getData.ConvertDBValueToDateTimeNullable(DataReader, DataReader.GetOrdinal("DATAFINAL"));
            entity.QUANTLOCACAO        = getData.ConvertDBValueToDecimalNullable(DataReader, DataReader.GetOrdinal("QUANTLOCACAO"));
            entity.IDFUNCIONARIO       = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDFUNCIONARIO"));
            entity.HORAINICIAL         = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("HORAINICIAL"));
            entity.HORAFINAL           = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("HORAFINAL"));
            entity.HORIMETROINICIAL    = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("HORIMETROINICIAL"));
            entity.HORIMETROFINAL      = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("HORIMETROFINAL"));
            entity.HORIMETROTOTAL      = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("HORIMETROTOTAL"));


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

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;

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


                reader = dbCommand.ExecuteReader();

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

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

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


                if (Entity.IDEQUIPAMENTO != null)
                {
                    dbCommand.Parameters.AddWithValue("@IDEQUIPAMENTO", Entity.IDEQUIPAMENTO);                             //ForeignKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDEQUIPAMENTO", DBNull.Value);                       //ForeignKey 5
                }
                dbCommand.Parameters.AddWithValue("@QUANTIDADE", Entity.QUANTIDADE);                         //Coluna
                dbCommand.Parameters.AddWithValue("@VALORUNITARIO", Entity.VALORUNITARIO);                   //Coluna
                dbCommand.Parameters.AddWithValue("@VALORTOTAL", Entity.VALORTOTAL);                         //Coluna

                if (Entity.IDORDEMSERVICO != null)
                {
                    dbCommand.Parameters.AddWithValue("@IDORDEMSERVICO", Entity.IDORDEMSERVICO);                             //ForeignKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDORDEMSERVICO", DBNull.Value);                    //ForeignKey 5
                }
                dbCommand.Parameters.AddWithValue("@TIPOLOCACAO", Entity.TIPOLOCACAO);                     //Coluna
                dbCommand.Parameters.AddWithValue("@DATAINICIAL", Entity.DATAINICIAL);                     //Coluna
                dbCommand.Parameters.AddWithValue("@DATAFINAL", Entity.DATAFINAL);                         //Coluna
                dbCommand.Parameters.AddWithValue("@QUANTLOCACAO", Entity.QUANTLOCACAO);                   //Coluna

                if (Entity.IDFUNCIONARIO != null)
                {
                    dbCommand.Parameters.AddWithValue("@IDFUNCIONARIO", Entity.IDFUNCIONARIO);                             //ForeignKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDFUNCIONARIO", DBNull.Value);                     //ForeignKey 5
                }
                dbCommand.Parameters.AddWithValue("@HORAINICIAL", Entity.HORAINICIAL);                     //Coluna
                dbCommand.Parameters.AddWithValue("@HORAFINAL", Entity.HORAFINAL);                         //Coluna
                dbCommand.Parameters.AddWithValue("@HORIMETROINICIAL", Entity.HORIMETROINICIAL);           //Coluna
                dbCommand.Parameters.AddWithValue("@HORIMETROFINAL", Entity.HORIMETROFINAL);               //Coluna
                dbCommand.Parameters.AddWithValue("@HORIMETROTOTAL", Entity.HORIMETROTOTAL);               //Coluna



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

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


                //Executando consulta
                dbCommand.ExecuteNonQuery();

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