private bool EnviaComando(string query)
        {
            if (ControllerBanco.AbreConexao() == true)
            {
                MySqlCommand cmd = new MySqlCommand(query, ControllerBanco.PegaConexao());
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (MySqlException err) {
                    switch (err.Number)
                    {
                    case (int)MySqlErrorCode.DuplicateKeyEntry:
                        InformaDiag.Erro("O registro já existe. Tente outros valores");
                        break;

                    default:
                        InformaDiag.Erro("Ocorreu um erro e a operação será abortada.");
                        break;
                    }
                    cmd.Dispose();
                    return(false);
                };
                ControllerBanco.FechaConexao();
                cmd.Dispose();
                return(true);
            }
            return(false);
        }
 private void btnApaga_Click(object sender, EventArgs e)
 {
     if (InformaDiag.ConfirmaSN("Remover um registro pode afetar vários outros. Recomenda-se observar as dependências antes de continuar" + '\n' + "Prosseguir?") == DialogResult.Yes)
     {
         if (InformaDiag.ConfirmaOkCancel("Esta ação é irreversível! Confirme a exculsão.") == DialogResult.OK)
         {
             crud.ApagaLinha(tabelasBd.PALAVRA, "Id=" + p.id.ToString());
             if (resPalavra.Count > 1)
             {
                 resPalavra.Remove(p);
                 if (ipal > 0)
                 {
                     btnAnterior_Click(sender, e);
                 }
                 else
                 {
                     btnProx_Click(sender, e);
                 }
             }
             else
             {
                 LimpaModel();
                 LimpaCampos();
             }
         }
     }
 }
Exemple #3
0
 private void btnApaga_Click(object sender, EventArgs e)
 {
     if (referencia.id > 0)
     {
         if (InformaDiag.ConfirmaSN("Remover um registro pode afetar vários outros. Recomenda-se observar as dependências antes de continuar" + '\n' + "Prosseguir?") == DialogResult.Yes)
         {
             if (InformaDiag.ConfirmaOkCancel("Esta ação é irreversível! Confirme a exculsão.") == DialogResult.OK)
             {
                 c.ApagaLinha(tabelasBd.REFERENCIAS, "Cod=" + referencia.Cod.ToString());
                 resultado.RemoveAt(p);
                 if (resultado.Count > 0)
                 {
                     try
                     {
                         referencia = resultado.ElementAt(--p);
                     }
                     catch (IndexOutOfRangeException)
                     {
                         referencia = resultado.ElementAt(++p);
                     }
                     MostraModel();
                 }
                 else
                 {
                     LimpaModel();
                     LimpaCampos();
                 }
             }
         }
     }
 }
 private void btnDescarta_Click(object sender, EventArgs e)
 {
     if (InformaDiag.ConfirmaSN("Serão carregadas as informações previamente salvas e\ntodas as alterações serão perdidas. Continuar?") == DialogResult.Yes)
     {
         frm_conjuga_Load(sender, e);
     }
 }
 private void button1_Click(object sender, EventArgs e)
 {
     if (InformaDiag.ConfirmaSN("Tem certeza?") == DialogResult.Yes)
     {
         c.ApagaLinha(tabelasBd.USUARIOS, "usr='******'");
     }
 }
Exemple #6
0
 private void btnApaga_Click(object sender, EventArgs e)
 {
     if (InformaDiag.ConfirmaSN("Deseja realmente apagar o relacionamento?\nA ação é irreversível!") == DialogResult.Yes)
     {
         crud.ApagaLinha(tabelasBd.EQUIVALENTE, "origem=" + ativo.origem.ToString() + " AND equivalente=" + ativo.equivalente.ToString());
         LimpaCampos();
     }
     btnPrimeiro_Click(sender, e);
 }
 private void BtnNovo_Click(object sender, EventArgs e)
 {
     if (txtusr.Text != usr.usr || txtpass.Text != usr.pass || txtEmail.Text != usr.email || converteAutorizacao() != usr.permissao || txtCpf.Text != usr.cpf)
     {
         if (InformaDiag.ConfirmaSN("Existem dados não salvos que serão perdidos. \n Deseja continuar?") == DialogResult.Yes)
         {
             LimpaCampo();
             LimpaModel();
         }
     }
 }
 private void btnNovo_Click(object sender, EventArgs e)
 {
     if (txtDesc.Text != rubrica.descricao || txtSigla.Text != rubrica.sigla)
     {
         if (InformaDiag.ConfirmaSN("Existem dados não salvos que serão perdidos. \n Deseja continuar?") == DialogResult.No)
         {
             return;
         }
     }
     LimpaCampos();
     LimpaModel();
 }
