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

            FirebirdGetDbData getData = new FirebirdGetDbData();

            entity.CODIGO_CLIENTE         = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("CODIGO_CLIENTE"));
            entity.NOME_CLIENTE           = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("NOME_CLIENTE"));
            entity.FANTASIA_CLIENTE       = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("FANTASIA_CLIENTE"));
            entity.CPF_CLIENTE            = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("CPF_CLIENTE"));
            entity.DOC_CLIENTE            = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("DOC_CLIENTE"));
            entity.ENDERECO_CLIENTE       = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("ENDERECO_CLIENTE"));
            entity.NUMEROEND_CLIENTE      = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("NUMEROEND_CLIENTE"));
            entity.COMPLEMENTOEND_CLIENTE = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("COMPLEMENTOEND_CLIENTE"));
            entity.BAIRRO_CLIENTE         = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("BAIRRO_CLIENTE"));
            entity.CEP_CLIENTE            = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("CEP_CLIENTE"));
            entity.EMAIL_CLIENTE          = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("EMAIL_CLIENTE"));
            entity.TELEFONE1_CLIENTE      = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("TELEFONE1_CLIENTE"));
            entity.TELEFONE2_CLIENTE      = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("TELEFONE2_CLIENTE"));
            entity.CELULAR_CLIENTE        = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("CELULAR_CLIENTE"));
            entity.COD_CIDADE             = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("COD_CIDADE"));

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

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;

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


                reader = dbCommand.ExecuteReader();

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

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

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

                dbCommand.CommandType = CommandType.StoredProcedure;


                if (Entity.CODIGO_CLIENTE != -1)
                {
                    dbCommand.Parameters.AddWithValue("@CODIGO_CLIENTE", Entity.CODIGO_CLIENTE); //PrimaryKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@CODIGO_CLIENTE", DBNull.Value);                      //PrimaryKey
                }
                dbCommand.Parameters.AddWithValue("@NOME_CLIENTE", Entity.NOME_CLIENTE);                     //Coluna
                dbCommand.Parameters.AddWithValue("@FANTASIA_CLIENTE", Entity.FANTASIA_CLIENTE);             //Coluna
                dbCommand.Parameters.AddWithValue("@CPF_CLIENTE", Entity.CPF_CLIENTE);                       //Coluna
                dbCommand.Parameters.AddWithValue("@DOC_CLIENTE", Entity.DOC_CLIENTE);                       //Coluna
                dbCommand.Parameters.AddWithValue("@ENDERECO_CLIENTE", Entity.ENDERECO_CLIENTE);             //Coluna
                dbCommand.Parameters.AddWithValue("@NUMEROEND_CLIENTE", Entity.NUMEROEND_CLIENTE);           //Coluna
                dbCommand.Parameters.AddWithValue("@COMPLEMENTOEND_CLIENTE", Entity.COMPLEMENTOEND_CLIENTE); //Coluna
                dbCommand.Parameters.AddWithValue("@BAIRRO_CLIENTE", Entity.BAIRRO_CLIENTE);                 //Coluna
                dbCommand.Parameters.AddWithValue("@CEP_CLIENTE", Entity.CEP_CLIENTE);                       //Coluna
                dbCommand.Parameters.AddWithValue("@EMAIL_CLIENTE", Entity.EMAIL_CLIENTE);                   //Coluna
                dbCommand.Parameters.AddWithValue("@TELEFONE1_CLIENTE", Entity.TELEFONE1_CLIENTE);           //Coluna
                dbCommand.Parameters.AddWithValue("@TELEFONE2_CLIENTE", Entity.TELEFONE2_CLIENTE);           //Coluna
                dbCommand.Parameters.AddWithValue("@CELULAR_CLIENTE", Entity.CELULAR_CLIENTE);               //Coluna
                dbCommand.Parameters.AddWithValue("@COD_CIDADE", Entity.COD_CIDADE);                         //Coluna



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

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


                //Executando consulta
                dbCommand.ExecuteNonQuery();

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