using System;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Collections.Generic;
using Telerik.Web.UI;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Web.UI;
using System.Globalization;
using System.Text;
using System.Collections;
using System.Linq;
using System.Web.Configuration;


public partial class EmpyPage : System.Web.UI.Page
{
	protected void Page_Init(object sender, EventArgs e)
	{
		RadGrid1.ItemDataBound += RadGrid1_ItemDataBound;
	}

	protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
	{
		if (e.Item is GridFilteringItem)
		{
			GridFilteringItem filterItem = e.Item as GridFilteringItem;
			RadComboBox combo = filterItem["ContactTitle"].Controls[1] as RadComboBox;
			string currentFilterValue = (combo.NamingContainer as GridFilteringItem).OwnerTableView.GetColumn("ContactTitle").CurrentFilterValue;
			if (!string.IsNullOrEmpty(currentFilterValue) && combo != null)
			{
				RadComboBoxItem item = new Telerik.Web.UI.RadComboBoxItem();
				item.Value = currentFilterValue;
				item.Text = currentFilterValue;
				combo.Items.Add(item);
				item.DataBind();
				item.Selected = true;
			}
		}
	}


	protected void Page_Load(object sender, System.EventArgs e)
	{

	}

	protected void RadGrid1_PreRender(object sender, System.EventArgs e)
	{
		if (RadGrid1.MasterTableView.FilterExpression != string.Empty)
		{
			RefreshCombos();
		}
	}

	protected void ImportedFilter_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
	{
		DataRowView rowView = (DataRowView)e.Item.DataItem;
		if (rowView["Bool"] is DBNull)
		{
			e.Item.Text = "No";
			e.Item.Value = "0";
		}
		else if ((bool)rowView["Bool"])
		{
			e.Item.Text = "Yes";
			e.Item.Value = "1";
		}
	}

	protected void RefreshCombos()
	{
		SqlDataSource2.SelectCommand = SqlDataSource2.SelectCommand + " WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();
		SqlDataSource3.SelectCommand = SqlDataSource3.SelectCommand + " WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();
		SqlDataSource4.SelectCommand = SqlDataSource4.SelectCommand + " WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();
		SqlDataSource6.SelectCommand = SqlDataSource6.SelectCommand + " WHERE " + RadGrid1.MasterTableView.FilterExpression.ToString();

		RadGrid1.MasterTableView.Rebind();
	}

	protected DateTime? SetShippedDate(GridItem item)
	{
		if (item.OwnerTableView.GetColumn("ShippedDate").CurrentFilterValue == string.Empty)
		{
			return new DateTime?();
		}
		else
		{
			return DateTime.Parse(item.OwnerTableView.GetColumn("ShippedDate").CurrentFilterValue);
		}
	}
	protected DateTime? startDate
	{
		set
		{
			ViewState["strD"] = value;
		}
		get
		{
			if (ViewState["strD"] != null)
				return (DateTime)ViewState["strD"];
			else
				return new DateTime(1996, 7, 4);
		}
	}
	protected DateTime? endDate
	{
		set
		{
			ViewState["endD"] = value;
		}
		get
		{
			if (ViewState["endD"] != null)
				return (DateTime)ViewState["endD"];
			else
				return new DateTime(1998, 5, 6);
		}
	}
	protected decimal startSlider
	{
		set
		{
			ViewState["strSl"] = value;
		}
		get
		{
			if (ViewState["strSl"] != null)
				return (decimal)ViewState["strSl"];
			else
				return 0;
		}
	}
	protected decimal endSlider
	{
		set
		{
			ViewState["endSl"] = value;
		}
		get
		{
			if (ViewState["endSl"] != null)
				return (decimal)ViewState["endSl"];
			else
				return 1010;
		}
	}
}
