Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="details"></param>
        /// <returns></returns>
        public bool CreateNewBuyDetails(int buyId,List<BBuyDetail> details)
        {
            bool result = false;
            if (this.CurrentUserPermission.ADD_BUY == 0)
            {
                throw new KMJXCException("没有权限创建验货单");
            }

            if (details == null)
            {
                throw new KMJXCException("输入错误");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                foreach (BBuyDetail detail in details)
                {
                    var d = from bdo in db.Buy_Detail where bdo.Buy_ID==buyId && bdo.Buy_Order_ID == detail.Buy_Order_ID && bdo.Product_ID == detail.Product.ID select bdo;
                    if (d != null && d.ToList<Buy_Detail>().Count > 0)
                    {
                        continue;
                    }

                    //if (buyId<=0)
                    //{
                    //    var d2 = from bdo in db.Buy_Detail where bdo.Buy_Order_ID == detail.Buy_Order_ID select bdo;

                    //    List<Buy_Detail> existed = d2.ToList<Buy_Detail>();
                    //    if (existed.Count > 0)
                    //    {
                    //        buyId = existed[0].Buy_ID;
                    //    }
                    //}

                    Buy_Detail dbDetail = new Buy_Detail();
                    dbDetail.Create_Date = KM.JXC.Common.Util.DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    dbDetail.Buy_ID = buyId;
                    dbDetail.Buy_Order_ID = detail.Buy_Order_ID;
                    dbDetail.Create_Date = detail.CreateDate;
                    dbDetail.Price = detail.Price;
                    dbDetail.Product_ID = detail.Product.ID;
                    dbDetail.Quantity = detail.Quantity;
                    dbDetail.Parent_Product_ID = detail.Parent_Product_ID;
                    db.Buy_Detail.Add(dbDetail);

                    Buy_Order_Detail boDetail = null;

                    var d3 = from bod in db.Buy_Order_Detail where bod.Buy_Order_ID == detail.Buy_Order_ID && bod.Product_ID == detail.Product.ID select bod;
                    if (d3.ToList<Buy_Order_Detail>().Count == 1)
                    {
                        boDetail = d3.ToList<Buy_Order_Detail>()[0];
                    }

                    boDetail.Status = 1;
                }

                db.SaveChanges();
            }
            return result;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create single buy detail
        /// </summary>
        /// <param name="detail"></param>
        /// <returns></returns>
        public bool CreateNewBuyDetail(int buyId,BBuyDetail detail)
        {
            bool ret = false;

            if (this.CurrentUserPermission.ADD_BUY == 0)
            {
                throw new KMJXCException("没有权限创建验货单信息");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                var d = from bdo in db.Buy_Detail where bdo.Buy_Order_ID == detail.Buy_Order_ID && bdo.Product_ID == detail.Product.ID select bdo;
                if (d != null && d.ToList<Buy_Detail>().Count > 0)
                {
                    throw new KMJXCException("已经验过货");
                }

                if (buyId<=0)
                {
                    var d2 = from bdo in db.Buy_Detail where bdo.Buy_Order_ID == detail.Buy_Order_ID select bdo;

                    List<Buy_Detail> existed = d2.ToList<Buy_Detail>();
                    if (existed.Count > 0)
                    {
                        buyId = existed[0].Buy_ID;
                    }
                }

                Buy_Detail dbDetail = new Buy_Detail();
                dbDetail.Buy_ID = buyId;
                dbDetail.Buy_Order_ID = detail.Buy_Order_ID;
                dbDetail.Create_Date = detail.CreateDate;
                dbDetail.Price = detail.Price;
                dbDetail.Product_ID = detail.Product.ID;
                dbDetail.Quantity = detail.Quantity;
                db.Buy_Detail.Add(dbDetail);

                Buy_Order_Detail boDetail = null;

                var d3 = from bod in db.Buy_Order_Detail where bod.Buy_Order_ID == detail.Buy_Order_ID && bod.Product_ID == detail.Product.ID select bod;
                if (d3.ToList<Buy_Order_Detail>().Count == 1)
                {
                    boDetail = d3.ToList<Buy_Order_Detail>()[0];
                }

                boDetail.Status = 1;

                db.SaveChanges();

                //Verify buy order status
                this.VerifyBuyOrder((int)detail.Buy_Order_ID);

                ret = true;
            }

            return ret;
        }