用jquery实现学校的校历(asp.net+jquery ui 1.72)
用jquery实现学校的校历(asp.net+jquery ui 1.72)
发布时间:2016-12-30 来源:查字典编辑
摘要:截图:controller代码:代码复制代码代码如下:publicActionResultCalendarDisplay(){BL.Date...

截图:

用jquery实现学校的校历(asp.net+jquery ui 1.72)1

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><%=ViewData["currentWeek"]%> </span> 周

<br />

<%=DateTime.Now.ToShortDateString() %>

<br />

<%

foreach(var item in Model)

{

%>

<%=Html.Encode(item.Content) %>

<%

}

%>

<br />

<div id="otherEvent"></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);

})

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Javascript教程学习
热门Javascript教程学习
编程开发子分类