private void AddButton_Click(object sender, EventArgs e)
    {
        Word wordToTranslate = new Word();

        wordToTranslate.word1       = insertWordTextBox.Text;
        wordToTranslate.language_id = languageService.getIdByTitle(selectLanguageComboBox.SelectedItem.ToString());

        Word translatedWord = new Word();

        translatedWord.word1       = googleTranslate.translateWord(wordToTranslate.word1, nativeLanguage.shortTitle);
        translatedWord.language_id = nativeLanguage.Id;

        if (!wordService.checkIfWordsExistInDb(wordToTranslate.word1, translatedWord.word1))
        {
            MessageBox.Show("Looks like you already have the same word in your dictionary, please add another word.");
            return;
        }

        //wordsFromDictionary.Items.Add(wordToTranslate.word1);
        //wordsFromDictionary.Items.Add(translatedWord.word1);
        wordsFromDictionary.Items.Add(wordToTranslate.word1 + " — " + translatedWord.word1);

        wordService.batchCreate(new List <Word> {
            wordToTranslate, translatedWord
        });
    }
Exemplo n.º 2
0
    private void AddButton_Click(object sender, EventArgs e)
    {
        if (!isInternetAccess)
        {
            MessageBox.Show("Looks like you don't have internet connection, please try later.");
            return;
        }
        String translatedWordString = googleTranslate.translateWord(insertWordTextBox.Text, nativeLanguage.shortTitle);

        if (translatedWordString.Equals(insertWordTextBox.Text))
        {
            MessageBox.Show("Looks like you've inserted wrong word, please add another word.");
            return;
        }
        Word wordToTranslate = new Word();

        wordToTranslate.word1       = insertWordTextBox.Text;
        wordToTranslate.language_id = languageService.getIdByTitle(selectLanguageComboBox.SelectedItem.ToString());

        Word translatedWord = new Word();

        translatedWord.word1       = googleTranslate.translateWord(wordToTranslate.word1, nativeLanguage.shortTitle);
        translatedWord.language_id = nativeLanguage.Id;

        if (!wordService.checkIfWordsExistInDb(wordToTranslate.word1, translatedWord.word1))
        {
            MessageBox.Show("Looks like you already have the same word in your dictionary, please add another word.");
            return;
        }
        wordsFromDictionary.Items.Add(wordToTranslate.word1 + " — " + translatedWord.word1);
        wordService.batchCreate(new List <Word> {
            wordToTranslate, translatedWord
        });
        Translation t = new Translation();

        t.word_id_1   = wordToTranslate.Id;
        t.word_id_2   = translatedWord.Id;
        t.retry_count = (Int16)applicationSettingsService.getRetryCounter();
        translationDBservice.create(t);
    }