Пример #1
0
        public void ProcessRequest(HttpContext context)
        {
            string             sortField     = context.Request.Params["sidx"];
            SortDirection      sortDirection = context.Request.Params["sord"] == "desc" ? SortDirection.Descending : SortDirection.Ascending;
            int                pageIndex     = Convert.ToInt32(context.Request.Params["page"]) - 1;
            int                pageSize      = Convert.ToInt32(context.Request.Params["rows"]);
            int                totalRecords  = itemDao.GetTotalRecordCount();
            IEnumerable <Item> items         =
                itemDao.FindAllPagedSorted(pageIndex * pageSize, pageSize, sortDirection, sortField);

            StringBuilder sb = new StringBuilder("{");

            sb.Append(string.Format("\"page\": {0},", pageIndex + 1));
            sb.Append(string.Format("\"total\": {0},", (int)Math.Ceiling((float)totalRecords / (float)pageSize)));
            sb.Append(string.Format("\"records\": {0},", totalRecords));
            sb.Append(string.Format("\"rows\":["));
            foreach (Item item in items)
            {//'Наименование','Остаток','Заказ','Производитель','Упаковка','Срок годности','Цена 1','Цена 2','Цена 3'],
                sb.Append("{" + string.Format("\"i\": \"{0}\", \"cell\":[\"{1}\", \"{2}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\",\"{7}\",\"{8}\"]",
                                              item.Id, item.Name.Replace("\"", "\\\""), item.Rest, item.Manufacter.Replace("\"", "\\\""), item.Pack, item.Date, item.Price1, item.Price2, item.Price3) + "},");
            }
            sb.Remove(sb.Length - 1, 1);
            sb.Append("]}");
            context.Response.ContentType = "application/json";
            context.Response.Write(sb.ToString());
            //, text/javascript, */*
        }
Пример #2
0
        private void CreateTestOrdersForUser(User user, int numberOrders)
        {
            if (!user.IsClient)
            {
                return;
            }
            Random random     = new Random();
            int    totalItems = itemDao.GetTotalRecordCount();

            for (int iOrder = 0; iOrder < numberOrders; iOrder++)
            {
                Order order = new Order();
                order.User     = user;
                order.DateSent = DateTime.Now;
                order.State    = OrderState.Sent;
                orderDao.Save(order);

                for (int iItem = 0; iItem < random.Next(0, 100); iItem++)
                {
                    Item item = itemDao.FindById(random.Next(1, totalItems));
                    if (item != null)
                    {
                        OrderItem orderItem = new OrderItem(random.Next(5, 123), item, PriceType.Price3, order);
                        orderItemDao.Save(orderItem);
                        order.Items.Add(orderItem);
                    }
                }

                orderDao.Save(order);
            }
        }
Пример #3
0
 public int AllItemsCount()
 {
     return(itemDao.GetTotalRecordCount());
 }