예제 #1
0
파일: BuyManager.cs 프로젝트: Bobom/kuanmai
        /// <summary>
        /// 
        /// </summary>
        /// <param name="buyPrice"></param>
        /// <returns></returns>
        public bool CreateBuyPrice(BBuyPrice buyPrice)
        {
            bool result = false;

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

            if (buyPrice == null)
            {
                throw new KMJXCException("输入不正确");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Buy_Price dbBuyPrice = new Buy_Price();
                if (buyPrice.Created <= 0)
                {
                    dbBuyPrice.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                }

                dbBuyPrice.Shop_ID = this.Shop.Shop_ID;
                if (buyPrice.Shop != null && buyPrice.Shop.ID > 0)
                {
                    dbBuyPrice.Shop_ID = buyPrice.Shop.ID;
                }

                dbBuyPrice.User_ID = this.CurrentUser.ID;
                if (buyPrice.User != null && buyPrice.User.ID > 0)
                {
                    dbBuyPrice.User_ID = buyPrice.User.ID;
                }

                dbBuyPrice.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                dbBuyPrice.Title = buyPrice.Title;
                dbBuyPrice.Description = buyPrice.Desc;
                db.Buy_Price.Add(dbBuyPrice);
                db.SaveChanges();
                result = true;
                if (dbBuyPrice.ID > 0 && buyPrice.Details!=null && buyPrice.Details.Count>0)
                {
                    result = result & this.SaveBuyPriceDetails(buyPrice.Details, dbBuyPrice.ID);
                }
            }

            return result;
        }
예제 #2
0
파일: BuyManager.cs 프로젝트: Bobom/kuanmai
        /// <summary>
        /// 
        /// </summary>
        /// <param name="buyPrice"></param>
        /// <returns></returns>
        public bool SaveBuyPrice(BBuyPrice buyPrice)
        {
            bool result = false;

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

            if (buyPrice == null)
            {
                throw new KMJXCException("输入不正确");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Buy_Price dbBuyPrice = null;
                bool isNew = false;
                if (buyPrice.ID > 0)
                {
                    dbBuyPrice = (from price in db.Buy_Price where price.ID == buyPrice.ID select price).FirstOrDefault<Buy_Price>();
                    if (dbBuyPrice == null)
                    {
                        isNew = true;
                        dbBuyPrice = new Buy_Price();
                    }
                }
                else
                {
                    isNew = true;
                    dbBuyPrice = new Buy_Price();
                }

                dbBuyPrice.Title = buyPrice.Title;
                dbBuyPrice.Description = buyPrice.Desc;
                if (string.IsNullOrEmpty(dbBuyPrice.Description))
                {
                    dbBuyPrice.Description = "";
                }

                if (isNew)
                {
                    dbBuyPrice.Shop_ID = this.Shop.Shop_ID;
                    if (buyPrice.Shop != null && buyPrice.Shop.ID > 0)
                    {
                        dbBuyPrice.Shop_ID = buyPrice.Shop.ID;
                    }

                    dbBuyPrice.User_ID = this.CurrentUser.ID;
                    if (buyPrice.User != null && buyPrice.User.ID > 0)
                    {
                        dbBuyPrice.User_ID = buyPrice.User.ID;
                    }

                    if (buyPrice.Created <= 0)
                    {
                        dbBuyPrice.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    }

                    dbBuyPrice.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    db.Buy_Price.Add(dbBuyPrice);
                }
                db.SaveChanges();
                result = true;
                if (dbBuyPrice.ID > 0 && buyPrice.Details != null && buyPrice.Details.Count > 0)
                {
                    result = result & this.SaveBuyPriceDetails(buyPrice.Details, dbBuyPrice.ID);
                }
            }

            return result;
        }