parking-html/Parking_spaces/Views/Engineering/Single_violation_detail.cshtml

329 lines
11 KiB
Plaintext
Raw Normal View History

2024-02-01 11:37:15 +08:00

@{
ViewData["Title"] = "Single_violation_detail";
Layout = "~/Views/Shared/_Layout_Engineering.cshtml";
var parking_spaces_name = ViewBag.parking_spaces_name;
}
<input type="hidden" id="parking_spaces_name_id" value=@parking_spaces_name />
<h1>違規車輛</h1>
<div class="size2">
<table class="table">
<thead>
<tr>
<th>
違規區域
</th>
<th>
車牌號碼
</th>
<!--<th>
進入圖片
</th>
<th>
違規圖片
</th>-->
<th>
時間
</th>
<th></th>
</tr>
</thead>
<tbody id="demo">
</tbody>
</table>
</div>
<!--車輛詳細-彈跳視窗-->
<div>
<dialog id="detail_car_data_view" style="width:100%;">
<table class="table">
<button class="btn btn-danger" style="float:right" onclick="detail_car_data_view.close();"> 關閉 </button>
<button class="btn btn-warning" style="float:right" onclick="updata_violation_car_get()"> 更新資料 </button><p></p>
<thead>
<tr>
<th>
違規區域
</th>
<th>
車牌號碼
</th>
<th>
進入圖片
</th>
<th>
違規圖片
</th>
<th>
時間
</th>
</tr>
</thead>
<tbody id="detail_car_data">
</tbody>
</table>
<button class="btn btn-outline-success" style="float:left" onclick="previous_detail_data()"> Previous</button>
<button class="btn btn-outline-success" style="float:right" onclick="next_detail_data()"> Next </button>
</dialog>
</div>
<!--獲取資料-->
<script>
var All_Model
var serial_number=0
function get_data() {
var name = document.getElementById("parking_spaces_name_id").value
//console.log(name)
$.ajax({
type: "GET",
url: "http://140.125.20.183:7700/api/Violation_car_table/violation_location_name-" + name,
data: {},
contentType: "application/json",
success: function (Model) {
//console.log(Model)
All_Model = Model
set_data(Model)
}
});
}
</script>
<!--放置資料-->
<script>
function set_data(Model) {
table = "<tr>";
console.log(Model.length)
if (Model.length > 0) {
for (var i = 0; i < Model.length; i++) {
if (Model[i].violation_location_name != null) {
table += "<td>" + Model[i].violation_location_name + "</td>"
table += "<td>" + Model[i].license_plate_number + "</td>"
//table += "<td>" + "</td>"
//table += "<td>" + "</td>"
// table += "<td>" + "<img src=" + Model[i].car_start_img + ' style="width:100%"' + ">" + "</td>"
// table += "<td>" + "<img src=" + Model[i].car_end_img + ' style="width:100% "' + ">" + "</td>"
// 将字符串转换为 Date 对象
var timestampDt = new Date(Model[i].create_data_time);
// 转换为其他格式
var options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' };
var formattedDate = timestampDt.toLocaleDateString('en-US', options);
table += "<td>" + formattedDate + "</td>"
table += "<td>" + '<button class="btn btn-outline-success" onclick="detail_data(' + "'" + Model[i].violation_location_name + "','" + i+ "','" + Model[i].create_data_time + "'" + ')">詳細</button>'
table += '<button class="btn btn-danger " onclick="delet_data(' + "'" + Model[i].violation_location_name + "','" + Model[i].license_plate_number + "','" + Model[i].create_data_time + "'" + ')">刪除</button>' + "</td>"
}
table += "</tr>"
table += "<tr>"
}
}
document.getElementById("demo").innerHTML = table
}
</script>
<!--更新違規車輛資料-->
<script>
function updata_violation_car_get() {
var violation_location_name = document.getElementById('parking_spaces_name_id').value
var time = document.getElementById('create_data_time_id').innerHTML
console.log(time)
$.ajax({
type: "GET",
url: "http://140.125.20.183:7700/api/Violation_car_table/location_nam-" + violation_location_name + "-time-" + time,
data: {},
contentType: "application/json",
success: function (Model) {
//console.log(Model)
updata_violation_car_put(Model)
}
});
}
function updata_violation_car_put(Model) {
var violation_location_name = document.getElementById('parking_spaces_name_id').value
var time = document.getElementById('create_data_time_id').innerHTML
var license_plate_number = document.getElementById('license_plate_number_text_id').value
Model.license_plate_number = license_plate_number
//console.log(Model)
var stringify_obj = JSON.stringify(Model);
$.ajax({
type: "PUT",
url: "http://140.125.20.183:7700/api/Violation_car_table/location_nam-" + violation_location_name + "-time-" + time,
data: stringify_obj,
contentType: "application/json",
success: function (Model) {
// console.log(Model)
//updata_violation_car_put(Model)
}
});
}
</script>
<!--下一筆資料-->
<script>
function next_detail_data() {
serial_number = Number(serial_number) + 1
if (serial_number >= All_Model.length) {
window.alert('無下一筆資料')
serial_number = All_Model.length-1
return
}
//console.log(serial_number)
//console.log(All_Model[serial_number])
detail_data(All_Model[serial_number]['violation_location_name'], serial_number, All_Model[serial_number]['create_data_time'])
}
</script>
<!--上一筆資料-->
<script>
function previous_detail_data() {
serial_number = Number(serial_number) - 1
if (serial_number < 0){
window.alert('無上一筆資料')
serial_number = 0
return
}
// console.log(serial_number)
//console.log(All_Model[serial_number])
detail_data(All_Model[serial_number]['violation_location_name'], serial_number, All_Model[serial_number]['create_data_time'])
}
</script>
<!--違規車輛詳細-->
<script>
function detail_data(location_name, car_serial_number, time) {
//console.log(location_name)
//console.log(All_Model[car_serial_number])
//console.log(time)
serial_number = car_serial_number
$.ajax({
type: "GET",
url: "http://140.125.20.183:7700/api/Violation_car_table/location_nam-" + location_name + "-time-" + time,
data: {},
contentType: "application/json",
success: function (Model) {
console.log(Model)
table = "<tr>";
table += "<td>" + Model.violation_location_name + "</td>"
table += "<td>" + '<input type="text" id = "license_plate_number_text_id" value="'+Model.license_plate_number+ '"/>' + "</td>"
//table += "<td>" + "</td>"
//table += "<td>" + "</td>"
table += "<td>" + "<img src=" + Model.car_start_img + ' style="width:100%"' + ">" + "</td>"
table += "<td>" + "<img src=" + Model.car_end_img + ' style="width:100% "' + ">" + "</td>"
table += "<td id = 'create_data_time_id' >" + Model.create_data_time + "</td>"
document.getElementById("detail_car_data").innerHTML = table
}
});
detail_car_data_view.showModal();
}
</script>
<!--刪除資料-->
<script>
function delet_data(location_name , name , time) {
console.log(location_name)
console.log(name)
console.log(time)
$.ajax({
type: "DELETE",
url: "http://140.125.20.183:7700/api/Violation_car_table/location_name-" + location_name + "-time-" + time,
data: {},
contentType: "application/json",
success: function (msg) {
console.log(msg)
get_data()
}
});
}
</script>
<!--檢查token-->
<script>
function token_check() {
// 检查本地存储中是否存在JWT令牌
var token = localStorage.getItem('token_park_space');
console.log(token)
$.ajax({
type: "GET",
url: 'http://140.125.20.183:7700/Users/token_check',
headers: {
'Authorization': token
},
success: function (response) {
console.log(response)
token_check = "true"
from_token_import_id()
},
error: function (xhr) {
token_check = "false"
window.location.href = '/';
// 处理错误响应,例如跳转到未授权页面
//window.location.href = 'https://example.com/unauthorized_page';
}
});
}
function from_token_import_id() {
var token = localStorage.getItem('token_park_space');
$.ajax({
type: "GET",
url: 'http://140.125.20.183:7700/Users/token-' + token,
headers: {
'Authorization': token
},
success: function (response) {
console.log(response)
from_id_import_user_data(response)
}
});
}
function from_id_import_user_data(id) {
var token = localStorage.getItem('token_park_space');
$.ajax({
type: "GET",
url: 'http://140.125.20.183:7700/Users/user_id-' + id,
headers: {
'Authorization': token
},
success: function (model) {
model = model.result
position = model.lastname
console.log(position)
if (position == "engineer") {
get_data()
}
else {
window.location.href = '/';
}
}
});
}
</script>
<!--開機自啟-->
<script>
window.onload = token_check;
</script>