예제 #1
0
        private static AGENDAEntity FillEntityObject(ref FbDataReader DataReader)
        {
            AGENDAEntity entity = new AGENDAEntity();

            FirebirdGetDbData getData = new FirebirdGetDbData();

            entity.IDAGENDA      = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDAGENDA"));
            entity.IDSTATUS      = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDSTATUS"));
            entity.DATA          = getData.ConvertDBValueToDateTimeNullable(DataReader, DataReader.GetOrdinal("DATA"));
            entity.HORA          = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("HORA"));
            entity.IDGRUPOAGENDA = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDGRUPOAGENDA"));
            entity.IDEVENTO      = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDEVENTO"));
            entity.COMENTARIO    = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("COMENTARIO"));
            entity.IDFUNCIONARIO = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDFUNCIONARIO"));
            entity.IDCLIENTE     = getData.ConvertDBValueToInt32Nullable(DataReader, DataReader.GetOrdinal("IDCLIENTE"));


            return(entity);
        }
예제 #2
0
        public AGENDAEntity Read(int IDAGENDA)
        {
            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_AGENDA", dbCnn);
                    dbCommand.Transaction = ((FbTransaction)(dbTransaction));
                }
                else
                {
                    if (dbCnn == null)
                    {
                        dbCnn = ((FbConnection)GetConnectionDB());
                    }

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;

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


                reader = dbCommand.ExecuteReader();

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

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

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

                dbCommand.Parameters.AddWithValue("@IDSTATUS", Entity.IDSTATUS);                 //Coluna
                dbCommand.Parameters.AddWithValue("@DATA", Entity.DATA);                         //Coluna
                dbCommand.Parameters.AddWithValue("@HORA", Entity.HORA);                         //Coluna
                dbCommand.Parameters.AddWithValue("@IDGRUPOAGENDA", Entity.IDGRUPOAGENDA);       //Coluna
                dbCommand.Parameters.AddWithValue("@IDEVENTO", Entity.IDEVENTO);                 //Coluna
                dbCommand.Parameters.AddWithValue("@COMENTARIO", Entity.COMENTARIO);             //Coluna

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



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

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


                //Executando consulta
                dbCommand.ExecuteNonQuery();

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