public ActionResult BuyOrderDetail(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; BBuyOrder order = null; if (oId <= 0) { return(Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("请输入正确的验货单编号"))); } try { UserManager userMgr = new UserManager(int.Parse(uid), null); BUser user = userMgr.CurrentUser; BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission); order = buyManager.GetBuyOrderFullInfo(oId); } catch (KMJXCException kex) { return(Redirect("/Home/Error?message=" + HttpUtility.UrlEncode(kex.Message))); } catch { return(Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("未知错误"))); } return(View(order)); }
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); }