管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-07-18 0a70f99e51b0ea0c83288213e3b1f7904d78ede0
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using SimuTools.Tools;
using System;
using System.IO;
using System.Windows.Forms;
 
namespace SimuTools
{
    public partial class FrmMain : Form
    {
        private bool flag;
 
        public FrmMain()
        {
            InitializeComponent();
        }
 
        private void FrmMain_Load(object sender, EventArgs e)
        {
            LogOut.Info("启动程序...");
            try
            {
                GdalHelper gdal = GdalHelper.Instance;
                LogOut.Info("> 初始化GDAL完成 <");
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.StackTrace);
                ShowErr("GDAL初始化出错:" + ex.Message);
            }
        }
 
        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            LogOut.Info("关闭程序...");
        }
 
        private void btnTerrainPath_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "Tif files(*.tif)|*.tif|Tiff files (*.tiff)|*.tiff";
            dialog.RestoreDirectory = true;
 
            string path = this.txtTerrainPath.Text.Trim();
            if (File.Exists(path))
            {
                dialog.InitialDirectory = Path.GetDirectoryName(path);
            }
 
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.txtTerrainPath.Text = dialog.FileName;
            }
        }
 
        private void btnWaterPath_Click(object sender, EventArgs e)
        {
            selectFolder(this.txtWaterPath, "水面");
        }
 
        private void btnFlowPath_Click(object sender, EventArgs e)
        {
            selectFolder(this.txtFlowPath, "流速");
        }
 
        private void btnOutPath_Click(object sender, EventArgs e)
        {
            selectFolder(this.txtOutPath, "输出");
        }
 
        private void selectFolder(TextBox tb, string title)
        {
            using (FolderBrowserDialog dialog = new FolderBrowserDialog())
            {
                string path = tb.Text.Trim();
                if (Directory.Exists(path))
                {
                    dialog.SelectedPath = path;
                }
 
                dialog.Description = "请选择" + title + "目录...";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    tb.Text = dialog.SelectedPath;
                }
            }
        }
 
        private void btnRun_Click(object sender, EventArgs e)
        {
            string serviceName = this.txtServiceName.Text.Trim();
            string terrainFile = this.txtTerrainPath.Text.Trim();
            string waterPath = this.txtWaterPath.Text.Trim();
            string flowPath = this.txtFlowPath.Text.Trim();
            string outPath = this.txtOutPath.Text.Trim();
 
            if (string.IsNullOrEmpty(serviceName))
            {
                ShowErr("服务名称,要求必填!");
                return;
            }
            if (!File.Exists(terrainFile))
            {
                ShowErr("地形文件,要求必须存在!");
                return;
            }
            if (!Directory.Exists(waterPath) || !Directory.Exists(flowPath) || !Directory.Exists(outPath))
            {
                ShowErr("水面、流速和输出目录,要求必须存在!");
                return;
            }
 
            if (flag) return;
            try
            {
                flag = true;
                LogOut.Info("开始运行 >>");
 
                outPath = Path.Combine(outPath, serviceName);
                if (!Directory.Exists(outPath))
                {
                    Directory.CreateDirectory(outPath);
                }
 
                Tools.Handle.Run(terrainFile, waterPath, flowPath, outPath);
 
                flag = false;
                LogOut.Info("运行结束 <<");
                MessageBox.Show("运行结束!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                flag = false;
                LogOut.Error(ex.StackTrace);
                ShowErr("运行出错:" + ex.Message);
            }
        }
 
        private void ShowErr(string message)
        {
            MessageBox.Show(message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
}