public DataTable PesquisarSenha(string senha)
        {
            DataTable tabela               = EstruturaHistorico();
            BD        bd                   = new BD();
            string    strStatus            = "";
            bool      pagamentoProcessado  = false;
            int       intVendaBilheteriaID = 0;

            try
            {
                using (IDataReader oDataReader = bd.Consulta("" +
                                                             "SELECT " +
                                                             "   tVendaBilheteria.ID, " +
                                                             "   tVendaBilheteria.Status, " +
                                                             "   tVendaBilheteria.PagamentoProcessado " +
                                                             "FROM " +
                                                             "  tVendaBilheteria (NOLOCK) " +
                                                             "WHERE " +
                                                             "  (Senha = '" + senha + "')"

                                                             ))
                {
                    if (!oDataReader.Read())
                    {
                        throw new ApplicationException("Venda não encontrada!");
                    }

                    if (bd.LerInt("ID") < 1)
                    {
                        throw new ApplicationException("Venda não encontrada!");
                    }

                    intVendaBilheteriaID = bd.LerInt("ID");

                    strStatus           = bd.LerString("Status");
                    pagamentoProcessado = bd.LerBoolean("PagamentoProcessado");
                }

                bd.Fechar();

                StringBuilder strSql = new StringBuilder();

                strSql.Append(" SELECT ");
                strSql.Append("( ");
                strSql.Append(" SELECT  ");
                strSql.Append(" COUNT(tIngressoLog.ID) ");
                strSql.Append(" FROM ");
                strSql.Append(" tIngressoLog (NOLOCK) ");
                strSql.Append(" WHERE ");
                strSql.Append(" (tIngressoLog.VendaBilheteriaID = " + intVendaBilheteriaID + ") ");
                strSql.Append(" ) AS TotIngressos, ");
                strSql.Append(" i.ID AS IngressoID, ");
                strSql.Append(" il.VendaBilheteriaID, ");
                strSql.Append(" i.Codigo, ");
                strSql.Append(" il.IngressoID, ");
                strSql.Append(" ev.ID EventoID, ");
                strSql.Append(" ev.Nome Evento, ");
                strSql.Append(" il.ID, ");
                strSql.Append(" il.[TimeStamp], ");
                strSql.Append(" il.Acao, ");
                strSql.Append(" il.Obs, ");
                strSql.Append(" p.Nome AS Preco, ");
                strSql.Append(" p.Valor, ");
                strSql.Append(" b.Nome AS Bloqueio, ");
                strSql.Append(" c.Nome AS Cortesia, ");
                strSql.Append(" lo.Nome AS Loja, ");
                strSql.Append(" i.Status, ");
                strSql.Append(" p.ID AS PrecoID, ");
                strSql.Append(" u.Nome AS Usuario, ");
                strSql.Append(" ci.Nome AS Cliente, ");
                strSql.Append(" vb.NotaFiscalEstabelecimento, ");
                strSql.Append(" vb.Senha, ");
                strSql.Append(" l.Nome AS Local, ");
                strSql.Append(" a.Horario AS Apresentacao, ");
                strSql.Append(" a.ID AS ApresentacaoID, ");
                strSql.Append(" s.Nome AS Setor, ");
                strSql.Append(" il.CodigoBarra, ");
                strSql.Append(" en.Tipo AS TaxaEntregaTipo, ");
                strSql.Append(" IsNull(us.Nome, ' - ') as  Supervisor, ");
                strSql.Append(" ep.Nome AS PeriodoAgenda ,");
                strSql.Append(" en.Nome AS EntregaNome ,");
                strSql.Append(" ea.Data AS DataAgenda ,");
                strSql.Append(" ear.Nome AS AreaEntrega ,");
                strSql.Append(" ISNULL(vb.ClienteEnderecoID,0) AS EnderecoEntrega , ");
                strSql.Append(" pdv.Nome as PDVEntrega, ");
                strSql.Append(" ev.TipoCodigoBarra, i.ApresentacaoSetorID ");
                strSql.Append(" ,ci.Email ");
                strSql.Append(" ,cl.Nome AS Canal ");
                strSql.Append(" ,en.ID AS EntregaID ");
                strSql.Append(" FROM tIngressoLog il (NOLOCK) ");
                strSql.Append(" LEFT JOIN tVendaBilheteria vb (NOLOCK) ON vb.ID = il.VendaBilheteriaID  ");
                strSql.Append(" INNER JOIN tUsuario u (NOLOCK) ON u.ID = il.UsuarioID ");
                strSql.Append(" LEFT JOIN tUsuario us (NOLOCK) ON us.ID = il.SupervisorID ");
                strSql.Append(" LEFT OUTER JOIN tPreco p (NOLOCK) ON p.ID = il.PrecoID ");
                strSql.Append(" INNER JOIN tIngresso i (NOLOCK) ON i.ID = IngressoID ");
                strSql.Append(" INNER JOIN tEvento ev (NOLOCK) ON ev.ID = i.EventoID ");
                strSql.Append(" INNER JOIN tLocal l (NOLOCK) ON l.ID = i.LocalID ");
                strSql.Append(" INNER JOIN tSetor s (NOLOCK) ON s.ID = i.SetorID ");
                strSql.Append(" INNER JOIN tApresentacao a (NOLOCK) ON a.ID = i.ApresentacaoID ");
                strSql.Append(" LEFT JOIN tLoja lo (NOLOCK) ON lo.ID = il.LojaID ");
                strSql.Append(" LEFT JOIN tCanal cl (NOLOCK) ON cl.ID = il.CanalID  ");
                strSql.Append(" LEFT JOIN tCliente ci (NOLOCK) ON ci.ID = vb.ClienteID ");
                strSql.Append(" LEFT JOIN tCortesia c (NOLOCK) ON c.ID = il.CortesiaID ");
                strSql.Append(" LEFT JOIN tBloqueio b (NOLOCK) ON b.ID = il.BloqueioID ");
                strSql.Append(" LEFT JOIN tEntregaControle ec (NOLOCK) ON vb.EntregaControleID = ec.ID ");
                strSql.Append(" LEFT JOIN tEntrega en (NOLOCK) ON ec.EntregaID = en.ID ");
                strSql.Append(" LEFT JOIN tEntregaPeriodo ep (NOLOCK) ON ec.PeriodoID = ep.ID ");
                strSql.Append(" LEFT JOIN tEntregaArea ear (NOLOCK) ON ec.EntregaAreaID = ear.ID ");
                strSql.Append(" LEFT JOIN tEntregaAgenda ea (NOLOCK) ON vb.EntregaAgendaID = ea.ID ");
                strSql.Append(" LEFT JOIN tPontoVenda pdv (NOLOCK) ON vb.PdvID = pdv.ID ");
                strSql.Append(" WHERE ");
                strSql.Append(" ( ");
                strSql.Append(" il.IngressoID IN ( ");
                strSql.Append(" SELECT ");
                strSql.Append(" IngressoID ");
                strSql.Append(" FROM  ");
                strSql.Append(" tIngressoLog (NOLOCK) ");
                strSql.Append(" WHERE ");
                strSql.Append(" (VendaBilheteriaID = " + intVendaBilheteriaID + ") ");
                strSql.Append(" ) ");
                strSql.Append(" ) ");
                strSql.Append(" ORDER BY ");
                strSql.Append(" il.IngressoID, ");
                strSql.Append(" il.ID ");

                using (IDataReader oDataReader = bd.Consulta(strSql.ToString()))
                {
                    int     ingressoID      = 0;
                    bool    blnInserirDados = false;
                    string  strSenhaVenda   = "";
                    DataRow linha           = null;

                    while (oDataReader.Read())
                    {
                        if (ingressoID != bd.LerInt("IngressoID"))
                        {
                            ingressoID      = bd.LerInt("IngressoID");
                            blnInserirDados = false;
                            strSenhaVenda   = "";
                        }

                        if (bd.LerString("Acao") == IngressoLog.VENDER)
                        {
                            strSenhaVenda = bd.LerString("Senha");
                        }

                        // Se a operação for venda, Liga o Flag de Inserir Dados
                        if (((bd.LerString("Acao") == IngressoLog.VENDER || bd.LerString("Acao") == IngressoLog.PRE_RESERVA) && strStatus != VendaBilheteria.CANCELADO && bd.LerInt("VendaBilheteriaID") == intVendaBilheteriaID) || (bd.LerString("Acao") == IngressoLog.CANCELAR && strStatus == VendaBilheteria.CANCELADO && bd.LerInt("VendaBilheteriaID") == intVendaBilheteriaID))
                        {
                            blnInserirDados = true;
                        }

                        // Insere as Informações dos Ingressos
                        if (blnInserirDados)
                        {
                            if (strSenhaVenda == "")
                            {
                                if (strStatus == VendaBilheteria.PRE_RESERVADO)
                                {
                                    strSenhaVenda = "-";
                                }
                                else
                                {
                                    strSenhaVenda = bd.LerString("Senha");
                                }
                            }

                            linha = tabela.NewRow();
                            linha["IngressoID"]          = bd.LerInt("IngressoID");
                            linha["IngressoLogID"]       = bd.LerInt("ID");
                            linha["Codigo"]              = bd.LerString("Codigo");
                            linha["Data"]                = bd.LerStringFormatoDataHora("TimeStamp");
                            linha["Cliente"]             = bd.LerString("Cliente");
                            linha["Evento"]              = bd.LerString("Evento");
                            linha["EventoID"]            = bd.LerString("EventoID");
                            linha["ApresentacaoID"]      = bd.LerString("ApresentacaoID");
                            linha["ApresentacaoSetorID"] = bd.LerInt("ApresentacaoSetorID");
                            linha["TipoCodigoBarra"]     = bd.LerString("TipoCodigoBarra");
                            // Se for uma senha de cancelamento alimentar a Senha de Venda e Senha de Cancelamento
                            if (strStatus == VendaBilheteria.CANCELADO)
                            {
                                linha["Senha"]             = strSenhaVenda;
                                linha["SenhaCancelamento"] = bd.LerString("Senha");
                            }
                            else
                            {
                                // Se for uma senha de venda, armazenar senha de venda, e somente a senha de cancalemento se for uma ação cancelar
                                linha["Senha"] = strSenhaVenda;

                                if (bd.LerString("Acao") == IngressoLog.CANCELAR)
                                {
                                    linha["SenhaCancelamento"] = bd.LerString("Senha");
                                }
                                else
                                {
                                    linha["SenhaCancelamento"] = " - ";
                                }
                            }

                            linha["Ação"]                = IngressoLog.AcaoDescritiva(bd.LerString("Acao"));
                            linha["Status"]              = Ingresso.StatusDescritivo(bd.LerString("Status"));
                            linha["StatusDetalhado"]     = Ingresso.StatusDetalhado(bd.LerString("Status"), bd.LerString("TaxaEntregaTipo"));
                            linha["PrecoID"]             = bd.LerInt("PrecoID");
                            linha["Preço"]               = bd.LerString("Preco");
                            linha["Loja"]                = bd.LerString("Loja");
                            linha["PagamentoProcessado"] = pagamentoProcessado;
                            linha["VendaBilheteriaID"]   = bd.LerString("VendaBilheteriaID");
                            linha["EntregaID"]           = bd.LerInt("EntregaID");
                            linha["Entrega"]             = bd.LerString("EntregaNome");
                            linha["Periodo"]             = bd.LerString("PeriodoAgenda");
                            linha["DataAgenda"]          = bd.LerDateTime("DataAgenda");
                            linha["AreaEntrega"]         = bd.LerString("AreaEntrega");
                            linha["EnderecoEntrega"]     = bd.LerInt("EnderecoEntrega");
                            linha["PDVEntrega"]          = bd.LerString("PDVEntrega");

                            if (bd.LerString("Acao") == IngressoLog.VENDER || bd.LerString("Acao") == IngressoLog.CANCELAR)
                            {
                                linha["Valor"] = bd.LerDecimal("Valor");
                            }

                            if (bd.LerString("Cortesia") != "")
                            {
                                linha["Cortesia"] = bd.LerString("Cortesia");
                            }
                            if (bd.LerString("Bloqueio") != "")
                            {
                                linha["Bloqueio"] = bd.LerString("Bloqueio");
                            }
                            linha["Usuario"] = bd.LerString("Usuario");
                            linha["Obs"]     = bd.LerString("Obs");

                            linha["Local"]        = bd.LerString("Local");
                            linha["Apresentacao"] = bd.LerStringFormatoDataHora("Apresentacao");
                            linha["Setor"]        = bd.LerString("Setor");
                            linha["CodigoBarra"]  = bd.LerString("CodigoBarra");
                            linha["Supervisor"]   = bd.LerString("Supervisor");
                            linha["Email"]        = bd.LerString("Email");
                            linha["Canal"]        = bd.LerString("Canal");

                            tabela.Rows.Add(linha);
                        }

                        // Caso a operação inserida for Cancelar, Desligar a Flag de Inserir Dados
                        if (bd.LerString("Acao") == IngressoLog.CANCELAR)
                        {
                            blnInserirDados = false;
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                throw new ApplicationException("Problemas ao acessar o banco de dados: " + ex.Message);
            }
            catch
            {
                throw;
            }
            finally
            {
                bd.Fechar();
            }

            return(tabela);
        }