/**
         * 26.员工为新建的出库登记表添加详细信息
         * 参数:货物Id,货物数量
         * 返回:是否成功出库(测试通过)                                   //增加修改库存信息
         */
        public bool addOutDetailToOutWithItemIdAndItemAmount(string currentOutId, string currentItemId, int currentItemAmount)
        {
            using (YMDBEntities db = new YMDBEntities())
            {
                try
                {
                    outDetail currentOutDetail = new outDetail
                    {
                        outId = currentOutId,
                        itemId = currentItemId,
                        outAmount = currentItemAmount,
                    };
                    db.outDetail.Add(currentOutDetail);

                    outBase currentOutBase = db.outBase.Where(p => p.outId == currentOutId).FirstOrDefault();

                    stock currentStock = db.stock.Where(p => p.shopId == currentOutBase.shopId & p.itemId == currentItemId).FirstOrDefault();
                    currentStock.stockAmount = currentStock.stockAmount - currentItemAmount;

                    db.SaveChanges();
                    return true;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("添加出库详细错误.");
                    System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                    return false;
                }
                
            }
        }
        /**
         * 18.员工在订单中添加一条订单详细信息
         * 参数:订单Id,货物Id,货物数量
         * 返回:成功返回true,失败返回false
         * 注意:不要重复添加某一条商品的信息(通过测试)
         */
        public bool addOrderDetailToOrderWithOrderIdAndItemIdAndItemAmount(string newOrderId, string newItemId, int newItemAmount)
        {
            using(YMDBEntities db = new YMDBEntities())
            {
                try
                {
                    string newId2 = "outBase_";
                    for (int i = 6; i < newOrderId.Length; i++)
                    {
                        newId2 = newId2 + newOrderId[i];
                    }

                    order currentOrder = db.order.Where(p => p.orderId == newOrderId).FirstOrDefault();
                    orderDetail currentOrderDetail = new orderDetail
                    {
                        orderId = newOrderId,
                        itemId = newItemId,
                        itemAmount = newItemAmount,
                    };
                    db.orderDetail.Add(currentOrderDetail);
                    item currentItem = db.item.Where(p => p.itemId == newItemId).FirstOrDefault();
                    currentOrder.totalPrice = currentOrder.totalPrice + currentItem.itemPrice * newItemAmount;

                    stock currentStock = db.stock.Where(p => p.shopId == currentOrder.shopId & p.itemId == newItemId).FirstOrDefault();
                    currentStock.stockAmount = currentStock.stockAmount - newItemAmount;
                    currentStock.saleAmount = currentStock.saleAmount + newItemAmount;

                    outDetail newOutBase = new outDetail
                    {
                        outId = newId2,
                        itemId = newItemId,
                        outAmount = newItemAmount,
                    };
                    db.outDetail.Add(newOutBase);

                    db.SaveChanges();
                    return true;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("添加orderDetail错误,可能是参数错误.");
                    System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                    return false;
                }
                
                
            }
        }