예제 #1
0
        public ApiMessage UpdateBuyOrder()
        {
            ApiMessage message = new ApiMessage();
            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
            {
                int oid = 0;
                long writedate = 0;
                long issuedate = 0;
                long enddate = 0;
                int supplier_id = 0;
                int order_user = 0;
                string odetails = request["order_products"];
                string desc = request["description"];
                int.TryParse(request["oid"],out oid);

                if (!string.IsNullOrEmpty(odetails))
                {
                    odetails = HttpUtility.UrlDecode(odetails);
                }

                if (!string.IsNullOrEmpty(request["writedate"]))
                {
                    writedate = DateTimeUtil.ConvertDateTimeToInt(Convert.ToDateTime(request["writedate"]));
                }

                if (!string.IsNullOrEmpty(request["issuedate"]))
                {
                    issuedate = DateTimeUtil.ConvertDateTimeToInt(Convert.ToDateTime(request["issuedate"]));
                }

                if (!string.IsNullOrEmpty(request["enddate"]))
                {
                    enddate = DateTimeUtil.ConvertDateTimeToInt(Convert.ToDateTime(request["enddate"]));
                }

                int.TryParse(request["supplier"], out supplier_id);
                int.TryParse(request["order_user"], out order_user);
                BBuyOrder order = new BBuyOrder();
                order.ID = oid;
                //order.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                //order.Created_By = new BUser() { ID = buyManager.CurrentUser.ID };
                order.Description = desc;
                order.EndTime = enddate;
                order.InsureTime = issuedate;
                order.OrderUser = new BUser() { ID = order_user };
                order.Shop = new BShop() { ID = buyManager.Shop.Shop_ID };
                order.Status = 0;
                order.Supplier = new Supplier() { Supplier_ID = supplier_id };
                order.WriteTime = writedate;
                if (!string.IsNullOrEmpty(odetails))
                {
                    JArray jOrders = JArray.Parse(odetails);
                    order.Details = new List<BBuyOrderDetail>();
                    if (jOrders != null && jOrders.Count > 0)
                    {
                        for (int i = 0; i < jOrders.Count; i++)
                        {
                            JObject jOrder = (JObject)jOrders[i];
                            int parent_product_id = (int)jOrder["product_id"];
                            JArray cjorders = (JArray)jOrder["orders"];
                            if (cjorders != null && cjorders.Count > 0)
                            {
                                for (int j = 0; j < cjorders.Count; j++)
                                {
                                    BBuyOrderDetail oDetail = new BBuyOrderDetail();
                                    oDetail.Parent_Product_ID = parent_product_id;
                                    double price = 0;
                                    int quantity = 0;
                                    double.TryParse(cjorders[j]["price"].ToString(), out price);
                                    int.TryParse(cjorders[j]["quantity"].ToString(), out quantity);
                                    oDetail.Product = new BProduct() { ID = (int)cjorders[j]["child_id"] };
                                    oDetail.Quantity = quantity;
                                    oDetail.Status = 0;
                                    oDetail.Price = price;
                                    if (quantity <= 0)
                                    {
                                        continue;
                                    }
                                    order.Details.Add(oDetail);
                                }
                            }
                        }
                    }
                }

                bool result = buyManager.UpdateBuyOrder(order);
                if (result)
                {
                    message.Status = "ok";
                }
                else
                {
                    message.Status = "failed";
                    message.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;
        }
예제 #2
0
파일: BuyManager.cs 프로젝트: Bobom/kuanmai
 /// <summary>
 /// 
 /// </summary>
 /// <param name="buy_Order"></param>
 /// <returns></returns>
 public bool CreateNewBuyOrder(BBuyOrder buy_Order)
 {
     return this.CreateNewBuyOrder(buy_Order, buy_Order.Details);
 }
예제 #3
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;
        }
예제 #4
0
파일: BuyManager.cs 프로젝트: Bobom/kuanmai
        /// <summary>
        /// 
        /// </summary>
        /// <param name="buyOrder"></param>
        /// <returns></returns>
        public bool UpdateBuyOrder(BBuyOrder buy_Order)
        {
            bool result = false;
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Buy_Order order = (from o in db.Buy_Order where o.Buy_Order_ID == buy_Order.ID select o).FirstOrDefault<Buy_Order>();
                if (order == null)
                {
                    throw new KMJXCException("订单不存在");
                }

                if (this.CurrentUserPermission.UPDATE_BUY_ORDER == 0)
                {
                    throw new KMJXCException("没有权限修改采购订单");
                }

                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.SaveChanges();
                result = true;
                if (result)
                {
                    result = this.DeleteBuyOrderDetails(buy_Order.ID);
                    if (result)
                    {
                        result=this.CreateNewBuyOrderDetails(buy_Order.ID, buy_Order.Details);
                    }
                }
            }
            return result;
        }