示例#1
0
        public void OrderItem_Should_Be_Equal_With_Same_Product_And_OrderID()
        {
            Guid      orderID = Guid.NewGuid();
            Product   p       = _catalogService.GetProduct(1);
            OrderItem item    = new OrderItem(orderID, p, 5);
            OrderItem item2   = new OrderItem(orderID, p, 5);

            Assert.AreEqual(item, item2);
            Assert.IsTrue(item.Equals(item2));
        }
示例#2
0
        //创建订单明细
        private void btnAddOrderItem_Click(object sender, EventArgs e)
        {
            try
            {
                int    orderID        = int.Parse(txtOrderItemID.Text);                       //添加订单明细订单的订单号
                string orderItemName  = txtItem.Text;                                         //货物名
                double unitOrderPrice = double.Parse(txtUnitItemPrice.Text);                  //货物单价
                int    count          = int.Parse(txtCount.Text);                             //货物数量

                OrderItem newOrderItem = new OrderItem(orderItemName, unitOrderPrice, count); //创建新订单明细

                bool isHavingOrder         = false;
                bool isHavingSameOrderItem = false;                  //同一订单是否存在相同的订单明细
                foreach (Order order in OrderService.orders)         //遍历订单集合,是否存在该订单号的订单
                {
                    if (orderID == order.OrderID)                    //如果存在该订单号的订单
                    {
                        isHavingOrder = true;
                        foreach (OrderItem orderItem in order.OrderItems) //遍历该订单号订单的订单明细集合
                        {
                            if (newOrderItem.Equals(orderItem))           //是否存在相同的订单明细
                            {
                                isHavingSameOrderItem = true;
                            }
                        }
                        if (!isHavingSameOrderItem)                       //如果订单明细不重复,添加订单明细到该订单号订单的订单详细集合
                        {
                            OrderService.AddOrderItem(order, newOrderItem);
                            MessageBox.Show("成功添加订单明细");
                        }
                        else                                              //如果订单详细重复,提示用户
                        {
                            MessageBox.Show("错误:订单明细已存在!");
                        }
                    }
                }
                if (!isHavingOrder)
                {
                    MessageBox.Show("错误:订单不存在!");
                }
            }
            catch (FormatException fe)
            {
                MessageBox.Show("错误:输入不正确,请重新输入!");
            }
        }
示例#3
0
        private void btnAddOrderItem_Click(object sender, EventArgs e)
        {
            try
            {
                int    orderID        = int.Parse(txtOrderItemID.Text);
                string orderItemName  = txtItem.Text;
                double unitOrderPrice = double.Parse(txtUnitItemPrice.Text);
                int    count          = int.Parse(txtCount.Text);

                OrderItem newOrderItem = new OrderItem(orderItemName, unitOrderPrice, count);

                bool isHavingOrder         = false;
                bool isHavingSameOrderItem = false;
                foreach (Order order in OrderService.orders)
                {
                    if (orderID == order.OrderID)
                    {
                        isHavingOrder = true;
                        foreach (OrderItem orderItem in order.OrderItems)
                        {
                            if (newOrderItem.Equals(orderItem))
                            {
                                isHavingSameOrderItem = true;
                            }
                        }
                        if (!isHavingSameOrderItem)
                        {
                            OrderService.AddOrderItem(order, newOrderItem);
                            MessageBox.Show("成功添加订单明细");
                        }
                        else
                        {
                            MessageBox.Show("错误:订单明细已存在!");
                        }
                    }
                }
                if (!isHavingOrder)
                {
                    MessageBox.Show("错误:订单不存在!");
                }
            }
            catch (FormatException fe)
            {
                MessageBox.Show("错误:输入不正确,请重新输入!");
            }
        }
示例#4
0
        public void EqualsTest()
        {
            OrderItem book1 = new OrderItem("《加油,湖北》", 1, 3);

            Assert.IsTrue(book1.Equals(book) && !book1.Equals(talk));
        }