My Blog is my notepad, I want to mark my work anytime, also i can share my harvest with everyone....

Teracy 's space--->

I love BS Develop ,So i am busying as a bee.Do more,Know more,you will get more.....

博客园 首页 新随笔 联系 订阅 管理

  /// <summary>
        /// 把字符串格式的Id列表转化为List<int>格式
        /// </summary>
        /// <param name="strList">字符串格式的Id列表</param>
        /// <param name="listSeparator">分隔符</param>
        /// <returns></returns>
        public static List<int> GetIntListFromString(string strList, char listSeparator)
        {
            List<int> list = new List<int>();

            string[] temp = strList.Split(new char[] { listSeparator });

            foreach (string str in temp)
            {
                int n;
                if (int.TryParse(str, out n) == false)
                    continue;

                list.Add(n);
            }

            return list;
        }

        /// <summary>
        /// 把int列表转换为字符串列表
        /// </summary>
        /// <param name="list">int列表</param>
        public static string GetStringFromIntList(List<int> list)
        {
            string strList = string.Empty;

            foreach (int id in list)
            {
                strList += (strList.Length == 0 ? "" : ",") + id.ToString();
            }

            return strList;
        }

        /// <summary>
        /// Get Client IP from HttpRequest Variables;
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static string GetClientIP(HttpRequest request)
        {
            if (request != null && request.ServerVariables["REMOTE_ADDR"] != null && String.IsNullOrEmpty(Convert.ToString(request.ServerVariables["REMOTE_ADDR"])) == false)
            {
                return request.ServerVariables["REMOTE_ADDR"].ToString().Trim();
            }
            else
            {
                return String.Empty;
            }
        }

        public class EnumItem
        {
            private object m_key;
            private object m_value;

            public object Key
            {
                get { return m_key; }
                set { m_key = value; }
            }

            public object Value
            {
                get { return m_value; }
                set { m_value = value; }
            }

            public EnumItem(object _key, object _value)
            {
                m_key = _key;
                m_value = _value;
            }
        }

        /// <summary>
        /// 获得枚举类型所包含的全部项的列表,不包含"All"(Value: -1)。
        /// </summary>
        /// <param name="enumType">枚举的类型</param>
        /// <returns></returns>
        public static List<EnumItem> GetEnumItems(Type enumType)
        {
            return GetEnumItems(enumType, false);
        }

        /// <summary>
        /// 获得枚举类型所包含的全部项的列表,包含"All"。
        /// </summary>
        /// <param name="enumType">枚举的类型</param>
        /// <returns></returns>
        public static List<EnumItem> GetEnumItemsWithAll(Type enumType)
        {
            return GetEnumItems(enumType, true);
        }

        /// <summary>
        /// 获得枚举类型所包含的全部项的列表。
        /// </summary>
        /// <param name="enumType">枚举的类型</param>
        /// <param name="withAll">是否包含"All"</param>
        /// <returns></returns>
        public static List<EnumItem> GetEnumItems(Type enumType, bool withAll)
        {
            List<EnumItem> list = new List<EnumItem>();

            if (enumType.IsEnum != true)
            {
                // 不是枚举类型
                throw new InvalidOperationException();
            }

            // 包含 All 选项
            if (withAll == true)
                list.Add(new EnumItem(AppConst.IntNull, "All"));

            // 获得特性Description的类型信息
            Type typeDescription = typeof(DescriptionAttribute);

            // 获得枚举的字段信息(因为枚举的值实际上是一个static的字段的值)
            System.Reflection.FieldInfo[] fields = enumType.GetFields();

            // 检索所有字段
            foreach (FieldInfo field in fields)
            {
                // 过滤掉一个不是枚举值的,记录的是枚举的源类型
                if (field.FieldType.IsEnum == false)
                    continue;

                // 通过字段的名字得到枚举的值
                int value = (int)enumType.InvokeMember(field.Name, BindingFlags.GetField, null, null, null);
                string text = string.Empty;

                // 获得这个字段的所有自定义特性,这里只查找Description特性
                object[] arr = field.GetCustomAttributes(typeDescription, true);
                if (arr.Length > 0)
                {
                    // 因为Description自定义特性不允许重复,所以只取第一个
                    DescriptionAttribute aa = (DescriptionAttribute)arr[0];

                    // 获得特性的描述值
                    text = aa.Description;
                }
                else
                {
                    // 如果没有特性描述,那么就显示英文的字段名
                    text = field.Name;
                }
                list.Add(new EnumItem(value, text));
            }

            return list;
        }

        /// <summary>
        /// 获得枚举值对应的描述信息。
        /// </summary>
        /// <param name="enumType">枚举类型</param>
        /// <param name="value">枚举值(int类型)</param>
        /// <returns></returns>
        public static string GetEnumValueDescription(Type enumType, int value)
        {
            List<EnumItem> list = GetEnumItems(enumType);
            foreach (EnumItem item in list)
            {
                if (Convert.ToInt32(item.Key) == value)
                    return item.Value.ToString();
            }
            return string.Empty;
        }

        /// <summary>
        /// 获得枚举值对应的描述信息(适用于位域枚举)。
        /// </summary>
        /// <param name="enumType">枚举类型</param>
        /// <param name="value">枚举值(int类型)</param>
        /// <returns></returns>
        public static string GetFlagEnumValueDescription(Type enumType, int value)
        {
            List<EnumItem> list = GetEnumItems(enumType);
            string descrip = string.Empty;

            foreach (EnumItem item in list)
            {
                if ((Convert.ToInt32(item.Key) & value) > 0)
                    descrip += (descrip.Length > 0 ? "," : "") + item.Value.ToString();
            }

            if (descrip.Length == 0)
                return "无";

            return descrip;
        }

        /// <summary>
        /// 判断是否符合ID的格式(自然数)
        /// </summary>
        /// <param name="number">Id Number</param>
        /// <returns></returns>
        public static bool IsIdNumber(string number)
        {
            throw new Exception("Not Finished.");
        }
        //快钱活动期间设置,为yyyy-mm-dd格式
        public static ArrayList GetFastCashSession()
        {
            ArrayList alFastCashSession = new ArrayList();

            ArrayList al1 = new ArrayList();
            al1.Add("2007-02-07");
            al1.Add("2007-02-17");
            ArrayList al2 = new ArrayList();
            al2.Add("2007-02-26");
            al2.Add("2007-03-14");

            alFastCashSession.Add(al1);
            alFastCashSession.Add(al2);

            return alFastCashSession;
        }
        /// <summary>
        /// 判断是否注册快钱帐户提升新蛋等级 
        /// Created By Shadow | 2007-02-27
        /// </summary>
        /// <returns></returns>
        public static bool IsRegFastCashPromotionRank()
        {
            bool flag = false;
            DateTime dateFrom = new DateTime(2007, 3, 1, 13, 30, 0);
            DateTime dateTo = new DateTime(2007, 4, 23, 13, 30, 0);
            //DateTime dateFrom = new DateTime(2007, 3, 1);
            //DateTime dateTo = new DateTime(2007, 4, 23, 13, 30, 0);
            //判断是否在注册快钱晋级用户级别的活动期间内
            if (DateTime.Now >= dateFrom && DateTime.Now <= dateTo)
            {
                flag = true;
            }
            return flag;
        }

        /// <summary>
        /// 转换 ProductName 里面的 单、双 引号,
        /// 并移除 HTML 标签。
        /// Add By Teracy
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string GetFormatNameForImgAlt(string productName)
        {
            return Util.RemoveHtmlTag(productName.Replace("'", "&rsquo;").Replace("\"", "&quot;"));
        }
        /// <summary>
        /// 用户名有@符号的替换(白颜色)
        /// Add By Teracy
        /// </summary>
        /// <param name="UserName"></param>
        /// <returns></returns>
        public static string FormatCustomerId_Black(string UserName)
        {
            return UserName.Replace("@", "<img src='/WebResources/images/Products/@2.gif' border=0>");
          
        }
        /// <summary>
        /// 用户名有@符号的替换(黑颜色)
        /// Add By Teracy
        /// </summary>
        /// <param name="UserName"></param>
        /// <returns></returns>
        public static string FormatCustomerId_Orange(string UserName)
        {
            return UserName.Replace("@", "<img src='/WebResources/images/Products/@1.gif' border=0>");
        }

posted on 2007-05-11 16:15  Teracy  阅读(246)  评论(0编辑  收藏  举报
One Two Three 向“前”走............
frontpage tracking
Sony Style Coupons