|
|
@@ -3,11 +3,12 @@ using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
using System.Text;
|
|
|
-using System.Text.RegularExpressions;
|
|
|
using System.Windows.Forms;
|
|
|
using UAS_LabelMachine.CustomControl;
|
|
|
using UAS_LabelMachine.CustomControl.GroupBoxWithBorder;
|
|
|
+using System.Security.Cryptography;
|
|
|
using static System.Windows.Forms.Control;
|
|
|
+using System.IO;
|
|
|
|
|
|
namespace UAS_LabelMachine
|
|
|
{
|
|
|
@@ -16,6 +17,8 @@ namespace UAS_LabelMachine
|
|
|
|
|
|
static string SysDisc;
|
|
|
|
|
|
+ private string Key = "96878265";
|
|
|
+
|
|
|
public static string SysDisc1
|
|
|
{
|
|
|
get
|
|
|
@@ -29,6 +32,213 @@ namespace UAS_LabelMachine
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static byte[] hexStr2ByteArr(string strIn)
|
|
|
+ {
|
|
|
+ byte[] arrB = Encoding.UTF8.GetBytes(strIn);
|
|
|
+ int iLen = arrB.Length;
|
|
|
+ // 两个字符表示一个字节,所以字节数组长度是字符串长度除以2
|
|
|
+ byte[] arrOut = new byte[iLen / 2];
|
|
|
+ for (int i = 0; i < iLen; i = i + 2)
|
|
|
+ {
|
|
|
+ string strTmp = new string(Encoding.UTF8.GetChars(arrB), i, 2);
|
|
|
+ arrOut[i / 2] = (byte)int.Parse(strTmp, System.Globalization.NumberStyles.HexNumber);
|
|
|
+ }
|
|
|
+ return arrOut;
|
|
|
+ }
|
|
|
+
|
|
|
+ public byte[] decrypt(byte[] arrB)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ //return decryptCipher.doFinal(arrB);
|
|
|
+ }
|
|
|
+
|
|
|
+ public string decrypt(string strIn)
|
|
|
+ {
|
|
|
+ return new string(Encoding.ASCII.GetChars(decrypt(hexStr2ByteArr(strIn))));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static string DESEnCode(string pToEncrypt, string sKey)
|
|
|
+ {
|
|
|
+ // string pToEncrypt1 = HttpContext.Current.Server.UrlEncode(pToEncrypt);
|
|
|
+ DESCryptoServiceProvider des = new DESCryptoServiceProvider();
|
|
|
+ byte[] inputByteArray = Encoding.GetEncoding("UTF-8").GetBytes(pToEncrypt);
|
|
|
+
|
|
|
+ //建立加密对象的密钥和偏移量
|
|
|
+ //原文使用ASCIIEncoding.ASCII方法的GetBytes方法
|
|
|
+ //使得输入密码必须输入英文文本
|
|
|
+ des.Key = Encoding.UTF8.GetBytes(sKey);
|
|
|
+ des.IV = Encoding.UTF8.GetBytes(sKey);
|
|
|
+ MemoryStream ms = new MemoryStream();
|
|
|
+ CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
|
|
|
+
|
|
|
+ cs.Write(inputByteArray, 0, inputByteArray.Length);
|
|
|
+ cs.FlushFinalBlock();
|
|
|
+
|
|
|
+ StringBuilder ret = new StringBuilder();
|
|
|
+ foreach (byte b in ms.ToArray())
|
|
|
+ {
|
|
|
+ ret.AppendFormat("{0:X2}", b);
|
|
|
+ }
|
|
|
+ ret.ToString();
|
|
|
+ return ret.ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static string DESDeCode(string pToDecrypt, string sKey)
|
|
|
+ {
|
|
|
+ DESCryptoServiceProvider des = new DESCryptoServiceProvider();
|
|
|
+
|
|
|
+ byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
|
|
|
+ for (int x = 0; x < pToDecrypt.Length / 2; x++)
|
|
|
+ {
|
|
|
+ int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
|
|
|
+ inputByteArray[x] = (byte)i;
|
|
|
+ }
|
|
|
+ des.Key = Encoding.UTF8.GetBytes(sKey);
|
|
|
+ des.IV = Encoding.UTF8.GetBytes(sKey);
|
|
|
+ MemoryStream ms = new MemoryStream();
|
|
|
+ CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
|
|
|
+ cs.Write(inputByteArray, 0, inputByteArray.Length);
|
|
|
+ cs.FlushFinalBlock();
|
|
|
+
|
|
|
+ return Encoding.UTF8.GetString(ms.ToArray());
|
|
|
+ }
|
|
|
+
|
|
|
+ public static byte[] Des3EncodeCBC(byte[] key, byte[] iv, byte[] data)
|
|
|
+ {
|
|
|
+ //复制于MSDN
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // Create a MemoryStream.
|
|
|
+ MemoryStream mStream = new MemoryStream();
|
|
|
+ TripleDESCryptoServiceProvider tdsp = new TripleDESCryptoServiceProvider();
|
|
|
+ tdsp.Mode = CipherMode.CBC; //默认值
|
|
|
+ tdsp.Padding = PaddingMode.PKCS7; //默认值
|
|
|
+ // Create a CryptoStream using the MemoryStream
|
|
|
+ // and the passed key and initialization vector (IV).
|
|
|
+ CryptoStream cStream = new CryptoStream(mStream,
|
|
|
+ tdsp.CreateEncryptor(key, iv),
|
|
|
+ CryptoStreamMode.Write);
|
|
|
+ // Write the byte array to the crypto stream and flush it.
|
|
|
+ cStream.Write(data, 0, data.Length);
|
|
|
+ cStream.FlushFinalBlock();
|
|
|
+ // Get an array of bytes from the
|
|
|
+ // MemoryStream that holds the
|
|
|
+ // encrypted data.
|
|
|
+ byte[] ret = mStream.ToArray();
|
|
|
+ // Close the streams.
|
|
|
+ cStream.Close();
|
|
|
+ mStream.Close();
|
|
|
+ // Return the encrypted buffer.
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ catch (CryptographicException e)
|
|
|
+ {
|
|
|
+ Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// DES3 CBC模式解密
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="key">密钥</param>
|
|
|
+ /// <param name="iv">IV</param>
|
|
|
+ /// <param name="data">密文的byte数组</param>
|
|
|
+ /// <returns>明文的byte数组</returns>
|
|
|
+ public static byte[] Des3DecodeCBC(byte[] key, byte[] iv, byte[] data)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // Create a new MemoryStream using the passed
|
|
|
+ // array of encrypted data.
|
|
|
+ MemoryStream msDecrypt = new MemoryStream(data);
|
|
|
+ TripleDESCryptoServiceProvider tdsp = new TripleDESCryptoServiceProvider();
|
|
|
+ tdsp.Mode = CipherMode.CBC;
|
|
|
+ tdsp.Padding = PaddingMode.PKCS7;
|
|
|
+ // Create a CryptoStream using the MemoryStream
|
|
|
+ // and the passed key and initialization vector (IV).
|
|
|
+ CryptoStream csDecrypt = new CryptoStream(msDecrypt, tdsp.CreateDecryptor(key, iv), CryptoStreamMode.Read);
|
|
|
+ // Create buffer to hold the decrypted data.
|
|
|
+ byte[] fromEncrypt = new byte[data.Length];
|
|
|
+ // Read the decrypted data out of the crypto stream
|
|
|
+ // and place it into the temporary buffer.
|
|
|
+ csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
|
|
|
+ //Convert the buffer into a string and return it.
|
|
|
+ return fromEncrypt;
|
|
|
+ }
|
|
|
+ catch (CryptographicException e)
|
|
|
+ {
|
|
|
+ Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// DES3 ECB模式加密
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="key">密钥</param>
|
|
|
+ /// <param name="iv">IV(当模式为ECB时,IV无用)</param>
|
|
|
+ /// <param name="str">明文的byte数组</param>
|
|
|
+ /// <returns>密文的byte数组</returns>
|
|
|
+ public static byte[] Des3EncodeECB(byte[] key, byte[] iv, byte[] data)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // Create a MemoryStream.
|
|
|
+ MemoryStream mStream = new MemoryStream();
|
|
|
+ TripleDESCryptoServiceProvider tdsp = new TripleDESCryptoServiceProvider();
|
|
|
+ tdsp.Mode = CipherMode.ECB;
|
|
|
+ tdsp.Padding = PaddingMode.PKCS7;
|
|
|
+ // Create a CryptoStream using the MemoryStream
|
|
|
+ // and the passed key and initialization vector (IV).
|
|
|
+ CryptoStream cStream = new CryptoStream(mStream, tdsp.CreateEncryptor(key, iv), CryptoStreamMode.Write);
|
|
|
+ // Write the byte array to the crypto stream and flush it.
|
|
|
+ cStream.Write(data, 0, data.Length);
|
|
|
+ cStream.FlushFinalBlock();
|
|
|
+ // Get an array of bytes from the
|
|
|
+ // MemoryStream that holds the
|
|
|
+ // encrypted data.
|
|
|
+ byte[] ret = mStream.ToArray();
|
|
|
+ // Close the streams.
|
|
|
+ cStream.Close();
|
|
|
+ mStream.Close();
|
|
|
+ // Return the encrypted buffer.
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ catch (CryptographicException e)
|
|
|
+ {
|
|
|
+ Console.WriteLine("A Cryptographic error occurred: {0}", e.Message);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// DES3 ECB模式解密
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="key">密钥</param>
|
|
|
+ /// <param name="iv">IV(当模式为ECB时,IV无用)</param>
|
|
|
+ /// <param name="str">密文的byte数组</param>
|
|
|
+ /// <returns>明文的byte数组</returns>
|
|
|
+ public static byte[] Des3DecodeECB(byte[] key, byte[] iv, byte[] data)
|
|
|
+ {
|
|
|
+
|
|
|
+ // Create a new MemoryStream using the passed
|
|
|
+ // array of encrypted data.
|
|
|
+ MemoryStream msDecrypt = new MemoryStream(data);
|
|
|
+ TripleDESCryptoServiceProvider tdsp = new TripleDESCryptoServiceProvider();
|
|
|
+ tdsp.Mode = CipherMode.ECB;
|
|
|
+ tdsp.Padding = PaddingMode.PKCS7;
|
|
|
+ // Create a CryptoStream using the MemoryStream
|
|
|
+ // and the passed key and initialization vector (IV).
|
|
|
+ CryptoStream csDecrypt = new CryptoStream(msDecrypt, tdsp.CreateDecryptor(key, iv), CryptoStreamMode.Read);
|
|
|
+ // Create buffer to hold the decrypted data.
|
|
|
+ byte[] fromEncrypt = new byte[data.Length];
|
|
|
+ // Read the decrypted data out of the crypto stream
|
|
|
+ // and place it into the temporary buffer.
|
|
|
+ csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
|
|
|
+ //Convert the buffer into a string and return it.
|
|
|
+ return fromEncrypt;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/// <summary>
|
|
|
/// 通过DataTable的ColumnName和Caption来拼接一条语句
|
|
|
@@ -41,7 +251,6 @@ namespace UAS_LabelMachine
|
|
|
DataTable dt = (DataTable)d.DataSource;
|
|
|
if (dt == null)
|
|
|
{
|
|
|
- Console.WriteLine("为空");
|
|
|
foreach (DataGridViewColumn dc in d.Columns)
|
|
|
{
|
|
|
if (dc.DataPropertyName != "" && dc.DataPropertyName != null)
|
|
|
@@ -52,15 +261,11 @@ namespace UAS_LabelMachine
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Console.WriteLine("不为空");
|
|
|
- Console.WriteLine(dt.Columns.Count);
|
|
|
foreach (DataColumn dc in dt.Columns)
|
|
|
{
|
|
|
- Console.WriteLine(dc.Caption);
|
|
|
selectConetnt.Append(dc.Caption + " as " + dc.ColumnName + ",");
|
|
|
}
|
|
|
}
|
|
|
- Console.WriteLine(selectConetnt);
|
|
|
return selectConetnt.Remove(selectConetnt.Length - 1, 1).ToString();
|
|
|
}
|
|
|
/// <summary>
|
|
|
@@ -187,15 +392,16 @@ namespace UAS_LabelMachine
|
|
|
/// <param name="URL"></param>
|
|
|
/// <param name="LabelName"></param>
|
|
|
/// <returns></returns>
|
|
|
- public static string GetLabelUrl(string URL, string LabelName,DateTime time)
|
|
|
+ public static string GetLabelUrl(string URL, string LabelName, DateTime time)
|
|
|
{
|
|
|
//如果是传入的数据是从FTP取的文件
|
|
|
if (URL.Contains("ftp:"))
|
|
|
{
|
|
|
ftpOperater ftp = new ftpOperater();
|
|
|
- return ftp.Download(LabelName,time);
|
|
|
+ return ftp.Download(LabelName, time);
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
return URL;
|
|
|
}
|
|
|
}
|
|
|
@@ -228,7 +434,8 @@ namespace UAS_LabelMachine
|
|
|
}
|
|
|
}
|
|
|
//否则直接获取全部的数据
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
for (int i = 0; i < dgv.RowCount; i++)
|
|
|
{
|
|
|
for (int j = 0; j < ColumnName.Length; j++)
|
|
|
@@ -522,7 +729,8 @@ namespace UAS_LabelMachine
|
|
|
{
|
|
|
condition += "(" + Condition[i].Tag + " like " + "'%" + (Condition[i] as ComboBox).SelectedValue + "%' or " + Condition[i].Tag + " is null) and ";
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
condition += "(" + Condition[i].Tag + " like " + "'%" + Condition[i].Text + "%' or " + Condition[i].Tag + " is null) and ";
|
|
|
}
|
|
|
}
|
|
|
@@ -532,7 +740,8 @@ namespace UAS_LabelMachine
|
|
|
{
|
|
|
condition += "(" + Condition[i].Tag + " like " + "'%" + (Condition[i] as ComboBox).SelectedValue + "%' or " + Condition[i].Tag + " is null)";
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
condition += "(" + Condition[i].Tag + " like " + "'%" + Condition[i].Text + "%' or " + Condition[i].Tag + " is null)";
|
|
|
}
|
|
|
}
|