private async void lnkEdit_Click(object sender, EventArgs e) { if (clientsGrid.Rows.Count > 0) { int id = Convert.ToInt32(clientsGrid.SelectedRows[0].Cells[0].Value); Client client = db.Clients.First(o => o.Id == id); if (client != null) { using (ClientAddEditForm frm = new ClientAddEditForm(client)) { frm.Theme = this.Theme; frm.Style = this.Style; if (frm.ShowDialog(this) == DialogResult.OK) { try { await db.SaveChangesAsync(); LoadClients(); } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } }
private void lnkAdd_Click(object sender, EventArgs e) { using (ClientAddEditForm frm = new ClientAddEditForm(new Client())) { frm.Theme = this.Theme; frm.Style = this.Style; if (frm.ShowDialog(this) == DialogResult.OK) { try { db.Clients.Add(frm.ClientInfo); db.SaveChanges(); LoadClients(); } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }