182 lines
		
	
	
		
			6.0 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			182 lines
		
	
	
		
			6.0 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System; | |||
|  | using System.Collections.Generic; | |||
|  | using System.Collections; | |||
|  | using System.Data; | |||
|  | using System.Data.OleDb; | |||
|  | using System.IO; | |||
|  | using System.Security.Cryptography; | |||
|  | using System.Text; | |||
|  | using System.Diagnostics; | |||
|  | using System.Reflection; | |||
|  | using System.Web; | |||
|  |   | |||
|  |   | |||
|  | 
 | |||
|  | 
 | |||
|  | namespace DeiNiu.Utils | |||
|  | { | |||
|  | 
 | |||
|  |     public enum enumLabelPickType { pick = 0, seed, tran } | |||
|  |     public class Util | |||
|  |     { | |||
|  |         public static string Encrypt(string password)//<2F><><EFBFBD>ܺ<EFBFBD><DCBA><EFBFBD> | |||
|  |         { | |||
|  |             Byte[] clearBytes = new UnicodeEncoding().GetBytes(password); | |||
|  |             Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes); | |||
|  |             return BitConverter.ToString(hashedBytes); | |||
|  |         } | |||
|  |         | |||
|  |         /// <summary> | |||
|  |         /// <20><><EFBFBD><EFBFBD>in sql,return like " 1,2,3" | |||
|  |         /// </summary> | |||
|  |         /// <param name="al"></param> | |||
|  |         /// <returns></returns> | |||
|  |         public static string buildWhereIntIn(ArrayList al) | |||
|  |         { | |||
|  |             string whereString = string.Empty; | |||
|  | 
 | |||
|  |             for (int i = 0; i < al.Count; i++) | |||
|  |             { | |||
|  |                 whereString += "'"+ al[i] + "',"; | |||
|  |             } | |||
|  |             if (whereString.EndsWith(",")) | |||
|  |             { | |||
|  |                 whereString = whereString.Substring(0, whereString.Length - 1); | |||
|  |             } | |||
|  |             return whereString; | |||
|  |         } | |||
|  | 
 | |||
|  |         public static DataSet Excel2DataSet(string filepath) | |||
|  |         { | |||
|  |             DataSet ds = new DataSet(); | |||
|  |             ArrayList SheeNames = ExcelSheetName(filepath); | |||
|  |             for(int i=0;i<SheeNames.Count;i++) | |||
|  |             { | |||
|  |                 DataTable dt = (ExcelDataSource(filepath, SheeNames[i].ToString())).Tables[0].Copy(); | |||
|  |                 dt.TableName = SheeNames[i].ToString(); | |||
|  |                 dt.TableName = dt.TableName.Substring(0, dt.TableName.IndexOf("$")); | |||
|  |                 ds.Tables.Add(dt);  | |||
|  |             } | |||
|  |             return ds; | |||
|  |         } | |||
|  |         //<2F>÷<EFBFBD><C3B7><EFBFBD>ʵ<EFBFBD>ִ<EFBFBD>Excel<65>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>DataSet<65>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD>filepathΪExcel<65>ļ<EFBFBD><C4BC>ľ<EFBFBD><C4BE><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD> sheetnameΪexcel<65>ļ<EFBFBD><C4BC>еı<D0B5><C4B1><EFBFBD> | |||
|  |         public static DataSet ExcelDataSource(string filepath, string sheetname) | |||
|  |         { | |||
|  |             string strConn; | |||
|  |             strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=Excel 8.0;"; | |||
|  |             OleDbConnection conn = new OleDbConnection(strConn); | |||
|  |             OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetname + "]", strConn); | |||
|  |             DataSet ds = new DataSet(); | |||
|  |             oada.Fill(ds); | |||
|  |             conn.Close(); | |||
|  |             return ds; | |||
|  |         } | |||
|  | 
 | |||
|  |         //<2F><><EFBFBD><EFBFBD>Excel<65>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>sheetname<6D><65> | |||
|  |         public static ArrayList ExcelSheetName(string filepath) | |||
|  |         { | |||
|  |             ArrayList al = new ArrayList(); | |||
|  |             string strConn; | |||
|  |             strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=Excel 8.0;"; | |||
|  |             OleDbConnection conn = new OleDbConnection(strConn); | |||
|  |             conn.Open(); | |||
|  |             DataTable sheetNames = conn.GetOleDbSchemaTable | |||
|  |             (System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); | |||
|  |             conn.Close(); | |||
|  |             foreach (DataRow dr in sheetNames.Rows) | |||
|  |             { | |||
|  |                 al.Add(dr[2]); | |||
|  |             } | |||
|  |             return al; | |||
|  |         } | |||
|  | 
 | |||
