private void AddButton_Click(object sender, EventArgs e) { AddCategoryForm addForm = new AddCategoryForm(); addForm.ShowDialog(); if (addForm.DialogResult == DialogResult.OK) { string queryText = "INSERT INTO categories(category) VALUES ('" + addForm.CategoryName + "')"; ExecuteQuery(queryText); ShowCategories(); } }
private void EditButton_Click(object sender, EventArgs e) { if (CategoriesDataGrid.CurrentCell != null) { int index = CategoriesDataGrid.CurrentCell.RowIndex; int id = Convert.ToInt32(CategoriesDataGrid[0, index].Value); string name = Convert.ToString(CategoriesDataGrid[1, index].Value); AddCategoryForm editForm = new AddCategoryForm { CategoryName = name }; editForm.ShowDialog(); if (editForm.DialogResult == DialogResult.OK) { name = editForm.CategoryName; string queryText = "UPDATE categories SET category='" + name + "' WHERE ID=" + Convert.ToString(id); ExecuteQuery(queryText); ShowCategories(); } } else { MessageBox.Show("Не выбрана категория для редактирования!", "ошибка!", MessageBoxButtons.OK); } }