Ejemplo n.º 1
0
        private void btnAddItem_Click(object sender, EventArgs e)
        {
            FormItemUpdate formItemEdit = new FormItemUpdate(new OrderItem());

            try
            {
                if (formItemEdit.ShowDialog() == DialogResult.OK)
                {
                    //int index = 0;
                    //if (CurrentOrder.OrderItems.Count != 0)
                    //{
                    //    index = CurrentOrder.OrderItems.Max(i => i.OrderItemID) + 1;
                    //}
                    using (var db = new OScontext())
                    {
                        formItemEdit.OrderItem.OrderItemID = db.OrderItems.Count() + 1;
                        int newID = db.Goods.Count() + 1;
                        formItemEdit.OrderItem.GoodsItem.GoodsID = newID.ToString();
                    }
                    CurrentOrder.AddItem(formItemEdit.OrderItem);
                    itemsBindingSource.ResetBindings(false);
                }
            }
            catch (Exception e2)
            {
                MessageBox.Show(e2.Message);
            }
        }
Ejemplo n.º 2
0
        private void EditItem()
        {
            OrderItem orderItem = itemsBindingSource.Current as OrderItem;

            if (orderItem == null)
            {
                MessageBox.Show("请选择一个订单项进行修改");
                return;
            }
            FormItemUpdate formItemEdit = new FormItemUpdate(orderItem);

            if (formItemEdit.ShowDialog() == DialogResult.OK)
            {
                itemsBindingSource.ResetBindings(false);
            }
        }