private void btnAddItem_Click(object sender, EventArgs e) { FormItemEdit formItemEdit = new FormItemEdit(new OrderItem()); try { if (formItemEdit.ShowDialog() == DialogResult.OK) { int index = 0; if (CurrentOrder.Items.Count != 0) { index = CurrentOrder.Items.Max(i => i.Index) + 1; } formItemEdit.OrderItem.Index = index; CurrentOrder.AddItem(formItemEdit.OrderItem); CurrentOrder.Items.ForEach(item => { item.GoodsItemId = item.GoodsItem.ID; item.GoodsName = item.GoodsItem.Name; item.UnitPrice = item.GoodsItem.Price; }); itemsBindingSource.ResetBindings(false); } } catch (Exception e2) { MessageBox.Show(e2.Message); } }
private void EditItem() { OrderItem orderItem = itemsBindingSource.Current as OrderItem; if (orderItem == null) { MessageBox.Show("请选择一个订单项进行修改"); return; } FormItemEdit formItemEdit = new FormItemEdit(orderItem); if (formItemEdit.ShowDialog() == DialogResult.OK) { itemsBindingSource.ResetBindings(false); } }
private void btnAddItem_Click(object sender, EventArgs e) { FormItemEdit formItemEdit = new FormItemEdit(new OrderDetail()); try { if (formItemEdit.ShowDialog() == DialogResult.OK) { uint index = 0; if (CurrentOrder.Details.Count != 0) { index = CurrentOrder.Details.Max(i => i.Index) + 1; } formItemEdit.OrderItem.Index = index; CurrentOrder.AddItem(formItemEdit.OrderItem); itemsBindingSource.ResetBindings(false); } }catch (Exception e2) { MessageBox.Show(e2.Message); } }