Mini Kabibi Habibi
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.Data;
using DevExpress.Web.ASPxClasses;
using System.Text;
using System.Drawing;
using System.Collections;
public partial class Results : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e) {
if(Data.Instance.CurrentQuery == null)
Response.Redirect("Default.aspx");
divSearchIsNotAvailable.Visible = Data.Instance.CurrentQuery.IsSearch;
filterPanel.Visible = !Data.Instance.CurrentQuery.IsSearch;
gvResults.Visible = !Data.Instance.CurrentQuery.IsSearch;
Utils.SetDefaultDateEditValues(deCheckIn, deCheckOut);
if(Data.Instance.CurrentQuery.IsSearch)
Data.Instance.CurrentQuery.IsSearch = false;
}
protected void Page_Load(object sender, EventArgs e) {
InitEditorsValues();
LoadGridData();
}
protected void deCheckIn_Validation(object sender, DevExpress.Web.ASPxEditors.ValidationEventArgs e) {
Utils.ValidateCheckInDate(e);
}
protected void deCheckOut_Validation(object sender, DevExpress.Web.ASPxEditors.ValidationEventArgs e) {
Utils.ValidateCheckOutDate((DateTime)deCheckIn.Value, e);
}
protected void btnRefresh_Click(object sender, EventArgs e) {
InitializeSearchQuery();
LoadGridData();
}
protected void cmbCity_Callback(object source, CallbackEventArgsBase e) {
string country = e.Parameter;
if(string.IsNullOrEmpty(country)) return;
cmbCity.DataSource = Data.Instance.Countries.Find(c => c.Name == country).Cities;
cmbCity.DataBind();
}
protected string GetHotelPrice(GridViewDataItemTemplateContainer container) {
Hotel hotel = GetHotel(container);
if(hotel.MinPrice == hotel.MaxPrice)
return string.Format("${0}", hotel.MinPrice);
return string.Format("${0} - ${1}", hotel.MinPrice, hotel.MaxPrice);
}
protected string GetOrderUrl(GridViewDataItemTemplateContainer container) {
return Utils.GetOrderFormUrl(GetHotel(container));
}
protected string GetHotelImageUrl(int index) {
return Utils.GetImageUrl(((Hotel)gvResults.GetRow(index)).ImageUrl, Utils.GridImageSize);
}
protected string GetHotelDescription(int index) {
return ((Hotel)gvResults.GetRow(index)).Description;
}
protected string GetPreviewHotelImageUrl(int index) {
return Utils.GetImageUrl(((Hotel)gvResults.GetRow(index)).ImageUrl, Utils.PopupImageSize);
}
protected string GetExpandButtonFunction(int index) {
return gvResults.DetailRows.IsVisible(index) ? "gvHideDetails" : "gvShowDetails";
}
protected string GetExpandButtonTitle(int index) {
return gvResults.DetailRows.IsVisible(index) ? "Hide details" : "Show details";
}
protected string GetExpandedBoldClass(int index) {
return gvResults.DetailRows.IsVisible(index) ? "bold" : "";
}
void InitEditorsValues() {
ccbHotelServices.DataSource = Data.Instance.HotelServices;
ccbHotelServices.DataBind();
ccbHotestars.DataSource = Data.Instance.HotelStars;
ccbHotestars.DataBind();
ccbRoomServices.DataSource = Data.Instance.RoomServices;
ccbRoomServices.DataBind();
cmbRoomType.DataSource = Data.Instance.RoomTypes;
cmbRoomType.DataBind();
cmbCountry.DataSource = Data.Instance.Countries;
cmbCountry.DataBind();
SearchQuery query = Data.Instance.CurrentQuery;
if(!IsPostBack) {
if(!string.IsNullOrEmpty(query.Country)) {
cmbCountry.Value = query.Country;
cmbCity.DataSource = Data.Instance.Countries.Find(c => c.Name == query.Country).Cities;
cmbCity.DataBind();
}
if(!string.IsNullOrEmpty(query.City))
cmbCity.Value = query.City;
deCheckIn.Value = query.FromDate ?? deCheckIn.Value;
deCheckOut.Value = query.ToDate ?? deCheckOut.Value;
seMinPrice.Value = query.MinPrice;
seMaxPrice.Value = query.MaxPrice;
cmbRoomType.Value = query.RoomType;
seAdults.Value = query.Adults;
seChildren.Value = query.Children;
ccbHotelServices.Values = query.HotelServices;
ccbHotestars.ValueType = typeof(int);
ccbHotestars.Values = query.Stars;
ccbRoomServices.Values = query.RoomServices;
}
}
void LoadGridData() {
gvResults.DataSource = Data.Instance.GetSearchResults();
gvResults.DataBind();
}
Hotel GetHotel(GridViewDataItemTemplateContainer container) {
return container.Grid.GetRow(container.VisibleIndex) as Hotel;
}
void InitializeSearchQuery() {
Data.Instance.CurrentQuery = new SearchQuery() {
Country = (string)cmbCountry.Value,
City = (string)cmbCity.Value,
MaxPrice = seMaxPrice.Value == null ? 0 : (decimal)seMaxPrice.Value,
MinPrice = seMinPrice.Value == null ? 0 : (decimal)seMinPrice.Value,
FromDate = (DateTime)deCheckIn.Value,
ToDate = (DateTime)deCheckOut.Value,
RoomType = (string)cmbRoomType.Value,
Adults = Convert.ToInt32(seAdults.Value),
Children = Convert.ToInt32(seChildren.Value),
Stars = ccbHotestars.Values.Cast<int>().ToArray(),
HotelServices = ccbHotelServices.Values.Cast<string>().ToArray(),
RoomServices = ccbRoomServices.Values.Cast<string>().ToArray()
};
}
}