浏览代码

自行添加缓存文件

章政 8 年之前
父节点
当前提交
22b1c70e68

+ 10 - 10
UAS_XmlAnalysor/App.config

@@ -1,33 +1,33 @@
 <?xml version="1.0" encoding="utf-8"?>
 <configuration>
     <configSections>
-        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
-            <section name="UAS_XmlAnalysor.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
+        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+            <section name="UAS_XmlAnalysor.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
         </sectionGroup>
     </configSections>
     <startup> 
-        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
     </startup>
     <userSettings>
         <UAS_XmlAnalysor.Properties.Settings>
-            <setting name="MES" serializeAs="String">
-                <value>Data Source=117.25.180.218/orcl;User ID=MES;PassWord=select!#%*(</value>
-            </setting>
             <setting name="FolderPath" serializeAs="String">
-                <value />
+                <value/>
             </setting>
             <setting name="BackUpFolderPath" serializeAs="String">
-                <value />
+                <value/>
             </setting>
             <setting name="Source" serializeAs="String">
-                <value />
+                <value/>
             </setting>
             <setting name="Master" serializeAs="String">
-                <value />
+                <value/>
             </setting>
             <setting name="AutoStart" serializeAs="String">
                 <value>False</value>
             </setting>
+            <setting name="MES" serializeAs="String">
+                <value>Data Source=117.25.180.218/orcl;User ID=MES;PassWord=select!#%*(</value>
+            </setting>
         </UAS_XmlAnalysor.Properties.Settings>
     </userSettings>
 </configuration>

+ 37 - 13
UAS_XmlAnalysor/Form1.cs

@@ -3,6 +3,7 @@ using System;
 using System.Collections.Generic;
 using System.Data;
 using System.IO;
+using System.Threading;
 using System.Windows.Forms;
 using System.Xml;
 
@@ -22,26 +23,49 @@ namespace UAS_XmlAnalysor
 
         private void Form1_Load(object sender, EventArgs e)
         {
-            FolderPath.Text = Properties.Settings.Default.FolderPath;
-            BackUpFolderPath.Text = Properties.Settings.Default.BackUpFolderPath;
-            Source.Text = Properties.Settings.Default.Source;
-            Master.Text = Properties.Settings.Default.Master;
-            AutoStart.Checked = Properties.Settings.Default.AutoStart;
+            try
+            {
+                StreamReader sr = new StreamReader(Application.StartupPath + @"/Cache/path.txt");
+                string line;
+                while ((line = sr.ReadLine()) != null)
+                {
+                    if (line != "")
+                    {
+                        break;
+                    }
+                }
+                object[] Data = line.Split('|');
+                FolderPath.Text = Data[0].ToString();
+                BackUpFolderPath.Text = Data[1].ToString();
+                Source.Text = Data[2].ToString();
+                Master.Text = Data[3].ToString();
+                AutoStart.Checked = (Data[4].ToString() == "True") ? true : false;
+                sr.Close();
+            }
+            catch (Exception)
+            {
+
+            }
             dt = (DataTable)dh.ExecuteSql("select ms_pwd,ma_user,ma_address from master ", "select");
             Master.DataSource = dt;
             Master.DisplayMember = "ma_user";
             Master.ValueMember = "ma_user";
-            StartWatch.PerformClick();
+            //StartWatch.PerformClick();
         }
 
         private void StartWatch_Click(object sender, EventArgs e)
         {
+            if (FolderPath.Text == "" || BackUpFolderPath.Text == "")
+            {
+                OperateResult.AppendText("请选择监控文件夹和备份文件夹\n");
+                return;
+            }
+
             for (int i = 0; i < dt.Rows.Count; i++)
             {
                 if (Master.Text == dt.Rows[i]["ma_user"].ToString())
                 {
                     DataHelper.DBConnectionString = "Data Source=" + dt.Rows[i]["ma_address"] + ";User ID=" + dt.Rows[i]["ma_user"] + ";PassWord=" + dt.Rows[i]["ms_pwd"]; ;
-                    Console.WriteLine(DataHelper.DBConnectionString);
                     dh = new DataHelper();
                 }
             }
@@ -54,12 +78,12 @@ namespace UAS_XmlAnalysor
             XmlWatcher.Filter = "*.xml";
             XmlWatcher.Created += new FileSystemEventHandler(XmlWatcher_Created);
             XmlWatcher.EnableRaisingEvents = true;
-            Properties.Settings.Default.FolderPath = FolderPath.Text;
-            Properties.Settings.Default.BackUpFolderPath = BackUpFolderPath.Text;
-            Properties.Settings.Default.Source = Source.Text;
-            Properties.Settings.Default.Master = Master.Text;
-            Properties.Settings.Default.AutoStart = AutoStart.Checked;
-            Properties.Settings.Default.Save();
+            string CacheString = FolderPath.Text + "|" + BackUpFolderPath.Text + "|" + Source.Text + "|" + Master.Text + "|" + AutoStart.Checked;
+            //写入前先删除文件
+            File.Delete(Application.StartupPath + @"/Cache/path.txt");
+            StreamWriter sw = File.AppendText(Application.StartupPath + @"\Cache\path.txt");
+            sw.WriteLine(CacheString);
+            sw.Close();
             Source.Enabled = false;
             StartWatch.Enabled = false;
             ChooseFolder.Enabled = false;

+ 3 - 0
UAS_XmlAnalysor/Program.cs

@@ -1,6 +1,7 @@
 using Microsoft.Win32;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Security.Principal;
 using System.Threading.Tasks;
@@ -22,6 +23,8 @@ namespace UAS_XmlAnalysor
                 WindowsPrincipal principal = new WindowsPrincipal(identity);
                 Application.EnableVisualStyles();
                 Application.SetCompatibleTextRenderingDefault(false);
+                if (!Directory.Exists(Application.StartupPath+@"\Cache"))
+                    Directory.CreateDirectory(Application.StartupPath + @"\Cache");
                 if (principal.IsInRole(WindowsBuiltInRole.Administrator))
                     Application.Run(new Form1());
                 else

+ 18 - 12
UAS_XmlAnalysor/Properties/Settings.Designer.cs

@@ -23,21 +23,10 @@ namespace UAS_XmlAnalysor.Properties {
             }
         }
         
