private async void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } if (e.ColumnIndex == dataGridView.Columns["Изменить"].Index) { try { var perms = API.GetInstance().CurrentUser.Permissions; if (!perms.HasFlag(UserPermissions.Write)) { throw new Exception("Доступ запрещен"); } var id = (long)dataGridView.Rows[e.RowIndex].Cells["ИД"].Value; var item = (T)(dataGridView.CurrentRow.DataBoundItem as DataRowView).Row[0]; CreateEditForm <T> createEditForm = new CreateEditForm <T>(item, id); await createEditForm.LoadAsync(); if (createEditForm.ShowDialog() == DialogResult.OK) { await AsyncGetData(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка"); } } else if (e.ColumnIndex == dataGridView.Columns["Удалить"].Index) { try { var perms = API.GetInstance().CurrentUser.Permissions; if (!perms.HasFlag(UserPermissions.Delete)) { throw new Exception("Доступ запрещен"); } var id = (long)dataGridView.Rows[e.RowIndex].Cells["ИД"].Value; DialogResult dialogResult = MessageBox.Show("Вы уверены?", "Удаление записи", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { API api = API.GetInstance(); await api.AsyncRemoveItem <T>(id); await AsyncGetData(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Во время удаления произошла ошибка"); } } return; }
private async void btnCreate_Click(object sender, EventArgs e) { try { var perms = API.GetInstance().CurrentUser.Permissions; if (!perms.HasFlag(UserPermissions.Write)) { throw new Exception("Доступ запрещен"); } CreateEditForm <T> createEditForm = new CreateEditForm <T>(); await createEditForm.LoadAsync(); if (createEditForm.ShowDialog() == DialogResult.OK) { await AsyncGetData(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка"); } }