Browse Source

修改接口

章政 8 years ago
parent
commit
2083d9c7a2

+ 8 - 9
MES接口/DataHelper.cs

@@ -4,7 +4,7 @@ using System.Data;
 using System.Text;
 using System.Configuration;
 
-namespace MES接口
+namespace MES_Interface
 {
     /// <summary>
     /// 数据库操作类
@@ -14,26 +14,25 @@ namespace MES接口
         //系统默认的的连接字符串
         private string ConnectionStrings = ConfigurationManager.ConnectionStrings["MES"].ConnectionString;
         //用户选择的数据库的连接字符串
-        public static string DBConnectionString;
         public static OracleConnection connection = null;
         OracleCommand command = null;
 
         /// <summary>
         /// 执行构造函数的时候打开数据库的链接
         /// </summary>
-        public DataHelper()
+        public DataHelper(string Environment)
         {
             try
             {
-                //如果选择的是默认数据则直接用配置文件的信息连接,否则选择数据库的账套信息
-                if (DBConnectionString == null || DBConnectionString == ConnectionStrings)
+                ftpOperater ftp = new ftpOperater();
+                if (Environment == "Formal")
                 {
-                    connection = new OracleConnection(ConnectionStrings);
+                    ConnectionStrings= Encryption.DecryptStr((ftp.GetFileContent("db.config")));
                 }
-                else
-                {
-                    connection = new OracleConnection(DBConnectionString);
+                else if (Environment == "Test") {
+
                 }
+                connection = new OracleConnection(ConnectionStrings);
                 connection.Open();
             }
             catch (Exception e)

+ 50 - 0
MES接口/Encryption.cs

@@ -0,0 +1,50 @@
+using System;
+using System.IO;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace MES_Interface
+{
+    class Encryption
+    {
+        private static string encryptKey = "DBDB";
+
+        public static string EncryptStr(string str)
+        {
+            DESCryptoServiceProvider descsp = new DESCryptoServiceProvider();   //实例化加/解密类对象   
+
+            byte[] key = Encoding.Unicode.GetBytes(encryptKey); //定义字节数组,用来存储密钥    
+
+            byte[] data = Encoding.Unicode.GetBytes(str);//定义字节数组,用来存储要加密的字符串  
+
+            MemoryStream MStream = new MemoryStream(); //实例化内存流对象      
+
+            //使用内存流实例化加密流对象   
+            CryptoStream CStream = new CryptoStream(MStream, descsp.CreateEncryptor(key, key), CryptoStreamMode.Write);
+
+            CStream.Write(data, 0, data.Length);  //向加密流中写入数据      
+
+            CStream.FlushFinalBlock();              //释放加密流      
+            return Convert.ToBase64String(MStream.ToArray());//返回加密后的字符串  
+        }
+
+        public static string DecryptStr(string str)
+        {
+            DESCryptoServiceProvider descsp = new DESCryptoServiceProvider();   //实例化加/解密类对象    
+
+            byte[] key = Encoding.Unicode.GetBytes(encryptKey); //定义字节数组,用来存储密钥    
+
+            byte[] data = Convert.FromBase64String(str);//定义字节数组,用来存储要解密的字符串  
+
+            MemoryStream MStream = new MemoryStream(); //实例化内存流对象      
+
+            //使用内存流实例化解密流对象       
+            CryptoStream CStream = new CryptoStream(MStream, descsp.CreateDecryptor(key, key), CryptoStreamMode.Write);
+            CStream.Write(data, 0, data.Length);      //向解密流中写入数据     
+
+            CStream.FlushFinalBlock();               //释放解密流      
+
+            return Encoding.Unicode.GetString(MStream.ToArray());       //返回解密后的字符串  
+        }
+    }
+}

File diff suppressed because it is too large
+ 198 - 570
MES接口/LogicHandler.cs


BIN
MES接口/MES接口.dll


+ 1 - 1
MES接口/Properties/Settings.Designer.cs

@@ -8,7 +8,7 @@
 // </auto-generated>
 //------------------------------------------------------------------------------
 
-namespace MES接口.Properties {
+namespace MES_Interface.Properties {
     
     
     [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]

+ 9 - 5
MES接口/UAS-MES接口.csproj

@@ -12,10 +12,14 @@
     <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <TargetFrameworkProfile />
-    <SccProjectName>SAK</SccProjectName>
-    <SccLocalPath>SAK</SccLocalPath>
-    <SccAuxPath>SAK</SccAuxPath>
-    <SccProvider>SAK</SccProvider>
+    <SccProjectName>
+    </SccProjectName>
+    <SccLocalPath>
+    </SccLocalPath>
+    <SccAuxPath>
+    </SccAuxPath>
+    <SccProvider>
+    </SccProvider>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -57,6 +61,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Encryption.cs" />
     <Compile Include="ftpOperater.cs" />
     <Compile Include="LogicHandler.cs" />
     <Compile Include="DataHelper.cs" />
@@ -75,7 +80,6 @@
     </None>
   </ItemGroup>
   <ItemGroup>
-    <Content Include="MES接口.dll" />
     <Content Include="tool\Oracle.ManagedDataAccess.dll" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

+ 50 - 5
MES接口/ftpOperater.cs

@@ -1,10 +1,11 @@
 using System;
+using System.Collections.Generic;
 using System.IO;
 using System.Net;
 using System.Text;
 using System.Windows.Forms;
 
-namespace MES接口
+namespace MES_Interface
 {
     public class ftpOperater
     {
@@ -19,10 +20,10 @@ namespace MES接口
 
         public ftpOperater()
         {
-            string[] FTPInf = "".Split('#');
-            this.ftpServerIP = "ftp://richwellgroup.com.cn";
-            this.ftpUser = "mesconfig";
-            this.ftpPwd = "Administrator1@";
+            string[] FTPInf = Properties.Settings.Default.Properties["FTPAddress"].DefaultValue.ToString().Split('|');
+            this.ftpServerIP = FTPInf[0];
+            this.ftpUser = FTPInf[1];
+            this.ftpPwd = FTPInf[2];
         }
 
         public void UpLoadFile(string filepath, string filename)
@@ -67,6 +68,50 @@ namespace MES接口
             }
         }
 
+        //获取指定的文件的内容
+        public string GetFileContent(string filename)
+        {
+            FtpWebRequest reqFTP;
+            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + "/" + filename));
+            reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
+            reqFTP.UseBinary = true;
+            reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPwd);
+
+            FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+
+            Stream ftpStream = response.GetResponseStream();
+
+            int bufferSize = GetFileContentLength(filename);
+            byte[] buffer = new byte[bufferSize];
+            ftpStream.Read(buffer, 0, bufferSize);
+            ftpStream.Close();
+            return Encoding.Default.GetString(buffer);
+        }
+
+
+        //获取指定文件的内容的字节长度
+        public int GetFileContentLength(string filename)
+        {
+            FtpWebRequest reqFTP;
+            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + "/" + filename));
+            reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
+            reqFTP.UseBinary = true;
+            reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPwd);
+
+            FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+
+            Stream ftpStream = response.GetResponseStream();
+
+            List<byte> buf = new List<byte>();
+            while (ftpStream.ReadByte() != -1)
+            {
+                buf.Add((byte)ftpStream.ReadByte());
+            }
+            ftpStream.Close();
+            return buf.ToArray().Length * 2;
+        }
+
+
         /// <summary>
         /// 获取ftp服务器上的文件信息
         /// </summary>

Some files were not shown because too many files changed in this diff