tangxu
2024-08-07 4921dcab67860943ae4cbfe7a41e3d65eb46080a
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
using DevExpress.XtraEditors;
using System.Collections.Generic;
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; }
 
 
            //导入
            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<JsonDataModel>(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;
            }
 
        }
    }
}