关于报表取枚举名称clr函数GetEnumName报错问题

by 马杰 2012.8.17 14:45

注:脚本执行有风险,对于客户正式环境请在研发指导下执行。

 

  如果报错为F_GetEnumName,Error 那么确定为加载的枚举项中存在多语言信息丢失的问题,需要补下多语言信息

 

注意:不是当前的多语项丢失,而在存在丢失的项所以报错!

 

       string retval = null;
            try
            {
                EnumValueStoreInstance evsi = DataStore.ExtEnumValueTable;
                retval = (string)evsi.GetDisplayName( Code, Evalue, SysMLFlag);
                return retval;
            }
            catch (Exception e)
            {
                return "<<F_GetEnumName,Error>>";
            }

 

补上杨砚的分析:

private void LoadTypeData()
{
    this.EnumTypeList
= new SortedList<string, EnumTypeInfo>(0xbb8, StringComparer.OrdinalIgnoreCase);
    this.BlackList
= new SortedList<string, long>();
    try
    {
        this.EnumValueCount
= 0;
        using (SqlConnection connection = new SqlConnection(Constant.ConnStr))
        {
            connection.Open();
            SqlDataReader reader = new SqlCommand("select b.Code, b.ID , COUNT(*) as c  from UBF_Sys_ExtEnumValue as a  left join UBF_Sys_ExtEnumType as b on ( a.ExtEnumType = b.ID )  group by b.Code ,b.ID order by Code", connection).ExecuteReader();
            using (reader)
            {
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0))
                    {
                        string key = reader.GetString(0);
                        EnumTypeInfo info = new EnumTypeInfo();
                        info.ID = reader.GetInt64(1);
                        info.Count = reader.GetInt32(2);
                        this.EnumTypeList.Add(key, info);
                        if (info.Count >= 200)
                        {
                            this.BlackList.Add(key, info.ID);
                            BlackEnumCacheUnit unit = new BlackEnumCacheUnit();
                            if (this._BlackEnumValueCache == null)
                            {
                                this._BlackEnumValueCache = new SortedDictionary<long, BlackEnumCacheUnit>();
                            }
                            this._BlackEnumValueCache.Add(info.ID, unit);
                        }
                        else
                        {
                            this.EnumValueCount += info.Count;
                        }
                    }
                }
            }
        }
    }
上面标黄色部分的代码,是取出所有枚举类型的枚举项个数。
 
这段代码是根据上一步得出的个数,一次性加载后,逐一遍历枚举项。因此在执行F_GetEnumName(xxx,’5141’) 取5141这项时空引用,而是中间某一项为空,导致空引用异常。
客户现场没办法调试,猜测解决。解决之后,仔细看了看杨历发的邮件,问题差不多,但也有不同,之前邮件说的是出错的那项枚举信息为空,而实际上只要有空值,都可能发生异常。主要是因为一次性加载。

 

评论 (3) -

gclub wrote at 2019/8/7 12:44:28 #

Thank you to this amazing and quality website that has a lot of knowledge for us all the time.
https://www.gclub45.com/

gclub-royal1688 wrote at 2019/8/7 12:45:02 #

Thank you for the great information that has many new knowledge available to us all the time from the best websites.
https://www.gclub-royal1688.com/

ducklife wrote at 2019/8/22 15:02:27 #

I appreciate it !. I really like it when people are together and sharing ideas. Great site, keep up the good work !. Either way, the web is great and I look forward to seeing it grow over time. Thanks very much.

https://templerun.co

添加评论



biuquote
微笑得意调皮害羞酷大笑惊讶发呆喜欢可怜尴尬闭嘴噘嘴皱眉伤心抓狂呕吐坏笑漫骂发怒
Loading


RecentComments

评论 RSS

Statistics

989 篇文章
0 个单页
644961 条评论
11 次评分
203138 次访问
访问统计开始于 2019年12月15日
平均日访问 5345 次
当前 132 人在线