2.Order1.aspx.cs
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
namespace
InnovativeWeb.Backend
{
public
partial
class
Order1 : System.Web.UI.Page
{
bool
numDisplayed =
false
;
DateTime minValue = DateTime.MaxValue;
DateTime maxValue = DateTime.MinValue;
protected
void
Page_Load(
object
sender, EventArgs e)
{
Label2.Text =
"<i>Results: </i>"
+
new
DateTime(DateTime.Now.Year, 1, 1) +
"<i> through </i>"
+ DateTime.Today.AddDays(1).AddSeconds(-1).ToString();
}
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridPagerItem)
{
if
(numDisplayed ==
false
)
{
Label1.Text =
"Total Orders: "
+ (e.Item
as
GridPagerItem).Paging.DataSourceCount.ToString();
Label1.ForeColor = System.Drawing.Color.Black;
numDisplayed =
true
;
}
}
DateTime dateValue;
if
(e.Item
is
GridDataItem)
{
dateValue = (DateTime)DataBinder.Eval(e.Item.DataItem,
"OrderDate"
);
if
(DateTime.Compare(minValue, dateValue) > 0)
{
minValue = dateValue;
if
(DateTime.Compare(maxValue, dateValue) < 0)
{
maxValue = dateValue;
}
}
else
{
if
(DateTime.Compare(maxValue, dateValue) < 0)
{
maxValue = dateValue;
}
}
//Label2.Text = "<i>Results: </i>" + minValue.ToString() + "<i> through </i>" + maxValue.ToString();
ViewState[
"MaxDateTime"
] = maxValue;
ViewState[
"MinDateTime"
] = minValue;
}
}
protected
void
RadGrid1_GridExporting(
object
sender, GridExportingArgs e)
{
if
(e.ExportType == ExportType.Excel)
{
string
css =
"<style> body { border:solid 0.1pt #dddddd; }</style>"
;
e.ExportOutput = e.ExportOutput.Replace(
"</head>"
, css +
"</head>"
);
}
}
protected
void
RadGrid1_ExportCellFormatting(
object
sender, ExcelExportCellFormattingEventArgs e)
{
GridDataItem item = e.Cell.Parent
as
GridDataItem;
if
(e.FormattedColumn.UniqueName ==
"OrderDate"
)
{
e.Cell.Style[
"text-align"
] =
"left"
;
//e.Cell.Style["border"] = "thin solid black";
}
if
(e.FormattedColumn.UniqueName ==
"FirstName"
)
{
e.Cell.Style[
"text-align"
] =
"left"
;
//e.Cell.Style["border"] = "thin solid black";
}
if
(e.FormattedColumn.UniqueName ==
"Email"
)
{
e.Cell.Style[
"text-align"
] =
"left"
;
//e.Cell.Style["border"] = "thin solid black";
}
if
(e.FormattedColumn.UniqueName ==
"GreetingCode"
)
{
e.Cell.Style[
"text-align"
] =
"left"
;
//e.Cell.Style["border"] = "thin solid black";
}
if
(e.FormattedColumn.UniqueName ==
"ChildFirstName"
)
{
e.Cell.Style[
"text-align"
] =
"left"
;
//e.Cell.Style["border"] = "thin solid black";
}
if
(e.FormattedColumn.UniqueName ==
"ChildLastName"
)
{
e.Cell.Style[
"text-align"
] =
"left"
;
//e.Cell.Style["border"] = "thin solid black";
}
if
(e.FormattedColumn.UniqueName ==
"ChildGender"
)
{
e.Cell.Style[
"text-align"
] =
"left"
;
//e.Cell.Style["border"] = "thin solid black";
}
GridHeaderItem HeaderItem = (GridHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0];
foreach
(TableCell cell
in
HeaderItem.Cells)
{
cell.Style[
"text-align"
] =
"left"
;
cell.Style[
"border"
] =
"thin solid black"
;
cell.Style[
"background-color"
] =
"#cccccc"
;
cell.Style[
"font-weight"
] =
"normal"
;
}
}
protected
void
ImageButton1_Click(
object
sender, ImageClickEventArgs e)
{
switch
(RadComboBox1.SelectedValue)
{
case
"Today"
:
SetFilter(
"OrderDate >= '"
+ DateTime.Today.ToString() +
"'"
);
Label2.Text =
"<i>Results: </i>"
+ DateTime.Today.ToString() +
"<i> through </i>"
+ DateTime.Today.AddDays(1).AddSeconds(-1).ToString();
break
;
case
"Yesterday"
:
SetFilter(
"(OrderDate <= '"
+ DateTime.Today.AddSeconds(-1).ToString() +
"') AND (OrderDate >= '"
+ DateTime.Today.AddDays(-1).ToString() +
"')"
);
Label2.Text =
"<i>Results: </i>"
+ DateTime.Today.AddDays(-1).ToString() +
"<i> through </i>"
+ DateTime.Today.AddSeconds(-1).ToString();
break
;
case
"Last 7 Days"
:
SetFilter(
"OrderDate >= '"
+ DateTime.Today.AddDays(-7).ToString() +
"'"
);
Label2.Text =
"<i>Results: </i>"
+ DateTime.Today.AddDays(-7).ToString() +
"<i> through </i>"
+ DateTime.Today.AddDays(1).AddSeconds(-1).ToString();
break
;
case
"This Month"
:
SetFilter(
"OrderDate >= '"
+
new
DateTime(DateTime.Now.Year, DateTime.Now.Month, 1) +
"'"
);
Label2.Text =
"<i>Results: </i>"
+
new
DateTime(DateTime.Now.Year, DateTime.Now.Month, 1) +
"<i> through </i>"
+ DateTime.Today.AddDays(1).AddSeconds(-1).ToString();
break
;
case
"This Year"
:
SetFilter(
"OrderDate >= '"
+
new
DateTime(DateTime.Now.Year, 1, 1) +
"'"
);
Label2.Text =
"<i>Results: </i>"
+
new
DateTime(DateTime.Now.Year, 1, 1) +
"<i> through </i>"
+ DateTime.Today.AddDays(1).AddSeconds(-1).ToString();
break
;
case
"All Time"
:
SetFilter(
""
);
Label2.Text =
"<i>Results: </i>"
+
"anytime"
+
"<i> through </i>"
+ DateTime.Today.AddDays(1).AddSeconds(-1).ToString();
break
;
default
:
SetFilter(
""
);
break
;
}
}
protected
void
SetFilter(
string
filterString)
{
RadGrid1.MasterTableView.FilterExpression = filterString;
RadGrid1.Rebind();
}
protected
void
ImageButton2_Click(
object
sender, ImageClickEventArgs e)
{
DateTime t1;
DateTime t2;
if
(RadDatePicker1.SelectedDate ==
null
)
{
t1 = DateTime.Now;
}
else
{
t1 = (DateTime)RadDatePicker1.SelectedDate;
}
if
(RadDatePicker2.SelectedDate ==
null
)
{
t2 = DateTime.Now;
}
else
{
t2 = ((DateTime)RadDatePicker2.SelectedDate).AddDays(1).AddSeconds(-1);
}
if
(DateTime.Compare(t1, t2) > 0)
{
t2 = t1;
}
SetFilter(
"(OrderDate >= '"
+ t1.ToString() +
"') AND (OrderDate <= '"
+ t2.ToString() +
"')"
);
Label2.Text =
"<i>Results: </i>"
+ t1.ToString() +
"<i> through </i>"
+ t2.ToString();
}
protected
void
ImageButton3_Click(
object
sender, ImageClickEventArgs e)
{
ConfigureExport();
RadGrid1.MasterTableView.ExportToExcel();
}
public
void
ConfigureExport()
{
RadGrid1.ExportSettings.IgnorePaging = CheckBox1.Checked;
RadGrid1.ExportSettings.OpenInNewWindow = CheckBox2.Checked;
RadGrid1.ExportSettings.ExportOnlyData =
true
;
minValue = (DateTime)ViewState[
"MinDateTime"
];
maxValue = (DateTime)ViewState[
"MaxDateTime"
];
if
(RadGrid1.ExportSettings.IgnorePaging ==
true
)
{
RadGrid1.ExportSettings.FileName =
"FPG_Orders_All_Pages"
;
}
else
{
RadGrid1.ExportSettings.FileName =
"FPG_Orders_"
+ minValue.Month.ToString() +
"_"
+ minValue.Day.ToString() +
"_"
+ minValue.Year.ToString() +
"_"
+
"thru_"
+ maxValue.Month.ToString() +
"_"
+ maxValue.Day.ToString() +
"_"
+ maxValue.Year.ToString();
}
}
}
}