Exemplo n.º 1
0
        public TFCad_SQL(TRegistro_Cad_Consulta Reg_Consulta, bool vEditar)
        {
            InitializeComponent();
            Cad_Consulta = Reg_Consulta;
            DS_SQL.Text  = Cad_Consulta.DS_SQL;
            Editar       = vEditar;

            //ADD O HIGHLIGHT
            //Parse();

            //BUSCA AS TABELAS PERMITIDAS
            if (!Editar)
            {
                ListaTabelasPermitidas = TCN_Cad_Usuario_X_Tabela.Busca(Utils.Parametros.pubLogin, "", "");
            }

            //DA O FOCUS
            if ((pNMConsulta.Visible))
            {
                NM_Consulta.Focus();
            }
            else
            {
                DS_SQL.Focus();
            }
        }
Exemplo n.º 2
0
 private void bb_Adicionar_Click(object sender, EventArgs e)
 {
     //ADICIONA VALOR DO PARAMETRO AO TEXTO
     DS_SQL.Text           = DS_SQL.Text.Insert(PosFocusRich, NM_CampoFormat.Text);
     DS_SQL.SelectionStart = (NM_CampoFormat.Text.Length + PosFocusRich);
     DS_SQL.Focus();
     pDadosParam.Visible = false;
 }
Exemplo n.º 3
0
 private void tsBB_Cancelar_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Deseja realmente cancelar a edição desta SQL?", "Mensagem",
                         MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) ==
         System.Windows.Forms.DialogResult.Yes)
     {
         this.Close();
     }
     else
     {
         DS_SQL.Focus();
     }
 }
Exemplo n.º 4
0
        private bool VerificaAcessoSyntax()
        {
            bool valido = true;

            if (!Editar)
            {
                string   sql            = DS_SQL.Text;
                string[] keywordsSyntax = keywordsArraySyntax();

                Regex    r      = new Regex("([ \\t{}();])");
                String[] tokens = r.Split(sql);

                if (keywordsSyntax != null)
                {
                    for (int x = 0; x < tokens.Length; x++)
                    {
                        string token       = tokens[x].Replace("\n", "").Replace("\t", "");
                        string tokenNormal = tokens[x];

                        // VERIFICA SE TEM OS KEYWORDS DA SQL
                        for (int i = 0; i < keywordsSyntax.Length; i++)
                        {
                            if (keywordsSyntax[i] == token || keywordsSyntax[i].ToLower() == token.ToLower())
                            {
                                DS_SQL.SelectionColor = Color.Red;
                                DS_SQL.SelectionFont  = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular);
                                valido = false;
                                break;
                            }
                        }

                        if (!valido)
                        {
                            break;
                        }
                    }
                }
            }
            if (valido)
            {
                return(true);
            }
            else
            {
                MessageBox.Show("Atenção, a SQL contém syntax não autorizadas!");
                DS_SQL.Focus();

                return(false);
            }
        }
Exemplo n.º 5
0
        public void adicionaMSGErro(string msg)
        {
            grid_Resultado.Visible = false;
            tabPageResult.Controls.Clear();
            EditDefault edit = new EditDefault();

            edit.Text      = msg;
            edit.ReadOnly  = true;
            edit.Multiline = true;
            edit.ForeColor = Color.Red;
            edit.Dock      = DockStyle.Fill;
            tabPageResult.Controls.Add(edit);
            DS_SQL.Focus();
        }
