在我的项目中,有很多员工,每个员工都有自己的日程安排,我已经实施了一个网络服务,该服务返回了代表代表工作日的整数列表指定的员工,所有这些的主要思想是,我需要阻止用户在一周的其他日子中进行约会。或者如果还有另一种方法?
Web服务
[WebMethod]
public void getWorkDays(int id)
{
WorkDays wd = new WorkDays(id);
List<Days> workDays = new List<Days>();
String docSch_query = "select * from workDays where empId = " + id + " and status=1";
DBConnect conn = new DBConnect();
DataTable dt = conn.select(docSch_query);
foreach (DataRow r in dt.Rows)
{
switch (r["dayId"].ToString())
{
case "1":
workDays.Add(new Days(1,"sat"));
break;
case "2":
workDays.Add(new Days(2, "sun"));
break;
case "3":
workDays.Add(new Days(3, "mon"));
break;
case "4":
workDays.Add(new Days(4, "tus"));
break;
case "5":
workDays.Add(new Days(5, "wed"));
break;
case "6":
workDays.Add(new Days(6, "thu"));
break;
}
}
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Write(js.Serialize(workDays));
}
日期选择器
$(document).ready(function () {
var dates=$.ajax({
type: "POST",
url: "getdays.asmx/getWorkDays",
data: {id:<%#int.Parse(Session["appWith"].ToString())%>},
dataType: "json",
success: function (data) {
return data.d;
}
});
$('#edob').datepicker({
firstDay: 3,
beforeShowDay: function (date) {
var available = $.inArray(date.getDay(), dates['int']) > -1;
if (available) {
return [1]; //return available date
}
else {
return [0]; //return not available
}
}
});
})
我找到了问题的解决方案。
$(document).ready(function () {
var dates = $.parseJSON(
$.ajax({
type: "POST",
url: "getdays.asmx/getWorkDays",
data: { id: <%=int.Parse(Session["appWith"].ToString())%> },
dataType: "json",
async: false
}).responseText);
$('#edob').datepicker({
firstDay: 3,
beforeShowDay: function (date) {
var a =[];
var weekend = false;
for (i = 0; i < dates.length; i++) {
a.push(dates[i].Id);
}
var weekend = date.getDay() == 5 || date.getDay() == 6 || !($.inArray(date.getDay(),a)>-1);
return [!weekend, weekend ? 'myweekend' : ''];
}
});
});