Пример #1
0
        public ActionResult PriceDetail(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("请输入正确的询价单编号")));
            }

            int oId = 0;

            int.TryParse(id, out oId);
            string uid = HttpContext.User.Identity.Name;

            if (oId <= 0)
            {
                return(Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("请输入正确的询价单编号")));
            }
            BBuyPrice buyPrice = null;

            try
            {
                UserManager userMgr    = new UserManager(int.Parse(uid), null);
                BUser       user       = userMgr.CurrentUser;
                BuyManager  buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
                buyPrice = buyManager.GetBuyPriceFullInfo(oId);
            }
            catch (KMJXCException kex)
            {
                return(Redirect("/Home/Error?message=" + HttpUtility.UrlEncode(kex.Message)));
            }
            catch
            {
                return(Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("未知错误")));
            }
            return(View(buyPrice));
        }
Пример #2
0
        public ApiMessage GetBuyPriceFullInfo()
        {
            ApiMessage message = new ApiMessage()
            {
                Status = "ok"
            };
            HttpContextBase context    = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request    = context.Request;
            string          user_id    = User.Identity.Name;
            UserManager     userMgr    = new UserManager(int.Parse(user_id), null);
            BUser           user       = userMgr.CurrentUser;
            BuyManager      buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            BBuyPrice       buyPrice   = null;
            int             priceId    = 0;

            try
            {
                int.TryParse(request["buy_price_id"], out priceId);
                if (priceId <= 0)
                {
                    message.Status  = "failed";
                    message.Message = "没有输入询价单编号";
                    return(message);
                }

                buyPrice = buyManager.GetBuyPriceFullInfo(priceId);

                if (buyPrice == null)
                {
                    message.Status  = "failed";
                    message.Message = "询价单编号错误";
                    return(message);
                }

                message.Item = buyPrice;
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbex)
            {
                message.Status  = "failed";
                message.Message = dbex.Message;
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status  = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status  = "failed";
                message.Message = ex.Message;
            }
            finally
            {
            }

            return(message);
        }
Пример #3
0
        public ApiMessage CreateBuyPrice()
        {
            ApiMessage message = new ApiMessage()
            {
                Status = "ok"
            };
            HttpContextBase context    = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request    = context.Request;
            string          user_id    = User.Identity.Name;
            UserManager     userMgr    = new UserManager(int.Parse(user_id), null);
            BUser           user       = userMgr.CurrentUser;
            BuyManager      buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);

            try
            {
                string details = request["price_details"];
                string desc    = request["desc"];
                string title   = request["title"];
                int    shopId  = 0;
                int.TryParse(request["shop_id"], out shopId);
                if (!string.IsNullOrEmpty(details))
                {
                    details = HttpUtility.UrlDecode(details);
                }

                JArray    jDetails = JArray.Parse(details);
                BBuyPrice buyPrice = new BBuyPrice()
                {
                    Desc = desc, Title = title, Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now)
                };
                buyPrice.Shop = new BShop()
                {
                    ID = buyManager.Shop.Shop_ID
                };
                if (shopId > 0)
                {
                    buyPrice.Shop = new BShop()
                    {
                        ID = shopId
                    };
                }
                buyPrice.Details = new List <BBuyPriceDetail>();
                for (int i = 0; i < jDetails.Count(); i++)
                {
                    JObject         jDetail = (JObject)jDetails[i];
                    BBuyPriceDetail bDetail = new BBuyPriceDetail();
                    bDetail.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    bDetail.Price   = (double)jDetail["price"];
                    bDetail.Product = new BProduct()
                    {
                        ID = (int)jDetail["sku_id"], ParentID = (int)jDetail["product_id"]
                    };
                    bDetail.Supplier = new BSupplier()
                    {
                        ID = (int)jDetail["supplier_id"]
                    };
                    buyPrice.Details.Add(bDetail);
                }

                bool result = buyManager.CreateBuyPrice(buyPrice);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbex)
            {
                message.Status  = "failed";
                message.Message = dbex.Message;
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status  = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status  = "failed";
                message.Message = ex.Message;
            }
            finally
            {
            }

            return(message);
        }