private void WordsTable_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (!this.btnSwitch.Checked) { string word = grdWords.Rows[e.RowIndex].Cells[0].Value.ToString(); string type = grdWords.Rows[e.RowIndex].Cells[1].Value.ToString(); string mean = grdWords.Rows[e.RowIndex].Cells[2].Value.ToString(); FrmEdit_Add frm = new FrmEdit_Add(false, word, manager.GetIdOfType(type), mean); if (frm.ShowDialog() == DialogResult.Yes) { try { Word obj = frm.PerformAction(); grdWords.Rows[e.RowIndex].Cells[0].Value = obj.word_o; grdWords.Rows[e.RowIndex].Cells[1].Value = manager.GetTypeOfId(obj.type_id).type_description; grdWords.Rows[e.RowIndex].Cells[2].Value = obj.word_m; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error" , MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("Edited successfully"); } frm.Dispose(); } else { int id = int.Parse(this.grdWords.SelectedRows[0].Cells[0].Value.ToString()); string type = this.grdWords.SelectedRows[0].Cells[1].Value.ToString(); FrmEdit_AddType frm = new FrmEdit_AddType(false, id, type); if (frm.ShowDialog() == DialogResult.Yes) { Data.Type obj = frm.PerformAction(); grdWords.Rows[e.RowIndex].Cells[1].Value = obj.type_description; MessageBox.Show("Edited successfully"); } frm.Dispose(); } }
private void btnAdd_Click(object sender, EventArgs e) { if (!this.btnSwitch.Checked) { FrmEdit_Add frm = new FrmEdit_Add(true); if (frm.ShowDialog() == DialogResult.Yes) { try { Word obj = frm.PerformAction(); grdWords.Rows.Add(obj.word_o, obj.Type.type_description, obj.word_m); grdWords.Sort(grdWords.Columns[0], System.ComponentModel.ListSortDirection.Ascending); LoadWordsToHintList(); LoadWordsToImExTab(); }catch (Exception) { MessageBox.Show("This word has already existed", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); return; } MessageBox.Show("Added successfully"); } } else { FrmEdit_AddType frm = new FrmEdit_AddType(true); if (frm.ShowDialog() == DialogResult.Yes) { Data.Type obj = frm.PerformAction(); grdWords.Rows.Add(obj.Id, obj.type_description); grdWords.Sort(grdWords.Columns[0], System.ComponentModel.ListSortDirection.Ascending); LoadWordsToHintList(); LoadWordsToImExTab(); MessageBox.Show("Added successfully"); } } }