/// <summary> /// Button handler for add word button on the dictionary screen. opens /// the word edit dialog and accepts a word and weight and attempts /// to insert it in the database /// </summary> /// <param name="sender">default arg</param> /// <param name="e">default arg</param> private void btn_addWord_Click(object sender, EventArgs e) { fEditDictionaryValues add = new fEditDictionaryValues(); add.Text = "Add word"; add.ShowDialog(); if (add.DialogResult == DialogResult.OK) { cAccess acc = new cAccess(); if (acc.addWordToDictionary(add.Word, add.Weight)) { updateDictionaryGrid(); MessageBox.Show("Word: " + add.Word + " successfully added!"); } else { MessageBox.Show("Word not added to dictionary."); } } }
/// <summary> /// Button handler for edit word button on the dictionary screen. Opens /// edit dialog allowing the user to modify the word's values. /// </summary> /// <param name="sender">default arg</param> /// <param name="e">default arg</param> private void btn_editWord_Click(object sender, EventArgs e) { if (gridView_Dictionary.SelectedRows.Count > 1) { MessageBox.Show("Please select one word at a time"); } else if (gridView_Dictionary.SelectedRows.Count < 1) { MessageBox.Show("Must select at least one word"); } else { var word = gridView_Dictionary.SelectedRows[0].Cells[0].Value.ToString(); //word selected var weight = gridView_Dictionary.SelectedRows[0].Cells[1].Value.ToString(); fEditDictionaryValues edit = new fEditDictionaryValues(word, weight); edit.Text = "Edit word"; edit.ShowDialog(); if (edit.DialogResult == DialogResult.OK) { cAccess acc = new cAccess(); if (word != edit.Word) { acc.modifyWordInDictionary(word, edit.Word, edit.Weight); } if (weight != edit.Weight.ToString()) { acc.modifyWeightInDictionary(edit.Word, edit.Weight); } updateDictionaryGrid(); } } }