예제 #1
0
파일: BuyManager.cs 프로젝트: Bobom/kuanmai
        /// <summary>
        /// Delete buy order
        /// </summary>
        /// <param name="buy_order_id"></param>
        /// <returns></returns>
        public bool DeleteBuyOrder(int buy_order_id)
        {
            bool result = false;

            if (buy_order_id == 0)
            {
                throw new KMJXCException("采购单合同ID不能为空");
            }

            if (this.CurrentUserPermission.DELETE_BUY_ORDER == 0)
            {
                throw new KMJXCException("没有权限删除采购单合同");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                var od = from odo in db.Buy_Order_Detail where odo.Buy_Order_ID == buy_order_id select odo;
                if (od.ToList<Buy_Order_Detail>().Count > 0)
                {
                    throw new KMJXCException("采购单合同里包含产品详细订单,所以不能删除");
                }
                Buy_Order buy_Order = new Buy_Order() { Buy_Order_ID = buy_order_id };
                db.Buy_Order.Attach(buy_Order);
                db.Buy_Order.Remove(buy_Order);
                db.SaveChanges();
                result = true;

            }
            return result;
        }
예제 #2
0
파일: BuyManager.cs 프로젝트: Bobom/kuanmai
        /// <summary>
        /// Add new buy order
        /// </summary>
        /// <param name="buy_Order">Buy_Order object</param>
        /// <returns>TRUE/FALSE</returns>
        public bool CreateNewBuyOrder(BBuyOrder buy_Order, List<BBuyOrderDetail> details)
        {
            bool result = false;

            if (this.CurrentUserPermission.ADD_BUY_ORDER == 0)
            {
                throw new KMJXCException("没有权限创建采购单合同");
            }

            if (buy_Order.Shop == null || buy_Order.Shop.ID<=0 || buy_Order.Supplier==null || buy_Order.Supplier.Supplier_ID==0)
            {
                throw new KMJXCException("Buy_Order 对象属性值不全,缺少店铺ID和供应商ID",ExceptionLevel.SYSTEM);
            }

            if (buy_Order.Supplier == null || buy_Order.Supplier.Supplier_ID == 0)
            {
                throw new KMJXCException("供应商不能为空");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Buy_Order order = new Buy_Order();

                order.Buy_Order_ID = buy_Order.ID;
                order.Create_Date = buy_Order.Created;
                order.Description = buy_Order.Description;
                order.End_Date = buy_Order.EndTime;
                order.Insure_Date = buy_Order.InsureTime;

                if (buy_Order.OrderUser != null)
                {
                    order.Order_User_ID = buy_Order.OrderUser.ID;
                }
                else
                {
                    order.Order_User_ID = this.CurrentUser.ID;
                }

                if (buy_Order.Shop != null)
                {
                    order.Shop_ID = buy_Order.Shop.ID;
                }
                else
                {
                    order.Shop_ID = this.Shop.Shop_ID;
                }

                order.Status = 0;
                order.Supplier_ID = buy_Order.Supplier.Supplier_ID;
                order.User_ID = this.CurrentUser.ID;
                order.Write_Date = buy_Order.WriteTime;

                db.Buy_Order.Add(order);
                db.SaveChanges();

                if (order.Buy_Order_ID > 0)
                {
                    result = true;
                    if (details != null && details.Count > 0)
                    {
                        result = result&this.CreateNewBuyOrderDetails(order.Buy_Order_ID, details);
                        base.CreateActionLog(new BUserActionLog() { Shop = new BShop { ID = order.Shop_ID }, Action = new BUserAction() { Action_ID = UserLogAction.CREATE_BUY_ORDER }, Description = "" });
                    }
                }

            }

            return result;
        }