-        [global::System.Configuration.UserScopedSettingAttribute()]
-        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("Data Source=117.25.180.218/orcl;User ID=MES;PassWord=select!#%*(")]
-        public string MES {
-            get {
-                return ((string)(this["MES"]));
-            }
-            set {
-                this["MES"] = value;
-            }
-        }
-        
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
         [global::System.Configuration.DefaultSettingValueAttribute("")]
+        [global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]
         public string FolderPath {
             get {
                 return ((string)(this["FolderPath"]));
@@ -50,6 +39,7 @@ namespace UAS_XmlAnalysor.Properties {
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
         [global::System.Configuration.DefaultSettingValueAttribute("")]
+        [global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]
         public string BackUpFolderPath {
             get {
                 return ((string)(this["BackUpFolderPath"]));
@@ -62,6 +52,7 @@ namespace UAS_XmlAnalysor.Properties {
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
         [global::System.Configuration.DefaultSettingValueAttribute("")]
+        [global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]
         public string Source {
             get {
                 return ((string)(this["Source"]));
@@ -74,6 +65,7 @@ namespace UAS_XmlAnalysor.Properties {
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
         [global::System.Configuration.DefaultSettingValueAttribute("")]
+        [global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]
         public string Master {
             get {
                 return ((string)(this["Master"]));
@@ -86,6 +78,7 @@ namespace UAS_XmlAnalysor.Properties {
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
         [global::System.Configuration.DefaultSettingValueAttribute("False")]
+        [global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]
         public bool AutoStart {
             get {
                 return ((bool)(this["AutoStart"]));
@@ -94,5 +87,18 @@ namespace UAS_XmlAnalysor.Properties {
                 this["AutoStart"] = value;
             }
         }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("Data Source=117.25.180.218/orcl;User ID=MES;PassWord=select!#%*(")]
+        [global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]
+        public string MES {
+            get {
+                return ((string)(this["MES"]));
+            }
+            set {
+                this["MES"] = value;
+            }
+        }
     }
 }

+ 8 - 8
UAS_XmlAnalysor/Properties/Settings.settings

@@ -2,23 +2,23 @@
 <SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="UAS_XmlAnalysor.Properties" GeneratedClassName="Settings">
   <Profiles />
   <Settings>
-    <Setting Name="MES" Type="System.String" Scope="User">
-      <Value Profile="(Default)">Data Source=117.25.180.218/orcl;User ID=MES;PassWord=select!#%*(</Value>
-    </Setting>
-    <Setting Name="FolderPath" Type="System.String" Scope="User">
+    <Setting Name="FolderPath" Roaming="true" Type="System.String" Scope="User">
       <Value Profile="(Default)" />
     </Setting>
-    <Setting Name="BackUpFolderPath" Type="System.String" Scope="User">
+    <Setting Name="BackUpFolderPath" Roaming="true" Type="System.String" Scope="User">
       <Value Profile="(Default)" />
     </Setting>
-    <Setting Name="Source" Type="System.String" Scope="User">
+    <Setting Name="Source" Roaming="true" Type="System.String" Scope="User">
       <Value Profile="(Default)" />
     </Setting>
-    <Setting Name="Master" Type="System.String" Scope="User">
+    <Setting Name="Master" Roaming="true" Type="System.String" Scope="User">
       <Value Profile="(Default)" />
     </Setting>
-    <Setting Name="AutoStart" Type="System.Boolean" Scope="User">
+    <Setting Name="AutoStart" Roaming="true" Type="System.Boolean" Scope="User">
       <Value Profile="(Default)">False</Value>
     </Setting>
+    <Setting Name="MES" Roaming="true" Type="System.String" Scope="User">
+      <Value Profile="(Default)">Data Source=117.25.180.218/orcl;User ID=MES;PassWord=select!#%*(</Value>
+    </Setting>
   </Settings>
 </SettingsFile>

+ 2 - 2
UAS_XmlAnalysor/UAS_XmlAnalysor.csproj

@@ -12,7 +12,7 @@
     <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
-    <TargetFrameworkProfile />
+    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
     <IsWebBootstrapper>true</IsWebBootstrapper>
     <PublishUrl>ftp://192.168.253.9/MESSetting/Xml/</PublishUrl>
     <Install>true</Install>
@@ -31,7 +31,7 @@
     <MinimumRequiredVersion>1.0.0.5</MinimumRequiredVersion>
     <CreateWebPageOnPublish>true</CreateWebPageOnPublish>
     <WebPage>publish.htm</WebPage>
-    <ApplicationRevision>10</ApplicationRevision>
+    <ApplicationRevision>13</ApplicationRevision>
     <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
     <UseApplicationTrust>false</UseApplicationTrust>
     <CreateDesktopShortcut>true</CreateDesktopShortcut>