Exemplo n.º 6
0
        private void DS_SQL_KeyPress()
        {
            //String[] vetor;
            //vetor = DS_SQL.Text.ToString().ToUpper().Split(' ');

            ////for (int j = 0; j < vetor.Length; j++)
            ////{
            //if (vetor.Length >= 1)
            //{
            //    string strin = vetor[vetor.Length-1 ];
            //    int i = DS_SQL.Find(strin.ToLower());

            //   if (i >= 0)
            //    {

            //        DS_SQL.SelectionStart = i;

            //        DS_SQL.SelectionLength = strin.Length;


            //        DS_SQL.SelectionColor = Cor(strin);
            //        //   DS_SQL.SelectedText = DS_SQL.SelectedText;
            //        DS_SQL.SelectionStart = DS_SQL.TextLength;

            //    }
            //}
            int inicio = DS_SQL.SelectionStart;

            int    start   = DS_SQL.SelectionStart;
            int    end     = DS_SQL.SelectionStart;
            string palavra = "";

            while (!palavra.Contains(" "))
            {
                if (start == 0)
                {
                    DS_SQL.SelectionColor = Cor(DS_SQL.SelectedText);
                    DS_SQL.SelectedText   = DS_SQL.SelectedText;
                    DS_SQL.SelectionStart = inicio;
                    return;
                }
                start--;
                DS_SQL.Select(start, end);
                palavra = DS_SQL.SelectedText;
            }
            DS_SQL.SelectionColor = Cor(DS_SQL.SelectedText);
            DS_SQL.SelectedText   = DS_SQL.SelectedText;
            DS_SQL.SelectionStart = inicio;
        }
