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 LogicTreeImportExportHelper
|
{
|
public class JsonDataModel
|
{
|
/// <summary>
|
/// 泵站列表
|
/// </summary>
|
public List<Model.Station> StationList { get; set; }
|
|
/// <summary>
|
/// 业务类别列表
|
/// </summary>
|
public List<Model.LogicCatalog> LogicCatalogList { get; set; }
|
|
/// <summary>
|
/// 业务区域列表
|
/// </summary>
|
public List<Model.LogicArea> LogicAreaList { get; set; }
|
|
/// <summary>
|
/// 业务清单
|
/// </summary>
|
public List<Model.LogicTree> LogicTreeList { get; set; }
|
}
|
|
//导入
|
public static bool Import(long projectId)
|
{
|
var dlg = new OpenFileDialog();
|
dlg.Title = "选择业务文件";
|
dlg.Filter = "Logic文档|*.logic";
|
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 model = JsonHelper.Json2Object<JsonDataModel>(json);
|
return Cover(projectId, model);
|
}
|
|
public static bool Cover(long projectId, JsonDataModel model)
|
{
|
if (model == null)
|
{
|
XtraMessageBox.Show("业务文件解析失败!");
|
return false;
|
}
|
if (!new BLL.Station().Covers(projectId, model.StationList))
|
{
|
XtraMessageBox.Show("未检测到泵站信息");
|
return false;
|
}
|
if (!new BLL.LogicCatalog().Covers(projectId, model.LogicCatalogList))
|
{
|
XtraMessageBox.Show("未检测到业务类别信息");
|
return false;
|
}
|
if (!new BLL.LogicArea().Covers(projectId, model.LogicAreaList))
|
{
|
XtraMessageBox.Show("未检测到业务区域信息");
|
return false;
|
}
|
if (!new BLL.LogicTree().Covers(projectId, model.LogicTreeList))
|
{
|
XtraMessageBox.Show("未检测到泵站列表信息");
|
return false;
|
}
|
return true;
|
}
|
|
//导出
|
public static bool Export(long projectId)
|
{
|
var dlg = new SaveFileDialog();
|
dlg.Title = "选择业务文件保存路径";
|
dlg.Filter = "Logic文档|*.logic";
|
dlg.AutoUpgradeEnabled = true;
|
if (dlg.ShowDialog() != DialogResult.OK)
|
{
|
return false;
|
}
|
var stations = new BLL.Station().GetAll(projectId);
|
var logicCatalogs = new BLL.LogicCatalog().GetAll(projectId);
|
var logicAreas = new BLL.LogicArea().GetAll(projectId);
|
var logicTrees = new BLL.LogicTree().GetAll(projectId);
|
|
var model = new JsonDataModel();
|
model.StationList = stations;
|
model.LogicAreaList = logicAreas;
|
model.LogicCatalogList = logicCatalogs;
|
model.LogicTreeList = logicTrees;
|
|
var json = JsonHelper.Object2FormatJson(model);
|
System.IO.File.WriteAllText(dlg.FileName, json);
|
return true;
|
}
|
|
}
|
}
|