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