532 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			532 lines
		
	
	
		
			14 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 op_flag { add = 1, update, delete, getObj, queryAll, queryExample,queryActived,getPk, getCount}; 
 | ||
| //    public enum ProjectStatus { 新增未提交, 新增待预审, 新增预审通过, 新增预审未通过, 新增审核通过, 新增审核未通过, 新增考核通过, 新增考核未通过,删减未提交,删减待预审,删减预审通过,删减预审未通过,删减审核通过,删减审核未通过,删减考核通过,删减考核未通过,项目完成 };
 | ||
|     public enum FileType {Project,ProjectDetail,半年度总结,年度总结,半年度计划,年度计划 };
 | ||
|     public struct ProjectDetailStatus
 | ||
|     {
 | ||
|         public static string 审核未通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "审核未通过";
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         public static string 考核通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "考核通过";
 | ||
|             }
 | ||
|         }
 | ||
|         public static string 考核未通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "考核未通过";
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         public static string 月度未提交
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "月度未提交";
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         public static string 月度已提交
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "月度已提交";
 | ||
|             }
 | ||
|         }
 | ||
|         public static string 待预审
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "待预审";
 | ||
|             }
 | ||
|         }
 | ||
|         public static string 预审通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "预审通过";
 | ||
|             }
 | ||
|         }
 | ||
|         public static string 预审未通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "预审未通过";
 | ||
|             }
 | ||
|         }
 | ||
|         public static string 审核通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "审核通过";
 | ||
|             }
 | ||
|         }
 | ||
|     }
 | ||
|     public struct ApproveRoles
 | ||
|     {
 | ||
|         public static string YuShen
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "项目预审";
 | ||
|             }
 | ||
|         }
 | ||
|         public static string ShenHe
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "项目审核";
 | ||
|             }
 | ||
|         }
 | ||
|         public static string KaoHe
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "项目考核";
 | ||
|             }
 | ||
|         }
 | ||
|         public static string 项目维护
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "项目维护";
 | ||
|             }
 | ||
|         }
 | ||
|     }
 | ||
|     public struct ProjectStatus
 | ||
|     {
 | ||
| 
 | ||
|         public static string 项目已分配
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "项目已分配";
 | ||
|             }
 | ||
|         }
 | ||
|         public static string 项目未分配
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "项目未分配";
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         public static string 新增未提交
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "新增未提交";
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         public static string 新增已提交
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "新增已提交";
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|          public static string 新增考核通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "新增考核通过";
 | ||
|             }
 | ||
|         }
 | ||
|         public static string 项目冻结
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "项目冻结";
 | ||
|             }
 | ||
|         }
 | ||
|         public static string 项目解冻
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "项目解冻";
 | ||
|             }
 | ||
|         }
 | ||
|          public static string 新增审核通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "新增审核通过";
 | ||
|             }
 | ||
|         }
 | ||
|             public static string 新增审核未通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "新增审核未通过";
 | ||
|             }
 | ||
|         }
 | ||
|          public static string 新增预审未通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "新增预审未通过";
 | ||
|             }
 | ||
|         }
 | ||
|          public static string 新增预审通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "新增预审通过";
 | ||
|             }
 | ||
|         }
 | ||
|         
 | ||
| 
 | ||
|           public static string 删减审核未通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "删减审核未通过";
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|          public static string 删减审核通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "删减审核通过";
 | ||
|             }
 | ||
|         }
 | ||
|          public static string 删减预审未通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "删减预审未通过";
 | ||
|             }
 | ||
|         }
 | ||
|             public static string 删减预审通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "删减预审通过";
 | ||
|             }
 | ||
|         }
 | ||
|        
 | ||
|          public static string 删减未提交
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "删减未提交";
 | ||
|             }
 | ||
|         }
 | ||
|         public static string 删减已提交
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "删减已提交";
 | ||
|             }
 | ||
|         }
 | ||
|          public static string 新增考核未通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "新增考核未通过";
 | ||
|             }
 | ||
|         }
 | ||
|             public static string 项目完成
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "项目完成";
 | ||
|             }
 | ||
|         }
 | ||
|         public static string 项目未完成
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "项目未完成";
 | ||
|             }
 | ||
|         }
 | ||
|          public static string 删减考核未通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "删减考核未通过";
 | ||
|             }
 | ||
|         }
 | ||
|          public static string 删减考核通过
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "删减考核通过";
 | ||
|             }
 | ||
|         }  
 | ||
|     }
 | ||
| 
 | ||
|     public struct appScope
 | ||
