code= new DataSet1TableAdapters.WeekTableAdapter ();
Days = code.Days(e.Day.Date.ToString());
if (Days.Rows.Equals("false")
{
e.Cell.BackColor = System.Drawing.Color.Gray;
e.Cell.ForeColor = System.Drawing.Color.White;
e.Day.IsSelectable = false;
}
Well your code is not right.
Here with if (Days.Rows.Equals("false") you are checking if Tables' row is equal to false.
If you would have checked the code I posted in the prev. post, you would have got some idea.
Your TableAdapter is getting the weekDays in true/false based on emp,
so your code should be something like this :
DataSet1TableAdapters.WeekTableAdapter ta = new WeekTableAdapter();
DataTable dt = ta.GetData(1); // I have Employee columns datatype as int
foreach (DataRow dr in dt.Rows)
{
if (Boolean.Parse(dr["Monday"].ToString()) == false)
{
e.Cell.BackColor = System.Drawing.Color.Gray;
e.Cell.ForeColor = System.Drawing.Color.White;
}
}
<div>But when you will execute this code all the days will have Grey/White colour, as for each day Monday is always false in db.</div><div>
</div><div>I am still not shore what you are trying to achieve, or ur database design for Week table is not right.</div>
The reason I used DataTable dt = ta.GetData(1); & not DataTable dt = ta.GetData(User.Identity.Name); was to avoid using ASP.net Membership.
Otherwise I would had to create a Login Page & Login using that so User.Identity.Name property could be set. If you want to use User.Identity.Name
u need to be Logged-In before u execute the calender code.
Now try to understand, when u use the following code in Calender's Day Render Event
DataSet1TableAdapters.WeekTableAdapter tatt = new DataSet1TableAdapters.WeekTableAdapter();
DataTable dt = tatt.WorkingWeek();
foreach (DataRow dr in dt.Rows)
{
if (Boolean.Parse(dr["Sunday"].ToString()) == false)
{
e.Cell.BackColor = System.Drawing.Color.Black;
e.Cell.ForeColor = System.Drawing.Color.White;
}
}
For each day it checks if Sunday is False, for that Particular user if Sunday is False in db, all days will be rendered Black/White
Reason for that is in DayRender Event u need to check Date and or Day not Day only. db Day in Week table will result same for all Days in Calender.
FROM Holidays INNER JOIN Employees ON Holidays.Employee = Employees.Employee
WHERE (Holidays.Date = @Date) AND (Holidays.Approved = 'True') AND (Employees.Department = @Param1) AND (@Param2
IS null OR Employees.Employee = @Param2)
nikhilgupta
Member
674 Points
204 Posts
Re: Thanks!
Jan 23, 2011 06:43 PM|LINK
Well your code is not right.
Here with if (Days.Rows.Equals("false") you are checking if Tables' row is equal to false.
If you would have checked the code I posted in the prev. post, you would have got some idea.
Your TableAdapter is getting the weekDays in true/false based on emp,
so your code should be something like this :
DataSet1TableAdapters.WeekTableAdapter ta = new WeekTableAdapter();
DataTable dt = ta.GetData(1); // I have Employee columns datatype as int
foreach (DataRow dr in dt.Rows)
{
if (Boolean.Parse(dr["Monday"].ToString()) == false)
{
e.Cell.BackColor = System.Drawing.Color.Gray;
e.Cell.ForeColor = System.Drawing.Color.White;
}
}
<div>But when you will execute this code all the days will have Grey/White colour, as for each day Monday is always false in db.</div><div></div><div>I am still not shore what you are trying to achieve, or ur database design for Week table is not right.</div>
ConfusedMonl...
Member
48 Points
140 Posts
Re: Thanks!
Jan 23, 2011 08:24 PM|LINK
Thanks!
ConfusedMonl...
Member
48 Points
140 Posts
Re: Thanks!
Jan 23, 2011 08:51 PM|LINK
Thanks!
ConfusedMonl...
Member
48 Points
140 Posts
Re: Thanks!
Jan 23, 2011 09:44 PM|LINK
Thanks!
nikhilgupta
Member
674 Points
204 Posts
Re: Thanks!
Jan 24, 2011 06:39 PM|LINK
The reason I used DataTable dt = ta.GetData(1); & not DataTable dt = ta.GetData(User.Identity.Name); was to avoid using ASP.net Membership.
Otherwise I would had to create a Login Page & Login using that so User.Identity.Name property could be set. If you want to use User.Identity.Name u need to be Logged-In before u execute the calender code.
Now try to understand, when u use the following code in Calender's Day Render Event
DataSet1TableAdapters.WeekTableAdapter tatt = new DataSet1TableAdapters.WeekTableAdapter();
DataTable dt = tatt.WorkingWeek();
foreach (DataRow dr in dt.Rows)
{
if (Boolean.Parse(dr["Sunday"].ToString()) == false)
{
e.Cell.BackColor = System.Drawing.Color.Black;
e.Cell.ForeColor = System.Drawing.Color.White;
}
}
For each day it checks if Sunday is False, for that Particular user if Sunday is False in db, all days will be rendered Black/White
Reason for that is in DayRender Event u need to check Date and or Day not Day only. db Day in Week table will result same for all Days in Calender.
I think following code is what u need.
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
DataSet1TableAdapters.WeekTableAdapter ta = new WeekTableAdapter();
DataTable dt = ta.GetData(1);
foreach (DataRow dr in dt.Rows)
{
if (e.Day.Date.DayOfWeek == DayOfWeek.Monday && Boolean.Parse(dr["Monday"].ToString()) == false)
{
e.Cell.BackColor = System.Drawing.Color.Gray;
e.Cell.ForeColor = System.Drawing.Color.White;
e.Day.IsSelectable = false;
}
else if (e.Day.Date.DayOfWeek == DayOfWeek.Tuesday && Boolean.Parse(dr["Tuesday"].ToString()) == false)
{
e.Cell.BackColor = System.Drawing.Color.Gray;
e.Cell.ForeColor = System.Drawing.Color.White;
e.Day.IsSelectable = false;
}
// else if for Other Days also
}
}
<div>I hope it helps.</div>nikhilgupta
Member
674 Points
204 Posts
Re: Thanks!
Jan 24, 2011 06:53 PM|LINK
And for Parametrized Query use ... WHERE Employee = @Employee & then GetData(User.Identity.Name), but create a
Login Page & first Login through it.
ConfusedMonl...
Member
48 Points
140 Posts
Re: Thanks!
Jan 24, 2011 08:11 PM|LINK
Thanks!
nikhilgupta
Member
674 Points
204 Posts
Re: Thanks!
Jan 24, 2011 08:42 PM|LINK
You are welcome man, glad I could help you in solving ur problem.
One thing more I don't think ur Week table will be of any good use as ur application grows.
U will need lots of changes in that table.
ConfusedMonl...
Member
48 Points
140 Posts
Re: Thanks!
Jan 29, 2011 01:26 PM|LINK
Thanks!
nikhilgupta
Member
674 Points
204 Posts
Re: Thanks!
Jan 29, 2011 02:11 PM|LINK
Change ur query as :
SELECT Employees.Employee, Holidays.Date, Holidays.Time, Holidays.Approved
FROM Holidays INNER JOIN Employees ON Holidays.Employee = Employees.Employee
WHERE (Holidays.Date = @Date) AND (Holidays.Approved = 'True') AND (Employees.Department = @Param1) AND (@Param2 IS null OR Employees.Employee = @Param2)
DropDownList_DataBound as :
empDropDow.Items.Insert(0, "All");
empDropDow.Items[0].Value = "-1";
Populating Calendar Control as :
DataTable HRApprovedHolidays;
DataSet1TableAdapters.HRApprovedTableAdapter ApproveHol;
ApproveHol = new DataSet1TableAdapters.HRApprovedTableAdapter();
HRApprovedHolidays = ApproveHol.HRFilterApproved(e.Day.Date.ToString(), deptDropDown.SelectedValue, empDropDown.SelectedValue == "-1" ? null : empDropDown.SelectedValue);
And in ur ApproveHol TableAdapter set Employee columns properties as :
AllowDBNull = True
NullValue = (Null)