Your code won't compile, since you never assign the variable "res" to anything. It also won't work, since only the cells matching the last row in the table will be set to business hours.
If you're loading "res" from the database, you should load it in the calendar's DataBinding event and store it in a private field, rather that loading it for every cell in your calendar. It would also be better to parse the values at the start, rather than parsing the same values for every cell.
Assuming you only have one set of business hours per day, then something like this should work:
private Dictionary<int, Func<TimeSpan, bool>> _res;
protected void DayPilotCalendar1_DataBinding(object sender, EventArgs e)
{
DataTable res = ...; // TODO: Insert your code to load the table here
_res = new Dictionary<int, Func<TimeSpan, bool>>(res.Rows.Count);
for (int i = 0; i < res.Rows.Count; i++)
{
TimeSpan start = TimeSpan.Parse(res.Rows[i][0].ToString());
TimeSpan end = TimeSpan.Parse(res.Rows[i][1].ToString());
int day = int.Parse(res.Rows[i][2].ToString());
day = (day - 2 < 0) ? day + 5 : day - 2;
_res[day] = time => start <= time && time <= end;
}
}
protected void DayPilotCalendar1_BeforeCellRender(object sender, BeforeCellRenderEventArgs e)
{
Func<TimeSpan, bool> predicate;
if (_res.TryGetValue((int)e.Start.DayOfWeek, out predicate) && predicate(e.Start.TimeOfDay))
{
e.IsBusiness = true;
e.BackgroundColor = "Teal";
}
else
{
e.IsBusiness = false;
}
}