private void button3_Click(object sender, EventArgs e) { try { OdbcConnection connection = new OdbcConnection(); connection.ConnectionString = "DSN=PostgreSQL35W;UID=masterwordcounter;PWD=masterwordcounter"; connection.Open(); string q = "SELECT id, word, root, type, irregular FROM words WHERE (root IS NULL) OR (root = 0)"; OdbcCommand getAllTexts = new OdbcCommand(q, connection); OdbcDataReader odr = getAllTexts.ExecuteReader(); lista_svih_rijeci_koje_su_root.Clear(); while (odr.Read()) { Rijec t = new Rijec(); t.Tekst = odr.GetString(1); t.Korijen = odr.GetString(1); t.Tip = odr.GetInt32(3); t.Irregular = odr.GetBoolean(4); t.Id = odr.GetInt32(0); lista_svih_rijeci_koje_su_root.Add(t); } c_root.DataSource = null; c_root.DataSource = lista_svih_rijeci_koje_su_root; q = "SELECT id, type FROM word_types"; odr.Close(); OdbcCommand getAllTypes = new OdbcCommand(q, connection); OdbcDataReader odr1 = getAllTypes.ExecuteReader(); lista_svih_rijeci_koje_su_root.Clear(); int i = 1; while (odr1.Read()) { TipRijeci t = new TipRijeci(); t.Id = i; t.Naziv = odr1.GetValue(1).ToString(); lista_tipova.Add(t); i++; } c_type.DataSource = null; c_type.DataSource = lista_tipova; odr1.Close(); q = "SELECT DISTINCT word, COALESCE(root,0), type, irregular,id FROM words"; OdbcCommand getAllWords = new OdbcCommand(q, connection); OdbcDataReader odr2 = getAllWords.ExecuteReader(); lista_svih_rijeci.Clear(); while (odr2.Read()) { Rijec t = new Rijec(); t.Tekst = odr2.GetString(0); t.Korijen = odr2.GetString(1); t.Tip = odr2.GetInt32(2); t.Irregular = odr2.GetBoolean(3); t.Id = odr2.GetInt32(4); lista_svih_rijeci.Add(t); } odr2.Close(); connection.Close(); int broj_poznatih = 0; bool dodaj = true; filtrirana_lista_rijeci.Clear(); foreach (Rijec r in lista_rijeci) { foreach (Rijec r1 in lista_svih_rijeci) { if (r1.Tekst == r.Tekst) { broj_poznatih++; dodaj = false; break; } } if (dodaj) filtrirana_lista_rijeci.Add(r); dodaj = true; } l_words.Text = lista_svih_rijeci_koje_su_root.Count.ToString(); t_word.Text = filtrirana_lista_rijeci[0].Tekst; l_InList.Text = "1/" + filtrirana_lista_rijeci.Count.ToString(); } catch(Exception e3) { MessageBox.Show(e3.Message); } }
private void InsertWords_Load(object sender, EventArgs e) { try { OdbcConnection connection = new OdbcConnection(); connection.ConnectionString = "DSN=PostgreSQL35W;UID=masterwordcounter;PWD=masterwordcounter"; connection.Open(); string q = "SELECT id, word, root, type, irregular FROM words WHERE (root IS NULL) OR (root = 0)"; OdbcCommand getAllTexts = new OdbcCommand(q, connection); OdbcDataReader odr = getAllTexts.ExecuteReader(); lista_svih_rijeci_koje_su_root.Clear(); while (odr.Read()) { Rijec t = new Rijec(); t.Tekst = odr.GetString(1); t.Korijen = odr.GetString(1); t.Tip = odr.GetInt32(3); t.Irregular = odr.GetBoolean(4); t.Id = odr.GetInt32(0); lista_svih_rijeci_koje_su_root.Add(t); } /* c_root.DropDownStyle = ComboBoxStyle.DropDown; * c_root.AutoCompleteMode = AutoCompleteMode.SuggestAppend; * c_root.AutoCompleteSource = AutoCompleteSource.ListItems;*/ c_root.DataSource = null; c_root.DataSource = lista_svih_rijeci_koje_su_root; q = "SELECT id, type FROM word_types"; odr.Close(); OdbcCommand getAllTypes = new OdbcCommand(q, connection); OdbcDataReader odr1 = getAllTypes.ExecuteReader(); int i = 1; while (odr1.Read()) { TipRijeci t = new TipRijeci(); t.Id = i; t.Naziv = odr1.GetValue(1).ToString(); lista_tipova.Add(t); i++; } c_type.DataSource = null; c_type.DataSource = lista_tipova; odr1.Close(); q = "SELECT DISTINCT word, COALESCE(root,0), type, irregular,id FROM words"; OdbcCommand getAllWords = new OdbcCommand(q, connection); OdbcDataReader odr2 = getAllWords.ExecuteReader(); lista_svih_rijeci.Clear(); while (odr2.Read()) { Rijec t = new Rijec(); t.Tekst = odr2.GetString(0); t.Korijen = odr2.GetString(1); t.Tip = odr2.GetInt32(2); t.Irregular = odr2.GetBoolean(3); t.Id = odr2.GetInt32(4); lista_svih_rijeci.Add(t); } odr2.Close(); connection.Close(); int broj_poznatih = 0; bool dodaj = true; foreach (Rijec r in lista_rijeci) { foreach (Rijec r1 in lista_svih_rijeci) { if (r1.Tekst == r.Tekst) { broj_poznatih++; dodaj = false; break; } } if (dodaj) { filtrirana_lista_rijeci.Add(r); } dodaj = true; } l_words.Text = lista_svih_rijeci_koje_su_root.Count.ToString(); t_word.Text = filtrirana_lista_rijeci[0].Tekst; l_InList.Text = "1/" + filtrirana_lista_rijeci.Count.ToString(); } catch (Exception er) { MessageBox.Show(er.Message); } }