EmployeeDynamicDataContainer.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using MonoTests.DataSource;
  9. namespace MonoTests.DataObjects
  10. {
  11. public class EmployeeDynamicDataContainer : DynamicDataContainer <List <Employee>>
  12. {
  13. public override Type ContainedType
  14. {
  15. get
  16. {
  17. return typeof (Employee);
  18. }
  19. }
  20. public EmployeeDynamicDataContainer ()
  21. : this (null)
  22. {
  23. }
  24. public EmployeeDynamicDataContainer (List<Employee> data)
  25. : base (data)
  26. {
  27. if (data == null)
  28. PopulateWithData ();
  29. }
  30. void PopulateWithData ()
  31. {
  32. Data = new List<Employee> {
  33. new Employee { FirstName = "Marek", LastName = "Habersack" }
  34. };
  35. }
  36. public override int Update (IDictionary keys, IDictionary values, IDictionary oldValues)
  37. {
  38. throw new NotImplementedException ();
  39. }
  40. public override int Insert (IDictionary values)
  41. {
  42. throw new NotImplementedException ();
  43. }
  44. public override int Delete (IDictionary keys, IDictionary oldValues)
  45. {
  46. throw new NotImplementedException ();
  47. }
  48. public override IEnumerable Select (DataSourceSelectArguments args, string where, ParameterCollection whereParams)
  49. {
  50. List<Employee> data = Data;
  51. int count = data == null ? 0 : data.Count;
  52. if (args.RetrieveTotalRowCount)
  53. args.TotalRowCount = count;
  54. int startIndex = args.StartRowIndex;
  55. if (count == 0 || count < startIndex)
  56. return new Employee[0];
  57. int max = args.MaximumRows;
  58. if (max == 0 || max > count)
  59. max = count;
  60. max -= startIndex;
  61. var ret = new List<Employee> ();
  62. ret.AddRange (data.GetRange (args.StartRowIndex, max));
  63. return ret;
  64. }
  65. public override List<DynamicDataTable> GetTables ()
  66. {
  67. var ret = new List<DynamicDataTable> ();
  68. ret.Add (new EmployeeTable ());
  69. return ret;
  70. }
  71. }
  72. }