Example #1
0
        //添加商品
        private void addItemBtn_Click(object sender, EventArgs e)
        {
            InfoLbl.Text = "";
            Order currentOrder = orderlistBindingSource.Current as Order;

            if (currentOrder == null)
            {
                InfoLbl.Text = "添加失败!当前没有订单";
                return;
            }
            else
            {
                ItemAdd itemadd = new ItemAdd();
                itemadd.ShowDialog();
                if (!string.IsNullOrEmpty(itemadd.NewItem.Name))
                {
                    currentOrder.AddItem(itemadd.NewItem);
                    using (var context = new OrderContext())
                    {
                        context.Orders.Load();
                        context.OrderItems.Load();
                        orderlistBindingSource.DataSource = context.Orders.Local.ToBindingList();
                        itemListBindingSource.DataSource  = context.OrderItems.Local.ToBindingList();
                    }
                }
                else
                {
                    InfoLbl.Text = "添加失败";
                    return;
                }
            }
        }
Example #2
0
        //添加商品
        private void addItemBtn_Click(object sender, EventArgs e)
        {
            InfoLbl.Text = "";
            Order currentOrder = orderlistBindingSource.Current as Order;

            if (currentOrder == null)
            {
                InfoLbl.Text = "添加失败!当前没有订单";
                return;
            }
            else
            {
                ItemAdd itemadd = new ItemAdd();
                itemadd.ShowDialog();
                if (!string.IsNullOrEmpty(itemadd.NewItem.Name))
                {
                    service.orderList[currentOrder.index - 1].AddItem(itemadd.NewItem);
                    orderlistBindingSource.ResetBindings(false);
                    itemListBindingSource.ResetBindings(false);
                }
                else
                {
                    InfoLbl.Text = "添加失败";
                    return;
                }
            }
        }