コード例 #1
0
        protected void InserirObjetoPorQueryString(string queryString, Hashtable parametros)
        {
            DbCommand command = null;

            try
            {
                if ((queryString == null) | (queryString.Trim().Length == 0))
                {
                    throw new ArgumentNullException("queryString", "Argumento n\x00e3o pode ser nulo ou vazio.");
                }

                // var database = DatabaseFactory.CreateDatabase();
                command = CommandFactory.GetCommand(database, queryString);

                MapeamentoParametrosSQLServer mapper = new MapeamentoParametrosSQLServer();
                mapper.SubstituiParametrosQueriesList(command, parametros);

                database.ExecuteNonQuery(command);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                command.Dispose();
            }
        }
コード例 #2
0
        protected void AtualizarObjetoPorNomeQuery(string nomeQuery, Hashtable parametros)
        {
            DbCommand command = null;

            try
            {
                if ((nomeQuery == null) | (nomeQuery.Trim().Length == 0))
                {
                    throw new ArgumentNullException("nomeQuery", "Argumento n\x00e3o pode ser nulo ou vazio.");
                }

                var queryString = GerenciadorDoArquivoDeQueries.Instancia.ObterQuery(nomeQuery);
                // var database = DatabaseFactory.CreateDatabase();
                command = CommandFactory.GetCommand(database, queryString);

                MapeamentoParametrosSQLServer mapper = new MapeamentoParametrosSQLServer();
                mapper.SubstituiParametrosQueriesList(command, parametros);

                database.ExecuteScalar(command);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                command.Dispose();
            }
        }
コード例 #3
0
        protected int InserirObjetoPorNomeQueryERetornarId(string nomeQuery, Hashtable parametros)
        {
            DbCommand command = null;

            try
            {
                if ((nomeQuery == null) | (nomeQuery.Trim().Length == 0))
                {
                    throw new ArgumentNullException("nomeQuery", "Argumento n\x00e3o pode ser nulo ou vazio.");
                }

                var queryString = GerenciadorDoArquivoDeQueries.Instancia.ObterQuery(nomeQuery).Trim();
                queryString += (queryString[queryString.Length - 1] == ';' ? "" : ";");
                var queryComRetornoId = string.Format("{0} SELECT LAST_INSERT_ID();", queryString);
                // var database = DatabaseFactory.CreateDatabase();
                command = CommandFactory.GetCommand(database, queryComRetornoId);

                MapeamentoParametrosSQLServer mapper = new MapeamentoParametrosSQLServer();
                mapper.SubstituiParametrosQueriesList(command, parametros);

                var retorno = database.ExecuteScalar(command);
                return(retorno is DBNull ? 0 : Convert.ToInt32(retorno));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                command.Dispose();
            }
        }
コード例 #4
0
        protected int SelecionarQuantidadePorNomeQuery(string nomeQuery, Hashtable parametros)
        {
            int         quantidade = 0;
            ArrayList   result     = new ArrayList();
            DbCommand   command    = null;
            IDataReader dr         = null;

            try
            {
                if ((nomeQuery == null) | (nomeQuery.Trim().Length == 0))
                {
                    throw new ArgumentNullException("nomeQuery", "Argumento n\x00e3o pode ser nulo ou vazio.");
                }

                string queryString = GerenciadorDoArquivoDeQueries.Instancia.ObterQuery(nomeQuery);
                string queryCount  = GerenciadorDoArquivoDeQueries.Instancia.ObterQuery("querySelecionarCount").ToUpper();

                queryCount = queryCount.Replace("@MINHAQUERY@", queryString);
                queryCount = queryCount.Replace("ORDER BY", "").Replace("@ORDER_BY", "");

                //// var database = DatabaseFactory.CreateDatabase();
                command = CommandFactory.GetCommand(database, queryCount);

                MapeamentoParametrosSQLServer mapper = new MapeamentoParametrosSQLServer();
                mapper.SubstituiParametrosQueriesList(command, parametros);

                dr = database.ExecuteReader(command);
                var sqlDataReader = ((RefCountingDataReader)dr).InnerReader as MySqlDataReader;

                while (sqlDataReader.Read())
                {
                    quantidade = Int32.Parse(sqlDataReader[0].ToString());
                }

                return(quantidade);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                bool flag = dr != null;
                if (flag)
                {
                    dr.Close();
                    dr.Dispose();
                }
                flag = (command != null);
                if (flag)
                {
                    command.Dispose();
                }
            }
        }
コード例 #5
0
        private ArrayList SelecionarPaginadoPorNomeQuery(string nomeQuery, Hashtable parametros, DataAccess.RecuperaObjetoDelegate recuperaFunction)
        {
            ArrayList   result  = new ArrayList();
            DbCommand   command = null;
            IDataReader dr      = null;

            try
            {
                if ((nomeQuery == null) | (nomeQuery.Trim().Length == 0))
                {
                    throw new ArgumentNullException("nomeQuery", "Argumento n\x00e3o pode ser nulo ou vazio.");
                }

                String query = GerenciadorDoArquivoDeQueries.Instancia.ObterQuery(nomeQuery).ToUpper();
                //query = query.Replace("ORDER BY", "").Replace("@ORDER_BY", "");

                string queryPaginacao = GerenciadorDoArquivoDeQueries.Instancia.ObterQuery("querySelecionarPaginado").ToUpper();
                queryPaginacao = queryPaginacao.Replace("@MINHAQUERY@", query);

                // var database = DatabaseFactory.CreateDatabase();
                command = CommandFactory.GetCommand(database, queryPaginacao);

                MapeamentoParametrosSQLServer mapper = new MapeamentoParametrosSQLServer();
                mapper.SubstituiParametrosQueriesList(command, parametros);

                dr = database.ExecuteReader(command);
                var sqlDataReader = ((RefCountingDataReader)dr).InnerReader as MySqlDataReader;

                while (dr.Read())
                {
                    Object obj = recuperaFunction(sqlDataReader);
                    result.Add(RuntimeHelpers.GetObjectValue(obj));
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                bool flag = dr != null;
                if (flag)
                {
                    dr.Close();
                    dr.Dispose();
                }
                flag = (command != null);
                if (flag)
                {
                    command.Dispose();
                }
            }
        }