Use jquery to implement school calendars (Asp.net+jquery UI 1.72) _jquery

Source: Internet
Author: User
Tags getdate
Screenshots:

Controller code:
Code
Copy Code code as follows:

Public ActionResult Calendardisplay ()
{
BL. Dateeventbl de = new BL. Dateeventbl ();
Get the day date, using a format that can be converted to a date by JavaScript
DateTimeFormatInfo Mydtfi = new CultureInfo ("en-us", false). DateTimeFormat;
String utctime = DateTime.Now.ToString ("MMM dd,yyyy HH:mm:ss", Mydtfi);
viewdata["Currentday"] = Utctime;
Get a date with an event in the month
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;
Get the Day Event
List<bl. Cdateevent> Deinfos = de. Getde (DateTime.Now, New Guid ("00000000-0000-0000-0000-000000000001"));
Get Current Week
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 (local view):
Code
Copy Code code as follows:

<%@ control language= "C # inherits=" SYSTEM.WEB.MVC.VIEWUSERCONTROL&LT;IENUMERABLE&LT;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) +" \ "}"; The last one
}
Else
{
JSON = "{\" time\ ": \" "+ dateshaveevent.elementat (i) +" \ "},"; //
}
}
JSON + = "]";
}
%>
<div id= "DatePicker" ></div>
<br/>
Currently is the first <span style= "color:red; font-size:14px; " ><%=viewdata["Currentweek"]%> </span> Week
<br/>
<%=datetime.now.toshortdatestring ()%>
<br/>
<%
foreach (var item in Model)
{
%>
<%=html.encode (item. Content)%>
<%
}
%>
<br/>
<div id= "otherevent" style= "width:300px;" ></div>

JavaScript (script):
Code
Copy Code code as follows:

Server vs. client current time conversion
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 ();
Get a list of dates
var jsn = eval (' <%=json%> ');
$ (function () {
var options = {
Prevtext: "Last month",//jump to the prompt text on the previous page
Nexttext: ' next month ',//jump to the prompt text on the next page
MinDate:-30,
Maxdate:30,
Hideifnoprevnext:false,
Defaultdate: "+" + yearoffset + "Y +" + monthoffset + "M +" + Dayoffset + "D",
Beforeshowday:displaydayhaveevent,//show actions before each date
Onselect:select//Select a callback function for a date
};
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;
}
Initializing a date control
$ (' #datePicker '). DatePicker (options);
})
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.