|     {
 | ||
|         /// <summary>
 | ||
|         /// used for  storing logic object in session
 | ||
|         /// when page changes in server side, logic object in session
 | ||
|         /// will be replaced by new one.
 | ||
|         /// </summary>
 | ||
|         public static string PagelevelObj
 | ||
|         {
 | ||
|             get
 | ||
|             {
 | ||
|                 return "PageLevelObj";
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|       
 | ||
|     }
 | ||
| 
 | ||
|     public class MyTracer
 | ||
|     {
 | ||
|         private static TraceSwitch appSwitch = new TraceSwitch("TraceSwitch", "Switch in config file");
 | ||
| 
 | ||
|         private static string render(object clz, string msg)
 | ||
|         {
 | ||
|             //time
 | ||
|             StringBuilder sb = new StringBuilder();
 | ||
|             DateTime dt = DateTime.Now;
 | ||
|             sb.Append(dt.ToLongDateString()).Append(" ").Append(dt.ToLongTimeString()).Append(" - ");
 | ||
|             
 | ||
|             
 | ||
|             StackTrace stackTrace = new StackTrace();
 | ||
|             StackFrame stackFrame = stackTrace.GetFrame(2);
 | ||
| 
 | ||
|             //class name
 | ||
|             sb.Append(clz.GetType().FullName).Append(" [");
 | ||
|             
 | ||
|             //method name
 | ||
|             MethodBase methodBase = stackFrame.GetMethod();
 | ||
| 
 | ||
|             sb.Append(methodBase.Name).Append("] ");
 | ||
| 
 | ||
|             //the msg
 | ||
|             sb.Append(msg);
 | ||
| 
 | ||
|             return sb.ToString();
 | ||
|             
 | ||
|         }
 | ||
|         public static void Error(object clz, string msg)
 | ||
|         {
 | ||
|             Trace.WriteLineIf(appSwitch.TraceError, render(clz, "[ERROR] " + msg));
 | ||
|         }
 | ||
|         public static void Warning(object clz, string msg)
 | ||
|         {
 | ||
|             Trace.WriteLineIf(appSwitch.TraceWarning, render(clz, "[WARNING] " + msg));
 | ||
|         }
 | ||
|         public static void Info(object clz, string msg)
 | ||
|         {
 | ||
|             Trace.WriteLineIf(appSwitch.TraceInfo, render(clz, "[INFO] " + msg));
 | ||
|         }
 | ||
|         public static void Verbose(object clz, string msg)
 | ||
|         {
 | ||
|             Trace.WriteLineIf(appSwitch.TraceVerbose, render(clz, "[VERBOSE] " + msg));
 | ||
|         }
 | ||
|     }
 | ||
| 
 | ||
|     public class Util
 | ||
|     {
 | ||
|         public static string Encrypt(string password)//加密函数
 | ||
|         {
 | ||
|             Byte[] clearBytes = new UnicodeEncoding().GetBytes(password);
 | ||
|             Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
 | ||
|             return BitConverter.ToString(hashedBytes);
 | ||
|         }
 | ||
|        
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 组合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;
 | ||
|         }
 | ||
|         //该方法实现从Excel中导出数据到DataSet中,其中filepath为Excel文件的绝对路径, sheetname为excel文件中的表名
 | ||
|         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;
 | ||
|         }
 | ||
| 
 | ||
|         //获得Excel中的所有sheetname。
 | ||
|         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 static DataView GetTopDataViewRows(DataView dv, int n)
 | ||
|         {
 | ||
|            DataTable dt = dv.Table.Clone();
 | ||
|    
 | ||
|            for (int i = 0; i < n - 1; i++)
 | ||
|            {
 | ||
|                if (i >= dv.Count)
 | ||
|                {
 | ||
|                    break;
 | ||
|               }
 | ||
|               dt.ImportRow(dv[i].Row);
 | ||
|            }
 | ||
|          return new DataView(dt, dv.RowFilter, dv.Sort,  dv.RowStateFilter);
 | ||
|       }
 | ||
| 
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 读取配置文件某项的值
 | ||
|         /// </summary>
 | ||
|         /// <param name="key">appSettings的key</param>
 | ||
|         /// <returns>appSettings的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;
 | ||
|         //}
 | ||
| 
 | ||
| 
 | ||
|         //条形码转换
 | ||
|         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 getOrderNo(enumCreateOrderType orderType,int seq)
 | ||
|         {
 | ||
|             string prefix = "UN";
 | ||
|             switch (orderType)
 | ||
|             {
 | ||
|                 case enumCreateOrderType.repOrderIn:
 | ||
|                     prefix = "RPI";
 | ||
|                     break;
 | ||
|                 
 | ||
|                     
 | ||
|             }
 | ||
| 
 | ||
|             return string.Format("{0}{1:D2}{2:D10}",prefix,DateTime.Now.Month,seq);
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         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);//获取名称
 | ||
|                 string strVaule = myCode.ToString();//获取值
 | ||
|                 dic[myCode] = strName;
 | ||
|                
 | ||
|             }
 | ||
| 
 | ||
|             return dic;
 | ||
|     }
 | ||
| 
 | ||
| 
 | ||
|     }
 | ||
| }
 |