|  |         public<EFBFBD><EFBFBD>static<EFBFBD><EFBFBD>DataView<EFBFBD><EFBFBD>GetTopDataViewRows(DataView<EFBFBD><EFBFBD>dv,<EFBFBD><EFBFBD>int<EFBFBD><EFBFBD>n) | |||
|  | <EFBFBD><EFBFBD>  <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{ | |||
|  | <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DataTable<EFBFBD><EFBFBD>dt<EFBFBD><EFBFBD>=<EFBFBD><EFBFBD>dv.Table.Clone(); | |||
|  | <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> | |||
|  | <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>for<EFBFBD><EFBFBD>(int<EFBFBD><EFBFBD>i<EFBFBD><EFBFBD>=<EFBFBD><EFBFBD>0;<EFBFBD><EFBFBD>i<EFBFBD><EFBFBD><<EFBFBD><EFBFBD>n<EFBFBD><EFBFBD>-<EFBFBD><EFBFBD>1;<EFBFBD><EFBFBD>i++) | |||
|  | <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{ | |||
|  | <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>if<EFBFBD><EFBFBD>(i<EFBFBD><EFBFBD>>=<EFBFBD><EFBFBD>dv.Count) | |||
|  | <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{ | |||
|  | <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>break; | |||
|  |  <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>} | |||
|  |  <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dt.ImportRow(dv[i].Row); | |||
|  |  <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> } | |||
|  |  <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>return<EFBFBD><EFBFBD>new<EFBFBD><EFBFBD>DataView(dt,<EFBFBD><EFBFBD>dv.RowFilter,<EFBFBD><EFBFBD>dv.Sort,<EFBFBD><EFBFBD> dv.RowStateFilter); | |||
|  |  <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>} | |||
|  | 
 | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD>ֵ | |||
|  |         /// </summary> | |||
|  |         /// <param name="key">appSettings<67><73>key</param> | |||
|  |         /// <returns>appSettings<67><73>Value</returns> | |||
|  |         //public static string GetConfig(string key) | |||
|  |         //{ | |||
|  |             //string _value = string.Empty; | |||
|  |             //System.Configuration.ConfigurationManager  config =  System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); | |||
|  |             //if (config.AppSettings.Settings[key] != null) | |||
|  |             //{ | |||
|  |             //    _value = config.AppSettings.Settings[key].Value; | |||
|  |             //} | |||
|  |             //return _value; | |||
|  |         //} | |||
|  | 
 | |||
|  | 
 | |||
|  |         //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA> | |||
|  |         public static string getCode128(string codeIn) | |||
|  |         { | |||
|  |             //string str =""; | |||
|  |             string result; | |||
|  |             int checksum = 104; | |||
|  |             for (int i = 0; i < codeIn.Length; i++) | |||
|  |             { | |||
|  |                 if (codeIn[i] >= 32) | |||
|  |                 { | |||
|  |                     checksum += (codeIn[i] - 32) * (i + 1); | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     checksum += (codeIn[i] + 64) * (i + 1); | |||
|  |                 } | |||
|  |             } | |||
|  |             checksum = checksum % 103; | |||
|  |             if (checksum < 95) | |||
|  |             { | |||
|  |                 checksum += 32; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 checksum += 100; | |||
|  |             } | |||
|  |             result = Convert.ToChar(204) + codeIn + | |||
|  |             Convert.ToChar(checksum) + Convert.ToChar(206); | |||
|  |             return result; | |||
|  |         } | |||
|  | 
 | |||
|  | 
 | |||
|  |          | |||
|  | 
 | |||
|  |         public static string getLightKey(int color,int labelId, int address) | |||
|  |         { | |||
|  |             return string.Format("{0}-{1}-{2}", color, labelId, address); | |||
|  |         } | |||
|  | 
 | |||
|  |         public static Dictionary<int,string> convertEnumToDic(Type enumType){ | |||
|  | 
 | |||
|  |             Dictionary<int, string> dic = new Dictionary<int, string>(); | |||
|  |             foreach (int myCode in Enum.GetValues(enumType)) | |||
|  |             { | |||
|  |                 string strName = Enum.GetName(enumType, myCode);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD> | |||
|  |                 string strVaule = myCode.ToString();//<2F><>ȡֵ | |||
|  |                 dic[myCode] = strName; | |||
|  |                 | |||
|  |             } | |||
|  | 
 | |||
|  |             return dic; | |||
|  |     } | |||
|  |         public static Dictionary<string, bool> WAVE_CURRENT_PICK_STATUS = new Dictionary<string, bool>(); | |||
|  |         public static Dictionary<string, bool> WAVE_CURRENT_LIGHTS_STATUS = new Dictionary<string, bool>(); | |||
|  |     } | |||
|  | } |