From 7d63936dd4f69a46c88f641229640fb4d9195468 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 18 七月 2024 15:16:12 +0800
Subject: [PATCH] 修改界面操作

---
 SimuTools/FrmMain.cs          |   83 +++++++++++++++++++++++++--
 SimuTools/FrmMain.Designer.cs |   70 ++++++++++++++++++-----
 SimuTools/SimuTools.csproj    |    1 
 SimuTools/Tools/Handle.cs     |   17 +++++
 4 files changed, 148 insertions(+), 23 deletions(-)

diff --git a/SimuTools/FrmMain.Designer.cs b/SimuTools/FrmMain.Designer.cs
index edb2709..c342cf3 100644
--- a/SimuTools/FrmMain.Designer.cs
+++ b/SimuTools/FrmMain.Designer.cs
@@ -38,6 +38,9 @@
             this.lblFlow = new System.Windows.Forms.Label();
             this.btnFlowPath = new System.Windows.Forms.Button();
             this.btnRun = new System.Windows.Forms.Button();
+            this.txtOutPath = new System.Windows.Forms.TextBox();
+            this.lblOut = new System.Windows.Forms.Label();
+            this.btnOutPath = new System.Windows.Forms.Button();
             this.SuspendLayout();
             // 
             // btnTerrainPath
@@ -45,9 +48,9 @@
             this.btnTerrainPath.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.btnTerrainPath.Location = new System.Drawing.Point(607, 27);
             this.btnTerrainPath.Name = "btnTerrainPath";
-            this.btnTerrainPath.Size = new System.Drawing.Size(90, 26);
+            this.btnTerrainPath.Size = new System.Drawing.Size(130, 26);
             this.btnTerrainPath.TabIndex = 47;
-            this.btnTerrainPath.Text = "閫夋嫨鍦板舰";
+            this.btnTerrainPath.Text = "閫夋嫨鍦板舰鏂囦欢";
             this.btnTerrainPath.UseVisualStyleBackColor = true;
             this.btnTerrainPath.Click += new System.EventHandler(this.btnTerrainPath_Click);
             // 
@@ -57,7 +60,7 @@
             this.lblTerrain.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.lblTerrain.Location = new System.Drawing.Point(24, 32);
             this.lblTerrain.Name = "lblTerrain";
-            this.lblTerrain.Size = new System.Drawing.Size(80, 16);
+            this.lblTerrain.Size = new System.Drawing.Size(79, 16);
             this.lblTerrain.TabIndex = 48;
             this.lblTerrain.Text = "鍦板舰鏁版嵁:";
             // 
@@ -87,7 +90,7 @@
             this.lblWater.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.lblWater.Location = new System.Drawing.Point(24, 81);
             this.lblWater.Name = "lblWater";
-            this.lblWater.Size = new System.Drawing.Size(80, 16);
+            this.lblWater.Size = new System.Drawing.Size(79, 16);
             this.lblWater.TabIndex = 51;
             this.lblWater.Text = "姘撮潰鏁版嵁:";
             // 
@@ -96,16 +99,16 @@
             this.btnWaterPath.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.btnWaterPath.Location = new System.Drawing.Point(607, 76);
             this.btnWaterPath.Name = "btnWaterPath";
-            this.btnWaterPath.Size = new System.Drawing.Size(90, 26);
+            this.btnWaterPath.Size = new System.Drawing.Size(130, 26);
             this.btnWaterPath.TabIndex = 50;
-            this.btnWaterPath.Text = "閫夋嫨姘撮潰";
+            this.btnWaterPath.Text = "閫夋嫨姘撮潰鐩綍";
             this.btnWaterPath.UseVisualStyleBackColor = true;
             this.btnWaterPath.Click += new System.EventHandler(this.btnWaterPath_Click);
             // 
             // txtFlowPath
             // 
             this.txtFlowPath.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.txtFlowPath.Location = new System.Drawing.Point(109, 125);
+            this.txtFlowPath.Location = new System.Drawing.Point(109, 126);
             this.txtFlowPath.MaxLength = 2000;
             this.txtFlowPath.Name = "txtFlowPath";
             this.txtFlowPath.Size = new System.Drawing.Size(482, 26);
@@ -116,20 +119,20 @@
             // 
             this.lblFlow.AutoSize = true;
             this.lblFlow.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.lblFlow.Location = new System.Drawing.Point(24, 130);
+            this.lblFlow.Location = new System.Drawing.Point(24, 131);
             this.lblFlow.Name = "lblFlow";
-            this.lblFlow.Size = new System.Drawing.Size(80, 16);
+            this.lblFlow.Size = new System.Drawing.Size(79, 16);
             this.lblFlow.TabIndex = 54;
             this.lblFlow.Text = "娴侀�熸祦鍚�:";
             // 
             // btnFlowPath
             // 
             this.btnFlowPath.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.btnFlowPath.Location = new System.Drawing.Point(607, 125);
+            this.btnFlowPath.Location = new System.Drawing.Point(607, 126);
             this.btnFlowPath.Name = "btnFlowPath";
-            this.btnFlowPath.Size = new System.Drawing.Size(90, 26);
+            this.btnFlowPath.Size = new System.Drawing.Size(130, 26);
             this.btnFlowPath.TabIndex = 53;
-            this.btnFlowPath.Text = "閫夋嫨姘撮潰";
+            this.btnFlowPath.Text = "閫夋嫨娴侀�熺洰褰�";
             this.btnFlowPath.UseVisualStyleBackColor = true;
             this.btnFlowPath.Click += new System.EventHandler(this.btnFlowPath_Click);
             // 
