From da528e999d6538a12f357b6c745974316d48c086 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期一, 09 九月 2024 15:27:16 +0800
Subject: [PATCH] 修改初始化fly

---
 SimuTools/FrmMain.cs |  128 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 119 insertions(+), 9 deletions(-)

diff --git a/SimuTools/FrmMain.cs b/SimuTools/FrmMain.cs
index 3cb3d5c..76264a9 100644
--- a/SimuTools/FrmMain.cs
+++ b/SimuTools/FrmMain.cs
@@ -1,11 +1,8 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+锘縰sing SimuTools.Domain;
+using SimuTools.Tools;
+using System;
+using System.Diagnostics;
+using System.IO;
 using System.Windows.Forms;
 
 namespace SimuTools
@@ -19,27 +16,140 @@
 
         private void FrmMain_Load(object sender, EventArgs e)
         {
+            LogOut.Info("鍚姩绋嬪簭...");
+            try
+            {
+                GdalHelper gdal = GdalHelper.Instance;
+                LogOut.Info("> 鍒濆鍖朑DAL瀹屾垚 <");
+            }
+            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)
         {
+            selectFile(this.txtTerrainPath);
+        }
 
+        private void btnBuildingPath_Click(object sender, EventArgs e)
+        {
+            selectFile(this.txtBuildingPath);
+        }
+
+        private void selectFile(TextBox tb)
+        {
+            OpenFileDialog dialog = new OpenFileDialog();
+            dialog.Filter = "Tif files(*.tif)|*.tif|Tiff files (*.tiff)|*.tiff";
+            dialog.RestoreDirectory = true;
+
+            string path = tb.Text.Trim();
+            if (File.Exists(path))
+            {
+                dialog.InitialDirectory = Path.GetDirectoryName(path);
+            }
+
+            if (dialog.ShowDialog() == DialogResult.OK)
+            {
+                tb.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 buildingFile = this.txtBuildingPath.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) || !File.Exists(buildingFile))
+            {
+                ShowErr("鍦板舰鍜屽缓绛戞枃浠讹紝瑕佹眰蹇呴』瀛樺湪锛�");
+                return;
+            }
+            if (!Directory.Exists(waterPath) || !Directory.Exists(flowPath) || !Directory.Exists(outPath))
+            {
+                ShowErr("姘撮潰銆佹祦閫熷拰杈撳嚭鐩綍锛岃姹傚繀椤诲瓨鍦紒");
+                return;
+            }
+
+            try
+            {
+                this.btnRun.Enabled = false;
+                LogOut.Info("寮�濮嬭繍琛� >>");
+
+                Stopwatch stopWatch = new Stopwatch();
+                stopWatch.Start();
+                Tools.Handle.Run(new Args(serviceName, terrainFile, buildingFile, waterPath, flowPath, outPath));
+                stopWatch.Stop();
+
+                this.btnRun.Enabled = true;
+                LogOut.Info("杩愯缁撴潫 <<");
+                MessageBox.Show("杩愯缁撴潫锛乗n鑰楁椂锛�" + GetSeconds(stopWatch.ElapsedMilliseconds) + " 绉�", "鎻愮ず", MessageBoxButtons.OK, MessageBoxIcon.Information);
+            }
+            catch (Exception ex)
+            {
+                this.btnRun.Enabled = true;
+                LogOut.Error(ex.StackTrace);
+                ShowErr("杩愯鍑洪敊锛�" + ex.Message);
+            }
+        }
+
+        private void ShowErr(string message)
+        {
+            MessageBox.Show(message, "鎻愮ず", MessageBoxButtons.OK, MessageBoxIcon.Error);
+        }
+
+        private string GetSeconds(long milliseconds)
+        {
+            return (milliseconds / 1000.0).ToString();
         }
     }
 }

--
Gitblit v1.9.3