2021-12-12 06:55:48 +00:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System;
|
|
|
|
|
using WalkingTec.Mvvm.Core;
|
|
|
|
|
using WalkingTec.Mvvm.Mvc;
|
|
|
|
|
using WalkingTec.Mvvm.Core.Extensions;
|
|
|
|
|
using IoTGateway.ViewModel.BasicData.DeviceVariableVMs;
|
2022-08-21 14:01:32 +00:00
|
|
|
|
using Opc.Ua.Security.Certificates;
|
2021-12-12 06:55:48 +00:00
|
|
|
|
|
|
|
|
|
namespace IoTGateway.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Area("BasicData")]
|
|
|
|
|
[ActionDescription("设备变量配置")]
|
|
|
|
|
public partial class DeviceVariableController : BaseController
|
|
|
|
|
{
|
|
|
|
|
#region Search
|
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
var vm = Wtm.CreateVM<DeviceVariableListVM>();
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ActionDescription("Sys.Search")]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public string Search(DeviceVariableSearcher searcher)
|
|
|
|
|
{
|
|
|
|
|
var vm = Wtm.CreateVM<DeviceVariableListVM>(passInit: true);
|
|
|
|
|
if (ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
vm.Searcher = searcher;
|
|
|
|
|
return vm.GetJson(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return vm.GetError();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Create
|
|
|
|
|
[ActionDescription("Sys.Create")]
|
|
|
|
|
public ActionResult Create()
|
|
|
|
|
{
|
|
|
|
|
var vm = Wtm.CreateVM<DeviceVariableVM>();
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ActionDescription("Sys.Create")]
|
|
|
|
|
public ActionResult Create(DeviceVariableVM vm)
|
|
|
|
|
{
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vm.DoAdd();
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
vm.DoReInit();
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return FFResult().CloseDialog().RefreshGrid();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Edit
|
|
|
|
|
[ActionDescription("Sys.Edit")]
|
|
|
|
|
public ActionResult Edit(string id)
|
|
|
|
|
{
|
|
|
|
|
var vm = Wtm.CreateVM<DeviceVariableVM>(id);
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ActionDescription("Sys.Edit")]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateFormItemOnly]
|
|
|
|
|
public ActionResult Edit(DeviceVariableVM vm)
|
|
|
|
|
{
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vm.DoEdit();
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
vm.DoReInit();
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Delete
|
|
|
|
|
[ActionDescription("Sys.Delete")]
|
|
|
|
|
public ActionResult Delete(string id)
|
|
|
|
|
{
|
|
|
|
|
var vm = Wtm.CreateVM<DeviceVariableVM>(id);
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ActionDescription("Sys.Delete")]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult Delete(string id, IFormCollection nouse)
|
|
|
|
|
{
|
|
|
|
|
var vm = Wtm.CreateVM<DeviceVariableVM>(id);
|
|
|
|
|
vm.DoDelete();
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return FFResult().CloseDialog().RefreshGrid();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Details
|
|
|
|
|
[ActionDescription("Sys.Details")]
|
|
|
|
|
public ActionResult Details(string id)
|
|
|
|
|
{
|
|
|
|
|
var vm = Wtm.CreateVM<DeviceVariableVM>(id);
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region BatchEdit
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ActionDescription("Sys.BatchEdit")]
|
|
|
|
|
public ActionResult BatchEdit(string[] IDs)
|
|
|
|
|
{
|
|
|
|
|
var vm = Wtm.CreateVM<DeviceVariableBatchVM>(Ids: IDs);
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ActionDescription("Sys.BatchEdit")]
|
|
|
|
|
public ActionResult DoBatchEdit(DeviceVariableBatchVM vm, IFormCollection nouse)
|
|
|
|
|
{
|
|
|
|
|
if (!ModelState.IsValid || !vm.DoBatchEdit())
|
|
|
|
|
{
|
|
|
|
|
return PartialView("BatchEdit",vm);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchEditSuccess", vm.Ids.Length]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region BatchDelete
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ActionDescription("Sys.BatchDelete")]
|
|
|
|
|
public ActionResult BatchDelete(string[] IDs)
|
|
|
|
|
{
|
|
|
|
|
var vm = Wtm.CreateVM<DeviceVariableBatchVM>(Ids: IDs);
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ActionDescription("Sys.BatchDelete")]
|
|
|
|
|
public ActionResult DoBatchDelete(DeviceVariableBatchVM vm, IFormCollection nouse)
|
|
|
|
|
{
|
|
|
|
|
if (!ModelState.IsValid || !vm.DoBatchDelete())
|
|
|
|
|
{
|
|
|
|
|
return PartialView("BatchDelete",vm);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchDeleteSuccess", vm.Ids.Length]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Import
|
|
|
|
|
[ActionDescription("Sys.Import")]
|
|
|
|
|
public ActionResult Import()
|
|
|
|
|
{
|
|
|
|
|
var vm = Wtm.CreateVM<DeviceVariableImportVM>();
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ActionDescription("Sys.Import")]
|
|
|
|
|
public ActionResult Import(DeviceVariableImportVM vm, IFormCollection nouse)
|
|
|
|
|
{
|
|
|
|
|
if (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData())
|
|
|
|
|
{
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.ImportSuccess", vm.EntityList.Count.ToString()]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
[ActionDescription("Sys.Export")]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult ExportExcel(DeviceVariableListVM vm)
|
|
|
|
|
{
|
|
|
|
|
return vm.GetExportData();
|
|
|
|
|
}
|
2022-05-09 15:57:46 +00:00
|
|
|
|
#region 下发写入
|
2022-08-22 04:46:01 +00:00
|
|
|
|
[ActionDescription("下发页面")]
|
2022-08-21 14:01:32 +00:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult SetValue(string[] IDs)
|
2022-05-09 15:57:46 +00:00
|
|
|
|
{
|
2022-08-21 14:01:32 +00:00
|
|
|
|
var vm = Wtm.CreateVM<SetValueVM>(Ids: IDs);
|
2022-05-09 15:57:46 +00:00
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
2021-12-12 06:55:48 +00:00
|
|
|
|
|
2022-05-09 15:57:46 +00:00
|
|
|
|
[HttpPost]
|
2022-08-22 04:46:01 +00:00
|
|
|
|
[ActionDescription("下发确认按钮")]
|
2022-08-21 14:01:32 +00:00
|
|
|
|
public ActionResult DoSetValue()
|
2022-05-09 15:57:46 +00:00
|
|
|
|
{
|
2022-08-21 14:01:32 +00:00
|
|
|
|
var ids = Request.Form["setValue.ID[]"].ToArray();
|
|
|
|
|
var values = Request.Form["setValue.SetRawValue[]"].ToArray();
|
2022-08-22 04:46:01 +00:00
|
|
|
|
if (ids.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
ids = Request.Form["setValue.ID"].ToArray();
|
|
|
|
|
values = Request.Form["setValue.SetRawValue"].ToArray();
|
|
|
|
|
}
|
2022-08-21 14:01:32 +00:00
|
|
|
|
|
|
|
|
|
var vm = Wtm.CreateVM<SetValueVM>(Ids: ids);
|
2022-05-09 15:57:46 +00:00
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
return PartialView(vm);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vm.Set();
|
|
|
|
|
return FFResult().CloseDialog().RefreshGrid().Alert($"{vm.设置结果}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2021-12-12 06:55:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|