PageRenderTime 15ms CodeModel.GetById 1ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/Veerabook/HotelDetailPages.aspx.cs

https://bitbucket.org/veerabooking/veerabooking
C# | 223 lines | 109 code | 64 blank | 50 comment | 0 complexity | dd16e78a5aa28aeea3d8be57670eca13 MD5 | raw file
  1using System;
  2using System.Collections;
  3using System.Collections.Generic;
  4using System.Data;
  5using System.IO;
  6using System.Linq;
  7using System.Net;
  8using System.Text;
  9using System.Web;
 10using System.Web.UI;
 11using System.Web.UI.WebControls;
 12using Newtonsoft.Json;
 13using Newtonsoft.Json.Linq;
 14using System.Xml;
 15using System.Xml.Linq;
 16
 17namespace Veerabook
 18{
 19    public partial class HotelDetailPages : System.Web.UI.Page
 20    {
 21        private DataRow newRow;
 22        Xtools xtools = new Xtools();
 23        Multi multi = new Multi();
 24        protected void Page_Load(object sender, EventArgs e)
 25        {
 26            BindHotelLv();
 27            StoreHotelDetails();
 28
 29        }
 30
 31        void BindHotelLv()
 32        {
 33
 34            string text = System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "Cache/" + Session["SessionSearchToken"] + ".XML");
 35
 36            StringReader theReader = new StringReader(text);
 37            DataSet originalDataSet = new DataSet("dataSet");
 38            originalDataSet.ReadXml(theReader);
 39
 40            //Get Only the Data of This Hotel out of the Cached XML 
 41            DataView view = new DataView(originalDataSet.Tables[0]);
 42            view.RowFilter = "Hotel_ID = '" + Request.QueryString["ID"].ToString() + "'";
 43            Session["Hotel_ID"] = Request.QueryString["ID"].ToString();
 44            var dv = view.ToTable();
 45
 46            //Get Basic Info into Literals and get slideshow images 
 47            Hotel_name.Text = lblHotelName.Text = dv.Rows[0]["Hotel_name"].ToString();
 48            Hotel_Address.Text = dv.Rows[0]["Hotel_Address"].ToString();
 49            Session["Hotel_Location_LAT"] = dv.Rows[0]["Hotel_Location_LAT"].ToString();
 50            Session["Hotel_Location_LNG"] = dv.Rows[0]["Hotel_Location_LNG"].ToString();
 51
 52            
 53
 54            //int hotelCatVal = int.Parse(dv.Rows[0]["Hotel_Category"].ToString());
 55            //string stars = "";
 56            //for (var i = 0; i < hotelCatVal; i++)
 57            //{
 58            //    stars += "<i class='fa fa-star'></i> ";
 59                
 60            //}
 61            //stars += " Star/s";
 62            //Hotel_Category.Text = stars;
 63            
 64            //Hotel_Category.Text = dv.Rows[0]["Hotel_Category"].ToString();
 65
 66            //Slideshow
 67            var dt = new DataTable();
 68            dt = xtools.getHotelImages(Hotel_name.Text + " " + dv.Rows[0]["Hotel_City_Name"].ToString(), 7);
 69
 70            //Set first slide 
 71            first_slide.Src = dt.Rows[0]["Contenturl"].ToString();
 72            Session["HotelImg"] = first_slide.Src.ToString();
 73
 74            HotelImgslideshow.DataSource = dt;
 75            HotelImgslideshow.DataBind();
 76
 77
 78            //Get all Rooms of This Hotel Databound into the Rooms Repeater 
 79            lvRooms.DataSource = dv;
 80            lvRooms.DataBind();
 81
 82        }
 83
 84
 85        void BindHotelItemLv()
 86        {
 87            string text = System.IO.File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "Cache/GetItemDetails/" + Request.QueryString["ID"].ToString() + "_Details.XML");
 88            Session["HotelIDAmenities"] = Request.QueryString["ID"].ToString();
 89            StringReader theReader = new StringReader(text);
 90            DataSet originalDataSet = new DataSet("dataSet");
 91            originalDataSet.ReadXml(theReader);
 92         //   lblLocation.Text = originalDataSet.Tables["HotelResult"].Rows[0]["Hotel_Location"].ToString();
 93         //   lblDescription.Text = originalDataSet.Tables["HotelResult"].Rows[0]["Hotel_Description"].ToString();
 94         //   lvAmenities.DataSource = originalDataSet.Tables["HotelResult"];
 95         //  lvAmenities.DataBind();
 96
 97            //for (int i = 0; i < 5; i++)
 98            //{
 99            //    lblamin.Text = originalDataSet.Tables["HotelResult"].Rows[i]["Hotel_Amenities"].ToString();
100            //}
101
102
103
104        }
105
106        void StoreHotelDetails() 
107        {
108            WebRequest requestItem = WebRequest.Create("http://api.multireisen.com/getitemdetails/");
109            requestItem.Method = "POST";
110            string postDataItem = "xml=" + "<MultireisenAPI_Request><RequestHeader><LoginName>admin@traveloo.club</LoginName><SessionId>"+ Session["SessionId"] + "</SessionId><SearchToken>"+ Session["SessionSearchToken"] + "</SearchToken><Language>en</Language></RequestHeader><GetItemDetails><Hotel><ItemID>"+ Request.QueryString["ID"].ToString() + "</ItemID></Hotel></GetItemDetails></MultireisenAPI_Request>";
111            byte[] byteArrayItem = Encoding.UTF8.GetBytes(postDataItem);
112            requestItem.ContentType = "application/x-www-form-urlencoded";
113            requestItem.ContentLength = byteArrayItem.Length;
114            Stream dataStreamItem = requestItem.GetRequestStream();
115            dataStreamItem.Write(byteArrayItem, 0, byteArrayItem.Length);
116            dataStreamItem.Close();
117            WebResponse responseItem = requestItem.GetResponse();
118
119            dataStreamItem = responseItem.GetResponseStream();
120            StreamReader readerItem = new StreamReader(dataStreamItem);
121            string responseFromServerItem = readerItem.ReadToEnd();
122
123            StringReader theReaderItem = new StringReader(responseFromServerItem);
124            DataSet OriginalDataSetItem = new DataSet("dataSet");
125
126            OriginalDataSetItem.ReadXml(theReaderItem);
127
128
129            //Write to Text File Caching
130            System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "Cache/GetItemDetails/" + Request.QueryString["ID"].ToString() + ".XML", responseFromServerItem);
131
132            //Split Rooms Using XML Nodes
133            XmlDocument xdocItem = new XmlDocument();
134            xdocItem.Load(AppDomain.CurrentDomain.BaseDirectory + "Cache/GetItemDetails/" + Request.QueryString["ID"].ToString() + ".XML");
135
136            //  var xmls = xDoc.Root.Elements().ToArray(); // split into elements
137            XmlNodeList listItem = xdocItem.SelectNodes("//HotelResult");
138
139            DataTable dtItem = new DataTable();
140
141            dtItem.Columns.Add("Hotel_Location");
142            dtItem.Columns.Add("Hotel_Description");
143
144            dtItem.Columns.Add("Hotel_Amenities");
145
146            //DataSet ds = new DataSet();
147            //ds.Tables.Add(dtItem);
148            int numAmen;
149            string nodeName;
150
151
152            //for (int i = 0; i < listItem.Count; i++)
153            //{
154            //    DataRow newRow1 = dtItem.NewRow();
155            //    newRow1["Hotel_Location"] = listItem[i].ChildNodes[0].ChildNodes[1].InnerText;
156            //    newRow1["Hotel_Description"] = listItem[i].ChildNodes[0].ChildNodes[7].InnerText;
157
158            //    dtItem.Rows.Add(newRow1);
159            //}
160
161            //for (int i = 0; i < 21; i++)
162            //{
163            //    DataRow newRow = dtItem.NewRow();
164            //    numAmen = i + 10;
165            //    nodeName = listItem[0].ChildNodes[0].ChildNodes[numAmen].Name.ToString();
166            //    if (nodeName != "rooms_description")
167            //    {
168            //        break;
169            //    }
170            //    else
171            //    {
172            //        newRow["Hotel_Amenities"] = "<i class='fa fa-check-circle circle-icon' aria-hidden='true'> " + listItem[0].ChildNodes[0].ChildNodes[numAmen].ChildNodes[0].InnerText + "</i><br />";
173            //        dtItem.Rows.Add(newRow);
174            //    }
175            //}
176
177
178
179            //Cache the Over All Result to XML File 
180            dtItem.TableName = "HotelResult";
181            dtItem.WriteXml(AppDomain.CurrentDomain.BaseDirectory + "Cache/GetItemDetails/" + Request.QueryString["ID"].ToString() + "_Details.XML");
182
183
184
185
186            BindHotelItemLv();
187
188
189            readerItem.Close();
190            dataStreamItem.Close();
191            responseItem.Close();
192        }
193
194     
195
196        protected void lvRooms_ItemDataBound(object sender, ListViewItemEventArgs e)
197        {
198            System.Data.DataRowView rowView = e.Item.DataItem as System.Data.DataRowView;
199
200            string hotel_id = rowView["Hotel_ID"].ToString() ;
201            string session_id = rowView["SessionId"].ToString();
202            string room_id = rowView["Room_ID"].ToString();
203            string search_token = rowView["SearchToken"].ToString();
204
205
206
207            string RoomInfo = multi.GetRoomData(hotel_id, room_id, session_id, search_token);
208
209            using (FileStream fs = File.Create(AppDomain.CurrentDomain.BaseDirectory + "Cache/RoomInfo_" + Session["SessionSearchToken"] + "_" + room_id + ".XML"))
210            {
211                byte[] info = new UTF8Encoding(true).GetBytes(RoomInfo);
212
213                fs.Write(info, 0, info.Length);
214            }
215
216
217
218        }
219
220
221
222    }
223}