У меня есть эта хранимая процедура, которая перестала возвращать строки, когда я добавил параметр ToDate. Все работало нормально, когда он был основан на дате от.
Create Procedure DailyHours(
@ToDate smalldatetime,
@FromDate smalldatetime
)AS
Begin
SELECT
Hours,
PayPeriod,
EmployeeName,
RegHrs,
OTHrs,
DblHrs,
PremHrs,
DivDesc,
Description,
DATEPART(weekday, WorkDate) as WorkDay,
DATEPART(month, WorkDate) as WorkMonth,
DATEPART(wk, WorkDate)as WorkWeek,
DATEPART(year, WorkDate) as WorkYear
FROM EmployeeHours
inner join EmpDept on EmpDept.Dept = EmployeeHours.Dept
WHERE PayPeriod between @ToDate and @FromDate
order by Payperiod,WorkDay, DivDesc asc, Description asc, EmployeeName asc
END
GO
Когда я запускаю это, он возвращает строки
SELECT
Hours,
PayPeriod,
EmployeeName,
RegHrs,
OTHrs,
DblHrs,
PremHrs,
DivDesc,
Description,
DATEPART(weekday, WorkDate) as WorkDay,
DATEPART(month, WorkDate) as WorkMonth,
DATEPART(wk, WorkDate)as WorkWeek,
DATEPART(year, WorkDate) as WorkYear
FROM EmployeeHours
inner join EmpDept on EmpDept.Dept = EmployeeHours.Dept
WHERE PayPeriod between '2020-04-13' and '2020-04-20'
order by Payperiod,WorkDay, DivDesc asc, Description asc, EmployeeName asc
ToDate и от Date передаются в Вот. Когда он попадает в то время, он прыгает, чтобы вернуться.
public List<DailyHoursQuery> GetAllHours(DateTime toDate, DateTime fromDate)
{
var totalHours = new List<DailyHoursQuery>();
{
using (var cn = new SqlConnection(Settings.GetHrConnectionString()))
{
SqlCommand cmd = new SqlCommand("DailyHours", cn)
{
CommandType = CommandType.StoredProcedure
};
cmd.Parameters.AddWithValue("@ToDate", toDate);
cmd.Parameters.AddWithValue("@FromDate", fromDate);
cn.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
var currentRow = new DailyHoursQuery()
{
Hours = Convert.ToDecimal(dr["Hours"]),
PayPeriod = Convert.ToDateTime(dr["PayPeriod"]),
EmployeeName = Convert.ToString(dr["EmployeeName"]),
RegHrs = Convert.ToDecimal(dr["RegHrs"]),
OTHrs = Convert.ToDecimal(dr["OTHrs"]),
DblHrs = Convert.ToDecimal(dr["DblHrs"]),
PremHrs = Convert.ToDecimal(dr["PremHrs"]),
DivDesc = Convert.ToString(dr["DivDesc"]),
Description = Convert.ToString(dr["Description"]),
WorkDay = Convert.ToInt32(dr["WorkDay"]),
WorkMonth = Convert.ToInt32(dr["WorkMonth"]),
WorkWeek = Convert.ToInt32(dr["WorkWeek"]),
WorkYear = Convert.ToInt32(dr["WorkYear"]),
};
var something = "";
currentRow.ShortDate = currentRow.PayPeriod.ToString("MM/dd/yyyy");
currentRow.PayPeriod = currentRow.PayPeriod.Date;
totalHours.Add(currentRow);
}
}
}
}
return totalHours;
}
repo
Я удалил предыдущую хранимую процедуру и заново создал ее с новым значением.
function getDailyHours() {
if ($.fn.DataTable.isDataTable('#dailyHoursTable')) {
$('#dailyHoursTable').DataTable().destroy();
}
$("#dailyHoursTable tbody").empty();
var fromDate = $("#fromDateInput").val();
var toDate = $("#toDateInput").val();
$("#dailyHoursTableBody").empty();
$.ajax({
type: 'POST',
url: "/api/DailyHours/?fromDate=" + fromDate + "&toDate="+toDate,
data: JSON.stringify({
}),
contentType: "application/json",
success: function (response) {
$.each(response, function (index, value) {
if (value.OTHrs !== 0 && value.DblHrs === 0 && value.PremHrs === 0) {
$("#dailyHoursTableBody").append(
'<tr>' +
"<td>" + value.ShortDate + "</td>" +
"<td>" + value.Hours + "</td>" +
"<td>" + value.EmployeeName + "</td>" +
"<td>" + value.RegHrs + "</td>" +
"<td style=\"background-color:yellow\">" + value.OTHrs + "</td>" +
"<td>" + value.DblHrs + "</td>" +
"<td>" + value.PremHrs + "</td>" +
"<td>" + value.DivDesc + " " + value.Description + "</td>" +
"<td>" + value.WorkWeek + "</td>" +
"<td>" + value.WorkDay + "</td>" +
//"<td>" + value.WorkMonth + "</td>" +
//"<td>" + value.WorkYear + "</td>" +
"</tr>"
);
}
else if (value.OTHrs === 0 && value.DblHrs !== 0 && value.PremHrs === 0) {
$("#dailyHoursTableBody").append(
'<tr>' +
"<td>" + value.ShortDate + "</td>" +
"<td>" + value.Hours + "</td>" +
"<td>" + value.EmployeeName + "</td>" +
"<td>" + value.RegHrs + "</td>" +
"<td>" + value.OTHrs + "</td>" +
"<td style=\"background-color:yellow\">" + value.DblHrs + "</td>" +
"<td>" + value.PremHrs + "</td>" +
"<td>" + value.DivDesc + " " + value.Description + "</td>" +
"<td>" + value.WorkWeek + "</td>" +
"<td>" + value.WorkDay + "</td>" +
//"<td>" + value.WorkMonth + "</td>" +
//"<td>" + value.WorkYear + "</td>" +
"</tr>"
);
}
else if (value.OTHrs === 0 && value.DblHrs === 0 && value.PremHrs !== 0) {
$("#dailyHoursTableBody").append(
'<tr>' +
"<td>" +
value.ShortDate +
"</td>" +
"<td>" +
value.Hours +
"</td>" +
"<td>" +
value.EmployeeName +
"</td>" +
"<td>" +
value.RegHrs +
"</td>" +
"<td" +
value.OTHrs +
"</td>" +
"<td>" +
value.DblHrs +
"</td>" +
"<td style=\"background-color:yellow\">" +
value.PremHrs +
"</td>" +
"<td>" +
value.DivDesc +
" " +
value.Description +
"</td>" +
"<td>" +
value.WorkWeek +
"</td>" +
"<td>" +
value.WorkDay +
"</td>" +
//"<td>" + value.WorkMonth + "</td>" +
//"<td>" + value.WorkYear + "</td>" +
"</tr>"
);
}
else if (value.OTHrs !== 0 && value.DblHrs !== 0 && value.PremHrs === 0) {
$("#dailyHoursTableBody").append(
'<tr>' +
"<td>" + value.ShortDate + "</td>" +
"<td>" + value.Hours + "</td>" +
"<td>" + value.EmployeeName + "</td>" +
"<td>" + value.RegHrs + "</td>" +
"<td style=\"background-color:yellow\">" + value.OTHrs + "</td>" +
"<td style=\"background-color:yellow\">" + value.DblHrs + "</td>" +
"<td>" + value.PremHrs + "</td>" +
"<td>" + value.DivDesc + " " + value.Description + "</td>" +
"<td>" + value.WorkWeek + "</td>" +
"<td>" + value.WorkDay + "</td>" +
//"<td>" + value.WorkMonth + "</td>" +
//"<td>" + value.WorkYear + "</td>" +
"</tr>"
);
}
else if (value.OTHrs === 0 && value.DblHrs !== 0 && value.PremHrs !== 0) {
$("#dailyHoursTableBody").append(
'<tr>' +
"<td>" + value.ShortDate + "</td>" +
"<td>" + value.Hours + "</td>" +
"<td>" + value.EmployeeName + "</td>" +
"<td>" + value.RegHrs + "</td>" +
"<td>" + value.OTHrs + "</td>" +
"<td style=\"background-color:yellow\">" + value.DblHrs + "</td>" +
"<td style=\"background-color:yellow\">" + value.PremHrs + "</td>" +
"<td>" + value.DivDesc + " " + value.Description + "</td>" +
"<td>" + value.WorkWeek + "</td>" +
"<td>" + value.WorkDay + "</td>" +
//"<td>" + value.WorkMonth + "</td>" +
//"<td>" + value.WorkYear + "</td>" +
"</tr>"
);
}
else if (value.OTHrs !== 0 && value.DblHrs === 0 && value.PremHrs !== 0) {
$("#dailyHoursTableBody").append(
'<tr>' +
"<td>" + value.ShortDate + "</td>" +
"<td>" + value.Hours + "</td>" +
"<td>" + value.EmployeeName + "</td>" +
"<td>" + value.RegHrs + "</td>" +
"<td style=\"background-color:yellow\">" + value.OTHrs + "</td>" +
"<td>" + value.DblHrs + "</td>" +
"<td style=\"background-color:yellow\">" + value.PremHrs + "</td>" +
"<td>" + value.DivDesc + " " + value.Description + "</td>" +
"<td>" + value.WorkWeek + "</td>" +
"<td>" + value.WorkDay + "</td>" +
//"<td>" + value.WorkMonth + "</td>" +
//"<td>" + value.WorkYear + "</td>" +
"</tr>"
);
}
else {
$("#dailyHoursTableBody").append(
'<tr>' +
"<td>" +
value.ShortDate +
"</td>" +
"<td>" +
value.Hours +
"</td>" +
"<td>" +
value.EmployeeName +
"</td>" +
"<td>" +
value.RegHrs +
"</td>" +
"<td>" +
value.OTHrs +
"</td>" +
"<td>" +
value.DblHrs +
"</td>" +
"<td>" +
value.PremHrs +
"</td>" +
"<td>" +
value.DivDesc +
" " +
value.Description +
"</td>" +
"<td>" +
value.WorkWeek +
"</td>" +
"<td>" +
value.WorkDay +
"</td>" +
//"<td>" + value.WorkMonth + "</td>" +
//"<td>" + value.WorkYear + "</td>" +
"</tr>");
};
});
$("#dailyHoursTableHead").show();
$('#dailyHoursTable').dataTable({
serverside: true,
paging: true,
searching: true,
responsive: true,
colReorder: true,
deferRender: true,
scrollY: 600,
scroller: true,
dom: 'Bfrtip',
buttons: [
{
extend: 'columnsToggle',
exportOptions: {
// columns: ':visible' or
columns: ':visible'
},
columns: '.toggle'
},
'colvis',
{
extend: 'csv',
filename: 'Test',
text: 'CSV',
exportOptions: {
modifier: {
search: 'none'
}
}
},
{
extend: 'pdfHtml5',
exportOptions: {
columns: ':visible',
// columns: ':visible' or
},
title: function () {
var date = new Date();
var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear().toString().slice(2);
var finalDate = month + '/' + day + '/' + year;
return "All IT Open (" + finalDate + ")";
},
orientation: 'landscape',
pageSize: 'LEGAL',
text: 'PDF',
titleAttr: 'PDF',
customize: function (doc) {
doc.content[1].margin = [0, 0, 0, 0] //left, top, right, bottom
},
},
{
extend: 'excelHtml5',
exportOptions: {
// columns: ':visible' or
columns: ':visible'
},
text: 'Excel',
filename: function () {
var date = new Date();
var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear().toString().slice(2);
var finalDate = month + '/' + day + '/' + year;
return "All IT Open (" + finalDate + ")";
},
//title: function () {
// var date = new Date();
// var day = date.getDate();
// var month = date.getMonth() + 1;
// var year = date.getFullYear().toString().slice(2);
// var finalDate = month + '/' + day + '/' + year;
// return "All IT Open (" + finalDate + ")";
//}
}
]
});
$("#returnedTable").show();
},
error: function (ex) {
//$("#errorContainer").html('Something went wrong, unable to update this employee!');
//$("#errorContainer").show().delay(5000).fadeOut("slow");
alert(ex.responseJSON.Message);
}
});
};
@model IEnumerable<WEBCFS.MODELS.Queries.DailyHoursQuery>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.3.1/jszip-2.5.0/dt-1.10.20/af-2.3.4/b-1.6.1/b-colvis-1.6.1/b-flash-1.6.1/b-html5-1.6.1/b-print-1.6.1/cr-1.5.2/fc-3.3.0/fh-3.1.6/kt-2.5.1/r-2.2.3/rg-1.1.1/rr-1.2.6/sc-2.0.1/sp-1.0.1/sl-1.3.1/datatables.min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-3.3.1/jszip-2.5.0/dt-1.10.20/af-2.3.4/b-1.6.1/b-colvis-1.6.1/b-flash-1.6.1/b-html5-1.6.1/b-print-1.6.1/cr-1.5.2/fc-3.3.0/fh-3.1.6/kt-2.5.1/r-2.2.3/rg-1.1.1/rr-1.2.6/sc-2.0.1/sp-1.0.1/sl-1.3.1/datatables.min.js"></script>
<script type="text/javascript" src="/Scripts/js/OperationsReports.js"></script>
<div class="row" style="margin:10px">
<div>
<label id="fromDate" for="fromDateInput" style="display: block">From Date</label>
</div>
<div class="col-md-2">
<input class="form-control" type="date" id="fromDateInput" />
</div>
<div>
<label id="toDate" for="toDateInput" style="display: block">To Date</label>
</div>
<div class="col-md-2">
<input class="form-control" type="date" id="toDateInput" />
</div>
<div class="col-md-2">
<button class="btn btn-primary" id="submitFromDate" onclick="getDailyHours()">Submit</button>
</div>
</div>
<div id="returnedTable">
<table id="dailyHoursTable">
<thead id="dailyHoursTableHead" style="display: none">
<tr>
<th>
Pay Period
</th>
<th>
Hours
</th>
<th>
Employee Name
</th>
<th>
Reg Hrs
</th>
<th>
OTH Hrs
</th>
<th>
Dbl Hrs
</th>
<th>
Prem Hrs
</th>
<th>
Department Name
</th>
<th>
Week No
</th>
<th>
Day
</th>
</tr>
</thead>
<tbody id="dailyHoursTableBody">
</tbody>
</table>
</div>