用jquery實現學校的校曆(asp.net+jquery ui 1.72)

來源:互聯網
上載者:User

:

controller代碼:
代碼 複製代碼 代碼如下:public ActionResult CalendarDisplay()
{
BL.DateEventBL de = new BL.DateEventBL();
//擷取當日日期,使用能被javascript轉換成日期的格式
DateTimeFormatInfo myDTFI = new CultureInfo("en-US", false).DateTimeFormat;
string utcTime = DateTime.Now.ToString("MMM dd,yyyy HH:mm:ss", myDTFI);
ViewData["currentDay"] = utcTime;
//擷取當月有事件的日期
List<DateTime> dateHaveEvent = de.GetTimeHaveEvent(DateTime.Now.Year, DateTime.Now.Month);
List<String> dates=dateHaveEvent.Select(u=>u.ToString("MMM dd,yyyy HH:mm:ss", myDTFI)).ToList();
ViewData["datesHaveEvent"] = dates;
//擷取當日事件
List<BL.CDateEvent> deInfos = de.GetDE(DateTime.Now, new Guid("00000000-0000-0000-0000-000000000001"));
//擷取當前周
BL.DateSpanBL ds = new BL.DateSpanBL();
int currentWeek = ds.GetCurrentWeek(DateTime.Now, new Guid("00000000-0000-0000-0000-000000000002"));
ViewData["currentWeek"] = currentWeek;
return View(deInfos);
}

partialview(局部視圖):
代碼 複製代碼 代碼如下:<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<BL.CDateEvent>>" %>
<%string json = ""; List<String> datesHaveEvent = ViewData["datesHaveEvent"] as List<String>; %>
<%
if (datesHaveEvent != null && datesHaveEvent.Count > 0)
{
json = "[";
for (int i = 0; i < datesHaveEvent.Count;i++)
{
if (i == datesHaveEvent.Count - 1)
{
json += "{\"time\":\"" + datesHaveEvent.ElementAt(i) + "\"}"; // 最後一項
}
else
{
json += "{\"time\":\"" + datesHaveEvent.ElementAt(i) + "\"},"; //
}
}
json += "]";
}
%>
<div id="datePicker"></div>
<br />
當前是第 <span style="color:Red; font-size:14px;"><%=ViewData["currentWeek"]%> </span> 周
<br />
<%=DateTime.Now.ToShortDateString() %>
<br />
<%
foreach(var item in Model)
{
%>
<%=Html.Encode(item.Content) %>
<%
}
%>
<br />
<div id="otherEvent" style=" width:300px;"></div>

javascript(指令碼):
代碼 複製代碼 代碼如下:///伺服器與用戶端目前時間的轉換
var a='<%= ViewData["currentDay"]%>';
var b = Date.parse(a);
var serviceDate = new Date(b);
var clientDate = new Date();
var yearOffset = serviceDate.getYear() - clientDate.getYear();
var monthOffset = serviceDate.getMonth() - clientDate.getMonth();
var dayOffset = serviceDate.getDate() - clientDate.getDate();
///擷取日期列表
var jsn = eval('<%=json %>');
$(function() {
var options = {
prevText: "上一月", //跳轉到上一頁的提示文本
nextText: '下一月', //跳轉到下一頁的提示文本
minDate: -30,
maxDate: 30,
hideIfNoPrevNext: false,
defaultDate: "+" + yearOffset + "y +" + monthOffset + "m +" + dayOffset + "d",
beforeShowDay: DisplayDayHaveEvent, //顯示每個日期之前的操作
onSelect: select // 選擇一個日期的回呼函數
};
function DisplayDayHaveEvent(date) {
for (var i = 0; i < jsn.length; i++) {
var cc = Date.parse(jsn[i].time);
var time = new Date(cc);
if (date.getMonth() == time.getMonth() && date.getDate() == time.getDate()) {
return [true, ""]
}
}
return [false, ""];
}
function select(dateText, inst) {
$('#otherEvent').load("http://www.jb51.net/Calendar/EventDetail?date=" + dateText);
return false;
}
//初始化日期控制項
$('#datePicker').datepicker(options);
})

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.