Explorar el Código

默认配模板文件路径

wb_han hace 5 años
padre
commit
a88df0660b
Se han modificado 3 ficheros con 48 adiciones y 5 borrados
  1. 1 1
      HOZProject/App.config
  2. 12 0
      HOZProject/FormHOZMain.cs
  3. 35 4
      HOZProject/UserControls/UControl_Init.cs

+ 1 - 1
HOZProject/App.config

@@ -18,7 +18,7 @@
       <add key="WQGF" value="100,200,300"/>
       <!--拉直操作需要的放大倍数_数据源-->
       <add key="WLZ" value="100,200,300"/>
-      <add key="ConfigFilePath" value="E:/ConfigFile"/>
+      <add key="TemplateFilePath" value="E:\TemplateFilePath"/>
       <!--PT使用的ELY文件-->
       <add key="PT_ELYFile" value=""/>
       <!--FIB使用的ELY文件-->

+ 12 - 0
HOZProject/FormHOZMain.cs

@@ -4,8 +4,10 @@ using MeasureThread;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
+using System.Configuration;
 using System.Data;
 using System.Drawing;
+using System.IO;
 using System.Linq;
 using System.Runtime.InteropServices;
 using System.Text;
@@ -316,8 +318,18 @@ namespace HOZProject
 
         private void pbImportTemplateFile_Click(object sender, EventArgs e)
         {
+            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
+            string m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
+            //判断保存的路径是否存在
+            if (!Directory.Exists(m_TemplateFilePath))
+            {
+                //创建路径
+                Directory.CreateDirectory(m_TemplateFilePath);
+            }
             //打开默认路径
             OpenFileDialog openFileDialog = new OpenFileDialog();
+            //设置默认打开路径(绝对路径)
+            openFileDialog.InitialDirectory = m_TemplateFilePath;
             openFileDialog.Filter = "样品参数文件|*.cfg";
             if (openFileDialog.ShowDialog() == DialogResult.OK)
             {

+ 35 - 4
HOZProject/UserControls/UControl_Init.cs

@@ -10,6 +10,7 @@ using System.Windows.Forms;
 using MeasureData;
 using System.Configuration;
 using FileManager;
+using System.IO;
 
 namespace HOZProject
 {
@@ -29,6 +30,8 @@ namespace HOZProject
         //模板路径
         private string readConfigPath;
         public string ReadConfigPath { get => readConfigPath; set => readConfigPath = value; }
+        //模板文件默认路径
+        private string m_TemplateFilePath;
         #endregion
 
         #region 构造方法
@@ -94,16 +97,25 @@ namespace HOZProject
         #region 加载PT模板文件
         private void pbTemplateFile_Click(object sender, EventArgs e)
         {
+            //判断保存的路径是否存在
+            if (!Directory.Exists(m_TemplateFilePath))
+            {
+                //创建路径
+                Directory.CreateDirectory(m_TemplateFilePath);
+            }
             string FilePathName;
             string fileNameWithoutExtension;
             //新建一个文件对话框
             OpenFileDialog pOpenFileDialog = new OpenFileDialog();
+            //设置默认打开路径(绝对路径)
+            pOpenFileDialog.InitialDirectory =  m_TemplateFilePath;
             //设置对话框标题
             pOpenFileDialog.Title = "选择模板文件";
             //设置打开文件类型
             pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
-            //监测文件是否存在
-            pOpenFileDialog.CheckFileExists = true;
+            ////监测文件是否存在
+            //pOpenFileDialog.CheckFileExists = true;
+            
             //文件打开后执行以下程序
             if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
             {
@@ -117,16 +129,24 @@ namespace HOZProject
         #region 加载FIB模板文件
         private void pbFIBTemplateFile_Click(object sender, EventArgs e)
         {
+            //判断保存的路径是否存在
+            if (!Directory.Exists(m_TemplateFilePath))
+            {
+                //创建路径
+                Directory.CreateDirectory(m_TemplateFilePath);
+            }
             string FilePathName;
             string fileNameWithoutExtension;
             //新建一个文件对话框
             OpenFileDialog pOpenFileDialog = new OpenFileDialog();
+            //设置默认打开路径(绝对路径)
+            pOpenFileDialog.InitialDirectory = m_TemplateFilePath;
             //设置对话框标题
             pOpenFileDialog.Title = "选择模板文件";
             //设置打开文件类型
             pOpenFileDialog.Filter = "ely文件(*.ely)|*.ely";
-            //监测文件是否存在
-            pOpenFileDialog.CheckFileExists = true;
+            ////监测文件是否存在
+            //pOpenFileDialog.CheckFileExists = true;
             //文件打开后执行以下程序
             if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
             {
@@ -166,7 +186,17 @@ namespace HOZProject
             cfm.SampleName = cbbWYP.Text;
             cfm.Firm = cbbWCS.Text;
             ConfigFile cf = new ConfigFile(cfm);
+            if (!m_TemplateFilePath.Equals(""))
+            {
+                if (!Directory.Exists(m_TemplateFilePath))
+                {
+                    //创建路径
+                    Directory.CreateDirectory(m_TemplateFilePath);
+                }
+            }
             SaveFileDialog saveFileDialog = new SaveFileDialog();
+            //设置默认打开路径(绝对路径)
+            saveFileDialog.InitialDirectory = m_TemplateFilePath;
             saveFileDialog.Filter = "样品参数文件|*.cfg";
             if (saveFileDialog.ShowDialog() == DialogResult.OK)
             {
@@ -388,6 +418,7 @@ namespace HOZProject
             cbbWQGF.Items.Clear();
             cbbWLZ.Items.Clear();
 
+            m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
             string sample_Type = config.AppSettings.Settings["Sample_Type"].Value.ToString();
             string firm = config.AppSettings.Settings["Firm"].Value.ToString();
             string WPZDTemp = config.AppSettings.Settings["WPZD"].Value.ToString();