Beispiel #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="details"></param>
        /// <returns></returns>
        public bool CreateNewBuyOrderDetails(int buyOrderId, List<BBuyOrderDetail> details)
        {
            if (this.CurrentUserPermission.ADD_BUY_ORDER == 0)
            {
                throw new KMJXCException("没有权限创建采购单合同");
            }
            bool result = false;

            if (details != null)
            {
                using (KuanMaiEntities db = new KuanMaiEntities())
                {
                    if (buyOrderId <= 0)
                    {
                        var o = from oo in db.Buy_Order where oo.Buy_Order_ID == details[0].BuyOrder.ID select oo;
                        Buy_Order order = (Buy_Order)o;
                        if (order.Status != 0)
                        {
                            throw new KMJXCException("此采购单已经验货或者验货未通过,不能继续添加采购合同产品信息");
                        }

                        buyOrderId = order.Buy_Order_ID;
                    }

                    foreach (BBuyOrderDetail detail in details)
                    {
                        if (detail.Quantity <= 0)
                        {
                            continue;
                        }

                        Buy_Order_Detail dbOrderDetail = new Buy_Order_Detail();
                        dbOrderDetail.Buy_Order_ID = buyOrderId;
                        dbOrderDetail.Price = detail.Price;
                        dbOrderDetail.Product_ID = detail.Product.ID;
                        dbOrderDetail.Quantity = detail.Quantity;
                        dbOrderDetail.Status = detail.Status;
                        dbOrderDetail.Parent_Product_ID = detail.Parent_Product_ID;
                        db.Buy_Order_Detail.Add(dbOrderDetail);
                    }

                    db.SaveChanges();
                    result = true;
                }
            }

            return result;
        }
Beispiel #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="detail"></param>
        /// <returns></returns>
        public bool CreateNewBuyOrderDetail(int buyOrderId,BBuyOrderDetail detail)
        {
            if (this.CurrentUserPermission.ADD_BUY_ORDER == 0)
            {
                throw new KMJXCException("没有权限创建采购单合同");
            }

            bool result = false;

            if (detail == null || detail.BuyOrder.ID == 0 || detail.Product.ID == 0 || detail.Quantity == 0)
            {
                throw new KMJXCException("采购单合同不能为空,产品不能为空,数量不能为零");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                var o = from oo in db.Buy_Order where oo.Buy_Order_ID == detail.BuyOrder.ID select oo;
                Buy_Order order = (Buy_Order)o;
                if (order.Status != 0)
                {
                    throw new KMJXCException("此采购单已经验货或者验货未通过,所以不能继续添加");
                }

                Buy_Order_Detail dbOrderDetail = new Buy_Order_Detail();
                if (buyOrderId <= 0)
                {
                    dbOrderDetail.Buy_Order_ID = detail.BuyOrder.ID;
                }
                else
                {
                    dbOrderDetail.Buy_Order_ID = buyOrderId;
                }
                dbOrderDetail.Price = detail.Price;
                dbOrderDetail.Product_ID = detail.Product.ID;
                dbOrderDetail.Quantity = detail.Quantity;
                dbOrderDetail.Status = detail.Status;
                db.Buy_Order_Detail.Add(dbOrderDetail);
                db.SaveChanges();
                result = true;
            }
            return result;
        }