DropDownList 项目 - 免费时间
DropDownList Items - Free hours
我想要 DropDownList.Items 闲置时间。
我的数据库中有 table:
Visit: visitID, trainerID,clientID,Data,Hour.
当客户想要添加新访问时,他必须选择培训师、日期并单击按钮 "Check avaible hours"。然后就DropDownList.Items应该不是占用小时了。
例如 - 所有时间:9:00、10:00、11:00、12:00、13:00、14:00。在 table 中有两个所选日期的访问:9:00 和 12:00,因此客户在添加新访问期间应该在 DropDownList 上看到免费时间:10:00,11:00,13: 00,14:00.
此代码添加到 DropDownList.Items 从数据库占用的时间:
using (myEntities dc = new myEntities())
{
var hours = (from a in dc.Visits
where (a.Data == TextBox1.Text && a.trainerID.Equals(DropDownList1.SelectedItem.Text))
orderby a.Hour
select new
{
a.visitID,
a.Hour,
});
DropDownList2.DataSource = hours.ToList();
DropDownList2.DataTextField = "Hour";
DropDownList2.DataValueField = "visitID";
DropDownList2.DataBind();
}
你说你想显示空闲时间的顺序。你有一个函数,returns 占用时间的集合。
通常情况下可用小时数的集合等于除占用小时数之外的所有小时数的集合。正如预期的那样,为您提供此功能的函数称为 Enumerable.Except
IEnumerable<Hour> allHours = GetAllHours();
IEnumerable<Hour> occupiedHours = RetrieveOccupiedHours();
IEnumerable<Hour> availableHours = allHours.Except(occupiedHours);
要使用它,您需要 class 小时。为了使将来的更改成为可能,请考虑使用与小时不同的名称,例如 appointmentPeriod。这允许您以后以半小时或五十分钟为单位更改约会周期,或其他任何时间。
一旦你有一个 class 来表示一个 "hour"(预约时间),函数 GetAllHours 将类似于:
IEnumerable<Hour> GetHoursOnDate(DateTime Date)
{
// something difficult making sure that 3 o' clock in the middle of the night
// is not considered as an available hour, nor the hours on Christmas day
// and possible also not Sundays, Easter day, New Year's eve at 0:0 etc.
}
private void OnDropDown_ComboBoxAvailableHours(object sender, ...)
{
DateTime selectedDate = GetSelectedDate();
IEnumerable<Hour> hoursOnSelectedDate = GetHoursOnDate(selectedDate);
IEnumerable<Hour> occupiedHoursOnSelectedDate = RetrieveOccupiedHours(date);
IEnumerable<Hour> availableHoursOnSelectedDate = hoursOnSelectedDate
.Except(occupiedHoursOnSelectedDate);
comboBoxAvailableHours.Items.Clear();
comboBoxAvailableHours.Items.AddRange(availableHoursOnSelectedDate
.ToArray());
}
我想要 DropDownList.Items 闲置时间。
我的数据库中有 table:
Visit: visitID, trainerID,clientID,Data,Hour.
当客户想要添加新访问时,他必须选择培训师、日期并单击按钮 "Check avaible hours"。然后就DropDownList.Items应该不是占用小时了。
例如 - 所有时间:9:00、10:00、11:00、12:00、13:00、14:00。在 table 中有两个所选日期的访问:9:00 和 12:00,因此客户在添加新访问期间应该在 DropDownList 上看到免费时间:10:00,11:00,13: 00,14:00.
此代码添加到 DropDownList.Items 从数据库占用的时间:
using (myEntities dc = new myEntities())
{
var hours = (from a in dc.Visits
where (a.Data == TextBox1.Text && a.trainerID.Equals(DropDownList1.SelectedItem.Text))
orderby a.Hour
select new
{
a.visitID,
a.Hour,
});
DropDownList2.DataSource = hours.ToList();
DropDownList2.DataTextField = "Hour";
DropDownList2.DataValueField = "visitID";
DropDownList2.DataBind();
}
你说你想显示空闲时间的顺序。你有一个函数,returns 占用时间的集合。
通常情况下可用小时数的集合等于除占用小时数之外的所有小时数的集合。正如预期的那样,为您提供此功能的函数称为 Enumerable.Except
IEnumerable<Hour> allHours = GetAllHours();
IEnumerable<Hour> occupiedHours = RetrieveOccupiedHours();
IEnumerable<Hour> availableHours = allHours.Except(occupiedHours);
要使用它,您需要 class 小时。为了使将来的更改成为可能,请考虑使用与小时不同的名称,例如 appointmentPeriod。这允许您以后以半小时或五十分钟为单位更改约会周期,或其他任何时间。
一旦你有一个 class 来表示一个 "hour"(预约时间),函数 GetAllHours 将类似于:
IEnumerable<Hour> GetHoursOnDate(DateTime Date)
{
// something difficult making sure that 3 o' clock in the middle of the night
// is not considered as an available hour, nor the hours on Christmas day
// and possible also not Sundays, Easter day, New Year's eve at 0:0 etc.
}
private void OnDropDown_ComboBoxAvailableHours(object sender, ...)
{
DateTime selectedDate = GetSelectedDate();
IEnumerable<Hour> hoursOnSelectedDate = GetHoursOnDate(selectedDate);
IEnumerable<Hour> occupiedHoursOnSelectedDate = RetrieveOccupiedHours(date);
IEnumerable<Hour> availableHoursOnSelectedDate = hoursOnSelectedDate
.Except(occupiedHoursOnSelectedDate);
comboBoxAvailableHours.Items.Clear();
comboBoxAvailableHours.Items.AddRange(availableHoursOnSelectedDate
.ToArray());
}