Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. if (sorting != null)
  2. {
  3. daa.OrderByDescending(i => i.Date);
  4. }
  5.  
  6. public JsonResult TopPlayedInVenueList1(string sorting, string StartDate = "", string EndDate = "", int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
  7. {
  8. try
  9. {
  10.  
  11. if (Request.IsAuthenticated == true)
  12. {
  13. string Path = @"C:\5Newwithdate-1k.xls";
  14. OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= '" + Path + "';Extended Properties=" + (char)34 + "Excel 8.0;IMEX=1;" + (char)34 + "");
  15. OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$]", con);
  16. con.Close();
  17. System.Data.DataTable data = new System.Data.DataTable();
  18. da.Fill(data);
  19.  
  20. List<TopPlayed> daa = new List<TopPlayed>();
  21.  
  22. foreach (DataRow p in data.Rows)
  23. {
  24. TopPlayed top = new TopPlayed()
  25. {
  26. TrackID = Convert.ToInt32(p.Field<double>("TrackID")),
  27. Date = p.Field<DateTime>("DateTimes"),
  28. TrackName = p.Field<string>("TrackName"),
  29. ArtistName = p.Field<string>("ArtistName"),
  30. Times = Convert.ToInt32(p.Field<double>("Times"))
  31. };
  32. daa.Add(top);
  33. }
  34.  
  35. var listOrder = daa.Where(i => i.Date >= Convert.ToDateTime(StartDate) && i.Date <= Convert.ToDateTime(EndDate)).ToList();
  36.  
  37. var newlist = listOrder.ToList().GetRange(jtStartIndex, jtPageSize);
  38. if (!string.IsNullOrWhiteSpace(sorting))
  39. {
  40. newlist = listOrder.OrderByDescending(i => i.Date);
  41. }
  42.  
  43. return Json(new { Result = "OK", Records = newlist, TotalRecordCount = listOrder.ToList().Count });
  44.  
  45. if (sorting != null)
  46. {
  47. daa.OrderBy(i => i.Date);
  48. }
  49. var result = daa.OrderBy(i => i.Date);
  50.  
  51. public JsonResult TopPlayedInVenueList1(string sorting, string StartDate = "", string EndDate = "", int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
  52. {
  53. try
  54. {
  55.  
  56. if (Request.IsAuthenticated == true)
  57. {
  58. string Path = @"C:\5Newwithdate-1k.xls";
  59. OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= '" + Path + "';Extended Properties=" + (char)34 + "Excel 8.0;IMEX=1;" + (char)34 + "");
  60. OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$]", con);
  61. con.Close();
  62. System.Data.DataTable data = new System.Data.DataTable();
  63. da.Fill(data);
  64.  
  65. List<TopPlayed> daa = new List<TopPlayed>();
  66.  
  67. foreach (DataRow p in data.Rows)
  68. {
  69. TopPlayed top = new TopPlayed()
  70. {
  71. TrackID = Convert.ToInt32(p.Field<double>("TrackID")),
  72. Date = p.Field<DateTime>("DateTimes"),
  73. TrackName = p.Field<string>("TrackName"),
  74. ArtistName = p.Field<string>("ArtistName"),
  75. Times = Convert.ToInt32(p.Field<double>("Times"))
  76. };
  77.  
  78. //Don't sort inside your foreach!
  79. //if (sorting != null)
  80. //{
  81. // daa.OrderBy(i => i.Date);
  82. //}
  83.  
  84. daa.Add(top);
  85. }
  86.  
  87. //var listOrder = daa.OrderBy(i => i.Date).ToList().Where(i => i.Date >= Convert.ToDateTime(StartDate) && i.Date <= Convert.ToDateTime(EndDate));
  88. //Don't run a Where after Orderby, probably you're fine...but not sure its guaruanteed, oh and you probably don't want to sort here either
  89. //I'm also a little surprised that the Convert statements in there aren't causing runtime errors..
  90. var listOrder = daa.Where(I => i.Date >= Convert.ToDateTime(StartDate) && i.Date <= Convert.ToDateTime(EndDate)).ToList();
  91.  
  92. //you don't need to convert .ToList() to get .Count
  93. if (jtStartIndex + 150 > listOrder.ToList().Count)
  94. {
  95. int val = listOrder.ToList().Count - jtStartIndex;
  96. jtPageSize = val;
  97. }
  98.  
  99. //This is the list that you actually return. This is where you sort your list
  100. var newlist = listOrder.OrderBy(i => i.Date).ToList().GetRange(jtStartIndex, jtPageSize);
  101. return Json(new { Result = "OK", Records = newlist, TotalRecordCount = listOrder.ToList().Count });
  102.  
  103. var newlist = listOrder.ToList().GetRange(jtStartIndex, jtPageSize);
  104. if(!string.IsNullOrWhiteSpace(sorting))
  105. {
  106. newlist = newlist.OrderByDescending(o => o.Date).ToList();
  107. }
  108.  
  109. daa.OrderBy(i => i.Date);
  110.  
  111. var result = daa.OrderBy(i => i.Date);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement