找回密码
 立即注册

QQ登录

只需一步,快速开始

RickyJen
中级会员   /  发表于:2024-7-3 09:00  /   查看:79  /  回复:8
20金币
问题描述:
在Wyn版本:7.0.01209.0 中,我使用了以下帖子的自定义函数,但是当我复制代码进去,并点击编译之后,一直加载编译不结束。
目前不清楚是否所有的自定义函数都会这样
自定义函数地址:


【报表-表达式】巧用自定义函数,实现动态单位
https://gcdn.grapecity.com.cn/showtopic-156044-1-1.html
(出处: 葡萄城开发者社区)



image.png173630370.png

最佳答案

查看完整内容

是的,新的已经修改,是缺少了类型定义。您可以使用以下代码:

8 个回复

倒序浏览
最佳答案
最佳答案
Felix.LiWyn认证
超级版主   /  发表于:4 天前
来自 6#
是的,新的已经修改,是缺少了类型定义。您可以使用以下代码:
  1. /// <function name="AutoFormat">
  2. /// <culture>
  3. /// <label>AutoFormat</label>
  4. /// <syntax>AutoFormat(object number, string unit = "", string format = "")</syntax>
  5. /// <description>自动转换中文单位</description>
  6. /// <example>AutoFormat(100) = 100
  7. /// AutoFormat(100000,"万") = 10.0万 (万与亿自动单位 1位小数)
  8. /// AutoFormat(100000,"万","0:0.00") = 10.00万 (可以用第二个参数自定义小数位数和格式化)
  9. /// </example>
  10. /// </culture>
  11. /// </function>
  12. public string AutoFormat(object number, string unit = "", string format = "")
  13. {
  14.     // 文本对应的数值单位
  15.     System.Collections.Generic.Dictionary<string, decimal> unitDic = new System.Collections.Generic.Dictionary<string, decimal>() {
  16.         {"百",100},{"千",1000},{"万",10000},{"十万",100000},{"百万",1000000},{"千万",10000000},{"亿",100000000},{"十亿",1000000000},{"万亿",1000000000000}
  17.     };

  18.     if (number == null)
  19.         return string.Empty;
  20.     try
  21.     {
  22.         // 如果不传单位,就根据数值自动判断单位(亿和万)
  23.         var result = Convert.ToDecimal(number);
  24.         if (string.IsNullOrWhiteSpace(unit))
  25.         {
  26.             if (Math.Abs(result) >= 100000000)
  27.             {
  28.                 unit = "亿";
  29.             }
  30.             else if(Math.Abs(result) >= 10000)
  31.             {
  32.                 unit = "万";
  33.             }
  34.         }
  35.         
  36.         if (unitDic.ContainsKey(unit))
  37.         {
  38.             // 如果是有文字单位,自动保留1位小数
  39.             if (string.IsNullOrEmpty(format)) format = "{0:0.0}";
  40.             return String.Format(format + unit, result / unitDic[unit]);
  41.         }
  42.         // 如果传了format,就用format,如果没有传就用自带toString()
  43.         return string.IsNullOrWhiteSpace(format)? result.ToString():String.Format(format, result);
  44.     }
  45.     catch (Exception e)
  46.     {
  47.         return "AutoFormat转换错误"+e.Message;
  48.     }
  49. }
复制代码


回复 使用道具 举报
Eden.SunWyn认证
超级版主   /  发表于:4 天前
2#

您好,您在浏览器控制台看一下,编译的时候有没有报错信息:
image.png998157043.png
回复 使用道具 举报
RickyJen
中级会员   /  发表于:4 天前
3#
Eden.Sun 发表于 2024-7-3 12:04
您好,您在浏览器控制台看一下,编译的时候有没有报错信息:


有以下报错信息:
image.png792863769.png
回复 使用道具 举报
Felix.LiWyn认证
超级版主   /  发表于:4 天前
4#
您好,这个目前确实有点问题,这个我们看着能不能改一下,做一个新的方法看能不能实现。有新结果了给您再分享
回复 使用道具 举报
RickyJen
中级会员   /  发表于:3 天前
5#
Felix.Li 发表于 2024-7-3 18:28
您好,这个目前确实有点问题,这个我们看着能不能改一下,做一个新的方法看能不能实现。有新结果了给您再分 ...

好的,那现在这个错误是因为“自定义函数本身有问题需要升版”是吧?
回复 使用道具 举报
RickyJen
中级会员   /  发表于:3 天前
7#
Felix.Li 发表于 2024-7-4 15:56
是的,新的已经修改,是缺少了类型定义。您可以使用以下代码:

好的,辛苦了
回复 使用道具 举报
Eden.SunWyn认证
超级版主   /  发表于:前天 09:56
8#

不客气的,有其他问题。欢迎您在开新帖解决
回复 使用道具 举报
lucas.Yan
超级版主   /  发表于:前天 11:47
9#
正常会报错的,现在的情况是一个bug GERM-6637
image.png405993956.png
后续bug修复我们会通知您的.
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部