我正在使用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,你用什麼代碼將數據表分配給日曆? –