private void lnkAdd_Click(object sender, EventArgs e) { using (OrderAddEditForm frm = new OrderAddEditForm(new Order() { DeliveryCost = 0 })) { frm.StyleManager = styleManager; if (frm.ShowDialog(this) == DialogResult.OK) { try { db.Orders.Add(frm.OrderInfo); db.SaveChanges(); LoadOrders(); } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.InnerException.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); db.Orders.Load(); LoadOrders(); } ordersGrid.Refresh(); } } }
private async void lnkEdit_Click(object sender, EventArgs e) { int id = Convert.ToInt32(ordersGrid.SelectedRows[0].Cells[0].Value); Order ord = db.Orders.First(o => o.Id == id); if (ord != null) { using (OrderAddEditForm frm = new OrderAddEditForm(ord)) { frm.StyleManager = styleManager; if (frm.ShowDialog(this) == DialogResult.OK) { try { await db.SaveChangesAsync(); db = new BrickWorksModel(); LoadOrders(); } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } ordersGrid.Refresh(); } } }