PageRenderTime 3ms CodeModel.GetById 2ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 1ms

/Veerabook/WebForm2.aspx.cs

https://bitbucket.org/veerabooking/veerabooking
C# | 221 lines | 173 code | 39 blank | 9 comment | 1 complexity | 1abd4f1ed91f8db70d45ba62de432f38 MD5 | raw file
  1using System;
  2using System.Collections.Generic;
  3using System.IO;
  4using System.Linq;
  5using System.Net;
  6using System.Text;
  7using System.Web;
  8using System.Web.UI;
  9using System.Web.UI.WebControls;
 10using System.Data;
 11using System.Text.RegularExpressions;
 12using Newtonsoft.Json.Linq;
 13using Newtonsoft.Json;
 14using System.Xml.Linq;
 15using System.Xml;
 16
 17namespace Veerabook
 18{
 19    public partial class WebForm2 : System.Web.UI.Page
 20    {
 21        private Xtools xtools = new Xtools();
 22        protected void Page_Load(object sender, EventArgs e)
 23        {
 24
 25        }
 26        protected void login()
 27        {
 28            WebRequest request = WebRequest.Create("http://api-test.multireisen.com/login/");
 29            request.Method = "POST";
 30            string postData = "xml=" + "<MultireisenAPI_Request><Login><LoginName>admin@dynawix.com</LoginName><Passw>123</Passw></Login></MultireisenAPI_Request>";
 31            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
 32            request.ContentType = "application/x-www-form-urlencoded";
 33            request.ContentLength = byteArray.Length;
 34            Stream dataStream = request.GetRequestStream();
 35            dataStream.Write(byteArray, 0, byteArray.Length);
 36            dataStream.Close();
 37            WebResponse response = request.GetResponse();
 38
 39            dataStream = response.GetResponseStream();
 40            StreamReader reader = new StreamReader(dataStream);
 41            string responseFromServer = reader.ReadToEnd();
 42            xresult.Text = responseFromServer;
 43            StringReader theReader = new StringReader(xresult.Text);
 44            DataSet OriginalDataSet = new DataSet("dataSet");
 45
 46            OriginalDataSet.ReadXml(theReader);
 47            //grid1.DataSource = OriginalDataSet.Tables["Login"];
 48            //grid1.DataBind();
 49
 50            Session["SessionId"] = OriginalDataSet.Tables["Login"].Rows[0]["SessionID"];
 51
 52
 53
 54
 55            reader.Close();
 56            dataStream.Close();
 57            response.Close();
 58
 59        }
 60
 61        protected void btnLogin_OnClick(object sender, EventArgs e)
 62        {
 63            login();
 64        }
 65
 66        protected void btnSearch_OnClick(object sender, EventArgs e)
 67        {
 68            SearchToken();
 69            GetHotelData();
 70
 71        }
 72
 73        void SearchToken()
 74        {
 75            WebRequest request = WebRequest.Create("http://api-test.multireisen.com/hotelsearch/");
 76            request.Method = "POST";
 77            string postData = "xml=" + "<MultireisenAPI_Request><RequestHeader><LoginName>admin@dynawix.com</LoginName><SessionId>" + Session["SessionId"].ToString() + "</SessionId><Language>en</Language><AsyncMode>FALSE</AsyncMode></RequestHeader><SearchData><Hotel><Destination><CityCode></CityCode><CityName>Hurghada</CityName></Destination><CheckIn>2018-09-01</CheckIn><CheckOut>2018-09-03</CheckOut><Rooms><Room><RoomType>2</RoomType><Children></Children></Room></Rooms><Category></Category></Hotel></SearchData></MultireisenAPI_Request>";
 78            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
 79            request.ContentType = "application/x-www-form-urlencoded";
 80            request.ContentLength = byteArray.Length;
 81            Stream dataStream = request.GetRequestStream();
 82            dataStream.Write(byteArray, 0, byteArray.Length);
 83            dataStream.Close();
 84            WebResponse response = request.GetResponse();
 85
 86            dataStream = response.GetResponseStream();
 87            StreamReader reader = new StreamReader(dataStream);
 88            string responseFromServer = reader.ReadToEnd();
 89            txtSearchHotel.Text = responseFromServer;
 90            StringReader theReader = new StringReader(txtSearchHotel.Text);
 91            DataSet OriginalDataSet = new DataSet("dataSet");
 92            OriginalDataSet.ReadXmlSchema(AppDomain.CurrentDomain.BaseDirectory + "XML/Schema/MR.XSD");
 93            OriginalDataSet.ReadXml(theReader);
 94            Session["SessionToken"] = OriginalDataSet.Tables[0].Rows[0]["SearchToken"];
 95
 96            //gvHotels.DataSource = OriginalDataSet.Tables[0];
 97            //gvHotels.DataBind();
 98
 99
100            reader.Close();
101            dataStream.Close();
102            response.Close();
103        }
104
105        void GetHotelData()
106        {
107            WebRequest request = WebRequest.Create("http://api-test.multireisen.com/hotelsearch/result/");
108            request.Method = "POST";
109            string postData = "xml=" + "<MultireisenAPI_Request><RequestHeader><LoginName>admin@dynawix.com</LoginName><SessionId>" + Session["SessionId"].ToString() + "</SessionId><SearchToken>" + Session["SessionToken"].ToString() + "</SearchToken></RequestHeader></MultireisenAPI_Request>";
110            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
111            request.ContentType = "application/x-www-form-urlencoded";
112            request.ContentLength = byteArray.Length;
113            Stream dataStream = request.GetRequestStream();
114            dataStream.Write(byteArray, 0, byteArray.Length);
115            dataStream.Close();
116            WebResponse response = request.GetResponse();
117
118            dataStream = response.GetResponseStream();
119            StreamReader reader = new StreamReader(dataStream);
120            string responseFromServer = reader.ReadToEnd();
121            txtSearchHotel.Text = responseFromServer;
122            StringReader theReader = new StringReader(txtSearchHotel.Text);
123            DataSet OriginalDataSet = new DataSet("dataSet");
124            OriginalDataSet.ReadXmlSchema(AppDomain.CurrentDomain.BaseDirectory + "XML/Schema/MR.XSD");
125            OriginalDataSet.ReadXml(theReader);
126            //Session["SessionToken"] = OriginalDataSet.Tables[0].Rows[0]["SearchToken"];
127
128            gvHotels.DataSource = OriginalDataSet.Tables["HotelResults"];
129            gvHotels.DataBind();
130
131
132            reader.Close();
133            dataStream.Close();
134            response.Close();
135        }
136        protected DataSet book()
137        {
138            WebRequest request = WebRequest.Create("http://api-test.multireisen.com/initbooking/");
139            request.Method = "POST";
140            string postData = "xml=" + "<MultireisenAPI_Request><RequestHeader><LoginName>admin@dynawix.com</LoginName><SessionId>4uffsvi4o0asb5k710i7sg0nv6</SessionId><SearchToken>79ae3d4b8ce84e5f450c78583d3c8817</SearchToken></RequestHeader><InitBookingData><Contact><Title>Mr</Title><Lastname>Teszt</Lastname><Firstname>Contact</Firstname><Email>test.user@gmail.com</Email><Phone>123456789</Phone><Country>HU</Country><Zip>1234</Zip><City>Budapest</City><Address>Teszt utca 11</Address></Contact><Invoice><Name> Test Company </Name><Country>HU</Country><Zip>1234</Zip><City>Budapest</City><Address>Teszt utca 11 </Address></Invoice><Passengers><Passenger><Type>ADT</Type><Title>Mr</Title><Firstname>John</Firstname><Lastname>Doe</Lastname><Birthdate>1971-05-13</Birthdate><Nationality>Egyptian</Nationality><PassportNumber>4545</PassportNumber><PassportCountry>Egypt</PassportCountry><PassportIssued>05/17</PassportIssued><PassportExp>05/22</PassportExp></Passenger><Passenger><Type>ADT</Type><Title>Mr</Title><Firstname>John</Firstname><Lastname>Doe</Lastname><Birthdate>1971-05-13</Birthdate><Nationality>Egyptian</Nationality><PassportNumber>4545</PassportNumber><PassportCountry>Egypt</PassportCountry><PassportIssued>05/17</PassportIssued><PassportExp>05/22</PassportExp></Passenger></Passengers><Paymode>9</Paymode></InitBookingData></MultireisenAPI_Request>";
141            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
142            request.ContentType = "application/x-www-form-urlencoded";
143            request.ContentLength = byteArray.Length;
144            Stream dataStream = request.GetRequestStream();
145            dataStream.Write(byteArray, 0, byteArray.Length);
146            dataStream.Close();
147            WebResponse response = request.GetResponse();
148
149            dataStream = response.GetResponseStream();
150            StreamReader reader = new StreamReader(dataStream);
151            string responseFromServer = reader.ReadToEnd();
152            xresult.Text = responseFromServer;
153            StringReader theReader = new StringReader(xresult.Text);
154            DataSet OriginalDataSet = new DataSet("dataSet");
155
156            OriginalDataSet.ReadXml(theReader);
157            return OriginalDataSet;
158
159        }
160
161        protected void btnInit_Click(object sender, EventArgs e)
162        {
163            WebRequest requestItem = WebRequest.Create("http://api-test.multireisen.com/initbooking/");
164            requestItem.Method = "POST";
165            string postDataItem = "xml=" + "<MultireisenAPI_Request><RequestHeader><LoginName>admin@dynawix.com</LoginName><SessionId>r74qj7tpl5bc58anlfmalrl0b2</SessionId><SearchToken>d5caefbcea268b812cbcd6772b6fa45c</SearchToken></RequestHeader><InitBookingData><Contact><Title>Mr</Title><Lastname>Teszt</Lastname><Firstname>Contact</Firstname><Email>test.user@gmail.com</Email><Phone>123456789</Phone><Country>HU</Country><Zip>1234</Zip><City>Budapest</City><Address>Teszt utca 11</Address></Contact><Invoice><Name> Test Company </Name><Country>HU</Country><Zip>1234</Zip><City>Budapest</City><Address>Teszt utca 11 </Address></Invoice><Passengers><Passenger><Type>ADT</Type><Title>Mr</Title><Firstname>John</Firstname><Lastname>Doe</Lastname><Birthdate>1971-05-13</Birthdate><Nationality>Egyptian</Nationality><PassportNumber>4545</PassportNumber><PassportCountry>Egypt</PassportCountry><PassportIssued>05/17</PassportIssued><PassportExp>05/22</PassportExp></Passenger><Passenger><Type>ADT</Type><Title>Mr</Title><Firstname>John</Firstname><Lastname>Doe</Lastname><Birthdate>1971-05-13</Birthdate><Nationality>Egyptian</Nationality><PassportNumber>4545</PassportNumber><PassportCountry>Egypt</PassportCountry><PassportIssued>05/17</PassportIssued><PassportExp>05/22</PassportExp></Passenger></Passengers><Paymode>9</Paymode></InitBookingData></MultireisenAPI_Request>";
166            byte[] byteArrayItem = Encoding.UTF8.GetBytes(postDataItem);
167            requestItem.ContentType = "application/x-www-form-urlencoded";
168            requestItem.ContentLength = byteArrayItem.Length;
169            Stream dataStreamItem = requestItem.GetRequestStream();
170            dataStreamItem.Write(byteArrayItem, 0, byteArrayItem.Length);
171            dataStreamItem.Close();
172            WebResponse responseItem = requestItem.GetResponse();
173
174            dataStreamItem = responseItem.GetResponseStream();
175            StreamReader readerItem = new StreamReader(dataStreamItem);
176            string responseFromServerItem = readerItem.ReadToEnd();
177
178            StringReader theReaderItem = new StringReader(responseFromServerItem);
179            DataSet OriginalDataSetItem = new DataSet("dataSet");
180
181            OriginalDataSetItem.ReadXml(theReaderItem);
182
183
184
185            //Write to Text File Caching
186            System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "Cache/GetItemDetails/HotelInitBooking.XML", responseFromServerItem);
187
188            //Split Rooms Using XML Nodes
189            XmlDocument xdocItem = new XmlDocument();
190            xdocItem.Load(AppDomain.CurrentDomain.BaseDirectory + "Cache/GetItemDetails/HotelInitBooking.XML");
191
192            //  var xmls = xDoc.Root.Elements().ToArray(); // split into elements
193            XmlNodeList listItem = xdocItem.SelectNodes("//InitBooking");
194
195            DataTable dtItem = new DataTable();
196
197            dtItem.Columns.Add("Hotel_ID");
198            dtItem.Columns.Add("bookingitemid");
199
200            dtItem.Columns.Add("total_Price");
201            dtItem.Columns.Add("BookingId");
202            string SessionId = "r74qj7tpl5bc58anlfmalrl0b2";
203            string SearchToken = "d5caefbcea268b812cbcd6772b6fa45c";
204
205            for (int i = 0; i < listItem.Count; i++)
206            {
207                DataRow newRow1 = dtItem.NewRow();
208                newRow1["Hotel_ID"] = listItem[i].ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes[0].InnerText;
209                newRow1["bookingitemid"] = listItem[i].ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes[4].InnerText;
210                newRow1["total_Price"] = listItem[i].ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes[6].ChildNodes[5].InnerText;
211                newRow1["BookingId"] = listItem[i].ChildNodes[2].InnerText;
212                //
213                string sqlQuery = "INSERT INTO [dbo].[Hotel_InitBooking] (Hotel_ID, bookingitemid, total_Price, BookingId, SessionId, SearchToken) VALUES (" + newRow1["Hotel_ID"].ToString() + "," + newRow1["bookingitemid"].ToString() + "," + decimal.Parse(newRow1["total_Price"].ToString()) + "," + newRow1["BookingId"].ToString() + "," + SessionId + "," + SearchToken + ")";
214                xtools.SQLINSERT(sqlQuery);
215                dtItem.Rows.Add(newRow1);
216            }
217            grid1.DataSource = dtItem;
218            grid1.DataBind();
219        }
220    }
221}