PageRenderTime 65ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/Veerabook/HotelListing.aspx.cs

https://bitbucket.org/veerabooking/veerabooking
C# | 417 lines | 283 code | 92 blank | 42 comment | 56 complexity | d8ad00622f07e437288bcdf4333e2611 MD5 | raw file
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Text;
  12. using System.Web;
  13. using System.Web.UI;
  14. using System.Web.UI.WebControls;
  15. using System.Xml;
  16. using System.Xml.Linq;
  17. using System.Web.Security;
  18. namespace Veerabook
  19. {
  20. public partial class HotelListing : System.Web.UI.Page
  21. {
  22. Xtools xtools = new Xtools() ;
  23. Multi multi = new Multi();
  24. Merger merger = new Merger();
  25. public string filterString = "";
  26. public string StarFilterStr = "";
  27. protected void Page_Load(object sender, EventArgs e)
  28. {
  29. if (!IsPostBack)
  30. {
  31. BindHotelList();
  32. }
  33. }
  34. void BindHotelList()
  35. {
  36. //Get Session Search Token Based On what's Sent
  37. Session["SessionSearchToken"] = multi.Search(Session["SessionId"].ToString(), Session["htlSrchPostData"].ToString());
  38. //Call the Binding Line
  39. BindHotelLv();
  40. }
  41. void BindHotelLv()
  42. {
  43. lvHotelsList.DataSource = xtools.RemoveDuplicateRows(merger.FinalSearchData(Session["SessionSearchToken"].ToString()),"Hotel_Name");
  44. lvHotelsList.DataBind();
  45. }
  46. protected void lvHotelsList_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
  47. {
  48. //set current page startindex, max rows and rebind to false
  49. lvDataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
  50. //rebind List View
  51. string text = System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "Cache/" + Session["SessionSearchToken"] + ".XML");
  52. StringReader theReader = new StringReader(text);
  53. DataSet originalDataSet = new DataSet("dataSet");
  54. originalDataSet.ReadXml(theReader);
  55. lvHotelsList.DataSource = xtools.RemoveDuplicateRows(GetRowsByFilter(originalDataSet, filterString).Tables[0], "Hotel_Name");
  56. lvHotelsList.DataBind();
  57. }
  58. protected void lvHotelsList_ItemDataBound(object sender, ListViewItemEventArgs e)
  59. {
  60. if (e.Item.ItemType == ListViewItemType.DataItem)
  61. {
  62. //Get Hotel Image from the Api
  63. Image htlImg = (Image)e.Item.FindControl("htlImg");
  64. System.Data.DataRowView rowView = e.Item.DataItem as System.Data.DataRowView;
  65. htlImg.ImageUrl = xtools.getHotelImages(Convert.ToString(rowView["Hotel_Name"]) + " " + Convert.ToString(rowView["Hotel_City_Name"]) ,1).Rows[0]["contentUrl"].ToString() ;
  66. //Register the Repeater and Bind it
  67. Repeater roomsRpt = (Repeater) e.Item.FindControl("RoomsRpt");
  68. //GridView gv1 = (GridView)e.Item.FindControl("gv1");
  69. // Register the Literal Control of Stars
  70. Literal Hotelstars = (Literal)e.Item.FindControl("Hotelstars");
  71. //Get Room Price
  72. string text = System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "Cache/" + Session["SessionSearchToken"] + ".XML");
  73. StringReader theReader = new StringReader(text);
  74. DataSet originalDataSet = new DataSet("dataSet");
  75. originalDataSet.ReadXml(theReader);
  76. //Fix for Stars Issue
  77. // int hotelCatVal = int.Parse(rowView["Hotel_Category"].ToString());
  78. // string stars = "";
  79. // for (var i = 0; i < hotelCatVal; i++)
  80. // {
  81. // stars += "<i class='fa fa-star'></i> ";
  82. // }
  83. Hotelstars.Text = "3";
  84. DataView view = new DataView(originalDataSet.Tables[0]);
  85. view.RowFilter = "Hotel_Name = '" + rowView["Hotel_Name"].ToString() + "'";
  86. view.Sort = "Room_TotalPrice ASC";
  87. //view.Tables[0].Columns.Add("column_1", typeof(string));
  88. roomsRpt.DataSource = new FilterRows(view, 2);
  89. roomsRpt.DataBind();
  90. }
  91. }
  92. private DataSet GetRowsByFilter(DataSet myDataSet, string expressionFilter)
  93. {
  94. DataTable table = myDataSet.Tables[0];
  95. // Presuming the DataTable has a column named Date.
  96. string expression;
  97. expression = expressionFilter;
  98. DataRow[] foundRows;
  99. DataSet ds = new DataSet();
  100. DataTable dt = new DataTable();
  101. dt.Columns.Add("Hotel_ID");
  102. dt.Columns.Add("Hotel_Name");
  103. dt.Columns.Add("Hotel_Category");
  104. dt.Columns.Add("Hotel_Address");
  105. dt.Columns.Add("Hotel_Phone");
  106. dt.Columns.Add("Hotel_City_Name");
  107. dt.Columns.Add("Hotel_City_Code");
  108. dt.Columns.Add("Hotel_Location_LAT");
  109. dt.Columns.Add("Hotel_Location_LNG");
  110. dt.Columns.Add("Room_ID");
  111. dt.Columns.Add("Room_Name");
  112. dt.Columns.Add("Meal_Code");
  113. dt.Columns.Add("Meal_Name");
  114. dt.Columns.Add("Cancellation_Deadline");
  115. dt.Columns.Add("Cancellation_Policy");
  116. dt.Columns.Add("Room_TotalPrice");
  117. dt.Columns.Add("Room_BasePrice");
  118. dt.Columns.Add("Room_BasePrice_Currency");
  119. dt.Columns.Add("Supplier");
  120. dt.Columns.Add("SessionId");
  121. dt.Columns.Add("SearchToken");
  122. // Use the Select method to find all rows matching the filter.
  123. foundRows = table.Select(expression);
  124. // Print column 0 of each returned row.
  125. for (int i = 0; i < foundRows.Length; i++)
  126. {
  127. DataRow newRow = dt.NewRow();
  128. newRow["Hotel_ID"] = foundRows[i]["Hotel_ID"];
  129. newRow["Hotel_Name"] = foundRows[i]["Hotel_Name"];
  130. newRow["Hotel_Category"] = foundRows[i]["Hotel_Category"];
  131. newRow["Hotel_Address"] = foundRows[i]["Hotel_Address"];
  132. newRow["Hotel_Phone"] = foundRows[i]["Hotel_Phone"];
  133. newRow["Hotel_City_Name"] = foundRows[i]["Hotel_City_Name"];
  134. newRow["Hotel_City_Code"] = foundRows[i]["Hotel_City_Code"];
  135. newRow["Hotel_Location_LAT"] = foundRows[i]["Hotel_Location_LAT"];
  136. newRow["Hotel_Location_LNG"] = foundRows[i]["Hotel_Location_LNG"];
  137. newRow["Room_ID"] = foundRows[i]["Room_ID"];
  138. newRow["Room_Name"] = foundRows[i]["Room_Name"];
  139. newRow["Meal_Code"] = foundRows[i]["Meal_Code"];
  140. newRow["Meal_Name"] = foundRows[i]["Meal_Name"];
  141. newRow["Cancellation_Deadline"] = foundRows[i]["Cancellation_Deadline"];
  142. newRow["Cancellation_Policy"] = foundRows[i]["Cancellation_Policy"];
  143. newRow["Room_BasePrice"] = foundRows[i]["Room_BasePrice"];
  144. newRow["Room_TotalPrice"] = foundRows[i]["Room_TotalPrice"];
  145. newRow["Room_BasePrice_Currency"] = foundRows[i]["Room_BasePrice_Currency"];
  146. newRow["Supplier"] = "Multi";
  147. newRow["SessionId"] = foundRows[i]["SessionId"];
  148. newRow["SearchToken"] = foundRows[i]["SearchToken"];
  149. dt.Rows.Add(newRow);
  150. }
  151. dt.TableName = "Search_Result";
  152. ds.Tables.Add(dt);
  153. return ds;
  154. }
  155. protected int getMinPrice()
  156. {
  157. string priceRangeStr;
  158. int Min = 0;
  159. priceRangeStr = amount.Value;
  160. String searchString = "$";
  161. int startIndex = priceRangeStr.IndexOf(searchString) + 1;
  162. searchString = " -";
  163. int endIndex = priceRangeStr.IndexOf(searchString);
  164. String substring = priceRangeStr.Substring(startIndex, endIndex - startIndex);
  165. Min = int.Parse(substring.Trim());
  166. return Min;
  167. }
  168. protected int getMaxPrice()
  169. {
  170. string priceRangeStr;
  171. int Max = 5000;
  172. priceRangeStr = amount.Value;
  173. String searchString = "- $";
  174. int startIndex = priceRangeStr.IndexOf(searchString) +3;
  175. searchString = "!";
  176. int endIndex = priceRangeStr.IndexOf(searchString);
  177. String substring = priceRangeStr.Substring(startIndex, endIndex - startIndex);
  178. Max = int.Parse(substring.Trim());
  179. return Max;
  180. }
  181. protected void btnApplyFilters_Click(object sender, EventArgs e)
  182. {
  183. //for hotel name/chain filter
  184. if (lblhotelname.Value.Trim() != "" && lblhotelname.Value.Trim() != null)
  185. {
  186. if (filterString != "" && filterString != null)
  187. {
  188. filterString += " AND ";
  189. }
  190. filterString += "Hotel_Name LIKE '%" + lblhotelname.Value.ToString() + "%'";
  191. }
  192. //for location filer
  193. if (lblloc.Value.Trim() != "" && lblloc.Value.Trim() != null)
  194. {
  195. if (filterString != "" && filterString != null)
  196. {
  197. filterString += " AND ";
  198. }
  199. filterString += "Hotel_Address LIKE '%" + lblloc.Value.ToString() + "%'";
  200. }
  201. //for star rating filter
  202. if (Star1.Checked)
  203. {
  204. if (StarFilterStr.Trim() != "" && StarFilterStr != null)
  205. {
  206. StarFilterStr += " OR ";
  207. }
  208. StarFilterStr += "(Hotel_Category = " + int.Parse(Star1.Text) + ")";
  209. }
  210. if (Star2.Checked)
  211. {
  212. if (StarFilterStr.Trim() != "" && StarFilterStr != null)
  213. {
  214. StarFilterStr += " OR ";
  215. }
  216. StarFilterStr += "(Hotel_Category = " + int.Parse(Star2.Text) + ")";
  217. }
  218. if (Star3.Checked)
  219. {
  220. if (StarFilterStr.Trim() != "" && StarFilterStr != null)
  221. {
  222. StarFilterStr += " OR ";
  223. }
  224. StarFilterStr += "(Hotel_Category = " + int.Parse(Star3.Text) + ")";
  225. }
  226. if (Star4.Checked)
  227. {
  228. if (StarFilterStr.Trim() != "" && StarFilterStr != null)
  229. {
  230. StarFilterStr += " OR ";
  231. }
  232. StarFilterStr += "(Hotel_Category = " + int.Parse(Star4.Text) + ")";
  233. }
  234. if (Star5.Checked)
  235. {
  236. if (StarFilterStr.Trim() != "" && StarFilterStr != null)
  237. {
  238. StarFilterStr += " OR ";
  239. }
  240. StarFilterStr += "(Hotel_Category = " + int.Parse(Star5.Text) + ")";
  241. }
  242. if (StarFilterStr.Trim() != "" && StarFilterStr != null)
  243. {
  244. if (filterString.Trim() != "" && filterString != null)
  245. {
  246. filterString += " AND ";
  247. }
  248. filterString += " ( " + StarFilterStr + " ) ";
  249. }
  250. //if (int.Parse(ddlStarRatingFilter.SelectedValue) > 1)
  251. //{
  252. // if (filterString.Trim() != "" && filterString != null)
  253. // {
  254. // filterString += " AND ";
  255. // }
  256. // filterString += "Hotel_Category >= " + int.Parse(ddlStarRatingFilter.SelectedValue) ;
  257. //}
  258. // for Price Range filter
  259. int MinPrice = 0;
  260. int MaxPrice = 5000;
  261. if (amount.Value != "$0 - $5000")
  262. {
  263. MinPrice = getMinPrice();
  264. MaxPrice = getMaxPrice();
  265. }
  266. //if (MinPrice > 1 || MaxPrice < 5000)
  267. //{
  268. // if (filterString.Trim() != "" && filterString != null)
  269. // {
  270. // filterString += " AND ";
  271. // }
  272. // filterString += "Room_TotalPrice >= CAST(" + MinPrice + " AS int)";
  273. //}
  274. string text = System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "Cache/" + Session["SessionSearchToken"] + ".XML");
  275. StringReader theReader = new StringReader(text);
  276. DataSet originalDataSet = new DataSet("dataSet");
  277. originalDataSet.ReadXml(theReader);
  278. lvHotelsList.DataSource = xtools.RemoveDuplicateRows(GetRowsByFilter(originalDataSet, filterString).Tables[0], "Hotel_Name"); ;
  279. lvHotelsList.DataBind();
  280. }
  281. }
  282. public class FilterRows : IEnumerable
  283. {
  284. DataView dataView;
  285. private int rowsToShow;
  286. public FilterRows(DataView dataView, int rowsToShow)
  287. {
  288. this.rowsToShow = rowsToShow;
  289. this.dataView = dataView;
  290. }
  291. public IEnumerator GetEnumerator()
  292. {
  293. return new PageOfData(this.dataView.GetEnumerator(), this.rowsToShow);
  294. }
  295. internal class PageOfData : IEnumerator
  296. {
  297. private IEnumerator e;
  298. private int cnt = 0;
  299. private int rowsToShow;
  300. internal PageOfData(IEnumerator e, int rowsToShow)
  301. {
  302. this.rowsToShow = rowsToShow;
  303. this.e = e;
  304. }
  305. public object Current
  306. {
  307. get { return e.Current; }
  308. }
  309. public bool MoveNext()
  310. {
  311. // If we've hit out limit return false
  312. if (cnt >= rowsToShow)
  313. return false;
  314. // Track the current row
  315. cnt++;
  316. return e.MoveNext();
  317. }
  318. public void Reset()
  319. {
  320. e.Reset();
  321. cnt = 0;
  322. }
  323. }
  324. }
  325. }