Ejemplo n.º 1
0
        private void btnAddDef_Click(object sender, EventArgs e)
        {
            if (TextBuilder.rgxText.IsMatch(txtDefinizione.Text))
            {
                Definition defDef = new Definition(txtDefinizione.Text);

                // insert synonyms
                if (txtSino.Text.Length != 0 && TextBuilder.rgx.IsMatch(txtSino.Text))
                {
                    string line = txtSino.Text;
                    if (line.ElementAt(line.Length - 1) == ';')
                    {
                        line.Remove(line.Length - 1);
                    }
                    string[] synonyms = line.Split(';');

                    foreach (string syn in synonyms)
                    {
                        Word wrd = dictManger.CurDict().findWord(syn);
                        if (wrd != null)
                        {
                            defDef.addSynonym(wrd);
                            Console.WriteLine(syn + " trovato");
                        }
                        else
                        {
                            Console.WriteLine(syn + " Non trovato");
                        }
                    }
                }


                // insert contradiction
                if (TextBuilder.rgx.IsMatch(txtContra.Text))
                {
                    string line = txtContra.Text;
                    if (line.ElementAt(line.Length - 1) == ';')
                    {
                        line.Remove(line.Length - 1);
                    }

                    string[] contraries = line.Split(';');
                    foreach (string ctr in contraries)
                    {
                        Word wrd = dictManger.CurDict().findWord(ctr);
                        if (wrd != null)
                        {
                            defDef.addContrary(wrd);
                            Console.WriteLine(ctr + " trovato");
                        }
                        else
                        {
                            Console.WriteLine(ctr + " Non trovato");
                        }
                    }
                }

                wrdBuilder.addDefinition(defDef);


                if (TextBuilder.rgx.IsMatch(txtTradu.Text))
                {
                    string line = txtTradu.Text;
                    if (line.ElementAt(line.Length - 1) == ';')
                    {
                        line.Remove(line.Length - 1);
                    }

                    string   language     = (string)cmbLanguage.SelectedItem;
                    string[] translations = line.Split(';');
                    foreach (string tra in translations)
                    {
                        for (int cntDict = 0; cntDict < dictManger.getDictCount(); cntDict++)
                        {
                            Dictionary dict = dictManger.getDict(cntDict);
                            if (dict.Language == language)
                            {
                                Text found = dict.find(tra);
                                if (found != null && found.GetType() == typeof(Word))
                                {
                                    wrdBuilder.addTranslation(new Translation(cntDict, language, found), cntDef);
                                    break;
                                }
                            }
                        }
                    }
                }

                cntDef++;
                clrDef();
            }
            else
            {
                MessageBox.Show("Inserire una definizione!");
            }
        }
Ejemplo n.º 2
0
        private void btnAddDef_Click(object sender, EventArgs e)
        {
            if (rgxText.IsMatch(txtDefinizione.Text))
            {
                Definition defDef = new Definition(txtDefinizione.Text);
                if (txtSino.Text.Length != 0 && rgx.IsMatch(txtSino.Text))
                {
                    string line = txtSino.Text;
                    if (line.ElementAt(line.Length - 1) == ';')
                    {
                        line.Remove(line.Length - 1);
                    }
                    string[] synonyms = line.Split(';');

                    foreach (string syn in synonyms)
                    {
                        Word wrd = dictManger.CurDict().findWord(syn);
                        if (wrd != null)
                        {
                            defDef.addSynonym(wrd);
                            Console.WriteLine(syn + " trovato");
                        }
                        else
                        {
                            Console.WriteLine(syn + " Non trovato");
                        }
                    }
                }


                if (rgx.IsMatch(txtContra.Text))
                {
                    string line = txtContra.Text;
                    if (line.ElementAt(line.Length - 1) == ';')
                    {
                        line.Remove(line.Length - 1);
                    }
                    string[] contraries = line.Split(';');

                    foreach (string ctr in contraries)
                    {
                        Word wrd = dictManger.CurDict().findWord(ctr);
                        if (wrd != null)
                        {
                            defDef.addContrary(wrd);
                            Console.WriteLine(ctr + " trovato");
                        }
                        else
                        {
                            Console.WriteLine(ctr + " Non trovato");
                        }
                    }
                }

                if (rgx.IsMatch(txtTradu.Text))
                {
                }

                wrdBuilder.addDefinition(defDef);
                clrDef();
            }
            else
            {
                MessageBox.Show("Inserire la definizione!");
            }
        }