using System;
using System.Collections.Generic;

namespace Telerik.Web.Examples.Grid
{
    public class MyBusinessObjectCollection
    {
        const int _maxItems = 100000;

        string[] names = new string[]{ "Côte de Blaye", "Boston Crab Meat", "Singaporean Hokkien Fried Mee", "Gula Malacca", "Rogede sild", "Spegesild", "Zaanse koeken", "Chocolade", "Maxilaku", "Valkoinen suklaa" };
        double[] prizes = new double[] { 23.2500, 9.0000, 45.6000, 32.0000, 14.0000, 19.0000, 263.5000, 18.4000, 3.0000, 14.0000 };
        DateTime[] dates = new DateTime[] { new DateTime(2007, 5, 10), new DateTime(2008, 9, 13), new DateTime(2008, 2, 22), new DateTime(2009, 1, 2), new DateTime(2007, 4, 13), new DateTime(2008, 5, 12), new DateTime(2008, 1, 19), new DateTime(2008, 8, 26), new DateTime(2008, 7, 31), new DateTime(2007, 7, 16) };
        bool[] bools = new bool[] { true, false, true, false, true, false, true, false, true, false };

        public MyBusinessObjectCollection()
        {
        }

        public int SelectCount()
        {
            return _maxItems;
        }

        public List<MyBusinessObject> Select()
        {
            if (System.Web.HttpContext.Current.Cache["data"] == null)
            {
                System.Web.HttpContext.Current.Cache["data"] = Select(0, _maxItems);
            }
            return (List<MyBusinessObject>)System.Web.HttpContext.Current.Cache["data"];
        }

        public List<MyBusinessObject> Select(int startRowIndex, int maximumRows)
        {
            Random Random1 = new Random();

            List<MyBusinessObject> list = new List<MyBusinessObject>();

            int i = startRowIndex;
            while (i < Math.Min(_maxItems, startRowIndex + maximumRows))
            {
                MyBusinessObject Product1 = new MyBusinessObject();
                Product1.ID = i;
                Product1.Name = names[Random1.Next(9)];
                Product1.UnitPrice = prizes[Random1.Next(9)];
                Product1.Date = dates[Random1.Next(9)];
                Product1.Discontinued = bools[Random1.Next(9)];
                list.Add(Product1);
                i++;
            }
            return list;
        }
    }



    public class MyBusinessObject
    {
        private int _id;
        private string _name;
        private double _unitPrice;
        private DateTime _date;
        private bool _discontinued;

        public MyBusinessObject()
        {

        }

        public MyBusinessObject(int _id, string _name, double _unitPrice, DateTime _date, bool _discontinued)
        {
            this._id = _id;
            this._name = _name;
            this._unitPrice = _unitPrice;
            this._date = _date;
            this._discontinued = _discontinued;
        }

        public int ID
        {
            get { return _id; }
            set { _id = value; }
        }

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public double UnitPrice
        {
            get { return _unitPrice; }
            set { _unitPrice = value; }
        }

        public DateTime Date
        {
            get { return _date; }
            set { _date = value; }
        }

        public bool Discontinued
        {
            get { return _discontinued; }
            set { _discontinued = value; }
        }


    }

}
