FastReportScript.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Threading.Tasks;
  8. namespace PTMedicalInsurance.Common
  9. {
  10. public class FastReportFunction
  11. {
  12. public static object moneyToChinese(object money)
  13. {
  14. try
  15. {
  16. double currency = Double.Parse(string.Format("{0}",money));
  17. return numberToChinese(currency);
  18. }
  19. catch (Exception e)
  20. {
  21. return money;
  22. }
  23. }
  24. private static string numberToChinese(double money)
  25. {
  26. try
  27. {
  28. string s = money.ToString("#L#E#D#C#K#E#D#C#J#E#D#C#I#E#D#C#H#E#D#C#G#E#D#C#F#E#D#C#.0B0A");
  29. string d = Regex.Replace(s, @"((?<=-|^)[^1-9]*)|((?'z'0)[0A-E]*((?=[1-9])|(?'-z'(?=[F-L\.]|$))))|((?'b'[F-L])(?'z'0)[0A-L]*((?=[1-9])|(?'-z'(?=[\.]|$))))", "${b}${z}");
  30. return Regex.Replace(d, ".", delegate (Match m) { return "负元空零壹贰叁肆伍陆柒捌玖空空空空空空空分角拾佰仟万億兆京垓秭穰"[m.Value[0] - '-'].ToString(); });
  31. }
  32. catch (Exception ex)
  33. {
  34. return money.ToString();
  35. }
  36. }
  37. public static void Register()
  38. {
  39. Type funType = typeof(FastReportFunction);
  40. MethodInfo method = funType.GetMethod("moneyToChinese");
  41. if(!FastReport.Utils.RegisteredObjects.IsTypeRegistered(funType) && method != null)
  42. {
  43. FastReport.Utils.RegisteredObjects.Add(funType, "Functions,CustomFunctions",0x34);
  44. FastReport.Utils.RegisteredObjects.AddFunction(method, "CustomFunctions");
  45. }
  46. }
  47. }
  48. }