<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#C1EFF9, #E8F1B7]" creationComplete="getcountry()">

<mx:Script>
	<![CDATA[
	import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			import mx.rpc.events.ResultEvent;
			import mx.rpc.events.FaultEvent;
			import mx.collections.XMLListCollection;
			import mx.collections.CursorBookmark;
			import mx.managers.DragManager;
			import mx.managers.SystemManager;
				[Bindable]
		private var result:String=new String;
		private static var cid:int=new int;
		public function getcon(event:ResultEvent):void
		{result=event.result.toString();
			
			if(result.length==4)
			{
	
				Alert.show("Values Inserted...");
			}
			else
			{
				Alert.show("Insertion Failed..");
			}
			
		}
		public function fault(event:FaultEvent):void
		{
			Alert.show("Error in Insertion..");
		}
		public function GetCityNames():void
		{
			cid=parseInt(CmbCountry.selectedItem.CountryID);
			HolidayTripWebService.GetCityNames(parseInt(CmbCountry.selectedItem.CountryID));
		}
		public function city(event:ResultEvent):void
		{
			var query:XML=new XML(event.result);
			var queryresult:XMLListCollection=new XMLListCollection(query.CityNames);
			
			CmbCity.dataProvider = queryresult;
			CmbCity.labelField="CityName";
			CmbCity.data="CityId";
		}
		public function getcountry():void
		{
			HolidayTripWebService.getcountry();
		}
		public function country(event:ResultEvent):void
		{
			var query:XML=new XML(event.result);
			var queryresult:XMLListCollection=new XMLListCollection(query.Country);
			
			CmbCountry.dataProvider = queryresult;
			CmbCountry.labelField="CountryName";
			CmbCountry.data="CountryID";

		}
		public function InsertHotel1():void
		{
			//Alert.show(cid.toString());
		//result=	HolidayTripWebService.InsertHotel(parseInt(CmbCity.selectedItem.CityId),Fname.text,Lname.text,parseInt( Noofbeds.text),parseFloat( Uname.text),parseFloat( Pwd.text),parseInt(CmbCountry.selectedItem.CountryId));
		HolidayTripWebService.InsertHotel(parseInt(CmbCity.selectedItem.CityId),HotelName.text,HType.text,parseInt(Noofbeds.text),parseFloat(Costperadult.text), parseFloat(Costperchild.text),cid);
		}
		
		public function Home():void
		{
			var url:URLRequest=new URLRequest("AdminHome.html");
			navigateToURL(url,"_self");
		}
		
		
		public function Logout():void
		{
			var url:URLRequest=new URLRequest("Login.html");
			navigateToURL(url,"_self");
		}
	]]>
</mx:Script>

<mx:WebService
		id="HolidayTripWebService" 
		wsdl="http://localhost:50854/HTWS/Service.asmx?wsdl"
		showBusyCursor="true" fault="mx.controls.Alert.show('Error loading WSDL', 'Webservice Error');" >
		<mx:operation name="InsertHotel" resultFormat="object" result="getcon(event)">
        </mx:operation>		
        <mx:operation name="getcountry" resultFormat="object" result="country(event)">
        </mx:operation>
        <mx:operation name="GetCityNames" resultFormat="object" result="city(event)">
        </mx:operation>
	</mx:WebService>
	
	
	<mx:Label x="297" y="66" text="Hotel Details" fontFamily="Courier New" fontSize="25" fontWeight="bold" fontStyle="normal" color="#823824"/>
	<mx:Form x="144.5" y="117" width="484" height="298">
	<mx:FormItem label="Hotel Name:" width="383" height="27" horizontalAlign="center" fontFamily="Courier New" fontSize="15" fontWeight="bold" fontStyle="italic" color="#6E2B6D">
		<mx:TextInput id="HotelName" color="#22230F"/>		
	</mx:FormItem>
	<mx:FormItem label="Hotel Type:" width="383" height="27" horizontalAlign="center" fontFamily="Courier New" fontSize="15" fontWeight="bold" fontStyle="italic" color="#6E2B6D">
		<mx:TextInput id="HType" color="#22230F"/>		
	</mx:FormItem>
	<mx:FormItem label="Country:" width="383" height="27" horizontalAlign="center" fontFamily="Courier New" fontSize="15" fontWeight="bold" fontStyle="italic" color="#6E2B6D">
		<mx:ComboBox height="22" id="CmbCountry" change="GetCityNames()"></mx:ComboBox>
	</mx:FormItem>
	<mx:FormItem label="City:" width="383" height="37" horizontalAlign="center" fontFamily="Courier New" fontSize="15" fontWeight="bold" fontStyle="italic" color="#6E2B6D">
		<mx:ComboBox height="22" id="CmbCity"></mx:ComboBox>
	</mx:FormItem>
	<mx:FormItem label="Number Of Beds:" width="383" height="37" horizontalAlign="center" fontFamily="Courier New" fontSize="15" fontWeight="bold" fontStyle="italic" color="#6E2B6D">
		<mx:TextInput id="Noofbeds" color="#22230F"/>
	</mx:FormItem>
	<mx:FormItem label="Cost Per Childern:" width="383" height="27" horizontalAlign="center" fontFamily="Courier New" fontSize="15" fontWeight="bold" fontStyle="italic" color="#6E2B6D">
		<mx:TextInput id="Costperchild" color="#22230F"/>		
	</mx:FormItem>
	<mx:FormItem label="Cost Per Adult:" width="383" height="27" horizontalAlign="center" fontFamily="Courier New" fontSize="15" fontWeight="bold" fontStyle="italic" color="#6E2B6D">
		<mx:TextInput id="Costperadult" color="#22230F"/>		
	</mx:FormItem>
	</mx:Form>
	<mx:Button x="326" y="480" label="Submit" width="80" height="27" borderColor="#259DF1" fillAlphas="[1.0, 1.0]" fillColors="[#D62F2F, #190606]" color="#B6D2D8" cornerRadius="20" id="button1" click="InsertHotel1()"/>
	<mx:Button x="768" y="50" label="Home" width="61" height="23" fillAlphas="[1.0, 1.0]" fillColors="[#C54242, #CFB3B3]" cornerRadius="20" click="Home()"/>
	<mx:Button x="898" y="50" label="Logout" width="75" height="23" fillAlphas="[1.0, 1.0]" fillColors="[#C54242, #CFB3B3]" cornerRadius="20" click="Logout()"/>
</mx:Application>
