文件操作 - NewFood.js
返回文件管理
返回主菜单
删除本文件
文件: E:\HostingSpaces\kimblycr\howell.kimbly.in\wwwroot\js\NewFood.js
编辑文件内容
function calcAmount() { var sdate = new Date(document.getElementById('txtSDate').value); var edate = new Date(document.getElementById('txtEDate').value); if (edate < sdate) { alert('Wrong Dates'); var dd = sdate.getDate(); var mm = sdate.getMonth() + 1; //January is 0! var yyyy = sdate.getFullYear(); if (dd < 10) { dd = '0' + dd } if (mm < 10) { mm = '0' + mm } var today = yyyy + '-' + mm + '-' + dd; console.log(today); document.getElementById('txtEDate').value = today; edate = new Date(document.getElementById('txtEDate').value); } var timeDiff = Math.abs(edate.getTime() - sdate.getTime()); var dayDifference = 1 + Math.ceil(timeDiff / (1000 * 3600 * 24)); console.log('dayDifference-' + dayDifference); if (dayDifference > 0) { document.getElementById('txtAmount').value = dayDifference * 300; } } function AddNewFood() { $('#dvFrm').show(); $("#dvFrmEdit").hide(); $("#dvGrdReportFood").hide(); $.ajax({ type: "POST", url: "MyFood.aspx/GetSites", data: "", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { if (data.d != null) { var selectSite = document.getElementById('SelSite'); $("#SelSite").empty(); for (i = 0; i < data.d.length; i++) { selectSite.options[selectSite.options.length] = new Option(data.d[i].Name, data.d[i].ID); } } }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log('error'); } }); } function HideAddForm() { $('#dvFrm').hide(); } function SaveFood() { var site = document.getElementById("SelSite").value; var dt = document.getElementById("txtSDate").value; if (dt == '') { alert('Please enter Start Date'); return; } dt = document.getElementById("txtEDate").value; if (dt == '') { alert('Please enter End Date'); return; } var amount = document.getElementById("txtAmount").value; var sdate = new Date(document.getElementById('txtSDate').value); var dd = sdate.getDate(); var mm = sdate.getMonth() + 1; //January is 0! var yyyy = sdate.getFullYear(); if (dd < 10) { dd = '0' + dd } if (mm < 10) { mm = '0' + mm } var date1 = yyyy + '-' + mm + '-' + dd; var edate = new Date(document.getElementById('txtEDate').value); dd = edate.getDate(); mm = edate.getMonth() + 1; //January is 0! yyyy = edate.getFullYear(); if (dd < 10) { dd = '0' + dd } if (mm < 10) { mm = '0' + mm } var date2 = yyyy + '-' + mm + '-' + dd; var LoggedInEmpID = sessionStorage.getItem("LoggedInEmpID"); var remarks = document.getElementById("txtRemarks").value; remarks = remarks.replace(/'/g, ""); $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "MyFood.aspx/AddFood", data: "{'Amount':'" + amount + "','SiteID':'" + site + "','date1':'" + date1 + "','date2':'" + date2 + "','EmpID':'" + LoggedInEmpID + "','Remarks':'" + remarks + "'}", dataType: "json", success: function (data) { if (data.d != null) { console.log(data.d); if (data.d == "0") { alert('Dates already claimed'); } else { HideAddForm(); $('#dvFrm').hide(); ViewNonSubmittedFood(data.d); } } }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(XMLHttpRequest.responseText); } }); } function GetNonSubmittedFood() { var LoggedInEmpID = sessionStorage.getItem("LoggedInEmpID"); $("#dvFrmEdit").hide(); $('#dvFrm').hide(); var collection = "Food"; $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "MyFood.aspx/ViewNonSubmittedFood", data: "{'EID': '" + LoggedInEmpID + "'}", dataType: "json", success: function (data) { if (data.d != null) { console.log(data.d); $("#grd" + collection).empty(); var str = "<thead><tr><td>ID</td><td>Site</td><td>Amount</td><td>Start Date</td><td>End Date</td><td>Remarks</td></tr></thead><tbody>"; for (i = 0; i < data.d.length; i++) { var hdr = data.d[i].RowData; str += hdr; } $("#grd" + collection).append(str); $("#grd" + collection).append("</tbody>"); $("#grd" + collection).show(); $("#dvGrdReport" + collection).show(); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(XMLHttpRequest.responseText); } }); } function ViewNonSubmittedFood(ID) { GetSites(ID); $("#dvFrmEdit").show(); $("#dvGrdReportFood").hide(); document.getElementById('hdnID').value = ID; } function GetSites(id) { $.ajax({ type: "POST", url: "MyFood.aspx/GetSites", data: "", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { if (data.d != null) { var selectSite = document.getElementById('SelSiteEdit'); $("#SelSiteEdit").empty(); for (i = 0; i < data.d.length; i++) { selectSite.options[selectSite.options.length] = new Option(data.d[i].Name, data.d[i].ID); } GetValues(id); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log('error'); } }); } function GetValues(id) { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "MyFood.aspx/ViewFoodByID", data: "{'id': '" + id + "'}", dataType: "json", success: function (data) { if (data.d != null) { console.log(data.d); var out = data.d.split(";"); document.getElementById('SelSiteEdit').value = out[0]; document.getElementById('txtRemarksEdit').value = out[1]; document.getElementById('txtAmountEdit').value = out[2]; document.getElementById('txtSDateEdit').value = out[3]; document.getElementById('txtEDateEdit').value = out[4]; } }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(XMLHttpRequest.responseText); } }); } function HideEditForm() { $("#dvFrmEdit").hide(); $("#dvGrdReportFood").show(); } function SubmitFood() { var id = document.getElementById('hdnID').value; $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "MyFood.aspx/SubmitFood", data: "{'ID':'" + id + "'}", dataType: "json", success: function (data) { if (data.d != null) { GetNonSubmittedFood(); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(XMLHttpRequest.responseText); } }); } function DeleteFood() { var id = document.getElementById('hdnID').value; $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "MyFood.aspx/DeleteFood", data: "{'ID':'" + id + "'}", dataType: "json", success: function (data) { GetNonSubmittedFood(); }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(XMLHttpRequest.responseText); } }); }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件