Exemple #9
0
 private void btnNovo_Click(object sender, EventArgs e)
 {
     if (txtDesc.Text != referencia.descricao || txtAno.Text != referencia.ano.ToString() || txtAutor.Text != referencia.autor)
     {
         if (InformaDiag.ConfirmaSN("Existem dados não salvos que serão perdidos. \n Deseja continuar?") == DialogResult.No)
         {
             return;
         }
     }
     LimpaCampos();
     LimpaModel();
 }
 private void btnNovo_Click(object sender, EventArgs e)
 {
     if (txtpalavra.Text != "")
     {
         if (InformaDiag.ConfirmaSN("Existem dados não salvos. Caso prossiga com a operação, todos os dados" + '\n' + "digitados serão perdidos. Continuar mesmo assim?") == DialogResult.No)
         {
             return;
         }
     }
     LimpaCampos();
     LimpaModel();
 }
 public bool FechaConexao()
 {
     try
     {
         conexao.Close();
         return(true);
     }
     catch (MySqlException ex)
     {
         InformaDiag.Erro(ex.Message);
         return(false);
     }
 }
Exemple #12
0
 private int LiberaArquivo(StreamReader f)
 {
     try{
         f.DiscardBufferedData();
         f.Dispose();
     }
     catch (IOException)
     {
         InformaDiag.Erro("Erro ao liberar o arquivo");
         return(1);
     }
     return(0);
 }
        private void txtBuscaCpf_Click(object sender, EventArgs e)
        {
            List <Usuario> resultado = Usuario.ConverteObject(c.SelecionarTabela(tabelasBd.USUARIOS, Usuario.ToListTabela(), "cpf='" + txtCpf.Text + "'"));

            if (resultado.Count > 0)
            {
                usr = resultado.First();
                MostraModel();
            }
            else
            {
                InformaDiag.Informa("Nenhum usuário encontrado.");
            }
        }
 private void btnApaga_Click(object sender, EventArgs e)
 {
     if (rubrica.id > 0)
     {
         if (InformaDiag.ConfirmaSN("Remover um registro pode afetar vários outros. Recomenda-se observar as dependências antes de continuar" + '\n' + "Prosseguir?") == DialogResult.Yes)
         {
             if (InformaDiag.ConfirmaOkCancel("Esta ação é irreversível! Confirme a exculsão.") == DialogResult.OK)
             {
                 c.ApagaLinha(tabelasBd.MARCAS_USO, "Id=" + rubrica.id.ToString());
                 LimpaModel();
                 LimpaCampos();
             }
         }
     }
 }
