ningshuxia
2023-02-24 1e4b358de58e36bfbf692ab2538ff9e7d60fd025
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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;
        }
 
    }
}