private void MostraRegistroAtivo() { chkHtonico.Checked = ativo.heterotonico; chkHsemantico.Checked = ativo.heterossemantico; chkHgenerico.Checked = ativo.heterogenerico; resP = Palavra.ConverteObject(crud.SelecionarTabela(tabelasBd.PALAVRA, Palavra.ToListTabela(true), "id=" + ativo.equivalente.ToString())); comboDestino.Text = resP.First().lema; txtApresentacao.Value = ativo.nOrdem; txtExemplo.Text = ativo.exemplo; txtExemploTraduzido.Text = ativo.exemplo_traduzido; resRef = Referencia.ConverteObject(crud.SelecionarTabela(tabelasBd.REFERENCIAS, Referencia.ToListTabela(true), "Id=" + ativo.Referencia.ToString())); if (resRef.Count > 0) { comboRef.Text = resRef.First().descricao; } resRubrica = MarcaUso.ConverteObject(crud.SelecionarTabela(tabelasBd.MARCAS_USO, MarcaUso.ToListTabela(true), "Id=" + ativo.MarcaUso.ToString())); if (resRubrica.Count > 0) { ComboRubrica.Text = resRubrica.First().descricao; } oldEqAt = ativo; txtCultura.Text = ativo.notasCulturais; txtGramatica.Text = ativo.notasGramaticais; }
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"); } }
private void timerDestino_Tick(object sender, EventArgs e) { string pesquisa = comboDestino.Text; comboDestino.Items.Clear(); if (pesquisa.Length > 0) { resP = Palavra.ConverteObject(crud.SelecionarTabela(tabelasBd.PALAVRA, Palavra.ToListTabela(true), "lema='" + pesquisa + "'", "LIMIT 25")); foreach (Palavra p in resP) { comboDestino.Items.Add(p.lema + " Idioma " + p.idioma + ", " + p.ClasseGram + " " + p.Genero); } } timerDestino.Enabled = false; }
private void btnSalva_Click(object sender, EventArgs e) { if (txtpalavra.Text == String.Empty) { InformaDiag.Erro("Palavra não pode ser vazio!"); return; } if (ComboClasseGram.SelectedItem == null) { InformaDiag.Erro("Selecione um valor válido de Classe gramatical!"); return; } if (ComboGenero.SelectedItem == null) { InformaDiag.Erro("Selecione um gênero válido!"); return; } if (ComboIdioma.SelectedItem == null) { InformaDiag.Erro("É obrigatório selecionar um idioma!"); return; } string lng; p.lema = txtpalavra.Text; switch (ComboIdioma.SelectedIndex) { case 0: lng = "PT"; break; case 2: lng = "EN"; break; case 1: lng = "ES"; break; default: lng = ""; break; } p.idioma = lng; p.notas_gramatica = txtGramatica.Text; p.nota_cultura = textCultura.Text; p.Definicao = txtDefinicao.Text; switch (ComboGenero.SelectedIndex) { case 0: p.Genero = "M"; break; case 1: p.Genero = "F"; break; case 2: p.Genero = "N"; break; default: p.Genero = "S"; break; } p.ClasseGram = ComboClasseGram.Text; if (p.id <= 0) { if (crud.InsereLinha(tabelasBd.PALAVRA, Palavra.ToListTabela(), p.ToListValores()) > 0) { InformaDiag.Informa("Salvo!"); LimpaCampos(); LimpaModel(); } else { ///CASO HOUVER UMA DUPLICATA, ENTÃO O REGISTRO EXISTENTE NO BANCO DEVE SER CARREGADO NO LUGAR DAS INFORMAÇÕES QUE O USUÁRIO PREENCHEU InformaDiag.Erro("Não foi possível salvar.\nO item caracterizado já existe."); if (InformaDiag.ConfirmaSN("Deseja carregar o registro existente?") == DialogResult.Yes) { p = Palavra.ConverteObject(crud.SelecionarTabela(tabelasBd.PALAVRA, Palavra.ToListTabela(true), "lema='" + p.lema + "' AND ClasseGram='" + p.ClasseGram + "' AND idioma='" + p.idioma + "' AND Genero='" + p.Genero + "'")).First(); MostraDados(); } } } else { crud.UpdateLine(tabelasBd.PALAVRA, Palavra.ToListTabela(), p.ToListValores(), "id=" + p.id.ToString()); InformaDiag.Informa("Salvo!"); LimpaCampos(); } //Uma excessão pode ser lançda aqui quando os valores das chaves estrangerias forem <1, pois estão refernciando um valor que não existe. Como o int no c# não cabe um NULL, seria melhor não enviar o tal valor que evitamos o problema }
private List <string> SanitizaValores(string tabela, List <string> valores) { //função para trocar possíveis valores em string por suas respectivas FK string saida; for (int i = 0; i < valores.Count; i++) { if (SanitizaString(valores.ElementAt(i), out saida)) { valores.RemoveAt(i); valores.Insert(i, saida); } } if (tabela == tabelasBd.CONJUGACAO) { List <string> FKs = new List <string>(); int idx, c = 0; bool[] fila = { false, false }; ///TODO: Ah, enumeradores... /////faço issoi para evitar que seja lançada uma exceção e os valores perdidos no cast logo abaixo //rubrica idx = Palavra.ToListTabela().FindIndex(bs => bs == "Rubrica"); if (!int.TryParse(valores.ElementAt(idx), out int conv) && (valores.ElementAt(idx) != "")) { FKs.Add(valores.ElementAt(idx)); valores.RemoveAt(idx); valores.Insert(idx, "0"); fila[c] = true; } c++; //referencia idx = Palavra.ToListTabela().FindIndex(bs => bs == "referencia_verbete"); if (!int.TryParse(valores.ElementAt(idx), out conv) && (valores.ElementAt(idx) != "")) { FKs.Add(valores.ElementAt(idx)); valores.RemoveAt(idx); valores.Insert(idx, "0"); fila[c++] = true; } c++; Palavra teste = new Palavra(); try { teste = (Palavra)valores; } catch (InvalidCastException) { LoggerErros(EnumErros.Erro_dados); return(null); } catch (FormatException) { LoggerErros(EnumErros.Erro_dados); return(null); } List <MarcaUso> lrub = new List <MarcaUso>(); List <Referencia> lref = new List <Referencia>(); IEnumerator <string> ff = FKs.GetEnumerator(); c = 0; if (fila[c++]) { saida = ff.Current; lrub = MarcaUso.ConverteObject(operacoes.SelecionarTabela(tabelasBd.MARCAS_USO, MarcaUso.ToListTabela(true), "sigla='" + saida + "'")); if (lrub.Count() > 0) { // teste.rubrica = lrub.First().id; } else { return(null); } ff.MoveNext(); } if (fila[c]) { saida = ff.Current; lref = Referencia.ConverteObject(operacoes.SelecionarTabela(tabelasBd.REFERENCIAS, Referencia.ToListTabela(true), "Cod='" + saida + "'")); if (lref.Count > 0) { // teste.referencia_verbete = lref.First().id; } else { return(null); } } valores.Clear(); valores.AddRange(teste.ToListValores()); } return(valores); }
private string MontaApresentaçãoInfinitivoPt(Palavra pReg) { string pesquisa, textoApresentado = "Equivalências" + NOVALINHA; List <Equivalente> listaEquiv = new List <Equivalente>(); List <Palavra> listaPEquiv = new List <Palavra>(); List <ConjugacaoEn> listaConjugaEn = new List <ConjugacaoEn>(); pesquisa = "Origem=" + pReg.id.ToString(); listaEquiv = Equivalente.ConverteObject(cRUD.SelecionarTabela(tabelasBd.EQUIVALENTE, Equivalente.ToListTabela(), pesquisa, "ORDER BY nApresentacao ASC")); pesquisa = ""; foreach (Equivalente itemEquiv in listaEquiv) { pesquisa += ("id=" + itemEquiv.equivalente.ToString() + " OR "); } pesquisa = pesquisa.Remove(pesquisa.Count() - 4); listaPEquiv = Palavra.ConverteObject(cRUD.SelecionarTabela(tabelasBd.PALAVRA, Palavra.ToListTabela(true), pesquisa)); pesquisa = ""; foreach (Palavra p in listaPEquiv) { pesquisa += ("idconjugacao=" + p.id.ToString() + " OR "); } pesquisa = pesquisa.Remove(pesquisa.Count() - 4); listaConjugaEn = ConjugacaoEn.ConverteObject(cRUD.SelecionarTabela(tabelasBd.CONJUGACAOEN, ConjugacaoEn.ToListTabela(true), pesquisa)); int elementos = listaEquiv.Count; //monta Indice for (int i = 0; i < elementos; i++) { textoApresentado += ((i + 1).ToString() + ". " + (listaPEquiv.ElementAt(i).lema) + " (" + listaEquiv.ElementAt(i).PalavraGuia + ")" + NOVALINHA); } ConjugacaoEn conjugacao = new ConjugacaoEn(); for (int i = 0; i < elementos; i++) { pReg = listaPEquiv.ElementAt(i); conjugacao = listaConjugaEn.ElementAt(i); textoApresentado += ((i + 1).ToString() + ". " + (pReg.lema) + NOVALINHA); textoApresentado += (listaEquiv.ElementAt(i).PalavraGuia + NOVALINHA); textoApresentado += (pReg.Definicao + NOVALINHA); textoApresentado += (conjugacao.ConstrPresente + NOVALINHA); textoApresentado += (conjugacao.ConstrPassado + NOVALINHA); textoApresentado += (conjugacao.ConstrWill + NOVALINHA); textoApresentado += (conjugacao.ConstrGoingTo + NOVALINHA); textoApresentado += (conjugacao.ConstrPresPer + NOVALINHA); textoApresentado += (conjugacao.ConstrPasPer + NOVALINHA); textoApresentado += (conjugacao.ConstrPresCon + NOVALINHA); textoApresentado += (conjugacao.ConstrPasCon + NOVALINHA); textoApresentado += (conjugacao.ExPresente + NOVALINHA); textoApresentado += (conjugacao.ExPassado + NOVALINHA); textoApresentado += (conjugacao.ExWill + NOVALINHA); textoApresentado += (conjugacao.ExGoingTo + NOVALINHA); textoApresentado += (conjugacao.ExPresPer + NOVALINHA); textoApresentado += (conjugacao.ExPasPer + NOVALINHA); textoApresentado += (conjugacao.ExPresCon + NOVALINHA); textoApresentado += (conjugacao.ExPasCon + NOVALINHA); textoApresentado += (pReg.notas_gramatica + NOVALINHA); textoApresentado += (pReg.nota_cultura + NOVALINHA); } textoApresentado += ("Fraseologia" + NOVALINHA + NOVALINHA); return(textoApresentado); }
private void searchButton_Click(object sender, EventArgs e) { if (searchBox.Text != "") { string filtroquery; int temp; switch (filterComboBox.SelectedIndex) { case 1: filtroquery = "Cod"; break; default: filtroquery = "lema"; break; } switch (ComboFiltroPrecisao.SelectedIndex) { case 1: filtroquery += " LIKE '" + searchBox.Text + "%'"; break; default: filtroquery += "="; if (int.TryParse(searchBox.Text, out temp)) { filtroquery += searchBox.Text; } else { filtroquery += "'" + searchBox.Text + "'"; } break; } switch (comboFiltroIdiomas.SelectedIndex) { case 1: filtroquery += "AND Idioma='PT'"; break; case 2: filtroquery += "AND Idioma='EN'"; break; case 3: filtroquery += "AND Idioma='ES'"; break; default: break; } if (ComboFiltroPrecisao.Text == "Precisamente") { resultados = crud.SelecionarTabela(tabelasBd.PALAVRA, Palavra.ToListTabela(true), "lema='" + searchBox.Text + "'"); } else { resultados = crud.SelecionarTabela(tabelasBd.PALAVRA, Palavra.ToListTabela(true), "lema LIKE '%" + searchBox.Text + "%'"); } if (resultados.Count > 0) { resPalavra = Palavra.ConverteObject(resultados); p = resPalavra.First(); MostraDados(); if (resPalavra.Count == 1) { DesativaNavegadores(); } else { AtivaNavegadores(); ipal = 0; } } else { InformaDiag.Erro("Nenhum resultado adequado encontrado."); } } }
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 searchButton_Click(object sender, EventArgs e) { List <object[]> lista = new List <object[]>(); if (searchBox.Text == "") { InformaDiag.Erro("A caixa de busca não pode estar vazia!"); return; } string filtro = ""; switch (filterComboBox.SelectedIndex) { case 1: filtro += "lema LIKE'" + searchBox.Text + "'"; break; case 2: //anagrama break; case 3: //filtro += "definicao LIKE '" + searchBox.Text + "'"; break; case 4: //exemplo break; case 5: //Heterogenérico break; case 6: //Heterotônico break; default: filtro += "lema='" + searchBox.Text + "'"; break; } lista = cRUD.SelecionarTabela("palavra", Palavra.ToListTabela(true), filtro, "ORDER BY lema ASC"); searchResultsListBox.Items.Clear(); if (lista.Count > 0) { try { resultadosPalavra.Clear(); } catch (NullReferenceException) { resultadosPalavra = new List <Palavra>(); } List <string> cabecalhos = new List <string>(); Palavra temPal = new Palavra(); resultadosPalavra = AgrupaResultados(Palavra.ConverteObject(lista), out cabecalhos, out int[] divisores); int c = 0, i; foreach (string conjunto in cabecalhos) { searchResultsListBox.Items.Add(conjunto); for (i = 0; i < divisores[c]; i++) { temPal = resultadosPalavra.ElementAt(i); filtro = temPal.lema + " Acep." + " " + " \""; //+ temPal.referencia_exemplo + "\"" + "\"" + temPal.ref_ex_tr + "\"" + temPal.referencia_verbete; searchResultsListBox.Items.Add(filtro); } c++; } searchResultsListBox.Enabled = true; similares = Palavra.ConverteObject(cRUD.SelecionarTabela(tabelasBd.PALAVRA, Palavra.ToListTabela(true), "referencia_exemplo LIKE '" + searchBox.Text + "'")); if (similares.Count > 0) { foreach (Palavra p in similares) { similarListBox.Items.Add(p.lema); } } else { similarListBox.Items.Clear(); similarListBox.Items.Add("Não há entradas similares além das pesquisadas."); similarListBox.Enabled = false; } similarListBox.Enabled = true; } else { similarListBox.Items.Clear(); searchResultsListBox.Items.Add("Nenhum resultado encontrado. Verifique seus critérios de pesquisa!"); searchResultsListBox.Enabled = false; similarListBox.Enabled = false; } this.searchResultsListBox.Show(); }
private void MostraDados() { txtpalavra.Text = p.lema; if (p.idioma == "PT") { ComboIdioma.SelectedIndex = 0; } else { if (p.idioma == "ES") { ComboIdioma.SelectedIndex = 1; } else { ComboIdioma.SelectedIndex = 2; } } switch (p.Genero) { case "M": ComboGenero.SelectedIndex = 0; break; case "N": ComboGenero.SelectedIndex = 2; break; case "F": ComboGenero.SelectedIndex = 1; break; case "S": ComboGenero.SelectedIndex = 3; break; case "SM": ComboGenero.SelectedIndex = 4; break; } ComboClasseGram.Text = p.ClasseGram; btnEquiv.Enabled = true; btnConjuga.Enabled = true; txtSubLema.Text = p.Sublema; if (p.Sinonimo1 > 0) { string filtro = "id=" + p.Sinonimo1.ToString(); if (p.Sinonimo2 > 0) { filtro += (" OR id=" + p.Sinonimo2.ToString()); } resSin = Palavra.ConverteObject(crud.SelecionarTabela(tabelasBd.PALAVRA, Palavra.ToListTabela(true), filtro)); comboSinonimo1.Text = resSin.First().lema; if (resSin.Count > 1) { comboSinonimo2.Text = resSin.ElementAt(1).lema; } } }
private void timerSinonimo_Tick(object sender, EventArgs e) { string pesquisa; if (Sin1Ativo) { pesquisa = comboSinonimo1.Text; comboSinonimo1.Items.Clear(); } else { pesquisa = comboSinonimo2.Text; comboSinonimo2.Items.Clear(); } if (pesquisa.Length > 0) { string idioma = p.idioma; if (idioma == "" || idioma == null) { idioma = PegaSiglaIdioma(); } if (idioma != "") { resSin = Palavra.ConverteObject(crud.SelecionarTabela(tabelasBd.PALAVRA, Palavra.ToListTabela(true), "lema LIKE '%" + pesquisa + "%' AND Idioma='" + idioma + "'", "LIMIT 10")); } if (Sin1Ativo) { foreach (Palavra p in resSin) { comboSinonimo1.Items.Add(p.lema); } } else { foreach (Palavra p in resSin) { comboSinonimo2.Items.Add(p.lema); } } } timerSinonimo.Enabled = false; }
private void btnSalva_Click(object sender, EventArgs e) { bool r; if (txtpalavra.Text == String.Empty) { InformaDiag.Erro("Palavra não pode ser vazio!"); return; } if (ComboClasseGram.SelectedItem == null) { InformaDiag.Erro("Selecione um valor válido de Classe gramatical!"); return; } if (ComboGenero.SelectedItem == null) { InformaDiag.Erro("Selecione um gênero válido!"); return; } if (ComboIdioma.SelectedItem == null) { InformaDiag.Erro("É obrigatório selecionar um idioma!"); return; } p.lema = txtpalavra.Text; p.idioma = PegaSiglaIdioma(); p.Definicao = txtDefinicao.Text; switch (ComboGenero.SelectedIndex) { case 0: p.Genero = "M"; break; case 1: p.Genero = "F"; break; case 2: p.Genero = "N"; break; case 3: p.Genero = "S"; break; case 4: p.Genero = "SM"; break; default: throw new Exception("Opção não disponível na lista de opções de gênero."); } if (p.Genero == "N" && p.idioma == "PT") { InformaDiag.Erro("Gênero inadequado ao idioma."); return; } p.ClasseGram = ComboClasseGram.Text; if (comboSinonimo1.Text == "") { p.Sinonimo1 = 0; } if (comboSinonimo2.Text == "") { p.Sinonimo2 = 0; } p.Sublema = txtSubLema.Text; AjustaSinonimos(); if (p.id <= 0) { r = crud.InsereLinha(tabelasBd.PALAVRA, Palavra.ToListTabela(), p.ToListValores()); } else { r = crud.UpdateLine(tabelasBd.PALAVRA, Palavra.ToListTabela(), p.ToListValores(), "id=" + p.id.ToString()); } //Uma excessão pode ser lançda aqui quando os valores das chaves estrangerias forem <1, pois estão refernciando um valor que não existe. Como o int no c# não cabe um NULL, seria melhor não enviar o tal valor que evitamos o problema if (r) { InformaDiag.Informa("Salvo!"); LimpaCampos(); LimpaModel(); btnNovo_Click(sender, e); } }