public IList <MemberDetailsModel> AddMemberDetails() { double totalMoney = 0.00; double totalPv = 0.00; ViewState["StateCount"] = false;//声明一个状态,判断选择的产品数量是否超出库存 //获取用户选择商品id集合 List <MemberDetailsModel> details = new List <MemberDetailsModel>(); //获取用户提交的选中商品id串 string pids = hidpids.Value; string[] orpids = pids.Split(','); if (orpids.Length > 1) { //获取商品集合 List <ProductModel> productModelList = registermemberBLL.GetProductModelList(); //用户选择商品到总商品集合里去匹配 for (int i = 1; i < orpids.Length; i++) { int productid = Convert.ToInt32(orpids[i].Substring(1)); ProductModel productuse = ProductDAL.GetProductById(productid); //获取对象 string productName = productuse.ProductName.ToString(); string numStr = Request[orpids[i]]; if (numStr == null) { numStr = "0"; } //读取用户输入的数量 double pdtNum; if (numStr != "") { try { pdtNum = Convert.ToInt32(numStr); } catch { return(null); } } else { pdtNum = 0; } // 读取用户输入的订货信息 if (pdtNum > 0) { //保存订单信息和汇总信息 double price = Convert.ToDouble(productuse.PreferentialPrice); double pv = Convert.ToDouble(productuse.PreferentialPV); totalMoney += price * pdtNum; totalPv += pv * pdtNum; MemberDetailsModel md = new MemberDetailsModel(); md.Price = (decimal)price; md.Pv = (decimal)pv; md.Quantity = (int)pdtNum; md.ProductId = (int)productuse.ProductID; md.ProductName = productName; details.Add(md); //判断不可销售的产品是否超出库存 if (MemberOrderAgainBLL.GetIsSellByProId(Convert.ToInt32(productuse.ProductID)) == "1") { int shuliang = md.Quantity; DataTable dtdetail = MemberOrderAgainBLL.GetMemberDetailsByOrderID(Request.QueryString["OrderID"].ToString()); for (int j = 0; j < dtdetail.Rows.Count; j++) { if (dtdetail.Rows[j]["productid"].ToString() == productuse.ProductID.ToString()) { shuliang = shuliang - Convert.ToInt32(dtdetail.Rows[j]["Quantity"]); } } if (MemberOrderAgainBLL.GetCountByProIdAndStoreId(Convert.ToInt32(productuse.ProductID), Request.QueryString["OrderID"].ToString()) + shuliang < 0) { ViewState["StateCount"] = true; } } } } } ViewState["TotalMoney"] = totalMoney; ViewState["TotalPv"] = totalPv; return(details); }