using DevExpress.XtraEditors; using System.Collections.Generic; using System.Windows.Forms; namespace IStation.WinFrmUI.Scatl { /// /// 业务树导入导出辅助类 /// public class LogicTreeImportExportHelper { public class JsonDataModel { /// /// 泵站列表 /// public List StationList { get; set; } //导入 public static bool Import() { 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(json); return Cover(model); } public static bool Cover(JsonDataModel model) { if (model == null) { XtraMessageBox.Show("业务文件解析失败!"); return false; } if (!new BLL.Station().Covers(model.StationList)) { XtraMessageBox.Show("未检测到泵站信息"); return false; } return true; } //导出 public static bool Export() { 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(); var model = new JsonDataModel(); model.StationList = stations; var json = JsonHelper.Object2FormatJson(model); System.IO.File.WriteAllText(dlg.FileName, json); return true; } } } }