private void btnAdd_Click(object sender, EventArgs e) { frmEditor editor = new frmEditor(); if (editor.ShowDialog() == DialogResult.OK) { this.goodsRepository.AddGoods(editor.goods); //添加后重新查询、绑定数据,保证一致性 //也有其他做法,不用再查询加载,而只添加一行, //但那样验证逻辑要复杂一点, //下同 this.ViewAllGoods(); } }
private void btnEdit_Click(object sender, EventArgs e) { Goods selGoods = this.GetFirstSelectedGoods(); if (selGoods != null) { frmEditor editor = new frmEditor(selGoods); int oldId = selGoods.Id; if (editor.ShowDialog() == DialogResult.OK) { this.goodsRepository.EditGoods(oldId, selGoods); this.ViewAllGoods(); } } }