using DevExpress.XtraEditors;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
|
namespace IStation.WinFrmUI.Scatl
|
{
|
/// <summary>
|
/// 设备导入导出辅助类
|
/// </summary>
|
public class MonitorPointImportExportHelper
|
{
|
/// <summary>
|
/// 测点组扩展 测点列表
|
/// </summary>
|
public class JsonDataModel : Model.MonitorPointGroup
|
{
|
public JsonDataModel() { }
|
public JsonDataModel(Model.MonitorPointGroup rhs, List<Model.MonitorPointExSignalList> monitorPointList) : base(rhs)
|
{
|
this.MonitorPointList = monitorPointList?.ToList();
|
}
|
|
/// <summary>
|
/// 监测点列表
|
/// </summary>
|
public List<Model.MonitorPointExSignalList> MonitorPointList { get; set; }
|
}
|
|
//导入
|
public static bool Import(long projectId)
|
{
|
var dlg = new OpenFileDialog();
|
dlg.Title = "选择监测点文件";
|
dlg.Filter = "Monitor文档|*.monitor";
|
dlg.AutoUpgradeEnabled = true;
|
if (dlg.ShowDialog() != DialogResult.OK)
|
{
|
return false;
|
}
|
var json = System.IO.File.ReadAllText(dlg.FileName);
|
if (string.IsNullOrEmpty(json))
|
{
|
XtraMessageBox.Show("监测点文件解析失败!");
|
return false;
|
}
|
var list = JsonHelper.Json2Object<List<JsonDataModel>>(json);
|
return Cover(projectId,list);
|
}
|
|
public static bool Cover(long projectId,List<JsonDataModel> list)
|
{
|
if (list == null || list.Count < 1)
|
{
|
XtraMessageBox.Show("监测点文件解析失败!");
|
return false;
|
}
|
var groups = list.Where(x => x.Id > 0).Select(x => new Model.MonitorPointGroup(x)).ToList();
|
if (groups.Count > 0)
|
{
|
groups.RemoveAll(x => x.Id < 1);
|
if (groups.Count > 0)
|
{
|
var bol = new BLL.MonitorPointGroup().Covers(projectId, groups);
|
if (!bol)
|
{
|
XtraMessageBox.Show("监测点组覆盖失败!");
|
return false;
|
}
|
}
|
}
|
var monitor_list = list.Where(x => x.MonitorPointList != null && x.MonitorPointList.Count > 0).SelectMany(x => x.MonitorPointList).ToList();
|
if (monitor_list.Count < 1)
|
{
|
XtraMessageBox.Show("未检测到监测点信息");
|
return false;
|
}
|
var result = new BLL.MonitorPoint().CoverEx(projectId, monitor_list);
|
if (!result)
|
{
|
XtraMessageBox.Show("监测点覆盖失败!");
|
return false;
|
}
|
return true;
|
}
|
|
//导出
|
public static bool Export(long projectId)
|
{
|
var dlg = new SaveFileDialog();
|
dlg.Title = "选择监测点文件保存路径";
|
dlg.Filter = "Monitor文档|*.monitor";
|
dlg.AutoUpgradeEnabled = true;
|
if (dlg.ShowDialog() != DialogResult.OK)
|
{
|
return false;
|
}
|
var group_list = new BLL.MonitorPointGroup().GetAll(projectId);
|
if (group_list == null)
|
group_list = new List<Model.MonitorPointGroup>();
|
var monitor_list = new BLL.MonitorPoint().GetExSignalList(projectId);
|
var list = group_list.Select(x => new JsonDataModel(x, monitor_list?.Where(t => t.GroupId == x.Id).ToList())).ToList();
|
if (list == null)
|
list = new List<JsonDataModel>();
|
var notGroupList = monitor_list?.Where(x => x.GroupId < 1).ToList();
|
if (notGroupList != null && notGroupList.Count > 0)
|
{
|
var group = new JsonDataModel();
|
group.MonitorPointList = notGroupList.ToList();
|
list.Add(group);
|
}
|
|
var json = JsonHelper.Object2FormatJson(list);
|
System.IO.File.WriteAllText(dlg.FileName, json);
|
return true;
|
}
|
|
|
|
|
}
|
}
|