heey guys
I have a question why is my fromdate drop down(sort expression) menu not working in selectyear and selectmonth I really dont get it cost me that much time
thanks for help !!!
I have a question why is my fromdate drop down(sort expression) menu not working in selectyear and selectmonth I really dont get it cost me that much time
using
HolidayTracker.Code;
using
HolidayTracker.Data.Model;
using
HolidayTracker.Report;
using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.Configuration;
using
System.Data;
using
System.Data.SqlClient;
using
System.Drawing;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
using
eis = Telerik.Web.UI.ExportInfrastructure;
namespace
HolidayTracker.Testing
{
public
partial
class
YearMonthReaport : System.Web.UI.Page
{
private
HtUser user;
private
HtUser User
{
get
{
user = HtUser.INIT_USER(
this
.Page,
true
);
return
user;
}
}
#region Views
private
int
selectYear
{
get
{
if
(
this
.ViewState[
"selectYear"
] ==
null
)
{
this
.ViewState[
"selectYear"
] =
new
int
();
}
return
(
int
)(
this
.ViewState[
"selectYear"
]);
}
set
{
this
.ViewState[
"selectYear"
] = value;
}
}
private
int
selectMonth
{
get
{
if
(
this
.ViewState[
"selectMonth"
]==
null
)
{
this
.ViewState[
"selectMonth"
]=
new
int
();
}
return
(
int
)(
this
.ViewState[
"selectMonth"
]);
}
set
{
this
.ViewState[
"selectMonth"
] = value;
}
}
//private HtVacationDay selectYear
//{
// get
// {
// return (HtVacationDay)ViewState["selectYear"];
// }
// set
// {
// ViewState["selectYear"] = value;
// }
//}
//Change type in int
//private HtVacationDay selectMonth
//{
// get
// {
// return (HtVacationDay)ViewState["selectMonth"];
// }
// set
// {
// ViewState["selectMonth"] = value;
// }
//}
private
HtLocationBusinessUnit selectLBU
{
get
{
return
(HtLocationBusinessUnit)ViewState[
"selectLBU"
];
}
set
{
ViewState[
"selectLBU"
] = value;
}
}
private
HtBusinessUnit selectBusinessUnit
{
get
{
return
(HtBusinessUnit)ViewState[
"selectBU"
];
}
set
{
ViewState[
"selectBU"
] = value;
}
}
private
HtDepartment selectDepartment
{
get
{
return
(HtDepartment)ViewState[
"selectDep"
];
}
set
{
ViewState[
"selectDep"
] = value;
}
}
#endregion
#region UAC
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
LoadYear();
LoadMonth();
LoadLBU();
}
if
(User.HtUserRoles.Where(u => u.Name == UserRoles.LbuLeader.ToString()).Any())
{
this
.rcbYear.Visible =
true
;
this
.rcbMonth.Visible =
true
;
this
.rcbLocationBusinessUnits.Visible =
true
;
this
.rcbBusinessUnits.Visible =
true
;
this
.rcbDepartment.Visible =
true
;
}
if
(User.HtUserRoles.Where(u => u.Name == UserRoles.Administrator.ToString()).Any())
{
this
.rcbMonth.Visible =
true
;
this
.rcbYear.Visible =
true
;
this
.rcbBusinessUnits.Visible =
true
;
this
.rcbDepartment.Visible =
true
;
this
.rcbLocationBusinessUnits.Visible =
true
;
}
else
if
(User.HtUserRoles.Where(u => u.Name == UserRoles.BuLeader.ToString()).Any())
{
this
.rcbMonth.Visible =
true
;
this
.rcbYear.Visible =
true
;
this
.rcbBusinessUnits.Visible =
true
;
}
else
if
(User.HtUserRoles.Where(u => u.Name == UserRoles.DepartmentLeader.ToString()).Any())
{
this
.rcbMonth.Visible =
true
;
this
.rcbYear.Visible =
true
;
this
.rcbDepartment.Visible =
true
;
}
else
if
(User.HtUserRoles.Where(u => u.Name == UserRoles.BackOffice.ToString()).Any())
{
this
.rcbYear.Visible =
true
;
this
.rcbMonth.Visible =
true
;
this
.rcbLocationBusinessUnits.Visible =
true
;
this
.rcbBusinessUnits.Visible =
true
;
this
.rcbDepartment.Visible =
true
;
}
}
#endregion
protected
void
LoadLBU()
{
SqlConnection connection =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"HolidayTrackerConnectionString"
].ConnectionString);
SqlDataAdapter adapter =
new
SqlDataAdapter(
"SELECT * FROM HtLocationBusinessUnit"
, connection);
DataTable dt =
new
DataTable();
adapter.Fill(dt);
rcbLocationBusinessUnits.DataTextField =
"Name"
;
rcbLocationBusinessUnits.DataValueField =
"LocationBusinessUnitId"
;
rcbLocationBusinessUnits.DataSource = dt;
rcbLocationBusinessUnits.DataBind();
rcbLocationBusinessUnits.Items.Insert(0,
new
RadComboBoxItem(
"-Select a LBU-"
));
}
protected
void
LoadBU(
string
locationBusinessUnitId)
{
SqlConnection connection =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"HolidayTrackerConnectionString"
].ConnectionString);
SqlDataAdapter adapter =
new
SqlDataAdapter(
"SELECT * FROM HtBusinessUnit WHERE LocationBusinessUnitId=@LocationBusinessUnitId"
, connection);
adapter.SelectCommand.Parameters.AddWithValue(
"@locationBusinessUnitId"
, locationBusinessUnitId);
DataTable dt =
new
DataTable();
adapter.Fill(dt);
rcbBusinessUnits.DataTextField =
"Name"
;
rcbBusinessUnits.DataValueField =
"BusinessUnitId"
;
rcbBusinessUnits.DataSource = dt;
rcbBusinessUnits.DataBind();
rcbBusinessUnits.Items.Insert(0,
new
RadComboBoxItem(
"-Select a BU-"
));
}
protected
void
LoadDep(
string
businessUnitId)
{
SqlConnection connection =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"HolidayTrackerConnectionString"
].ConnectionString);
SqlDataAdapter adapter =
new
SqlDataAdapter(
"SELECT * FROM HtDepartment WHERE BusinessUnitId=@BusinessUnitId"
, connection);
adapter.SelectCommand.Parameters.AddWithValue(
"@businessUnitId"
, businessUnitId);
DataTable dt =
new
DataTable();
adapter.Fill(dt);
rcbDepartment.DataTextField =
"Name"
;
rcbDepartment.DataValueField =
"DepartmentId"
;
rcbDepartment.DataSource = dt;
rcbDepartment.DataBind();
rcbDepartment.Items.Insert(0,
new
RadComboBoxItem(
"-Select a Dep-"
));
}
protected
void
LoadYear()
{
rcbYear.DataSource = HtVacationDay.GetAllVacationYears();
rcbYear.DataBind();
rcbYear.Items.Insert(0,
new
RadComboBoxItem(
"-Select a Year-"
));
}
protected
void
LoadMonth()
{
rcbMonth.DataSource = HtVacationDay.GetAllVacationMonths();
rcbMonth.DataBind();
rcbMonth.Items.Insert(0,
new
RadComboBoxItem(
"-Select a Month-"
));
}
protected
void
UserGrid_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName ||
e.CommandName == Telerik.Web.UI.RadGrid.ExportToWordCommandName ||
e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName)
{
}
if
(e.CommandName ==
"EnablePaging"
)
{
UserGrid.AllowPaging =
true
;
UserGrid.Rebind();
}
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
UserGrid.Visible =
true
;
ImageButton1.Visible =
true
;
}
protected
void
ImageButton1_Click(
object
sender, ImageClickEventArgs e)
{
foreach
(GridItem item
in
UserGrid.MasterTableView.GetItems(
new
GridItemType[] { GridItemType.Pager, GridItemType.FilteringItem }))
item.Display =
false
;
RadAjaxPanel1.ResponseScripts.Add(
"PrintRadGrid('"
+ UserGrid.ClientID +
"')"
);
}
protected
override
PageStatePersister PageStatePersister
{
get
{
return
new
SessionPageStatePersister(
this
); }
}
private
void
dataSourceFilterChanged()
{
IEnumerable<MonthReportRowItem> reportRowItems = HtUser.GetAll().Select(u =>
new
MonthReportRowItem(u,selectMonth,selectYear)); ;
if
(
this
.selectLBU !=
null
)
{
if
(
this
.selectBusinessUnit !=
null
)
{
if
(
this
.selectDepartment !=
null
)
{
if
(
this
.selectDepartment.HtUsers.Any())
{
reportRowItems =
this
.selectDepartment.HtUsers.Select(u =>
new
MonthReportRowItem(u, 2012));
}
}
else
{
if
(
this
.selectBusinessUnit.HtUsers.Any())
{
reportRowItems =
this
.selectBusinessUnit.GetAllUser().Select(u =>
new
MonthReportRowItem(u, 2012));
}
}
}
else
{
if
(
this
.selectLBU.HtUsers.Any())
{
reportRowItems =
this
.selectLBU.GetAllUsers().Select(u =>
new
MonthReportRowItem(u, 2012));
}
}
}
if
(
this
.selectYear !=
null
)
{
if
(
this
.selectMonth !=
null
)
{
if
(
this
.selectMonth)
{
}
}
else
{
if
(
this
.selectYear)
{
}
}
}
this
.UserGrid.DataSource = reportRowItems;
this
.UserGrid.DataBind();
}
protected
void
UserGrid_DataBound(
object
sender, EventArgs e)
{
if
(
this
.UserGrid.Items.Count > 0)
{
for
(
int
item = 0; item <= UserGrid.Items.Count - 1; item++)
//loops through each grid row
{
GridDataItem dataItem =
this
.UserGrid.Items[item];
for
(
int
c = 1; c <= 31; c++)
{
dataItem[c.ToString()].Text = ((IEnumerable<MonthReportRowItem>)
this
.UserGrid.DataSource).ElementAt(item).MonthDayReport[c - 1].ToString();
}
}
}
}
protected
void
rcbYear_SelectedIndexChanged(
object
sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
this
.selectYear = HtVacationDay.GetById(
int
.Parse(e.Value));
dataSourceFilterChanged();
}
protected
void
rcbMonth_SelectedIndexChanged(
object
sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
this
.selectMonth = HtVacationDay.GetById(
int
.Parse(e.Value));
dataSourceFilterChanged();
}
protected
void
rcbLocationBusinessUnits_SelectedIndexChanged(
object
sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
this
.selectLBU = HtLocationBusinessUnit.GetById(
int
.Parse(e.Value));
LoadBU(selectLBU.LocationBusinessUnitId.ToString());
dataSourceFilterChanged();
}
protected
void
rcbBusinessUnits_SelectedIndexChanged(
object
sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
this
.selectBusinessUnit = HtBusinessUnit.GetById(
int
.Parse(e.Value));
LoadDep(
this
.selectBusinessUnit.BusinessUnitId.ToString());
dataSourceFilterChanged();
}
protected
void
rcbDepartment_SelectedIndexChanged(
object
sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
this
.selectDepartment = HtDepartment.GetById(
int
.Parse(e.Value));
dataSourceFilterChanged();
}
}
}
thanks for help !!!