StdFunctions.cs 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using FastReport.Utils;
  5. using System.Globalization;
  6. using FastReport.Data;
  7. namespace FastReport.Functions
  8. {
  9. /// <summary>
  10. /// Contains standard functions registered in the "Data" window.
  11. /// </summary>
  12. public static class StdFunctions
  13. {
  14. #region Math functions
  15. /// <summary>
  16. /// Returns the larger of two 32-bit signed integers.
  17. /// </summary>
  18. /// <param name="val1">The first of two values to compare.</param>
  19. /// <param name="val2">The second of two values to compare.</param>
  20. /// <returns>Parameter val1 or val2, whichever is larger.</returns>
  21. public static int Maximum(int val1, int val2)
  22. {
  23. return Math.Max(val1, val2);
  24. }
  25. /// <summary>
  26. /// Returns the larger of two 64-bit signed integers.
  27. /// </summary>
  28. /// <param name="val1">The first of two values to compare.</param>
  29. /// <param name="val2">The second of two values to compare.</param>
  30. /// <returns>Parameter val1 or val2, whichever is larger.</returns>
  31. public static long Maximum(long val1, long val2)
  32. {
  33. return Math.Max(val1, val2);
  34. }
  35. /// <summary>
  36. /// Returns the larger of two single-precision floating-point numbers.
  37. /// </summary>
  38. /// <param name="val1">The first of two values to compare.</param>
  39. /// <param name="val2">The second of two values to compare.</param>
  40. /// <returns>Parameter val1 or val2, whichever is larger.</returns>
  41. public static float Maximum(float val1, float val2)
  42. {
  43. return Math.Max(val1, val2);
  44. }
  45. /// <summary>
  46. /// Returns the larger of two double-precision floating-point numbers.
  47. /// </summary>
  48. /// <param name="val1">The first of two values to compare.</param>
  49. /// <param name="val2">The second of two values to compare.</param>
  50. /// <returns>Parameter val1 or val2, whichever is larger.</returns>
  51. public static double Maximum(double val1, double val2)
  52. {
  53. return Math.Max(val1, val2);
  54. }
  55. /// <summary>
  56. /// Returns the larger of two decimal numbers.
  57. /// </summary>
  58. /// <param name="val1">The first of two values to compare.</param>
  59. /// <param name="val2">The second of two values to compare.</param>
  60. /// <returns>Parameter val1 or val2, whichever is larger.</returns>
  61. public static decimal Maximum(decimal val1, decimal val2)
  62. {
  63. return Math.Max(val1, val2);
  64. }
  65. /// <summary>
  66. /// Returns the smaller of two 32-bit signed integers.
  67. /// </summary>
  68. /// <param name="val1">The first of two values to compare.</param>
  69. /// <param name="val2">The second of two values to compare.</param>
  70. /// <returns>Parameter val1 or val2, whichever is smaller.</returns>
  71. public static int Minimum(int val1, int val2)
  72. {
  73. return Math.Min(val1, val2);
  74. }
  75. /// <summary>
  76. /// Returns the smaller of two 64-bit signed integers.
  77. /// </summary>
  78. /// <param name="val1">The first of two values to compare.</param>
  79. /// <param name="val2">The second of two values to compare.</param>
  80. /// <returns>Parameter val1 or val2, whichever is smaller.</returns>
  81. public static long Minimum(long val1, long val2)
  82. {
  83. return Math.Min(val1, val2);
  84. }
  85. /// <summary>
  86. /// Returns the smaller of two single-precision floating-point numbers.
  87. /// </summary>
  88. /// <param name="val1">The first of two values to compare.</param>
  89. /// <param name="val2">The second of two values to compare.</param>
  90. /// <returns>Parameter val1 or val2, whichever is smaller.</returns>
  91. public static float Minimum(float val1, float val2)
  92. {
  93. return Math.Min(val1, val2);
  94. }
  95. /// <summary>
  96. /// Returns the smaller of two double-precision floating-point numbers.
  97. /// </summary>
  98. /// <param name="val1">The first of two values to compare.</param>
  99. /// <param name="val2">The second of two values to compare.</param>
  100. /// <returns>Parameter val1 or val2, whichever is smaller.</returns>
  101. public static double Minimum(double val1, double val2)
  102. {
  103. return Math.Min(val1, val2);
  104. }
  105. /// <summary>
  106. /// Returns the smaller of two decimal numbers.
  107. /// </summary>
  108. /// <param name="val1">The first of two values to compare.</param>
  109. /// <param name="val2">The second of two values to compare.</param>
  110. /// <returns>Parameter val1 or val2, whichever is smaller.</returns>
  111. public static decimal Minimum(decimal val1, decimal val2)
  112. {
  113. return Math.Min(val1, val2);
  114. }
  115. #endregion
  116. #region Text functions
  117. /// <summary>
  118. /// Returns an integer value representing the character code corresponding to a character.
  119. /// </summary>
  120. /// <param name="c">Character to convert.</param>
  121. /// <returns>The character code.</returns>
  122. public static int Asc(char c)
  123. {
  124. return (int)c;
  125. }
  126. /// <summary>
  127. /// Returns the character associated with the specified character code.
  128. /// </summary>
  129. /// <param name="i">Character code to convert.</param>
  130. /// <returns>The character.</returns>
  131. public static char Chr(int i)
  132. {
  133. return (char)i;
  134. }
  135. /// <summary>
  136. /// Inserts a specified string at a specified index position in the original string.
  137. /// </summary>
  138. /// <param name="s">The original string.</param>
  139. /// <param name="startIndex">The index position of the insertion.</param>
  140. /// <param name="value">The string to insert.</param>
  141. /// <returns>A new string.</returns>
  142. public static string Insert(string s, int startIndex, string value)
  143. {
  144. return s == null ? "" : s.Insert(startIndex, value);
  145. }
  146. /// <summary>
  147. /// Gets the number of characters in a string.
  148. /// </summary>
  149. /// <param name="s">The original string.</param>
  150. /// <returns>The number of characters.</returns>
  151. public static int Length(string s)
  152. {
  153. return s == null ? 0 : s.Length;
  154. }
  155. /// <summary>
  156. /// Converts a specified string to lowercase.
  157. /// </summary>
  158. /// <param name="s">The string to convert.</param>
  159. /// <returns>A string in lowercase.</returns>
  160. public static string LowerCase(string s)
  161. {
  162. return s == null ? "" : s.ToLower();
  163. }
  164. /// <summary>
  165. /// Right-aligns the characters in a string, padding with spaces on the left for a specified total length.
  166. /// </summary>
  167. /// <param name="s">The original string.</param>
  168. /// <param name="totalWidth">The number of characters in the resulting string.</param>
  169. /// <returns>Right-aligned string, padded on the left with spaces.</returns>
  170. public static string PadLeft(string s, int totalWidth)
  171. {
  172. return s == null ? "" : s.PadLeft(totalWidth);
  173. }
  174. /// <summary>
  175. /// Right-aligns the characters in a string, padding on the left with a specified character
  176. /// for a specified total length.
  177. /// </summary>
  178. /// <param name="s">The original string.</param>
  179. /// <param name="totalWidth">The number of characters in the resulting string.</param>
  180. /// <param name="paddingChar">A padding character.</param>
  181. /// <returns>Right-aligned string, padded on the left with padding characters.</returns>
  182. public static string PadLeft(string s, int totalWidth, char paddingChar)
  183. {
  184. return s == null ? "" : s.PadLeft(totalWidth, paddingChar);
  185. }
  186. /// <summary>
  187. /// Left-aligns the characters in a string, padding with spaces on the right, for a specified total length.
  188. /// </summary>
  189. /// <param name="s">The original string.</param>
  190. /// <param name="totalWidth">The number of characters in the resulting string.</param>
  191. /// <returns>Left-aligned string, padded on the right with spaces.</returns>
  192. public static string PadRight(string s, int totalWidth)
  193. {
  194. return s == null ? "" : s.PadRight(totalWidth);
  195. }
  196. /// <summary>
  197. /// Left-aligns the characters in a string, padding on the right with a specified character,
  198. /// for a specified total length.
  199. /// </summary>
  200. /// <param name="s">The original string.</param>
  201. /// <param name="totalWidth">The number of characters in the resulting string.</param>
  202. /// <param name="paddingChar">A padding character.</param>
  203. /// <returns>Left-aligned string, padded on the right with padding characters.</returns>
  204. public static string PadRight(string s, int totalWidth, char paddingChar)
  205. {
  206. return s == null ? "" : s.PadRight(totalWidth, paddingChar);
  207. }
  208. /// <summary>
  209. /// Converts the specified string to titlecase.
  210. /// </summary>
  211. /// <param name="s">The string to convert.</param>
  212. /// <returns>A new string.</returns>
  213. public static string TitleCase(string s)
  214. {
  215. return s == null ? "" : CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s);
  216. }
  217. /// <summary>
  218. /// Deletes all the characters from a string beginning at a specified position.
  219. /// </summary>
  220. /// <param name="s">The original string.</param>
  221. /// <param name="startIndex">The position to begin deleting characters.</param>
  222. /// <returns>A new string.</returns>
  223. public static string Remove(string s, int startIndex)
  224. {
  225. return s == null ? "" : s.Remove(startIndex);
  226. }
  227. /// <summary>
  228. /// Deletes a specified number of characters from a string beginning at a specified position.
  229. /// </summary>
  230. /// <param name="s">The original string.</param>
  231. /// <param name="startIndex">The position to begin deleting characters.</param>
  232. /// <param name="count">The number of characters to delete.</param>
  233. /// <returns>A new string.</returns>
  234. public static string Remove(string s, int startIndex, int count)
  235. {
  236. return s == null ? "" : s.Remove(startIndex, count);
  237. }
  238. /// <summary>
  239. /// Replaces all occurrences of a specified string in the original string, with another specified string.
  240. /// </summary>
  241. /// <param name="s">The original string.</param>
  242. /// <param name="oldValue">A string to be replaced.</param>
  243. /// <param name="newValue">A string to replace all occurrences of oldValue.</param>
  244. /// <returns>A new string.</returns>
  245. public static string Replace(string s, string oldValue, string newValue)
  246. {
  247. return s == null ? "" : s.Replace(oldValue, newValue);
  248. }
  249. /// <summary>
  250. /// Retrieves a substring from the original string, starting at a specified character position.
  251. /// </summary>
  252. /// <param name="s">The original string.</param>
  253. /// <param name="startIndex">The starting character position of a substring.</param>
  254. /// <returns>A new string.</returns>
  255. public static string Substring(string s, int startIndex)
  256. {
  257. if (s != null && startIndex < s.Length)
  258. {
  259. return s.Substring(startIndex);
  260. }
  261. return "";
  262. }
  263. /// <summary>
  264. /// Retrieves a substring from the original string, starting at a specified character position,
  265. /// with a specified length.
  266. /// </summary>
  267. /// <param name="s">The original string.</param>
  268. /// <param name="startIndex">The starting character position of a substring.</param>
  269. /// <param name="length">The number of characters in the substring.</param>
  270. /// <returns>A new string.</returns>
  271. public static string Substring(string s, int startIndex, int length)
  272. {
  273. if (s != null && startIndex < s.Length)
  274. {
  275. if (startIndex + length < s.Length)
  276. {
  277. return s.Substring(startIndex, length);
  278. }
  279. else
  280. {
  281. return s.Substring(startIndex);
  282. }
  283. }
  284. return "";
  285. }
  286. /// <summary>
  287. /// Returns "true" if a specified pattern occurs within this source string, else returns "false".
  288. /// </summary>
  289. /// <param name="s">The original string.</param>
  290. /// <param name="value">Substring looking for.</param>
  291. /// <returns>true if the pattern parameter occurs within this source string, or if value is the empty string; otherwise, false</returns>
  292. public static bool Contains(string s, string value)
  293. {
  294. if (s != null && value != null && s.Contains(value))
  295. {
  296. return true;
  297. }
  298. return false;
  299. }
  300. /// <summary>
  301. /// Removes all occurrences of white space characters from the beginning and end of the original string.
  302. /// </summary>
  303. /// <param name="s">The original string.</param>
  304. /// <returns>A new string.</returns>
  305. public static string Trim(string s)
  306. {
  307. return s == null ? "" : s.Trim();
  308. }
  309. /// <summary>
  310. /// Converts a specified string to uppercase.
  311. /// </summary>
  312. /// <param name="s">The string to convert.</param>
  313. /// <returns>A string in uppercase.</returns>
  314. public static string UpperCase(string s)
  315. {
  316. return s == null ? "" : s.ToUpper();
  317. }
  318. #endregion
  319. #region Date & Time functions
  320. /// <summary>
  321. /// Adds the specified number of days to the original date.
  322. /// </summary>
  323. /// <param name="date">The original date.</param>
  324. /// <param name="value">A number of whole and fractional days.</param>
  325. /// <returns>A new DateTime value.</returns>
  326. public static DateTime AddDays(DateTime date, double value)
  327. {
  328. return date.AddDays(value);
  329. }
  330. /// <summary>
  331. /// Adds the specified number of hours to the original date.
  332. /// </summary>
  333. /// <param name="date">The original date.</param>
  334. /// <param name="value">A number of whole and fractional hours.</param>
  335. /// <returns>A new DateTime value.</returns>
  336. public static DateTime AddHours(DateTime date, double value)
  337. {
  338. return date.AddHours(value);
  339. }
  340. /// <summary>
  341. /// Adds the specified number of minutes to the original date.
  342. /// </summary>
  343. /// <param name="date">The original date.</param>
  344. /// <param name="value">A number of whole and fractional minutes.</param>
  345. /// <returns>A new DateTime value.</returns>
  346. public static DateTime AddMinutes(DateTime date, double value)
  347. {
  348. return date.AddMinutes(value);
  349. }
  350. /// <summary>
  351. /// Adds the specified number of months to the original date.
  352. /// </summary>
  353. /// <param name="date">The original date.</param>
  354. /// <param name="value">A number of months.</param>
  355. /// <returns>A new DateTime value.</returns>
  356. public static DateTime AddMonths(DateTime date, int value)
  357. {
  358. return date.AddMonths(value);
  359. }
  360. /// <summary>
  361. /// Adds the specified number of seconds to the original date.
  362. /// </summary>
  363. /// <param name="date">The original date.</param>
  364. /// <param name="value">A number of whole and fractional seconds.</param>
  365. /// <returns>A new DateTime value.</returns>
  366. public static DateTime AddSeconds(DateTime date, double value)
  367. {
  368. return date.AddSeconds(value);
  369. }
  370. /// <summary>
  371. /// Adds the specified number of years to the original date.
  372. /// </summary>
  373. /// <param name="date">The original date.</param>
  374. /// <param name="value">A number of years.</param>
  375. /// <returns>A new DateTime value.</returns>
  376. public static DateTime AddYears(DateTime date, int value)
  377. {
  378. return date.AddYears(value);
  379. }
  380. /// <summary>
  381. /// Subtracts the specified date and time from the original date.
  382. /// </summary>
  383. /// <param name="date1">The original date.</param>
  384. /// <param name="date2">The date and time to subtract.</param>
  385. /// <returns>A TimeSpan interval between two dates.</returns>
  386. public static TimeSpan DateDiff(DateTime date1, DateTime date2)
  387. {
  388. return date1.Subtract(date2);
  389. }
  390. /// <summary>
  391. /// Initializes a new instance of the DateTime.
  392. /// </summary>
  393. /// <param name="year">The year.</param>
  394. /// <param name="month">The month.</param>
  395. /// <param name="day">The day.</param>
  396. /// <returns>A new DateTime value.</returns>
  397. public static DateTime DateSerial(int year, int month, int day)
  398. {
  399. return new DateTime(year, month, day);
  400. }
  401. /// <summary>
  402. /// Gets the day of the month.
  403. /// </summary>
  404. /// <param name="date">The date value.</param>
  405. /// <returns>The day component.</returns>
  406. public static int Day(DateTime date)
  407. {
  408. return date.Day;
  409. }
  410. /// <summary>
  411. /// Gets the localized name of the day of the week.
  412. /// </summary>
  413. /// <param name="date">The date value.</param>
  414. /// <returns>The name of the day of the week.</returns>
  415. public static string DayOfWeek(DateTime date)
  416. {
  417. return date.ToString("dddd");
  418. }
  419. /// <summary>
  420. /// Gets the day of the year.
  421. /// </summary>
  422. /// <param name="date">The date value.</param>
  423. /// <returns>The day of the year.</returns>
  424. public static int DayOfYear(DateTime date)
  425. {
  426. return date.DayOfYear;
  427. }
  428. /// <summary>
  429. /// Returns the number of days in the specified month and year.
  430. /// </summary>
  431. /// <param name="year">The year.</param>
  432. /// <param name="month">The month.</param>
  433. /// <returns>The number of days in month for the specified year.</returns>
  434. public static int DaysInMonth(int year, int month)
  435. {
  436. return DateTime.DaysInMonth(year, month);
  437. }
  438. /// <summary>
  439. /// Gets the hour component of the date.
  440. /// </summary>
  441. /// <param name="date">The date.</param>
  442. /// <returns>The hour component.</returns>
  443. public static int Hour(DateTime date)
  444. {
  445. return date.Hour;
  446. }
  447. /// <summary>
  448. /// Gets the minute component of the date.
  449. /// </summary>
  450. /// <param name="date">The date.</param>
  451. /// <returns>The minute component.</returns>
  452. public static int Minute(DateTime date)
  453. {
  454. return date.Minute;
  455. }
  456. /// <summary>
  457. /// Gets the month component of the date.
  458. /// </summary>
  459. /// <param name="date">The date.</param>
  460. /// <returns>The month component.</returns>
  461. public static int Month(DateTime date)
  462. {
  463. return date.Month;
  464. }
  465. /// <summary>
  466. /// Gets the localized month name.
  467. /// </summary>
  468. /// <param name="month">The month number.</param>
  469. /// <returns>The month name.</returns>
  470. public static string MonthName(int month)
  471. {
  472. return new DateTime(2000, month, 1).ToString("MMMM");
  473. }
  474. /// <summary>
  475. /// Gets the seconds component of the date.
  476. /// </summary>
  477. /// <param name="date">The date.</param>
  478. /// <returns>The seconds component.</returns>
  479. public static int Second(DateTime date)
  480. {
  481. return date.Second;
  482. }
  483. /// <summary>
  484. /// Gets the week of the year.
  485. /// </summary>
  486. /// <param name="date">The date value.</param>
  487. /// <returns>The week of the year.</returns>
  488. public static int WeekOfYear(DateTime date)
  489. {
  490. CalendarWeekRule rule = CultureInfo.CurrentCulture.DateTimeFormat.CalendarWeekRule;
  491. DayOfWeek day = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek;
  492. return CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(date, rule, day);
  493. }
  494. /// <summary>
  495. /// Gets the year component of the date.
  496. /// </summary>
  497. /// <param name="date">The date.</param>
  498. /// <returns>The year component.</returns>
  499. public static int Year(DateTime date)
  500. {
  501. return date.Year;
  502. }
  503. #endregion
  504. #region Formatting
  505. /// <summary>
  506. /// Replaces the format item in a specified String with the text equivalent of the value of a
  507. /// corresponding Object instance in a specified array.
  508. /// </summary>
  509. /// <param name="format">A String containing zero or more format items.</param>
  510. /// <param name="args">An Object array containing zero or more objects to format.</param>
  511. /// <returns>A copy of format in which the format items have been replaced by the String equivalent of the corresponding instances of Object in args.</returns>
  512. public static string Format(string format, params object[] args)
  513. {
  514. if (args != null)
  515. {
  516. for (int i = 0; i < args.Length; i++)
  517. {
  518. if (args[i] is Variant)
  519. args[i] = ((Variant)args[i]).Value;
  520. }
  521. }
  522. return String.Format(format, args);
  523. }
  524. /// <summary>
  525. /// Returns a string formatted as a currency value.
  526. /// </summary>
  527. /// <param name="value">The value to format.</param>
  528. /// <returns>The formatted string.</returns>
  529. public static string FormatCurrency(object value)
  530. {
  531. if (value is Variant)
  532. value = ((Variant)value).Value;
  533. return String.Format("{0:c}", value);
  534. }
  535. /// <summary>
  536. /// Returns a string formatted as a currency value with specified number of decimal digits.
  537. /// </summary>
  538. /// <param name="value">The value to format.</param>
  539. /// <param name="decimalDigits">Number of decimal digits.</param>
  540. /// <returns>The formatted string.</returns>
  541. public static string FormatCurrency(object value, int decimalDigits)
  542. {
  543. if (value is Variant)
  544. value = ((Variant)value).Value;
  545. NumberFormatInfo info = CultureInfo.CurrentCulture.NumberFormat.Clone() as NumberFormatInfo;
  546. info.CurrencyDecimalDigits = decimalDigits;
  547. return String.Format(info, "{0:c}", value);
  548. }
  549. /// <summary>
  550. /// Returns a string formatted as a date/time value.
  551. /// </summary>
  552. /// <param name="value">The value to format.</param>
  553. /// <returns>The formatted string.</returns>
  554. public static string FormatDateTime(DateTime value)
  555. {
  556. string format = "G";
  557. if (value.TimeOfDay.Ticks == value.Ticks)
  558. format = "T";
  559. else if (value.TimeOfDay.Ticks == 0)
  560. format = "d";
  561. return value.ToString(format, null);
  562. }
  563. /// <summary>
  564. /// Returns a string formatted as a date/time value.
  565. /// </summary>
  566. /// <param name="value">The value to format.</param>
  567. /// <param name="format">The format specifier, one of the
  568. /// "Long Date", "Short Date", "Long Time", "Short Time" values.</param>
  569. /// <returns>The formatted string.</returns>
  570. public static string FormatDateTime(DateTime value, string format)
  571. {
  572. string _format = format.ToLower().Replace(" ", "");
  573. switch (_format)
  574. {
  575. case "longdate":
  576. return value.ToString("D", null);
  577. case "shortdate":
  578. return value.ToString("d", null);
  579. case "longtime":
  580. return value.ToString("T", null);
  581. case "shorttime":
  582. return value.ToString("HH:mm", null);
  583. }
  584. return value.ToString(format, null);
  585. }
  586. /// <summary>
  587. /// Returns a string formatted as a numeric value.
  588. /// </summary>
  589. /// <param name="value">The value to format.</param>
  590. /// <returns>The formatted string.</returns>
  591. public static string FormatNumber(object value)
  592. {
  593. if (value is Variant)
  594. value = ((Variant)value).Value;
  595. return String.Format("{0:n}", value);
  596. }
  597. /// <summary>
  598. /// Returns a string formatted as a numeric value with specified number of decimal digits.
  599. /// </summary>
  600. /// <param name="value">The value to format.</param>
  601. /// <param name="decimalDigits">Number of decimal digits.</param>
  602. /// <returns>The formatted string.</returns>
  603. public static string FormatNumber(object value, int decimalDigits)
  604. {
  605. if (value is Variant)
  606. value = ((Variant)value).Value;
  607. NumberFormatInfo info = CultureInfo.CurrentCulture.NumberFormat.Clone() as NumberFormatInfo;
  608. info.NumberDecimalDigits = decimalDigits;
  609. return String.Format(info, "{0:n}", value);
  610. }
  611. /// <summary>
  612. /// Returns a string formatted as a percent value.
  613. /// </summary>
  614. /// <param name="value">The value to format.</param>
  615. /// <returns>The formatted string.</returns>
  616. public static string FormatPercent(object value)
  617. {
  618. if (value is Variant)
  619. value = ((Variant)value).Value;
  620. return String.Format("{0:p}", value);
  621. }
  622. /// <summary>
  623. /// Returns a string formatted as a percent value with specified number of decimal digits.
  624. /// </summary>
  625. /// <param name="value">The value to format.</param>
  626. /// <param name="decimalDigits">Number of decimal digits.</param>
  627. /// <returns>The formatted string.</returns>
  628. public static string FormatPercent(object value, int decimalDigits)
  629. {
  630. if (value is Variant)
  631. value = ((Variant)value).Value;
  632. NumberFormatInfo info = CultureInfo.CurrentCulture.NumberFormat.Clone() as NumberFormatInfo;
  633. info.PercentDecimalDigits = decimalDigits;
  634. return String.Format(info, "{0:p}", value);
  635. }
  636. #endregion
  637. #region Conversion
  638. /// <summary>
  639. /// Converts a numeric value to Roman string representation.
  640. /// </summary>
  641. /// <param name="value">Integer value in range 0-3998.</param>
  642. /// <returns>The string in Roman form.</returns>
  643. public static string ToRoman(object value)
  644. {
  645. return Roman.Convert(Convert.ToInt32(value));
  646. }
  647. /// <summary>
  648. /// Converts a currency value to an english (US) string representation of that value.
  649. /// </summary>
  650. /// <param name="value">The currency value to convert.</param>
  651. /// <returns>The string representation of the specified value.</returns>
  652. public static string ToWords(object value)
  653. {
  654. return ToWords(value, "USD");
  655. }
  656. /// <summary>
  657. /// Converts a currency value to an english (US) string representation of that value,
  658. /// using the specified currency.
  659. /// </summary>
  660. /// <param name="value">The currency value to convert.</param>
  661. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  662. /// <returns>The string representation of the specified value.</returns>
  663. public static string ToWords(object value, string currencyName)
  664. {
  665. return new NumToWordsEn().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  666. }
  667. /// <summary>
  668. /// Converts a numeric value to an english (US) string representation of that value.
  669. /// </summary>
  670. /// <param name="value">The numeric value to convert.</param>
  671. /// <param name="one">The name in singular form, for example "page".</param>
  672. /// <param name="many">The name in plural form, for example "pages".</param>
  673. /// <returns>The string representation of the specified value.</returns>
  674. public static string ToWords(object value, string one, string many)
  675. {
  676. return new NumToWordsEn().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  677. }
  678. /// <summary>
  679. /// Converts a currency value to an english (GB) string representation of that value.
  680. /// </summary>
  681. /// <param name="value">The currency value to convert.</param>
  682. /// <returns>The string representation of the specified value.</returns>
  683. public static string ToWordsEnGb(object value)
  684. {
  685. return ToWordsEnGb(value, "GBP");
  686. }
  687. /// <summary>
  688. /// Converts a currency value to an english (GB) string representation of that value,
  689. /// using the specified currency.
  690. /// </summary>
  691. /// <param name="value">The currency value to convert.</param>
  692. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  693. /// <returns>The string representation of the specified value.</returns>
  694. public static string ToWordsEnGb(object value, string currencyName)
  695. {
  696. return new NumToWordsEnGb().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  697. }
  698. /// <summary>
  699. /// Converts a numeric value to an english (GB) string representation of that value.
  700. /// </summary>
  701. /// <param name="value">The numeric value to convert.</param>
  702. /// <param name="one">The name in singular form, for example "page".</param>
  703. /// <param name="many">The name in plural form, for example "pages".</param>
  704. /// <returns>The string representation of the specified value.</returns>
  705. public static string ToWordsEnGb(object value, string one, string many)
  706. {
  707. return new NumToWordsEnGb().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  708. }
  709. /// <summary>
  710. /// Converts a currency value to a spanish string representation of that value.
  711. /// </summary>
  712. /// <param name="value">The currency value to convert.</param>
  713. /// <returns>The string representation of the specified value.</returns>
  714. public static string ToWordsEs(object value)
  715. {
  716. return ToWordsEs(value, "EUR");
  717. }
  718. /// <summary>
  719. /// Converts a currency value to a spanish string representation of that value,
  720. /// using the specified currency.
  721. /// </summary>
  722. /// <param name="value">The currency value to convert.</param>
  723. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  724. /// <returns>The string representation of the specified value.</returns>
  725. public static string ToWordsEs(object value, string currencyName)
  726. {
  727. return new NumToWordsEs().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  728. }
  729. /// <summary>
  730. /// Converts a numeric value to a spanish string representation of that value.
  731. /// </summary>
  732. /// <param name="value">The numeric value to convert.</param>
  733. /// <param name="one">The name in singular form, for example "page".</param>
  734. /// <param name="many">The name in plural form, for example "pages".</param>
  735. /// <returns>The string representation of the specified value.</returns>
  736. public static string ToWordsEs(object value, string one, string many)
  737. {
  738. return new NumToWordsEs().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  739. }
  740. /// <summary>
  741. /// Converts a currency value to a russian string representation of that value.
  742. /// </summary>
  743. /// <param name="value">The currency value to convert.</param>
  744. /// <returns>The string representation of the specified value.</returns>
  745. public static string ToWordsRu(object value)
  746. {
  747. return ToWordsRu(value, "RUR");
  748. }
  749. /// <summary>
  750. /// Converts a currency value to a russian string representation of that value,
  751. /// using the specified currency.
  752. /// </summary>
  753. /// <param name="value">The currency value to convert.</param>
  754. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  755. /// <returns>The string representation of the specified value.</returns>
  756. public static string ToWordsRu(object value, string currencyName)
  757. {
  758. return new NumToWordsRu().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  759. }
  760. /// <summary>
  761. /// Converts a numeric value to a russian string representation of that value.
  762. /// </summary>
  763. /// <param name="value">The numeric value to convert.</param>
  764. /// <param name="male">True if the name is of male gender.</param>
  765. /// <param name="one">The name in singular form, for example "страница".</param>
  766. /// <param name="two">The name in plural form, for example "страницы".</param>
  767. /// <param name="many">The name in plural form, for example "страниц".</param>
  768. /// <returns>The string representation of the specified value.</returns>
  769. public static string ToWordsRu(object value, bool male, string one, string two, string many)
  770. {
  771. return new NumToWordsRu().ConvertNumber(Convert.ToDecimal(value), male, one, two, many);
  772. }
  773. /// <summary>
  774. /// Converts a currency value to a german string representation of that value.
  775. /// </summary>
  776. /// <param name="value">The currency value to convert.</param>
  777. /// <returns>The string representation of the specified value.</returns>
  778. public static string ToWordsDe(object value)
  779. {
  780. return ToWordsDe(value, "EUR");
  781. }
  782. /// <summary>
  783. /// Converts a currency value to a german string representation of that value,
  784. /// using the specified currency.
  785. /// </summary>
  786. /// <param name="value">The currency value to convert.</param>
  787. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  788. /// <returns>The string representation of the specified value.</returns>
  789. public static string ToWordsDe(object value, string currencyName)
  790. {
  791. return new NumToWordsDe().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  792. }
  793. /// <summary>
  794. /// Converts a numeric value to a german string representation of that value.
  795. /// </summary>
  796. /// <param name="value">The numeric value to convert.</param>
  797. /// <param name="one">The name in singular form, for example "page".</param>
  798. /// <param name="many">The name in plural form, for example "pages".</param>
  799. /// <returns>The string representation of the specified value.</returns>
  800. public static string ToWordsDe(object value, string one, string many)
  801. {
  802. return new NumToWordsDe().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  803. }
  804. /// <summary>
  805. /// Converts a currency value to a french string representation of that value.
  806. /// </summary>
  807. /// <param name="value">The currency value to convert.</param>
  808. /// <returns>The string representation of the specified value.</returns>
  809. public static string ToWordsFr(object value)
  810. {
  811. return ToWordsFr(value, "EUR");
  812. }
  813. /// <summary>
  814. /// Converts a currency value to a french string representation of that value,
  815. /// using the specified currency.
  816. /// </summary>
  817. /// <param name="value">The currency value to convert.</param>
  818. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  819. /// <returns>The string representation of the specified value.</returns>
  820. public static string ToWordsFr(object value, string currencyName)
  821. {
  822. return new NumToWordsFr().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  823. }
  824. /// <summary>
  825. /// Converts a numeric value to a french string representation of that value.
  826. /// </summary>
  827. /// <param name="value">The numeric value to convert.</param>
  828. /// <param name="one">The name in singular form, for example "page".</param>
  829. /// <param name="many">The name in plural form, for example "pages".</param>
  830. /// <returns>The string representation of the specified value.</returns>
  831. public static string ToWordsFr(object value, string one, string many)
  832. {
  833. return new NumToWordsFr().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  834. }
  835. /// <summary>
  836. /// Converts a currency value to a dutch string representation of that value.
  837. /// </summary>
  838. /// <param name="value">The currency value to convert.</param>
  839. /// <returns>The string representation of the specified value.</returns>
  840. public static string ToWordsNl(object value)
  841. {
  842. return ToWordsNl(value, "EUR");
  843. }
  844. /// <summary>
  845. /// Converts a currency value to a dutch string representation of that value,
  846. /// using the specified currency.
  847. /// </summary>
  848. /// <param name="value">The currency value to convert.</param>
  849. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  850. /// <returns>The string representation of the specified value.</returns>
  851. public static string ToWordsNl(object value, string currencyName)
  852. {
  853. return new NumToWordsNl().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  854. }
  855. /// <summary>
  856. /// Converts a numeric value to a dutch string representation of that value.
  857. /// </summary>
  858. /// <param name="value">The numeric value to convert.</param>
  859. /// <param name="one">The name in singular form, for example "page".</param>
  860. /// <param name="many">The name in plural form, for example "pages".</param>
  861. /// <returns>The string representation of the specified value.</returns>
  862. public static string ToWordsNl(object value, string one, string many)
  863. {
  864. return new NumToWordsNl().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  865. }
  866. /// <summary>
  867. /// Converts a numeric value to a indian numbering system string representation of that value.
  868. /// </summary>
  869. /// <param name="value">the currency value to convert</param>
  870. /// <returns>The string representation of the specified value.</returns>
  871. public static string ToWordsIn(object value)
  872. {
  873. return ToWordsIn(value, "INR");
  874. }
  875. /// <summary>
  876. /// Converts a numeric value to a indian numbering system string representation of that value.
  877. /// </summary>
  878. /// <param name="value">he numeric value to convert.</param>
  879. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "INR".</param>
  880. /// <returns></returns>
  881. public static string ToWordsIn(object value, string currencyName)
  882. {
  883. return new NumToWordsIn().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  884. }
  885. /// <summary>
  886. /// Converts a numeric value to a indian numbering system string representation of that value.
  887. /// </summary>
  888. /// <param name="value">The numeric value to convert.</param>
  889. /// <param name="one">The name in singular form, for example "page".</param>
  890. /// <param name="many">The name in plural form, for example "pages".</param>
  891. /// <returns>The string representation of the specified value.</returns>
  892. public static string ToWordsIn(object value, string one, string many)
  893. {
  894. return new NumToWordsIn().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  895. }
  896. /// <summary>
  897. /// Converts a numeric value to a ukrainian string representation of that value.
  898. /// </summary>
  899. /// <param name="value">The numeric value to convert.</param>
  900. /// <returns>The string representation of the specified value.</returns>
  901. public static string ToWordsUkr(object value)
  902. {
  903. return ToWordsUkr(value, "UAH");
  904. }
  905. /// <summary>
  906. /// Converts a currency value to a ukrainian string representation of that value,
  907. /// using the specified currency.
  908. /// </summary>
  909. /// <param name="value">The currency value to convert.</param>
  910. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "UAH".</param>
  911. /// <returns>The string representation of the specified value.</returns>
  912. public static string ToWordsUkr(object value, string currencyName)
  913. {
  914. return new NumToWordsUkr().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  915. }
  916. /// <summary>
  917. /// Converts a numeric value to a ukrainian string representation of that value.
  918. /// </summary>
  919. /// <param name="value">The numeric value to convert.</param>
  920. /// <param name="male">True if the name is of male gender.</param>
  921. /// <param name="one">The name in singular form, for example "сторінка".</param>
  922. /// <param name="two">The name in plural form, for example "сторінки".</param>
  923. /// <param name="many">The name in plural form, for example "сторінок".</param>
  924. /// <returns>The string representation of the specified value.</returns>
  925. public static string ToWordsUkr(object value, bool male, string one, string two, string many)
  926. {
  927. return new NumToWordsUkr().ConvertNumber(Convert.ToDecimal(value), male, one, two, many);
  928. }
  929. /// <summary>
  930. /// Converts a numeric value to a spanish string representation of that value.
  931. /// </summary>
  932. /// <param name="value">The numeric value to convert.</param>
  933. /// <returns>The string representation of the specified value.</returns>
  934. public static string ToWordsSp(object value)
  935. {
  936. return ToWordsSp(value, "EUR");
  937. }
  938. /// <summary>
  939. /// Converts a numeric value to a spanish representation of that value.
  940. /// </summary>
  941. /// <param name="value">he numeric value to convert.</param>
  942. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  943. /// <returns></returns>
  944. public static string ToWordsSp(object value, string currencyName)
  945. {
  946. return new NumToWordsSp().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  947. }
  948. /// <summary>
  949. /// Converts a numeric value to a spanish string representation of that value.
  950. /// </summary>
  951. /// <param name="value">The numeric value to convert.</param>
  952. /// <param name="one">The name in singular form, for example "silla".</param>
  953. /// <param name="many">The name in plural form, for example "Sillas".</param>
  954. /// <returns>The string representation of the specified value.</returns>
  955. public static string ToWordsSp(object value, string one, string many)
  956. {
  957. return new NumToWordsSp().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  958. }
  959. /// <summary>
  960. /// Converts a numeric value to a persian string representation of that value.
  961. /// </summary>
  962. /// <param name="value">The numeric value to convert.</param>
  963. /// <returns>The string representation of the specified value.</returns>
  964. public static string ToWordsPersian(object value)
  965. {
  966. return ToWordsPersian(value, "EUR");
  967. }
  968. /// <summary>
  969. /// Converts a numeric value to a persian representation of that value.
  970. /// </summary>
  971. /// <param name="value">he numeric value to convert.</param>
  972. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  973. /// <returns></returns>
  974. public static string ToWordsPersian(object value, string currencyName)
  975. {
  976. return new NumToWordsPersian().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  977. }
  978. /// <summary>
  979. /// Converts a numeric value to a persian string representation of that value.
  980. /// </summary>
  981. /// <param name="value">The numeric value to convert.</param>
  982. /// <param name="one">The name in singular form, for example "silla".</param>
  983. /// <param name="many">The name in plural form, for example "Sillas".</param>
  984. /// <returns>The string representation of the specified value.</returns>
  985. public static string ToWordsPersian(object value, string one, string many)
  986. {
  987. return new NumToWordsPersian().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  988. }
  989. /// <summary>
  990. /// Converts a numeric value to a polish string representation of that value.
  991. /// </summary>
  992. /// <param name="value">The numeric value to convert.</param>
  993. /// <returns>The string representation of the specified value.</returns>
  994. public static string ToWordsPl(object value)
  995. {
  996. return ToWordsPl(value, "PLN");
  997. }
  998. /// <summary>
  999. /// Converts a numeric value to a polish representation of that value.
  1000. /// </summary>
  1001. /// <param name="value">he numeric value to convert.</param>
  1002. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  1003. /// <returns></returns>
  1004. public static string ToWordsPl(object value, string currencyName)
  1005. {
  1006. return new NumToWordsPl().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  1007. }
  1008. /// <summary>
  1009. /// Converts a numeric value to a polish string representation of that value.
  1010. /// </summary>
  1011. /// <param name="value">The numeric value to convert.</param>
  1012. /// <param name="one">The name in singular form, for example "silla".</param>
  1013. /// <param name="many">The name in plural form, for example "Sillas".</param>
  1014. /// <returns>The string representation of the specified value.</returns>
  1015. public static string ToWordsPl(object value, string one, string many)
  1016. {
  1017. return new NumToWordsPl().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  1018. }
  1019. /// <summary>
  1020. /// Converts a value to an english (US) alphabet string representation of that value.
  1021. /// </summary>
  1022. /// <param name="value">The value to convert.</param>
  1023. /// <returns>The alphabet string representation of the specified value.</returns>
  1024. public static string ToLetters(object value)
  1025. {
  1026. return ToLetters(value, false);
  1027. }
  1028. /// <summary>
  1029. /// Converts a value to an english (US) alphabet string representation of that value.
  1030. /// </summary>
  1031. /// <param name="value">The value to convert.</param>
  1032. /// <param name="isUpper">Bool indicating that letters should be in upper registry.</param>
  1033. /// <returns>The alphabet string representation of the specified value.</returns>
  1034. public static string ToLetters(object value, bool isUpper)
  1035. {
  1036. return new NumToLettersEn().ConvertNumber(Convert.ToInt32(value), isUpper);
  1037. }
  1038. /// <summary>
  1039. /// Converts a value to a russian alphabet string representation of that value.
  1040. /// </summary>
  1041. /// <param name="value">The value to convert.</param>
  1042. /// <returns>The alphabet string representation of the specified value.</returns>
  1043. public static string ToLettersRu(object value)
  1044. {
  1045. return ToLettersRu(value, false);
  1046. }
  1047. /// <summary>
  1048. /// Converts a value to a russian alphabet string representation of that value.
  1049. /// </summary>
  1050. /// <param name="value">The value to convert.</param>
  1051. /// <param name="isUpper">Bool indicating that letters should be in upper registry.</param>
  1052. /// <returns>The alphabet string representation of the specified value.</returns>
  1053. public static string ToLettersRu(object value, bool isUpper)
  1054. {
  1055. return new NumToLettersRu().ConvertNumber(Convert.ToInt32(value), isUpper);
  1056. }
  1057. #endregion
  1058. #region Program Flow
  1059. /// <summary>
  1060. /// Selects and returns a value from a list of arguments.
  1061. /// </summary>
  1062. /// <param name="index">A value between 1 and the number of elements passed in the "choice" argument.</param>
  1063. /// <param name="choice">Object parameter array.</param>
  1064. /// <returns>One of the values in the "choice" argument.</returns>
  1065. public static object Choose(double index, params object[] choice)
  1066. {
  1067. int ind = (int)index - 1;
  1068. if (ind < 0 || ind >= choice.Length)
  1069. return null;
  1070. return choice[ind];
  1071. }
  1072. /// <summary>
  1073. /// Returns one of two objects, depending on the evaluation of an expression.
  1074. /// </summary>
  1075. /// <param name="expression">The expression you want to evaluate.</param>
  1076. /// <param name="truePart">Returned if Expression evaluates to True.</param>
  1077. /// <param name="falsePart">Returned if Expression evaluates to False.</param>
  1078. /// <returns>Either truePart os falsePart.</returns>
  1079. public static object IIf(bool expression, object truePart, object falsePart)
  1080. {
  1081. return expression ? truePart : falsePart;
  1082. }
  1083. /// <summary>
  1084. /// Evaluates a list of expressions and returns a value corresponding to the first
  1085. /// expression in the list that is True.
  1086. /// </summary>
  1087. /// <param name="expressions">Parameter array consists of paired expressions and values.</param>
  1088. /// <returns>The value corresponding to an expression which returns true.</returns>
  1089. public static object Switch(params object[] expressions)
  1090. {
  1091. for (int i = 0; i + 1 < expressions.Length; i += 2)
  1092. {
  1093. if (Convert.ToBoolean(expressions[i]) == true)
  1094. return expressions[i + 1];
  1095. }
  1096. return null;
  1097. }
  1098. /// <summary>
  1099. /// Checks if the specified object is null.
  1100. /// </summary>
  1101. /// <param name="thisReport">The report instance.</param>
  1102. /// <param name="name">Either a name of DB column, or a parameter name, or a total name to check. The name must be enclosed in double quotes, for example, [IsNull("Parameter")].</param>
  1103. /// <returns><b>true</b> if the object's value is null.</returns>
  1104. public static bool IsNull(Report thisReport, string name)
  1105. {
  1106. object value = null;
  1107. if (DataHelper.IsValidColumn(thisReport.Dictionary, name))
  1108. {
  1109. value = thisReport.GetColumnValueNullable(name);
  1110. }
  1111. else if (DataHelper.IsValidParameter(thisReport.Dictionary, name))
  1112. {
  1113. value = thisReport.GetParameterValue(name);
  1114. }
  1115. else if (DataHelper.IsValidTotal(thisReport.Dictionary, name))
  1116. {
  1117. value = thisReport.GetTotalValueNullable(name).Value;
  1118. }
  1119. return value == null || value == DBNull.Value;
  1120. }
  1121. #endregion
  1122. internal static void Register()
  1123. {
  1124. #region Math
  1125. RegisteredObjects.AddFunctionCategory("Math", "Functions,Math");
  1126. Type math = typeof(Math);
  1127. RegisteredObjects.AddFunction(math.GetMethod("Abs", new Type[] { typeof(sbyte) }), "Math,Abs");
  1128. RegisteredObjects.InternalAddFunction(math.GetMethod("Abs", new Type[] { typeof(short) }), "Math,Abs");
  1129. RegisteredObjects.InternalAddFunction(math.GetMethod("Abs", new Type[] { typeof(int) }), "Math,Abs");
  1130. RegisteredObjects.InternalAddFunction(math.GetMethod("Abs", new Type[] { typeof(long) }), "Math,Abs");
  1131. RegisteredObjects.InternalAddFunction(math.GetMethod("Abs", new Type[] { typeof(float) }), "Math,Abs");
  1132. RegisteredObjects.InternalAddFunction(math.GetMethod("Abs", new Type[] { typeof(double) }), "Math,Abs");
  1133. RegisteredObjects.InternalAddFunction(math.GetMethod("Abs", new Type[] { typeof(decimal) }), "Math,Abs");
  1134. RegisteredObjects.InternalAddFunction(math.GetMethod("Acos"), "Math");
  1135. RegisteredObjects.InternalAddFunction(math.GetMethod("Asin"), "Math");
  1136. RegisteredObjects.InternalAddFunction(math.GetMethod("Atan"), "Math");
  1137. RegisteredObjects.InternalAddFunction(math.GetMethod("Ceiling", new Type[] { typeof(double) }), "Math,Ceiling");
  1138. RegisteredObjects.InternalAddFunction(math.GetMethod("Ceiling", new Type[] { typeof(decimal) }), "Math,Ceiling");
  1139. RegisteredObjects.InternalAddFunction(math.GetMethod("Cos"), "Math");
  1140. RegisteredObjects.InternalAddFunction(math.GetMethod("Exp"), "Math");
  1141. RegisteredObjects.InternalAddFunction(math.GetMethod("Floor", new Type[] { typeof(double) }), "Math,Floor");
  1142. RegisteredObjects.InternalAddFunction(math.GetMethod("Floor", new Type[] { typeof(decimal) }), "Math,Floor");
  1143. RegisteredObjects.InternalAddFunction(math.GetMethod("Log", new Type[] { typeof(double) }), "Math");
  1144. Type myMath = typeof(StdFunctions);
  1145. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Maximum", new Type[] { typeof(int), typeof(int) }), "Math,Maximum");
  1146. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Maximum", new Type[] { typeof(long), typeof(long) }), "Math,Maximum");
  1147. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Maximum", new Type[] { typeof(float), typeof(float) }), "Math,Maximum");
  1148. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Maximum", new Type[] { typeof(double), typeof(double) }), "Math,Maximum");
  1149. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Maximum", new Type[] { typeof(decimal), typeof(decimal) }), "Math,Maximum");
  1150. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Minimum", new Type[] { typeof(int), typeof(int) }), "Math,Minimum");
  1151. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Minimum", new Type[] { typeof(long), typeof(long) }), "Math,Minimum");
  1152. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Minimum", new Type[] { typeof(float), typeof(float) }), "Math,Minimum");
  1153. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Minimum", new Type[] { typeof(double), typeof(double) }), "Math,Minimum");
  1154. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Minimum", new Type[] { typeof(decimal), typeof(decimal) }), "Math,Minimum");
  1155. RegisteredObjects.InternalAddFunction(math.GetMethod("Round", new Type[] { typeof(double) }), "Math,Round");
  1156. RegisteredObjects.InternalAddFunction(math.GetMethod("Round", new Type[] { typeof(decimal) }), "Math,Round");
  1157. RegisteredObjects.InternalAddFunction(math.GetMethod("Round", new Type[] { typeof(double), typeof(int) }), "Math,Round");
  1158. RegisteredObjects.InternalAddFunction(math.GetMethod("Round", new Type[] { typeof(decimal), typeof(int) }), "Math,Round");
  1159. RegisteredObjects.InternalAddFunction(math.GetMethod("Sin"), "Math");
  1160. RegisteredObjects.InternalAddFunction(math.GetMethod("Sqrt"), "Math");
  1161. RegisteredObjects.InternalAddFunction(math.GetMethod("Tan"), "Math");
  1162. RegisteredObjects.InternalAddFunction(math.GetMethod("Truncate", new Type[] { typeof(double) }), "Math,Truncate");
  1163. RegisteredObjects.InternalAddFunction(math.GetMethod("Truncate", new Type[] { typeof(decimal) }), "Math,Truncate");
  1164. #endregion
  1165. #region Text
  1166. RegisteredObjects.AddFunctionCategory("Text", "Functions,Text");
  1167. Type str = typeof(StdFunctions);
  1168. RegisteredObjects.InternalAddFunction(str.GetMethod("Asc"), "Text");
  1169. RegisteredObjects.InternalAddFunction(str.GetMethod("Chr"), "Text");
  1170. RegisteredObjects.InternalAddFunction(str.GetMethod("Contains"), "Text");
  1171. RegisteredObjects.InternalAddFunction(str.GetMethod("Insert"), "Text");
  1172. RegisteredObjects.InternalAddFunction(str.GetMethod("Length"), "Text");
  1173. RegisteredObjects.InternalAddFunction(str.GetMethod("LowerCase"), "Text");
  1174. RegisteredObjects.InternalAddFunction(str.GetMethod("PadLeft", new Type[] { typeof(string), typeof(int) }), "Text,PadLeft");
  1175. RegisteredObjects.InternalAddFunction(str.GetMethod("PadLeft", new Type[] { typeof(string), typeof(int), typeof(char) }), "Text,PadLeft");
  1176. RegisteredObjects.InternalAddFunction(str.GetMethod("PadRight", new Type[] { typeof(string), typeof(int) }), "Text,PadRight");
  1177. RegisteredObjects.InternalAddFunction(str.GetMethod("PadRight", new Type[] { typeof(string), typeof(int), typeof(char) }), "Text,PadRight");
  1178. RegisteredObjects.InternalAddFunction(str.GetMethod("Remove", new Type[] { typeof(string), typeof(int) }), "Text,Remove");
  1179. RegisteredObjects.InternalAddFunction(str.GetMethod("Remove", new Type[] { typeof(string), typeof(int), typeof(int) }), "Text,Remove");
  1180. RegisteredObjects.InternalAddFunction(str.GetMethod("Replace"), "Text");
  1181. RegisteredObjects.InternalAddFunction(str.GetMethod("Substring", new Type[] { typeof(string), typeof(int) }), "Text,Substring");
  1182. RegisteredObjects.InternalAddFunction(str.GetMethod("Substring", new Type[] { typeof(string), typeof(int), typeof(int) }), "Text,Substring");
  1183. RegisteredObjects.InternalAddFunction(str.GetMethod("TitleCase"), "Text");
  1184. RegisteredObjects.InternalAddFunction(str.GetMethod("Trim"), "Text");
  1185. RegisteredObjects.InternalAddFunction(str.GetMethod("UpperCase"), "Text");
  1186. #endregion
  1187. #region Date & Time
  1188. RegisteredObjects.AddFunctionCategory("DateTime", "Functions,DateTime");
  1189. Type dt = typeof(StdFunctions);
  1190. RegisteredObjects.InternalAddFunction(dt.GetMethod("AddDays"), "DateTime");
  1191. RegisteredObjects.InternalAddFunction(dt.GetMethod("AddHours"), "DateTime");
  1192. RegisteredObjects.InternalAddFunction(dt.GetMethod("AddMinutes"), "DateTime");
  1193. RegisteredObjects.InternalAddFunction(dt.GetMethod("AddMonths"), "DateTime");
  1194. RegisteredObjects.InternalAddFunction(dt.GetMethod("AddSeconds"), "DateTime");
  1195. RegisteredObjects.InternalAddFunction(dt.GetMethod("AddYears"), "DateTime");
  1196. RegisteredObjects.InternalAddFunction(dt.GetMethod("DateDiff"), "DateTime");
  1197. RegisteredObjects.InternalAddFunction(dt.GetMethod("DateSerial"), "DateTime");
  1198. RegisteredObjects.InternalAddFunction(dt.GetMethod("Day"), "DateTime");
  1199. RegisteredObjects.InternalAddFunction(dt.GetMethod("DayOfWeek"), "DateTime");
  1200. RegisteredObjects.InternalAddFunction(dt.GetMethod("DayOfYear"), "DateTime");
  1201. RegisteredObjects.InternalAddFunction(dt.GetMethod("DaysInMonth"), "DateTime");
  1202. RegisteredObjects.InternalAddFunction(dt.GetMethod("Hour"), "DateTime");
  1203. RegisteredObjects.InternalAddFunction(dt.GetMethod("Minute"), "DateTime");
  1204. RegisteredObjects.InternalAddFunction(dt.GetMethod("Month"), "DateTime");
  1205. RegisteredObjects.InternalAddFunction(dt.GetMethod("MonthName"), "DateTime");
  1206. RegisteredObjects.InternalAddFunction(dt.GetMethod("Second"), "DateTime");
  1207. RegisteredObjects.InternalAddFunction(dt.GetMethod("WeekOfYear"), "DateTime");
  1208. RegisteredObjects.InternalAddFunction(dt.GetMethod("Year"), "DateTime");
  1209. #endregion
  1210. #region Formatting
  1211. RegisteredObjects.AddFunctionCategory("Formatting", "Functions,Formatting");
  1212. Type fmt = typeof(StdFunctions);
  1213. RegisteredObjects.InternalAddFunction(fmt.GetMethod("Format", new Type[] { typeof(string), typeof(object[]) }), "Formatting");
  1214. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatCurrency", new Type[] { typeof(object) }), "Formatting,FormatCurrency");
  1215. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatCurrency", new Type[] { typeof(object), typeof(int) }), "Formatting,FormatCurrency");
  1216. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatDateTime", new Type[] { typeof(DateTime) }), "Formatting,FormatDateTime");
  1217. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatDateTime", new Type[] { typeof(DateTime), typeof(string) }), "Formatting,FormatDateTime");
  1218. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatNumber", new Type[] { typeof(object) }), "Formatting,FormatNumber");
  1219. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatNumber", new Type[] { typeof(object), typeof(int) }), "Formatting,FormatNumber");
  1220. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatPercent", new Type[] { typeof(object) }), "Formatting,FormatPercent");
  1221. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatPercent", new Type[] { typeof(object), typeof(int) }), "Formatting,FormatPercent");
  1222. #endregion
  1223. #region Conversion
  1224. RegisteredObjects.AddFunctionCategory("Conversion", "Functions,Conversion");
  1225. Type stdConv = typeof(Convert);
  1226. Type myConv = typeof(StdFunctions);
  1227. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToBoolean", new Type[] { typeof(object) }), "Conversion");
  1228. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToByte", new Type[] { typeof(object) }), "Conversion");
  1229. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToChar", new Type[] { typeof(object) }), "Conversion");
  1230. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToDateTime", new Type[] { typeof(object) }), "Conversion");
  1231. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToDecimal", new Type[] { typeof(object) }), "Conversion");
  1232. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToDouble", new Type[] { typeof(object) }), "Conversion");
  1233. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToInt32", new Type[] { typeof(object) }), "Conversion");
  1234. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToRoman"), "Conversion");
  1235. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToSingle", new Type[] { typeof(object) }), "Conversion");
  1236. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToString", new Type[] { typeof(object) }), "Conversion");
  1237. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWords", new Type[] { typeof(object) }), "Conversion,ToWords");
  1238. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWords", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWords");
  1239. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWords", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWords");
  1240. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsIn", new Type[] { typeof(object) }), "Conversion,ToWordsIn");
  1241. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsIn", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsIn");
  1242. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsIn", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsIn");
  1243. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsDe", new Type[] { typeof(object) }), "Conversion,ToWordsDe");
  1244. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsDe", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsDe");
  1245. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsDe", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsDe");
  1246. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsEnGb", new Type[] { typeof(object) }), "Conversion,ToWordsEnGb");
  1247. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsEnGb", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsEnGb");
  1248. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsEnGb", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsEnGb");
  1249. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsEs", new Type[] { typeof(object) }), "Conversion,ToWordsEs");
  1250. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsEs", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsEs");
  1251. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsEs", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsEs");
  1252. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsFr", new Type[] { typeof(object) }), "Conversion,ToWordsFr");
  1253. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsFr", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsFr");
  1254. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsFr", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsFr");
  1255. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsNl", new Type[] { typeof(object) }), "Conversion,ToWordsNl");
  1256. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsNl", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsNl");
  1257. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsNl", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsNl");
  1258. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsRu", new Type[] { typeof(object) }), "Conversion,ToWordsRu");
  1259. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsRu", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsRu");
  1260. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsRu", new Type[] { typeof(object), typeof(bool), typeof(string), typeof(string), typeof(string) }), "Conversion,ToWordsRu");
  1261. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsUkr", new Type[] { typeof(object) }), "Conversion,ToWordsUkr");
  1262. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsUkr", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsUkr");
  1263. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsUkr", new Type[] { typeof(object), typeof(bool), typeof(string), typeof(string), typeof(string) }), "Conversion,ToWordsUkr");
  1264. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsSp", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsSp");
  1265. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsSp", new Type[] { typeof(object) }), "Conversion,ToWordsSp");
  1266. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsSp", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsSp");
  1267. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsPersian", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsPersian");
  1268. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsPersian", new Type[] { typeof(object) }), "Conversion,ToWordsPersian");
  1269. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsPersian", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsPersian");
  1270. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToLetters", new Type[] { typeof(object) }), "Conversion,ToLetters");
  1271. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToLetters", new Type[] { typeof(object), typeof(bool) }), "Conversion,ToLetters");
  1272. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToLettersRu", new Type[] { typeof(object) }), "Conversion,ToLettersRu");
  1273. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToLettersRu", new Type[] { typeof(object), typeof(bool) }), "Conversion,ToLettersRu");
  1274. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsPl", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsPl");
  1275. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsPl", new Type[] { typeof(object) }), "Conversion,ToWordsPl");
  1276. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsPl", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsPl");
  1277. #endregion
  1278. #region Program Flow
  1279. RegisteredObjects.AddFunctionCategory("ProgramFlow", "Functions,ProgramFlow");
  1280. Type misc = typeof(StdFunctions);
  1281. RegisteredObjects.InternalAddFunction(misc.GetMethod("Choose"), "ProgramFlow");
  1282. RegisteredObjects.InternalAddFunction(misc.GetMethod("IIf"), "ProgramFlow");
  1283. RegisteredObjects.InternalAddFunction(misc.GetMethod("Switch"), "ProgramFlow");
  1284. RegisteredObjects.InternalAddFunction(misc.GetMethod("IsNull"), "ProgramFlow");
  1285. #endregion
  1286. }
  1287. }
  1288. }