我正在使用Daypilot创建主轮盘。Daypilot - 从SQL Server加载约会
我目前在数据库中存储约会,但我想检索某一天的所有约会,并将它们显示在与日期无关的日历上。
E.G星期一创建的所有约会应始终显示在星期一,与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();
}
}
数据库条目:数据库记录每个条目的日子,所以理论上它应该是可能的加载给定日期值的所有值
E.G为“1天”的所有条目,都应该显示在周一,不相关的日期的
日历看起来像下面。正如你可以看到有没有显示日期,如果有一天匹配
可能有人请帮助我建立select语句,以便任命加载到日历正确应该总是加载预约吗? EG第1天预约到周一,2日周二等等....
你没有向我们展示填充日历的代码吗?你只是在填写一张DataTable –
现在就添加它 –
这只是INSERT,你用什么代码将数据表分配给日历? –