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
    {
        /// 
        /// used for  storing logic object in session
        /// when page changes in server side, logic object in session
        /// will be replaced by new one.
        /// 
        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);
        }
       
        /// 
        /// 组合in sql,return like " 1,2,3"
        /// 
        /// 
        /// 
        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= dv.Count)
               {
                   break;
              }
              dt.ImportRow(dv[i].Row);
           }
         return new DataView(dt, dv.RowFilter, dv.Sort,  dv.RowStateFilter);
      }
        /// 
        /// 读取配置文件某项的值
        /// 
        /// appSettings的key
        /// appSettings的Value
        //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 convertEnumToDic(Type enumType){
            Dictionary dic = new Dictionary();
            foreach (int myCode in Enum.GetValues(enumType))
            {
                string strName = Enum.GetName(enumType, myCode);//获取名称
                string strVaule = myCode.ToString();//获取值
                dic[myCode] = strName;
               
            }
            return dic;
    }
    }
}