我正在使用日历列表进行一些房间预订,一切都很好,但只能在同一天和某个时间与房间的 Overlapp或双重预订挣扎。
我试图通过将表单中用户输入的数据传递给CAML查询并检查此条目是否存在
如果该条目已经存在取消预订,或者如果没有,则继续。
例如:如果从:上午10:00到上午11:00已经预订。
重叠的场景可能是:
如果用户输入表格从:上午10:00到上午10:30
从:上午9:00到上午11:00 .. 我假设日期相同,只有时间对我很重要。
如果日期相同且只有时间变化,如何获取CAML查询并检查用户输入From&在已预订的项目中存在范围内的时间。
使用下面的查询但不验证所有场景
<Where><And><Geq><FieldRef Name='EventDate' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + strSPEventDateFormat + "</Value></Geq><And><Leq><FieldRef Name='EndDate' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + strSPEndDateFormat + "</Value></Leq><Eq><FieldRef Name='Room' /><Value Type='Lookup'>" + strCheckRoomAvail + "</Value></Eq></And></And></Where>
请帮我解决这个问题
提前致谢
答案 0 :(得分:3)
写入CAML以使所有房间与START时间冲突。开始时间不得介于用户选择的开始时间和结束时间之间 和 编写CAML以使所有房间与END Time冲突。结束时间不得在用户选择的开始和结束时间之间
如果用户选择的房间不在CAML返回的上述结果中,那么您可以继续预订房间。
q.Query = "<Where><And><Geq><FieldRef Name=""StartTime"" /><Value IncludeTimeValue=""TRUE"" Type=""DateTime"">" + _
Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(startTime) + _
"</Value></Geq><Leq><FieldRef Name=""StartTime"" /><Value IncludeTimeValue=""TRUE"" Type=""DateTime"">" + _
Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(endTime) + _
"</Value></Leq></And></Where><OrderBy><FieldRef Name=""ID"" Ascending=""True"" /></OrderBy>"
q1.Query = "<Where><And><Geq><FieldRef Name=""EndTime"" /><Value IncludeTimeValue=""TRUE"" Type=""DateTime"">" + _
Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(startTime) + _
"</Value></Geq><Leq><FieldRef Name=""EndTime"" /><Value IncludeTimeValue=""TRUE"" Type=""DateTime"">" + _
Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(endTime) + _
"</Value></Leq></And></Where><OrderBy><FieldRef Name=""ID"" Ascending=""True"" /></OrderBy>"
答案 1 :(得分:0)
这个线程很旧,但是我遇到了同样的问题。所以这是我的工作解决方案,可能对您有所帮助。
注意:对于与时间相关的搜索骆驼,您需要
的IncludeTimeValue ='TRUE'参数
/**
* {Boolean} formModeEdit To determine if this form is an New or Edit form
*/
function checkDoubleBooking(formModeEdit, listId, currentItemId, startDate, endDate) {
var results = [];
var liHtml = "";
var checkOverlappingQueryArray = [];
//Construct caml query
checkOverlappingQueryArray.push("<And>");
checkOverlappingQueryArray.push("<Leq>");
checkOverlappingQueryArray.push("<FieldRef Name='EventDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>" + moment(endDate).format() + "</Value>");
checkOverlappingQueryArray.push("</Leq>");
checkOverlappingQueryArray.push("<Geq>");
checkOverlappingQueryArray.push("<FieldRef Name='EndDate' /><Value Type='DateTime' IncludeTimeValue='TRUE'>" + moment(startDate).format() + "</Value>");
checkOverlappingQueryArray.push("</Geq>");
checkOverlappingQueryArray.push("</And>");
if (formModeEdit) {
checkOverlappingQueryArray.unshift("<And>");
checkOverlappingQueryArray.push("<Neq>");
checkOverlappingQueryArray.push("<FieldRef Name='ID' /><Value Type='Integer'>" + currentItemId + "</Value>");
checkOverlappingQueryArray.push("</Neq>");
checkOverlappingQueryArray.push("</And>");
}
checkOverlappingQueryArray.unshift("<Where>");
checkOverlappingQueryArray.push("</Where>");
checkOverlappingQueryArray.unshift("<Query>");
checkOverlappingQueryArray.push("</Query>");
jQuery().SPServices({
operation: "GetListItems",
async: false,
listName: listId,
CAMLViewFields: "<ViewFields>" +
"<FieldRef Name='ID' />" +
"<FieldRef Name='Title' />" +
"<FieldRef Name='EventDate' />" +
"<FieldRef Name='EndDate' />" +
"<FieldRef Name='PeoplePickerField1' />" +
"</ViewFields>",
CAMLQuery: checkOverlappingQuery,
CAMLQueryOptions: "<QueryOptions>" +
"<ExpandUserField>True</ExpandUserField>" + //Expand People Picker values
"</QueryOptions>",
CAMLRowLimit: 10, // Override the default view rowlimit
completefunc: function(xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
countOverlappingEvents++;
results.push({
title: $(this).attr("ows_Title"),
eventDate: $(this).attr("ows_EventDate"),
endDate: $(this).attr("ows_EndDate"),
peoplePickerField1: userToJsonObject($(this).attr("ows_PeoplePickerField1"))
});
}
}
});
return results;
}
function userToJsonObject(userObj) {
if (userObj.length === 0) {
return null;
} else {
var thisUser = userObj.split(";#");
var thisUserExpanded = thisUser[1].split(",#")
if (thisUserExpanded.length == 1) {
return {
userId: thisUser[0],
userName: thisUser[1]
}
} else {
return {
userId: thisUser[0],
userName: thisUserExpanded[0].replace(/(,,)/g, ","),
loginName: thisUserExpanded[1].replace(/(,,)/g, ","),
email: thisUserExpanded[2].replace(/(,,)/g, ","),
sipAddress: thisUserExpanded[3].replace(/(,,)/g, ","),
title: thisUserExpanded[4].replace(/(,,)/g, ",")
}
}
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment-with-locales.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>