ibms-dome/Backend/Views/NiagaraDataSynchronize/Index.cshtml
2022-12-31 16:49:47 +08:00

177 lines
7.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@{
ViewData["MainNum"] = "2";
ViewData["SubNum"] = "3";
ViewData["Title"] = "Niagara資料同步";
}
<ol class="breadcrumb page-breadcrumb">
<li class="breadcrumb-item"><a href="javascript:void(0);">首頁</a></li>
<li class="breadcrumb-item">設備管理</li>
<li class="breadcrumb-item active">Niagara資料同步</li>
<li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
</ol>
<div class="row">
<div class="col-xl-12">
<div id="panel-5" class="panel">
<div class="panel-container show">
<div class="panel-content">
<div class="form-row align-items-center">
<div class="col-12 mb-3">
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" id="Building_B" name="Building" value="B" class="custom-control-input">
<label class="custom-control-label" for="Building_B">三菱B1</label>
</div>
@*<div class="custom-control custom-radio custom-control-inline">
<input type="radio" id="Building_O" name="Building" value="O" class="custom-control-input">
<label class="custom-control-label" for="Building_O">辦公棟</label>
</div>*@
</div>
</div>
<div class="form-row align-items-center">
<button id="loadDataBtn" type="button" class="btn btn-primary" onclick="LoadData()">載入資料</button>
<button id="synchornizeDataBtn" type="button" class="btn btn-dark" onclick="SynchronizeData()">同步資料</button>
</div>
<br />
<br />
<div class="form-row align-items-center">
<p id="loadDataText"></p>
</div>
<div class="mb-5">
<div class="card p-3 w-100">
<div class="card-header d-flex align-items-center flex-wrap">
<div class="card-title">
Niagara資料
</div>
</div>
<div class="card-body row">
<div class="col-12">
<!-- datatable start -->
<table id="niagara_data_table" class="table table-bordered table-hover m-0 text-center">
<thead class="thead-themed">
<tr>
<th>value</th>
<th>tag_name</th>
<th>point_name</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@section Scripts {
<script>
var buildingId, building;
var rawDataImportTable;
var ds;
var today = new Date();
var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
$(function () {
ds = null;
building = "B1";
document.getElementById("Building_B").checked = true;
rawDataImportTable = $("#niagara_data_table").DataTable({
"columns": [
{
"data": "value"
},
{
"data": "tag_name"
},
{
"data": "point_name"
},
],
"ajax": {
"url": "/NiagaraDataSynchronize/RawDataList",
"type": "POST",
"dataSrc": function (rel) {
if (rel.code == "9999") {
toast_error(rel.msg);
document.getElementById('loadDataText').innerText = "載入資料出錯了!";
return;
}
var data = rel.data;
ds = data;
if (data == null || data.length == 0) {
this.data = [];
document.getElementById('loadDataText').innerText = "";
}
else if(data.length > 0) {
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date + ' ' + time;
document.getElementById('loadDataText').innerText = "共 " + rel.data.length + " 筆資料 \n" + dateTime;
}
return data;
}
}
});
});
//#region 載入Niagara資料
function LoadData() {
document.getElementById('loadDataText').innerText = "Loading...";
buildingId = document.querySelector('input[name="Building"]:checked').value;
if (buildingId == "B") {
building = "B1";
rawDataImportTable.ajax.reload();
}
}
//#endregion
function SynchronizeData() {
document.getElementById('loadDataText').innerText = "同步中...";
if (ds.length > 0) {
//比對資料有差異的話再同步到device等資料表
var url_synchronize_data = "/NiagaraDataSynchronize/CompareData/";
$.each(ds, function (i, v) {
v.building = building;
})
$.ajax({
method: "POST",
url: url_synchronize_data,
data: JSON.stringify(ds),
cache: false,
async: false,
contentType: "application/json; charset=UTF-8",
dataType: 'json',
success: function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
document.getElementById('loadDataText').innerText = "比對資料出錯了!";
return;
}
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date + ' ' + time;
document.getElementById('loadDataText').innerText = "比對完成 \n" + dateTime;
},
});
}
else {
document.getElementById('loadDataText').innerText = "查無資料 無法比對!";
}
}
</script>
}