Exemple #15
0
 private void BtnGrava_Click(object sender, EventArgs e)
 {
     if (InformaDiag.ConfirmaSN("Você tem certeza que deseja continuar?\n" + "Todos os dados válidos da tabela serão salvos no Banco de Dados!") == DialogResult.Yes)
     {
         if (importador(ComboTable.Text) == 1)
         {
             InformaDiag.Informa("Houveram erros na importação e alguns registros foram ignorados.");
         }
         BtnProcura.Enabled = true;
         LblArquivo.Text    = "Nenhum arquivo selecionado";
         progressBar1.MarqueeAnimationSpeed = 0;
         dataGridView1.Rows.Clear();
         dataGridView1.Columns.Clear();
     }
 }
 ///TODO: Sugerir que as informações nas textboxes sejam quebradas uma por linha. A apresentação das informçãoes de cada uma delas será contolada pelo CHR(13) na exibição do lema
 private void button2_Click(object sender, EventArgs e)
 {
     if (lingua == "PT")
     {
         ConjugacaoPt nPt = new ConjugacaoPt();
         nPt.ConstrPresente   = txtC1.Text;
         nPt.ExPresente       = txtE1.Text;
         nPt.ConstrPretImp    = txtC2.Text;
         nPt.ExPretImp        = txtE2.Text;
         nPt.ConstrPretPer    = txtC3.Text;
         nPt.ExPretPer        = txtE3.Text;
         nPt.ConstrFutPres    = txtC4.Text;
         nPt.ExFutPres        = txtE4.Text;
         nPt.ConstrFutPret    = txtC5.Text;
         nPt.ExFutPret        = txtE5.Text;
         nPt.ConstrInfPessoal = txtC6.Text;
         nPt.ExInfPessoal     = txtE6.Text;
         nPt.ConstrParticipio = txtC7.Text;
         nPt.ExParticipio     = txtE7.Text;
         nPt.ConstrGerundio   = txtC8.Text;
         nPt.ExGerundio       = txtE8.Text;
         crud.UpdateLine(tabelasBd.CONJUGACAOPT, ConjugacaoPt.ToListTabela(), nPt.ToListValores(), "idConjugacao=" + cPt.id.ToString());
         cPt = nPt;
     }
     else
     {
         ConjugacaoEn nEn = new ConjugacaoEn();
         nEn.ConstrPresente = txtC1.Text;
         nEn.ExPresente     = txtE1.Text;
         nEn.ConstrPassado  = txtC2.Text;
         nEn.ExPassado      = txtE2.Text;
         nEn.ConstrWill     = txtC3.Text;
         nEn.ExWill         = txtE3.Text;
         nEn.ConstrGoingTo  = txtC4.Text;
         nEn.ExGoingTo      = txtE4.Text;
         nEn.ConstrPresPer  = txtC5.Text;
         nEn.ExPresPer      = txtE5.Text;
         nEn.ConstrPasPer   = txtC6.Text;
         nEn.ExPasPer       = txtE6.Text;
         nEn.ConstrPresCon  = txtC7.Text;
         nEn.ExPresCon      = txtE7.Text;
         nEn.ConstrPasCon   = txtC8.Text;
         nEn.ExPasCon       = txtE8.Text;
         crud.UpdateLine(tabelasBd.CONJUGACAOEN, ConjugacaoEn.ToListTabela(), nEn.ToListValores(), "idConjugacao=" + cEn.id.ToString());
         cEn = nEn;
     }
     InformaDiag.InformaSalvo();
 }
Exemple #17
0
 private void btnApaga_Click(object sender, EventArgs e)
 {
     if (InformaDiag.ConfirmaSN("Deseja apagar o registro ativo?") == DialogResult.Yes)
     {
         cRUD.ApagaLinha(tabelasBd.FRASEOLOGIA, "IdPalavra=" + frs_old.IdPalavra.ToString() + " AND FraseOrig='" + frs_old.FraseOrig + "' AND FraseEquiv='" + frs_old.FraseEquiv + "' AND Categoria='" + frs_old.Categoria + "'");
         lFrase.Remove(frs);
         LimpaCampos();
         LimpaRegistro();
         btnProx_Click(sender, e);
         btnAnterior_Click(sender, e);
         if (lFrase.Count < 2)
         {
             DesativaNavegadores();
         }
     }
 }