Exemplo n.º 7
0
        private bool VerificaTabelasPermitidas()
        {
            bool retorno = true;

            if (!Editar)
            {
                String[] sqlArray = DS_SQL.Text.ToUpper().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                for (int x = 0; x < sqlArray.Length; x++)
                {
                    string NMTabelas = sqlArray[x].Trim();
                    if (NMTabelas.StartsWith("TB_") || NMTabelas.StartsWith("VTB_"))
                    {
                        if (NMTabelas.Contains("JOIN") ||
                            NMTabelas.Contains("FROM"))
                        {
                            retorno = false;

                            for (int i = 0; i < ListaTabelasPermitidas.Count; i++)
                            {
                                if (ListaTabelasPermitidas[i].NM_Tabela.ToUpper().Trim() == NMTabelas)
                                {
                                    retorno = true;
                                    break;
                                }
                            }

                            if (!retorno)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            if (retorno)
            {
                return(true);
            }
            else
            {
                MessageBox.Show("Atenção, a SQL contém tabelas não autorizadas que o usuário " + CamadaDados.TDataQuery.getPubVariavel(TInfo.pub, "LOGIN") + " não tem permissão de acesso!");
                DS_SQL.Focus();

                return(false);
            }
        }
Exemplo n.º 8
0
        public TFSqlEditor()
        {
            InitializeComponent();
            //  Cad_Consulta = Reg_Consulta;
            // DS_SQL.Text = Cad_Consulta.DS_SQL;
            // Editar = vEditar;

            //ADD O HIGHLIGHT
            //Parse();

            //BUSCA AS TABELAS PERMITIDAS
            if (!Editar)
            {
                ListaTabelasPermitidas = TCN_Cad_Usuario_X_Tabela.Busca(Utils.Parametros.pubLogin, "", "");
            }

            //DA O FOCUS

            DS_SQL.Focus();
        }
Exemplo n.º 9
0
        private void tsBB_Executar_Click(object sender, EventArgs e)
        {
            string login = Utils.Parametros.pubLogin;

            if (DS_SQL.ToString().ToUpper().Contains("UPDATE") || DS_SQL.ToString().ToUpper().Contains("INSERT") || DS_SQL.ToString().ToUpper().Contains("DROP") || DS_SQL.ToString().ToUpper().Contains("DELETE") ||
                DS_SQL.ToString().ToUpper().Contains("ALTER"))
            {
                if (!CamadaNegocio.Diversos.TCN_Usuario_RegraEspecial.ValidaRegra(Utils.Parametros.pubLogin, "PERMITIR UPDATE", null))
                {
                    using (Proc_Commoditties.TFLanSessaoPDV fSessao = new Proc_Commoditties.TFLanSessaoPDV())
                    {
                        fSessao.Mensagem = "Usuário sem permissão de update";
                        if (fSessao.ShowDialog() == DialogResult.OK)
                        {
                            if (!CamadaNegocio.Diversos.TCN_Usuario_RegraEspecial.ValidaRegra(fSessao.Usuario, "PERMITIR UPDATE", null))
                            {
                                MessageBox.Show("Usuário não tem permissão!");
                                return;
                            }
                            else
                            {
                                login = fSessao.Usuario;
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }


            List <string> lista = new List <string>();

            System.IO.StringReader rd = new System.IO.StringReader(DS_SQL.Text);
            string linha = string.Empty;

            while (linha != null)
            {
                linha = rd.ReadLine();
                if (linha != null)
                {
                    if (linha.Contains("'{@"))
                    {
                        string[] var = linha.Split(new char[] { '{' });
                        for (int i = 0; var.Length > i; i++)
                        {
                            if (var[i].Contains("@") && var[i].Contains("}"))
                            {
                                if (!lista.Exists(p => p.Equals(var[i])))
                                {
                                    lista.Add(var[i].Split(new char[] { '}' })[0]);
                                }
                            }
                        }
                    }
                }
                ;
            }
            //if (lista.Count > 0)
            //{
            //    using (TFParametrosConsulta fParam = new TFParametrosConsulta())
            //    {
            //        //Criar fonte de dados
            //        fParam.lista = lista;
            //        if (fParam.ShowDialog() == DialogResult.OK)
            //            if (fParam.data != null)
            //            {
            //                string Sql = DS_SQL.Text;
            //                for (int i = 0; fParam.data.Rows.Count > i; i++)
            //                {
            //                    if (!string.IsNullOrEmpty(ConsultaSql))
            //                        Sql = ConsultaSql;
            //                    string param = "{" + fParam.data.Rows[i]["param"] + "}";
            //                    string valor = fParam.data.Rows[i]["valor"].ToString();
            //                    ConsultaSql = Sql.Replace(param, valor);
            //                }
            //            }
            //    }
            //}
            //else
            ConsultaSql = DS_SQL.Text;

            // if (VerificaAcessoSyntax() && VerificaTabelasPermitidas())
            // {
            try
            {
                adicionaMSGErro("Aguarde... executanto a consulta SQL!");

                if (grid_Resultado.Columns.Count > 0)
                {
                    grid_Resultado.Columns.Clear();
                }

                if (grid_Resultado.Rows.Count > 0)
                {
                    grid_Resultado.Rows.Clear();
                }

                if (DS_SQL.Text != "")
                {
                    TCD_SqlEditor       cd  = new TCD_SqlEditor();
                    TRegistro_SqlEditor sed = new TRegistro_SqlEditor();
                    sed.Login       = login;
                    sed.DS_Consulta = ConsultaSql;
                    cd.Grava(sed);
                    DataTable dataTable = cd.BuscarSQL(ConsultaSql.Replace("\n", " ").Replace("\t", " "));

                    if (DS_SQL.ToString().ToUpper().Contains("SELECT"))
                    {
                        for (int i = 0; i < dataTable.Columns.Count; i++)
                        {
                            DataGridViewTextBoxColumn coluna = new DataGridViewTextBoxColumn();
                            coluna.Name             = dataTable.Columns[i].ColumnName;
                            coluna.HeaderText       = dataTable.Columns[i].ColumnName;
                            coluna.DataPropertyName = dataTable.Columns[i].ColumnName;
                            coluna.AutoSizeMode     = DataGridViewAutoSizeColumnMode.DisplayedCells;
                            grid_Resultado.Columns.Add(coluna);
                        }

                        BS_Resultado.DataSource = dataTable;
                        BS_Resultado.ResetBindings(true);

                        grid_Resultado.Visible = true;
                        tabPageResult.Controls.Clear();
                        tabPageResult.Controls.Add(grid_Resultado);
                    }
                    else
                    {
                        adicionaMSGErro("Registros afetados: " + cd.tamanho.ToString());
                    }
                }
                else
                {
                    adicionaMSGErro("Atenção há erros na SQL!");
                }
            }
            catch (Exception erro)
            {
                adicionaMSGErro("ERRO: " + erro.Message);
            }
        }