我有一个关于插入带有时间值的动态表的问题。以下是我必须在db中插入的表的示例:
Schedule for 12/15/2015
08:30 AM - 09:30 AM Remove
09:30 AM - 10:30 AM Remove
10:30 AM - 11:30 AM Remove
11:30 AM - 12:30 PM Remove
02:30 PM - 03:30 PM Remove
如果我的时差始终相同,我输入值时没有问题。就像前几个时段增加了30分钟但是我从中午12点到下午5点都有差距。我的问题在那里。我不知道保存这些值的最佳方法是什么。由于值是动态创建的,并且所有值都链接到同一日期。如果我没有时间休息会很容易,但在这种情况下,我有时间差距看起来很复杂。如果有人能告诉我在数据库中存储这个的最佳方法,请告诉我。现在我只存储每次增加时间的开始时间,结束时间,日期和间隔。看起来像这样:
ID Date Start End Interval
4 2015-12-15 08:30:00.0000000 15:30:00.0000000 60
在这种情况下,如果我想用查询提取值并在表格中显示时间段,我只能以60分钟的间隔进行操作。但是从下午12:30到下午2:30我有差距。这种差距总是不同取决于用户的愿望。
以下是我构建表格的查询:
<cfscript>
param name = "FORM.datepicker" type = "date";
param name = "FORM.stime" type = "time";
param name = "FORM.etime" type = "time";
param name = "FORM.meeting" type = "range" min = "5" max = "60";
TimeStart = createDateTime(year(FORM.datepicker), month(FORM.datepicker), day(FORM.datepicker), hour(FORM.stime), minute(FORM.stime), 0);
TimeEnd = createDateTime(year(FORM.datepicker), month(FORM.datepicker), day(FORM.datepicker), hour(FORM.etime), minute(FORM.etime), 0);
meetingLength = dateAdd("n", FORM.meeting*-1, TimeEnd);
</cfscript>
<form name="myForm" id="myForm" method="post" autocomplete="off">
<cfoutput>
<table>
<thead>
<tr>
<th>Schedule for #dateFormat(FORM.datepicker, "mm/dd/yyyy")#</th>
</tr>
</thead>
<tbody>
<cfloop condition="TimeStart LTE meetingLength">
<cfset TimeEnd = dateAdd("n", FORM.meeting, TimeStart)>
<tr>
<td></td>
<td>#timeFormat(TimeStart, "hh:mm tt")# - #timeFormat(TimeEnd, "hh:mm tt")#</td>
<td><a class="remove" onClick ="removeTime($(this))">Remove</a></td>
</tr>
<cfset TimeStart = dateAdd("n", FORM.meeting, TimeStart)>
</cfloop>
<tr>
<td>
<input type="button" name="Submit" value="Save" onClick="saveSchedule('#FORM.datepicker#','#FORM.stime#','#FORM.etime#','#FORM.meeting#')" />
</td>
</tr>
</tbody>
</table>
</cfoutput>
插入记录的代码:
<cffunction name="Save" access="remote" output="no" returnformat='JSON'>
<cfargument name="datepicker" type="date" required="yes">
<cfargument name="stime" type="numeric" required="yes">
<cfargument name="etime" type="numeric" required="yes">
<cfargument name="meeting" type="numeric" required="yes">
<cfset fncResults = structNew()>
<cfquery name="addSchedule" datasource="Test">
Insert Into Schedule(Date, Start, Eend, meeting)
Values (<cfqueryparam cfsqltype="cf_sql_date" maxlength="10" value="#arguments.datepicker#">,
<cfqueryparam cfsqltype="cf_sql_time" maxlength="10" value="#arguments.stime#">,
<cfqueryparam cfsqltype="cf_sql_time" maxlength="10" value="#arguments.etime#">,
<cfqueryparam cfsqltype="cf_sql_integer" maxlength="2" value="#arguments.meeting#">);
</cfquery>
<cfreturn fncResults>
</cffunction>