我正在使用 Daypilot 创建一个主轮班表。
我目前正在数据库中存储约会,但我想检索某一天的所有约会并将它们显示在日历上,与日期无关。
EG 在星期一创建的所有约会都应始终显示在星期一,与 DATE 无关。
当前选择
public DataTable GetAssignmentsForLocation(DayPilotCalendar calendar)
{
DataTable dt = new DataTable();
var da = CreateDataAdapter("select * from [master_rota] where [LocationId] = @location and Week = @Week");
AddParameterWithValue(da.SelectCommand, "location", (int)calendar.ClientState["location"]);
AddParameterWithValue(da.SelectCommand, "week", (int)calendar.ClientState["week"]);
da.Fill(dt);
return dt;
}
和
protected void DayPilotCalendar1_Command(object sender, CommandEventArgs e)
{
switch (e.Command)
{
case "navigate":
var start = (DateTime)e.Data["start"];
DayPilotCalendar1.StartDate = start;
DayPilotCalendar1.DataSource = new DataManager_MasterRota().GetAssignmentsForLocation(DayPilotCalendar1);
DayPilotCalendar1.DataBind();
DayPilotCalendar1.Update();
break;
case "refresh":
DayPilotCalendar1.DataSource = new DataManager_MasterRota().GetAssignmentsForLocation(DayPilotCalendar1);
DayPilotCalendar1.DataBind();
DayPilotCalendar1.Update();
break;
case "day":
DayPilotCalendar1.ViewType = ViewTypeEnum.Day;
DayPilotCalendar1.StartDate = (DateTime)e.Data["date"];
DayPilotCalendar1.DataSource = new DataManager_MasterRota().GetAssignmentsForLocation(DayPilotCalendar1);
DayPilotCalendar1.DataBind();
DayPilotCalendar1.Update();
break;
case "week":
DayPilotCalendar1.ViewType = ViewTypeEnum.Week;
DayPilotCalendar1.DataSource = new DataManager_MasterRota().GetAssignmentsForLocation(DayPilotCalendar1);
DayPilotCalendar1.DataBind();
DayPilotCalendar1.Update();
break;
}
}
创建
public void CreateAssignment(DateTime start, DateTime end, int location, int week, int person, string note, DayOfWeek day)
{
using (DbConnection con = CreateConnection())
{
con.Open();
// string id = "";
var cmd = CreateCommand("insert into [master_rota] ([AssignmentStart], [AssignmentEnd], [LocationId], [PersonId], [AssignmentNote], week, day) values (@start, @end, @location, @person, @note, @Week, @day)", con);
AddParameterWithValue(cmd, "start", start);
AddParameterWithValue(cmd, "end", end);
AddParameterWithValue(cmd, "location", location);
AddParameterWithValue(cmd, "week", week);
AddParameterWithValue(cmd, "person", person);
AddParameterWithValue(cmd, "note", note);
AddParameterWithValue(cmd, "day", day);
cmd.ExecuteScalar();
}
}
数据库条目:数据库记录每个条目的日期,因此理论上应该可以加载给定日期值的所有值
EG “第 1 天”的所有条目,都应在星期一显示,与 DATE 无关
日历如下所示。如您所见,没有显示日期,因为如果 DAY 匹配,它应该始终加载约会
有人可以帮助我建立选择语句,以便约会正确加载到日历上吗?EG 第 1 天到周一,第 2 天到周二等......