Exemple #18
0
 private void BtnCancela_Click(object sender, EventArgs e)
 {
     if (InformaDiag.ConfirmaSN("Você tem certeza que deseja apagar todos os dados não salvos?") == DialogResult.Yes)
     {
         progressBar1.MarqueeAnimationSpeed = 50;
         dataGridView1.Rows.Clear();
         dataGridView1.Columns.Clear();
         BtnCancela.Enabled = false;
         BtnGrava.Enabled   = false;
         BtnStart.Enabled   = false;
         ComboTable.Enabled = true;
         BtnProcura.Enabled = true;
         LblArquivo.Text    = "Nenhum arquivo selecionado";
         progressBar1.MarqueeAnimationSpeed = 0;
     }
 }
        private void searchButton_Click(object sender, EventArgs e)
        {
            List <Palavra> lista = new List <Palavra>();
            string         chavePesquisa = searchBox.Text, pesquisa;

            if (chavePesquisa == "")
            {
                InformaDiag.Erro("A caixa de busca não pode estar vazia!");
                return;
            }
            if (chavePesquisa.Contains(" "))
            {
            }
            else
            {
                if (chavePesquisa.EndsWith("ing") || chavePesquisa.EndsWith("ed") || chavePesquisa.EndsWith("ies") || chavePesquisa.EndsWith("es"))
                {
                    InformaDiag.Erro("Entradas em inglês não acessíveis no momento.");
                    return;
                }
                if (chavePesquisa.EndsWith("ar") || chavePesquisa.EndsWith("ir"))
                {
                    //caso suspeitarmos que seja um infinitivo em portugues...
                    pesquisa = "Lema = '" + chavePesquisa + "' AND Idioma = 'PT'";
                    lista    = Palavra.ConverteObject(cRUD.SelecionarTabela(tabelasBd.PALAVRA, Palavra.ToListTabela(true), pesquisa));

                    if (lista.Count >= 1) //Existe somente aquele resultado?
                    {
                        if (lista.Count == 1)
                        {
                            txtResultado.Text = MontaApresentaçãoInfinitivoPt(lista.First());
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        InformaDiag.Erro("Busca não encontrada!");
                    }
                }
                else
                {
                    //caso suspeitarmos que é um verbo flexionado em português
                }
            }
        }
        private void Frm_busca_Load(object sender, EventArgs e)
        {
            string versaoAt = cRUD.SelecionarTabela("config", new List <string> {
                "versaoPc"
            }).First()[0].ToString();
            string versaoEx = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            if (versaoAt != versaoEx)
            {
                if (InformaDiag.ConfirmaSN("A versão do software está desatualizada.\nPara continuar utilizando, é necessário obter e instalar uma" +
                                           " nova versão pela Internet. Deseja prosseguir?\nVocê será redirecinado para a página de download ao continuar.") == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start("https://github.com/russkibrazil/dicionario-gpel/releases/latest");
                }
                this.Close();
            }
        }
Exemple #21
0
 private void btnPesquisa_Click(object sender, EventArgs e)
 {
     resultado = Referencia.ConverteObject(c.SelecionarTabela(tabelasBd.REFERENCIAS, Referencia.ToListTabela(true), "Cod='" + txtCodPSQ.Text + "'"));
     if (resultado.Count < 1)
     {
         InformaDiag.Informa("Nenhum resultado encontrado.");
         return;
     }
     referencia = resultado.First();
     MostraModel();
     if (resultado.Count > 1)
     {
         btnAnt.Visible  = true;
         btnProx.Visible = true;
     }
     p = 0;
     txtCod.ReadOnly = true;
 }
 private void btnSalva_Click(object sender, EventArgs e)
 {
     if (equivDestModificado || ativo.equivalente < 1)
     {
         if (novo)
         {
             InformaDiag.Erro("Selecione uma palavra equivalente dentro dos\nresultados da caixa de pesquisa Verbete Destino!");
             return;
         }
         else
         {
             if (InformaDiag.ConfirmaSN("O valor selecionado no verbete destino foi modificado para um valor inconsistente.\nDeseja continuar com o valor antigo?") == DialogResult.No)
             {
                 return;
             }
         }
     }
     ativo.exemplo           = txtExemplo.Text;
     ativo.exemplo_traduzido = txtExemploTraduzido.Text;
     ativo.DefinirOrdemApresentação((int)txtApresentacao.Value);
     ativo.heterogenerico   = chkHgenerico.Checked;
     ativo.heterotonico     = chkHtonico.Checked;
     ativo.heterossemantico = chkHsemantico.Checked;
     ativo.notasCulturais   = txtCultura.Text;
     ativo.notasGramaticais = txtGramatica.Text;
     if (!novo)
     {
         crud.UpdateLine(tabelasBd.EQUIVALENTE, Equivalente.ToListTabela(), ativo.ToListValores(), "Origem=" + oldEqAt.origem.ToString() + " AND equivalente=" + oldEqAt.equivalente.ToString() + " AND nApresentacao=" + oldEqAt.nOrdem.ToString());
         int tpos = equivO.IndexOf(ativo);
         equivO.RemoveAt(tpos);
         equivO.Insert(tpos, ativo);
     }
     else
     {
         crud.InsereLinha(tabelasBd.EQUIVALENTE, Equivalente.ToListTabela(), ativo.ToListValores());
         equivO.Add(ativo);
         if (equivO.Count > 1)
         {
             AtivaNavegadores();
         }
     }
     InformaDiag.InformaSalvo();
     novo = false;
 }
        private void btnincluir_Click(object sender, EventArgs e)
        {
            //campos não nulos: usuario, senha, nivel de permissão, email e cpf
            if (txtusr.Text == "" || txtpass.Text == "" || txtEmail.Text == "" || txtCpf.Text == "")
            {
                InformaDiag.Erro("Campos obrigatórios não foram preenchidos.");
            }
            else
            {
                bool edicao;
                if (usr.cpf != "")
                {
                    edicao = true;
                }
                else
                {
                    edicao = false;
                }
                usr.usr  = txtusr.Text;
                usr.pass = txtpass.Text;

                usr.permissao = converteAutorizacao();
                usr.email     = txtEmail.Text;
                usr.nome      = txtNome.Text;
                usr.tel       = txtTelefone.Text;
                usr.rsocial   = txtRSoc.Text;
                usr.cpf       = txtCpf.Text;
                usr.contato   = txtContato.Text;
                if (edicao)
                {
                    c.UpdateLine(tabelasBd.USUARIOS, Usuario.ToListTabela(), usr.ToListValores(), "cpf='" + usr.cpf + "'");
                }
                else
                {
                    c.InsereLinha(tabelasBd.USUARIOS, Usuario.ToListTabela(), usr.ToListValores());
                }

                InformaDiag.InformaSalvo();
                LimpaCampo();
            }
        }
 private void btnSalva_Click(object sender, EventArgs e)
 {
     if (txtDesc.Text == "" || txtSigla.Text == "")
     {
         InformaDiag.Erro("Existem campos obrigatórios vazios!");
         return;
     }
     rubrica.descricao = txtDesc.Text;
     rubrica.sigla     = txtSigla.Text;
     if (rubrica.id > 0)
     {
         c.UpdateLine(tabelasBd.MARCAS_USO, MarcaUso.ToListTabela(false), rubrica.ToListValores(), "id=" + rubrica.id.ToString());
     }
     else
     {
         c.InsereLinha(tabelasBd.MARCAS_USO, MarcaUso.ToListTabela(false), rubrica.ToListValores());
     }
     InformaDiag.InformaSalvo();
     LimpaCampos();
     LimpaModel();
 }
Exemple #25
0
 private void btnSalva_Click(object sender, EventArgs e)
 {
     if (txtDesc.Text == "" || txtAno.Text == "" || txtAutor.Text == "" || txtCod.Text == "")
     {
         InformaDiag.Erro("Existem campos obrigatórios vazios!");
         return;
     }
     referencia.Cod       = txtCod.Text;
     referencia.descricao = txtDesc.Text;
     referencia.ano       = int.Parse(txtAno.Text);
     referencia.autor     = txtAutor.Text;
     if (referencia.id > 0)
     {
         c.UpdateLine(tabelasBd.REFERENCIAS, Referencia.ToListTabela(false), referencia.ToListValores(), "Id=" + referencia.id.ToString());
     }
     else
     {
         c.InsereLinha(tabelasBd.REFERENCIAS, Referencia.ToListTabela(false), referencia.ToListValores());
     }
     InformaDiag.InformaSalvo();
     LimpaCampos();
     LimpaModel();
 }
Exemple #26
0
        private void btnSalva_Click(object sender, EventArgs e)
        {
            ativo.exemplo           = txtExemplo.Text;
            ativo.exemplo_traduzido = txtExemploTraduzido.Text;
            ativo.DefinirOrdemApresentação((int)txtApresentacao.Value);
            ativo.PalavraGuia = txtGuia.Text;
            //ativo.heterogenerico = chkHgenerico.Checked;
            //ativo.heterotonico = chkHtonico.Checked;
            //ativo.heterossemantico = chkHsemantico.Checked;
            List <string> fld = Equivalente.ToListTabela();

            fld.Remove("heterotonico");
            fld.Remove("heterogenerico");
            fld.Remove("heterossemantico");

            if (!novo)
            {
                crud.UpdateLine(tabelasBd.EQUIVALENTE, fld, ativo.ToListValores(), "Origem=" + oldEqAt.origem.ToString() + " AND equivalente=" + oldEqAt.equivalente.ToString() + " AND nApresentacao=" + oldEqAt.nOrdem.ToString());
            }
            else
            {
                if (ativo.equivalente < 1)
                {
                    InformaDiag.Erro("Selecione um equivalente na lista de pesquisa.");
                    return;
                }
                else
                {
                    crud.InsereLinha(tabelasBd.EQUIVALENTE, Equivalente.ToListTabela(), ativo.ToListValores());
                    equivO.Add(ativo);
                    AtivaNavegadores();
                }
            }
            InformaDiag.InformaSalvo();
            novo = false;
        }
        public bool AbreConexao()
        {
            try
            {
                conexao.Open();
                if (conexao.ConnectionString.Contains("localhost"))
                {
                    InformaDiag.Erro("Banco de testes ativo.");
                }
                return(true);
            }
            catch (MySqlException ex)
            {
                {
                    switch (ex.Number)
                    {
                    case 0:
                        InformaDiag.Erro("Falha ao conectar no servidor de dados.");
                        break;

                    case (int)MySqlErrorCode.NoSuchUser:
                        InformaDiag.Erro("A combinação de usuário e senha não existe. Tente novamente.");
                        break;

                    default:
                        InformaDiag.Erro("Erro " + ex.Code.ToString() + ex.Message);
                        break;
                    }
                }
                return(false);
            }
            catch (InvalidOperationException)
            {
                return(false);
            }
        }
Exemple #28
0
 private void btnSalva_Click(object sender, EventArgs e)
 {
     frs_old = frs;
     if (comboCategoria.SelectedIndex == 0)
     {
         frs.Categoria = "I";
     }
     else
     {
         frs.Categoria = "C";
     }
     frs.ExemploEquivalente = txtExemploTrad.Text;
     frs.ExemploOriginal    = txtExemplo.Text;
     frs.FraseEquiv         = txtFequivalente.Text;
     frs.FraseOrig          = txtForiginal.Text;
     frs.NotasCultura       = txtCultura.Text;
     frs.NotasGramatica     = txtGramatica.Text;
     if (novo)
     {
         cRUD.InsereLinha(tabelasBd.FRASEOLOGIA, Fraseologia.ToListTabela(), frs.ToListValores());
         lFrase.Add(frs);
         if (lFrase.Count < 2)
         {
             DesativaNavegadores();
         }
     }
     else
     {
         cRUD.UpdateLine(tabelasBd.FRASEOLOGIA, Fraseologia.ToListTabela(), frs.ToListValores(), "IdPalavra=" + frs_old.IdPalavra.ToString() + " AND FraseOrig='" + frs_old.FraseOrig + "' AND FraseEquiv='" + frs_old.FraseEquiv + "' AND Categoria='" + frs_old.Categoria + "'");
         int idx = lFrase.FindIndex(frl => frl == frs);
         lFrase.RemoveAt(idx);
         lFrase.Insert(idx, frs);
     }
     InformaDiag.InformaSalvo();
     novo = false;
 }
Exemple #29
0
        private void BtnStart_Click(object sender, EventArgs e)
        //NOTE: Usar ponto e vírgula como separador no CSV
        {
            string linha;

            string[] divisor;
            int      v = 0;

            progressBar1.MarqueeAnimationSpeed = 50;
            if (ComboTable.Text != "")
            {
                switch (ComboTable.Text)
                {
                case "Palavra":
                    ptlt = Palavra.ToListTabela();
                    ptlt.RemoveRange(Palavra.ToListTabela().Count - 2, 2);
                    v = ptlt.Count;
                    break;

                case "Marca de Uso":
                    v    = MarcaUso.ToListTabela().Count;
                    ptlt = MarcaUso.ToListTabela();
                    break;

                case "Referência":
                    v    = Referencia.ToListTabela().Count;
                    ptlt = Referencia.ToListTabela();
                    break;

                default:
                    throw new Exception("Não implementado");
                    break;
                }
                try
                {
                    StreamReader leitor = new StreamReader(LblArquivo.Text, Encoding.Default);
                    try
                    {
                        do
                        {
                            linha = leitor.ReadLine();
                            if (linha != "")
                            {
                                divisor = linha.Split(';');
                                //varificar dimensao antes de prosseguir
                                if (divisor.Count() != v)
                                {
                                    InformaDiag.Erro("A quantidade de colunas da entrada é diferente do destino.\nOperação Abortada.");
                                    progressBar1.MarqueeAnimationSpeed = 0;
                                    BtnStart.Enabled = false;
                                    LiberaArquivo(leitor);
                                    return;
                                }

                                for (int i = 0; i < divisor.GetLength(0); i++)
                                {
                                    if (divisor[i] == ptlt.ElementAt(i))
                                    {
                                        dataGridView1.Columns.Add(divisor[i], divisor[i]);
                                    }
                                    else
                                    {
                                        dataGridView1.Columns.Clear();
                                        EnumeraColunasFaltantes(divisor, ptlt);
                                        progressBar1.MarqueeAnimationSpeed = 0;
                                        BtnStart.Enabled = false;
                                        LiberaArquivo(leitor);
                                        return;
                                    }
                                }
                            }
                        } while (linha == "");
                        do //implementar thread
                        {
                            linha = leitor.ReadLine();
                            if (linha != "")
                            {
                                divisor = linha.Split(';');
                                dataGridView1.Rows.Add(divisor);
                            }
                        } while (leitor.Peek() != -1);
                        LiberaArquivo(leitor);
                    }
                    catch (IndexOutOfRangeException) { }
                    catch (EndOfStreamException) { }
                }

                catch (FileLoadException) {
                    return;
                }
                catch (FileNotFoundException) {
                    return;
                }
                catch (IOException)
                {
                    InformaDiag.Erro("O arquivo está inacessível no momento.\nTente novamente mais tarde.");
                    return;
                }
                BtnStart.Enabled   = false;
                BtnProcura.Enabled = false;
                BtnCancela.Enabled = true;
                BtnGrava.Enabled   = true;
                ComboTable.Enabled = false;
                progressBar1.MarqueeAnimationSpeed = 0;
            }
            else
            {
                InformaDiag.Informa("Escolha uma tabela destino");
            }
        }
Exemple #30
0
        private int importador(string NomeTabela)
        {
            DataGridViewRow[]  linhas       = new DataGridViewRow[dataGridView1.Rows.Count];
            DataGridViewCell[] cell         = new DataGridViewCell[dataGridView1.ColumnCount];
            List <string>      ValoresLinha = new List <string>();
            string             query        = "";

            switch (NomeTabela)
            {
            case "Palavra":
                NomeTabela = tabelasBd.PALAVRA;
                break;

            case "Marca de Uso":
                NomeTabela = tabelasBd.MARCAS_USO;
                break;

            case "Referência":
                NomeTabela = tabelasBd.REFERENCIAS;
                break;
            }

            progressBar1.MarqueeAnimationSpeed = 50;
            BtnCancela.Enabled = false;
            BtnGrava.Enabled   = false;
            BtnStart.Enabled   = false;
            BtnProcura.Enabled = false;

            try
            {
                dataGridView1.Rows.CopyTo(linhas, 0);
            }
            catch (OutOfMemoryException)
            {
                InformaDiag.Erro("Memória esgotada!\nTente novamente importando menos registros.");
            }

            for (int i = 0; i < dataGridView1.RowCount - 1; i++)
            {
                //pegar uma linha da grade e coloca no ValoresLinha
                linhas[i].Cells.CopyTo(cell, 0);
                for (int j = 0; j < dataGridView1.ColumnCount; j++)
                {
                    ValoresLinha.Add(Convert.ToString(cell[j].Value));
                }

                query       += "(";
                ValoresLinha = SanitizaValores(NomeTabela, ValoresLinha);
                if (ValoresLinha == null)
                {
                    ValoresLinha = new List <string>();
                    query        = query.Remove(query.Count() - 1);
                    continue;
                }
                foreach (string s in ValoresLinha)
                {
                    if (HelperBd.VerificaInt(s))
                    {
                        query += (s + ",");
                    }
                    else
                    {
                        if (HelperBd.VerificaBool(s, out string valor))
                        {
                            query += (valor + ",");
                        }
                        else
                        {
                            query += "'" + s + "',";
                        }
                    }
                }
                query  = query.Remove(query.Count() - 1);
                query += "),";
                ValoresLinha.Clear();
            }
            if (query.Count() > 0)
            {
                query  = query.Remove(query.Count() - 1);
                query += ";";
                if (NomeTabela == tabelasBd.PALAVRA)
                {
                    operacoes.InserirEmMassa(NomeTabela, query, ptlt);
                }
                else
                {
                    operacoes.InserirEmMassa(NomeTabela, query);
                }
                return(0);
            }
            return(1);
        }