示例#1
0
 public bool SaveToDB()
 {
     if (uid <= 0)
         return false;
     if (orderList.Count <= 0)
         return false;
     Order order = new Order();
     order.Uid = uid;
     order.OrderState = OrderState.MakingUp;
     order.Number = GetNumber();
     order.Total = TotalPrice;
     order.Address = Address;
     order.AddTime = DateTime.Now;
     order.LinkMan = LinkMan;
     order.Phone = Phone;
     order.Delivery = Delivery;
     OrderOperation orderop = new OrderOperation();
     int orderid = orderop.Add(order);
     int rows =0;
     bool result =false;
     if (orderid > 0)
     {
         List<OrderItem> orderItems = new List<OrderItem>();
         foreach (DetailItem detail in orderList)
         {
             OrderItem item = detail.ToOrderItem(orderid);
             orderItems.Add(item);
         }
         OrderItemOperation oiop = new OrderItemOperation();
         rows = oiop.AddList(orderItems);
         if (rows > 0)
         {
             result = true;
         }
         else
         {
             orderop.Delete(orderid);
         }
     }
     return result;
 }
        public ActionResult Orders(string type = "latest", int page = 1)
        {
            string[] types = new string[] { "latest", "all", OrderState.MakingUp, OrderState.Delivering, OrderState.Delivered };
            type = type.ToLower();
            if (types.Contains(type))
            {
                try
                {
                    OrderOperation oop = new OrderOperation();
                    List<Order> orders = new List<Order>();
                    TextileCity.Entity.User loginUser = Session["LoginUser"] as TextileCity.Entity.User;
                    switch (type)
                    {
                        case "all":
                            ViewData["Navi"] = 1;
                            if (page > 0)
                            {
                                int count = 0;
                                orders = oop.GetOrders(loginUser.Uid, page, 10, out count);
                                Pager pager = new Pager(page, count, 10);
                                ViewData["PagerItems"] = pager.CreatePager();
                            }
                            else
                            {
                                throw new Exception();
                            }
                            break;
                        case "latest":
                            ViewData["Navi"] = 0;
                            orders = oop.GetMinOrders(loginUser.Uid);
                            break;
                        case OrderState.MakingUp:
                            ViewData["Navi"] = 2;
                            if (page > 0)
                            {
                                int count = 0;
                                orders = oop.GetOrders(loginUser.Uid, type, page, 10, out count);
                                Pager pager = new Pager(page, count, 10);

                                ViewData["PagerItems"] = pager.CreatePager();
                            }
                            else
                            {
                                throw new Exception();
                            }
                            break;
                        case OrderState.Delivering:
                            ViewData["Navi"] = 3;
                            if (page > 0)
                            {
                                int count = 0;
                                orders = oop.GetOrders(loginUser.Uid, type, page, 10, out count);
                                Pager pager = new Pager(page, count, 10);

                                ViewData["PagerItems"] = pager.CreatePager();
                            }
                            else
                            {
                                throw new Exception();
                            }
                            break;
                        case OrderState.Delivered:
                            ViewData["Navi"] = 4;
                            if (page > 0)
                            {
                                int count = 0;
                                orders = oop.GetOrders(loginUser.Uid, type, page, 10, out count);
                                Pager pager = new Pager(page, count, 10);

                                ViewData["PagerItems"] = pager.CreatePager();
                            }
                            else
                            {
                                throw new Exception();
                            }
                            break;
                    }

                    ViewData["Type"] = type;
                    ViewData["Orders"] = orders;
                }
                catch(Exception ex)
                {

                    return new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound);
                }
                ViewBag.NaviCss.Current = TextileCity.Models.Navigation.Account;
                return View();
            }
            else
            {
                return new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound);
            }
        }
示例#3
0
 public string GetNumber()
 {
     OrderOperation orderop = new OrderOperation();
     int n = orderop.GetTodayCount()+1;
     string number = string.Format("{0}{1}", DateTime.Now.ToString("yyyyMMddHHmmss"), n.ToString("00000"));
     return number;
 }
 public ActionResult Order(int id)
 {
     TextileCity.Entity.Order dataModel = new Order();
     dataModel = new OrderOperation().GetModel(id);
     TextileCity.Entity.User loginUser = Session["LoginUser"] as TextileCity.Entity.User;
     if (dataModel != null && dataModel.Uid == loginUser.Uid)
     {
         List<OrderItem> items = new OrderItemOperation().GetItems(dataModel.OrderID);
         ViewData["Items"] = items;
         ViewData["DataModel"] = dataModel;
         Dictionary<int, string> craftNames = new Dictionary<int, string>();
         List<Craft> craftsList = new CraftOperation().GetMinList();
         foreach (Craft c in craftsList)
         {
             craftNames.Add(c.CraftID, c.Name);
         }
         ViewData["CraftNames"] = craftNames;
         ViewBag.NaviCss.Current = TextileCity.Models.Navigation.Account;
         return View();
     }
     else
     {
         return new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound);
     }
 }