@@ -137,19 +140,53 @@
             // 
             this.btnRun.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.btnRun.ForeColor = System.Drawing.SystemColors.Highlight;
-            this.btnRun.Location = new System.Drawing.Point(27, 172);
+            this.btnRun.Location = new System.Drawing.Point(27, 229);
             this.btnRun.Name = "btnRun";
-            this.btnRun.Size = new System.Drawing.Size(670, 26);
+            this.btnRun.Size = new System.Drawing.Size(710, 26);
             this.btnRun.TabIndex = 57;
             this.btnRun.Text = "杩�    琛�";
             this.btnRun.UseVisualStyleBackColor = true;
             this.btnRun.Click += new System.EventHandler(this.btnRun_Click);
             // 
+            // txtOutPath
+            // 
+            this.txtOutPath.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.txtOutPath.Location = new System.Drawing.Point(109, 178);
+            this.txtOutPath.MaxLength = 2000;
+            this.txtOutPath.Name = "txtOutPath";
+            this.txtOutPath.Size = new System.Drawing.Size(482, 26);
+            this.txtOutPath.TabIndex = 60;
+            this.txtOutPath.Text = "D:\\simu\\out";
+            // 
+            // lblOut
+            // 
+            this.lblOut.AutoSize = true;
+            this.lblOut.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.lblOut.Location = new System.Drawing.Point(24, 183);
+            this.lblOut.Name = "lblOut";
+            this.lblOut.Size = new System.Drawing.Size(79, 16);
+            this.lblOut.TabIndex = 59;
+            this.lblOut.Text = "杈撳嚭鐩綍:";
+            // 
+            // btnOutPath
+            // 
+            this.btnOutPath.Font = new System.Drawing.Font("瀹嬩綋", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.btnOutPath.Location = new System.Drawing.Point(607, 178);
+            this.btnOutPath.Name = "btnOutPath";
+            this.btnOutPath.Size = new System.Drawing.Size(130, 26);
+            this.btnOutPath.TabIndex = 58;
+            this.btnOutPath.Text = "閫夋嫨杈撳嚭鐩綍";
+            this.btnOutPath.UseVisualStyleBackColor = true;
+            this.btnOutPath.Click += new System.EventHandler(this.btnOutPath_Click);
+            // 
             // FrmMain
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(735, 222);
+            this.ClientSize = new System.Drawing.Size(751, 280);
+            this.Controls.Add(this.txtOutPath);
+            this.Controls.Add(this.lblOut);
+            this.Controls.Add(this.btnOutPath);
             this.Controls.Add(this.btnRun);
             this.Controls.Add(this.txtFlowPath);
             this.Controls.Add(this.lblFlow);
@@ -182,6 +219,9 @@
         private System.Windows.Forms.Label lblFlow;
         private System.Windows.Forms.Button btnFlowPath;
         private System.Windows.Forms.Button btnRun;
+        private System.Windows.Forms.TextBox txtOutPath;
+        private System.Windows.Forms.Label lblOut;
+        private System.Windows.Forms.Button btnOutPath;
     }
 }
 
diff --git a/SimuTools/FrmMain.cs b/SimuTools/FrmMain.cs
index c81923b..9fced93 100644
--- a/SimuTools/FrmMain.cs
+++ b/SimuTools/FrmMain.cs
@@ -1,18 +1,14 @@
 锘縰sing SimuTools.Tools;
 using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.IO;
 using System.Windows.Forms;
 
 namespace SimuTools
 {
     public partial class FrmMain : Form
     {
+        private bool flag;
+
         public FrmMain()
         {
             InitializeComponent();
@@ -30,22 +26,93 @@
 
         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 terrainFile = this.txtTerrainPath.Text.Trim();
+            string waterPath = this.txtWaterPath.Text.Trim();
+            string flowPath = this.txtFlowPath.Text.Trim();
+            string outPath = this.txtOutPath.Text.Trim();
 
+            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("寮�濮嬭繍琛� >>");
+                Tools.Handle.Run(terrainFile, waterPath, flowPath, outPath);
+                LogOut.Info("杩愯缁撴潫 >>");
+                flag = false;
+            }
+            catch (Exception ex)
+            {
+                flag = false;
+                LogOut.Error(ex.StackTrace);
+                ShowErr("杩愯鍑洪敊锛�" + ex.Message);
+            }
+        }
+
+        private void ShowErr(string message)
+        {
+            MessageBox.Show(message, "鎻愮ず", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
diff --git a/SimuTools/SimuTools.csproj b/SimuTools/SimuTools.csproj
index 451acb4..88ffa1e 100644
--- a/SimuTools/SimuTools.csproj
+++ b/SimuTools/SimuTools.csproj
@@ -63,6 +63,7 @@
     </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Tools\Handle.cs" />
     <Compile Include="Tools\LogOut.cs" />
     <EmbeddedResource Include="FrmMain.resx">
       <DependentUpon>FrmMain.cs</DependentUpon>
diff --git a/SimuTools/Tools/Handle.cs b/SimuTools/Tools/Handle.cs
new file mode 100644
index 0000000..b29c6f4
--- /dev/null
+++ b/SimuTools/Tools/Handle.cs
@@ -0,0 +1,17 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace SimuTools.Tools
+{
+    public class Handle
+    {
+        public static void Run(string terrainFile, string waterPath, string flowPath, string outPath)
+        {
+            //
+        }
+    }
+}

--
Gitblit v1.9.3