StdFunctions.cs 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  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. /// Removes all occurrences of white space characters from the beginning and end of the original string.
  288. /// </summary>
  289. /// <param name="s">The original string.</param>
  290. /// <returns>A new string.</returns>
  291. public static string Trim(string s)
  292. {
  293. return s == null ? "" : s.Trim();
  294. }
  295. /// <summary>
  296. /// Converts a specified string to uppercase.
  297. /// </summary>
  298. /// <param name="s">The string to convert.</param>
  299. /// <returns>A string in uppercase.</returns>
  300. public static string UpperCase(string s)
  301. {
  302. return s == null ? "" : s.ToUpper();
  303. }
  304. #endregion
  305. #region Date & Time functions
  306. /// <summary>
  307. /// Adds the specified number of days to the original date.
  308. /// </summary>
  309. /// <param name="date">The original date.</param>
  310. /// <param name="value">A number of whole and fractional days.</param>
  311. /// <returns>A new DateTime value.</returns>
  312. public static DateTime AddDays(DateTime date, double value)
  313. {
  314. return date.AddDays(value);
  315. }
  316. /// <summary>
  317. /// Adds the specified number of hours to the original date.
  318. /// </summary>
  319. /// <param name="date">The original date.</param>
  320. /// <param name="value">A number of whole and fractional hours.</param>
  321. /// <returns>A new DateTime value.</returns>
  322. public static DateTime AddHours(DateTime date, double value)
  323. {
  324. return date.AddHours(value);
  325. }
  326. /// <summary>
  327. /// Adds the specified number of minutes to the original date.
  328. /// </summary>
  329. /// <param name="date">The original date.</param>
  330. /// <param name="value">A number of whole and fractional minutes.</param>
  331. /// <returns>A new DateTime value.</returns>
  332. public static DateTime AddMinutes(DateTime date, double value)
  333. {
  334. return date.AddMinutes(value);
  335. }
  336. /// <summary>
  337. /// Adds the specified number of months to the original date.
  338. /// </summary>
  339. /// <param name="date">The original date.</param>
  340. /// <param name="value">A number of months.</param>
  341. /// <returns>A new DateTime value.</returns>
  342. public static DateTime AddMonths(DateTime date, int value)
  343. {
  344. return date.AddMonths(value);
  345. }
  346. /// <summary>
  347. /// Adds the specified number of seconds to the original date.
  348. /// </summary>
  349. /// <param name="date">The original date.</param>
  350. /// <param name="value">A number of whole and fractional seconds.</param>
  351. /// <returns>A new DateTime value.</returns>
  352. public static DateTime AddSeconds(DateTime date, double value)
  353. {
  354. return date.AddSeconds(value);
  355. }
  356. /// <summary>
  357. /// Adds the specified number of years to the original date.
  358. /// </summary>
  359. /// <param name="date">The original date.</param>
  360. /// <param name="value">A number of years.</param>
  361. /// <returns>A new DateTime value.</returns>
  362. public static DateTime AddYears(DateTime date, int value)
  363. {
  364. return date.AddYears(value);
  365. }
  366. /// <summary>
  367. /// Subtracts the specified date and time from the original date.
  368. /// </summary>
  369. /// <param name="date1">The original date.</param>
  370. /// <param name="date2">The date and time to subtract.</param>
  371. /// <returns>A TimeSpan interval between two dates.</returns>
  372. public static TimeSpan DateDiff(DateTime date1, DateTime date2)
  373. {
  374. return date1.Subtract(date2);
  375. }
  376. /// <summary>
  377. /// Initializes a new instance of the DateTime.
  378. /// </summary>
  379. /// <param name="year">The year.</param>
  380. /// <param name="month">The month.</param>
  381. /// <param name="day">The day.</param>
  382. /// <returns>A new DateTime value.</returns>
  383. public static DateTime DateSerial(int year, int month, int day)
  384. {
  385. return new DateTime(year, month, day);
  386. }
  387. /// <summary>
  388. /// Gets the day of the month.
  389. /// </summary>
  390. /// <param name="date">The date value.</param>
  391. /// <returns>The day component.</returns>
  392. public static int Day(DateTime date)
  393. {
  394. return date.Day;
  395. }
  396. /// <summary>
  397. /// Gets the localized name of the day of the week.
  398. /// </summary>
  399. /// <param name="date">The date value.</param>
  400. /// <returns>The name of the day of the week.</returns>
  401. public static string DayOfWeek(DateTime date)
  402. {
  403. return date.ToString("dddd");
  404. }
  405. /// <summary>
  406. /// Gets the day of the year.
  407. /// </summary>
  408. /// <param name="date">The date value.</param>
  409. /// <returns>The day of the year.</returns>
  410. public static int DayOfYear(DateTime date)
  411. {
  412. return date.DayOfYear;
  413. }
  414. /// <summary>
  415. /// Returns the number of days in the specified month and year.
  416. /// </summary>
  417. /// <param name="year">The year.</param>
  418. /// <param name="month">The month.</param>
  419. /// <returns>The number of days in month for the specified year.</returns>
  420. public static int DaysInMonth(int year, int month)
  421. {
  422. return DateTime.DaysInMonth(year, month);
  423. }
  424. /// <summary>
  425. /// Gets the hour component of the date.
  426. /// </summary>
  427. /// <param name="date">The date.</param>
  428. /// <returns>The hour component.</returns>
  429. public static int Hour(DateTime date)
  430. {
  431. return date.Hour;
  432. }
  433. /// <summary>
  434. /// Gets the minute component of the date.
  435. /// </summary>
  436. /// <param name="date">The date.</param>
  437. /// <returns>The minute component.</returns>
  438. public static int Minute(DateTime date)
  439. {
  440. return date.Minute;
  441. }
  442. /// <summary>
  443. /// Gets the month component of the date.
  444. /// </summary>
  445. /// <param name="date">The date.</param>
  446. /// <returns>The month component.</returns>
  447. public static int Month(DateTime date)
  448. {
  449. return date.Month;
  450. }
  451. /// <summary>
  452. /// Gets the localized month name.
  453. /// </summary>
  454. /// <param name="month">The month number.</param>
  455. /// <returns>The month name.</returns>
  456. public static string MonthName(int month)
  457. {
  458. return new DateTime(2000, month, 1).ToString("MMMM");
  459. }
  460. /// <summary>
  461. /// Gets the seconds component of the date.
  462. /// </summary>
  463. /// <param name="date">The date.</param>
  464. /// <returns>The seconds component.</returns>
  465. public static int Second(DateTime date)
  466. {
  467. return date.Second;
  468. }
  469. /// <summary>
  470. /// Gets the week of the year.
  471. /// </summary>
  472. /// <param name="date">The date value.</param>
  473. /// <returns>The week of the year.</returns>
  474. public static int WeekOfYear(DateTime date)
  475. {
  476. CalendarWeekRule rule = CultureInfo.CurrentCulture.DateTimeFormat.CalendarWeekRule;
  477. DayOfWeek day = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek;
  478. return CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(date, rule, day);
  479. }
  480. /// <summary>
  481. /// Gets the year component of the date.
  482. /// </summary>
  483. /// <param name="date">The date.</param>
  484. /// <returns>The year component.</returns>
  485. public static int Year(DateTime date)
  486. {
  487. return date.Year;
  488. }
  489. #endregion
  490. #region Formatting
  491. /// <summary>
  492. /// Replaces the format item in a specified String with the text equivalent of the value of a
  493. /// corresponding Object instance in a specified array.
  494. /// </summary>
  495. /// <param name="format">A String containing zero or more format items.</param>
  496. /// <param name="args">An Object array containing zero or more objects to format.</param>
  497. /// <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>
  498. public static string Format(string format, params object[] args)
  499. {
  500. if (args != null)
  501. {
  502. for (int i = 0; i < args.Length; i++)
  503. {
  504. if (args[i] is Variant)
  505. args[i] = ((Variant)args[i]).Value;
  506. }
  507. }
  508. return String.Format(format, args);
  509. }
  510. /// <summary>
  511. /// Returns a string formatted as a currency value.
  512. /// </summary>
  513. /// <param name="value">The value to format.</param>
  514. /// <returns>The formatted string.</returns>
  515. public static string FormatCurrency(object value)
  516. {
  517. if (value is Variant)
  518. value = ((Variant)value).Value;
  519. return String.Format("{0:c}", value);
  520. }
  521. /// <summary>
  522. /// Returns a string formatted as a currency value with specified number of decimal digits.
  523. /// </summary>
  524. /// <param name="value">The value to format.</param>
  525. /// <param name="decimalDigits">Number of decimal digits.</param>
  526. /// <returns>The formatted string.</returns>
  527. public static string FormatCurrency(object value, int decimalDigits)
  528. {
  529. if (value is Variant)
  530. value = ((Variant)value).Value;
  531. NumberFormatInfo info = CultureInfo.CurrentCulture.NumberFormat.Clone() as NumberFormatInfo;
  532. info.CurrencyDecimalDigits = decimalDigits;
  533. return String.Format(info, "{0:c}", value);
  534. }
  535. /// <summary>
  536. /// Returns a string formatted as a date/time value.
  537. /// </summary>
  538. /// <param name="value">The value to format.</param>
  539. /// <returns>The formatted string.</returns>
  540. public static string FormatDateTime(DateTime value)
  541. {
  542. string format = "G";
  543. if (value.TimeOfDay.Ticks == value.Ticks)
  544. format = "T";
  545. else if (value.TimeOfDay.Ticks == 0)
  546. format = "d";
  547. return value.ToString(format, null);
  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. /// <param name="format">The format specifier, one of the
  554. /// "Long Date", "Short Date", "Long Time", "Short Time" values.</param>
  555. /// <returns>The formatted string.</returns>
  556. public static string FormatDateTime(DateTime value, string format)
  557. {
  558. string _format = format.ToLower().Replace(" ", "");
  559. switch (_format)
  560. {
  561. case "longdate":
  562. return value.ToString("D", null);
  563. case "shortdate":
  564. return value.ToString("d", null);
  565. case "longtime":
  566. return value.ToString("T", null);
  567. case "shorttime":
  568. return value.ToString("HH:mm", null);
  569. }
  570. return value.ToString(format, null);
  571. }
  572. /// <summary>
  573. /// Returns a string formatted as a numeric value.
  574. /// </summary>
  575. /// <param name="value">The value to format.</param>
  576. /// <returns>The formatted string.</returns>
  577. public static string FormatNumber(object value)
  578. {
  579. if (value is Variant)
  580. value = ((Variant)value).Value;
  581. return String.Format("{0:n}", value);
  582. }
  583. /// <summary>
  584. /// Returns a string formatted as a numeric value with specified number of decimal digits.
  585. /// </summary>
  586. /// <param name="value">The value to format.</param>
  587. /// <param name="decimalDigits">Number of decimal digits.</param>
  588. /// <returns>The formatted string.</returns>
  589. public static string FormatNumber(object value, int decimalDigits)
  590. {
  591. if (value is Variant)
  592. value = ((Variant)value).Value;
  593. NumberFormatInfo info = CultureInfo.CurrentCulture.NumberFormat.Clone() as NumberFormatInfo;
  594. info.NumberDecimalDigits = decimalDigits;
  595. return String.Format(info, "{0:n}", value);
  596. }
  597. /// <summary>
  598. /// Returns a string formatted as a percent value.
  599. /// </summary>
  600. /// <param name="value">The value to format.</param>
  601. /// <returns>The formatted string.</returns>
  602. public static string FormatPercent(object value)
  603. {
  604. if (value is Variant)
  605. value = ((Variant)value).Value;
  606. return String.Format("{0:p}", value);
  607. }
  608. /// <summary>
  609. /// Returns a string formatted as a percent value with specified number of decimal digits.
  610. /// </summary>
  611. /// <param name="value">The value to format.</param>
  612. /// <param name="decimalDigits">Number of decimal digits.</param>
  613. /// <returns>The formatted string.</returns>
  614. public static string FormatPercent(object value, int decimalDigits)
  615. {
  616. if (value is Variant)
  617. value = ((Variant)value).Value;
  618. NumberFormatInfo info = CultureInfo.CurrentCulture.NumberFormat.Clone() as NumberFormatInfo;
  619. info.PercentDecimalDigits = decimalDigits;
  620. return String.Format(info, "{0:p}", value);
  621. }
  622. #endregion
  623. #region Conversion
  624. /// <summary>
  625. /// Converts a numeric value to Roman string representation.
  626. /// </summary>
  627. /// <param name="value">Integer value in range 0-3998.</param>
  628. /// <returns>The string in Roman form.</returns>
  629. public static string ToRoman(object value)
  630. {
  631. return Roman.Convert(Convert.ToInt32(value));
  632. }
  633. /// <summary>
  634. /// Converts a currency value to an english (US) string representation of that value.
  635. /// </summary>
  636. /// <param name="value">The currency value to convert.</param>
  637. /// <returns>The string representation of the specified value.</returns>
  638. public static string ToWords(object value)
  639. {
  640. return ToWords(value, "USD");
  641. }
  642. /// <summary>
  643. /// Converts a currency value to an english (US) string representation of that value,
  644. /// using the specified currency.
  645. /// </summary>
  646. /// <param name="value">The currency value to convert.</param>
  647. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  648. /// <returns>The string representation of the specified value.</returns>
  649. public static string ToWords(object value, string currencyName)
  650. {
  651. return new NumToWordsEn().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  652. }
  653. /// <summary>
  654. /// Converts a numeric value to an english (US) string representation of that value.
  655. /// </summary>
  656. /// <param name="value">The numeric value to convert.</param>
  657. /// <param name="one">The name in singular form, for example "page".</param>
  658. /// <param name="many">The name in plural form, for example "pages".</param>
  659. /// <returns>The string representation of the specified value.</returns>
  660. public static string ToWords(object value, string one, string many)
  661. {
  662. return new NumToWordsEn().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  663. }
  664. /// <summary>
  665. /// Converts a currency value to an english (GB) string representation of that value.
  666. /// </summary>
  667. /// <param name="value">The currency value to convert.</param>
  668. /// <returns>The string representation of the specified value.</returns>
  669. public static string ToWordsEnGb(object value)
  670. {
  671. return ToWordsEnGb(value, "GBP");
  672. }
  673. /// <summary>
  674. /// Converts a currency value to an english (GB) string representation of that value,
  675. /// using the specified currency.
  676. /// </summary>
  677. /// <param name="value">The currency value to convert.</param>
  678. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  679. /// <returns>The string representation of the specified value.</returns>
  680. public static string ToWordsEnGb(object value, string currencyName)
  681. {
  682. return new NumToWordsEnGb().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  683. }
  684. /// <summary>
  685. /// Converts a numeric value to an english (GB) string representation of that value.
  686. /// </summary>
  687. /// <param name="value">The numeric value to convert.</param>
  688. /// <param name="one">The name in singular form, for example "page".</param>
  689. /// <param name="many">The name in plural form, for example "pages".</param>
  690. /// <returns>The string representation of the specified value.</returns>
  691. public static string ToWordsEnGb(object value, string one, string many)
  692. {
  693. return new NumToWordsEnGb().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  694. }
  695. /// <summary>
  696. /// Converts a currency value to a spanish string representation of that value.
  697. /// </summary>
  698. /// <param name="value">The currency value to convert.</param>
  699. /// <returns>The string representation of the specified value.</returns>
  700. public static string ToWordsEs(object value)
  701. {
  702. return ToWordsEs(value, "EUR");
  703. }
  704. /// <summary>
  705. /// Converts a currency value to a spanish string representation of that value,
  706. /// using the specified currency.
  707. /// </summary>
  708. /// <param name="value">The currency value to convert.</param>
  709. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  710. /// <returns>The string representation of the specified value.</returns>
  711. public static string ToWordsEs(object value, string currencyName)
  712. {
  713. return new NumToWordsEs().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  714. }
  715. /// <summary>
  716. /// Converts a numeric value to a spanish string representation of that value.
  717. /// </summary>
  718. /// <param name="value">The numeric value to convert.</param>
  719. /// <param name="one">The name in singular form, for example "page".</param>
  720. /// <param name="many">The name in plural form, for example "pages".</param>
  721. /// <returns>The string representation of the specified value.</returns>
  722. public static string ToWordsEs(object value, string one, string many)
  723. {
  724. return new NumToWordsEs().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  725. }
  726. /// <summary>
  727. /// Converts a currency value to a russian string representation of that value.
  728. /// </summary>
  729. /// <param name="value">The currency value to convert.</param>
  730. /// <returns>The string representation of the specified value.</returns>
  731. public static string ToWordsRu(object value)
  732. {
  733. return ToWordsRu(value, "RUR");
  734. }
  735. /// <summary>
  736. /// Converts a currency value to a russian string representation of that value,
  737. /// using the specified currency.
  738. /// </summary>
  739. /// <param name="value">The currency value to convert.</param>
  740. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  741. /// <returns>The string representation of the specified value.</returns>
  742. public static string ToWordsRu(object value, string currencyName)
  743. {
  744. return new NumToWordsRu().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  745. }
  746. /// <summary>
  747. /// Converts a numeric value to a russian string representation of that value.
  748. /// </summary>
  749. /// <param name="value">The numeric value to convert.</param>
  750. /// <param name="male">True if the name is of male gender.</param>
  751. /// <param name="one">The name in singular form, for example "страница".</param>
  752. /// <param name="two">The name in plural form, for example "страницы".</param>
  753. /// <param name="many">The name in plural form, for example "страниц".</param>
  754. /// <returns>The string representation of the specified value.</returns>
  755. public static string ToWordsRu(object value, bool male, string one, string two, string many)
  756. {
  757. return new NumToWordsRu().ConvertNumber(Convert.ToDecimal(value), male, one, two, many);
  758. }
  759. /// <summary>
  760. /// Converts a currency value to a german string representation of that value.
  761. /// </summary>
  762. /// <param name="value">The currency value to convert.</param>
  763. /// <returns>The string representation of the specified value.</returns>
  764. public static string ToWordsDe(object value)
  765. {
  766. return ToWordsDe(value, "EUR");
  767. }
  768. /// <summary>
  769. /// Converts a currency value to a german string representation of that value,
  770. /// using the specified currency.
  771. /// </summary>
  772. /// <param name="value">The currency value to convert.</param>
  773. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  774. /// <returns>The string representation of the specified value.</returns>
  775. public static string ToWordsDe(object value, string currencyName)
  776. {
  777. return new NumToWordsDe().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  778. }
  779. /// <summary>
  780. /// Converts a numeric value to a german string representation of that value.
  781. /// </summary>
  782. /// <param name="value">The numeric value to convert.</param>
  783. /// <param name="one">The name in singular form, for example "page".</param>
  784. /// <param name="many">The name in plural form, for example "pages".</param>
  785. /// <returns>The string representation of the specified value.</returns>
  786. public static string ToWordsDe(object value, string one, string many)
  787. {
  788. return new NumToWordsDe().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  789. }
  790. /// <summary>
  791. /// Converts a currency value to a french string representation of that value.
  792. /// </summary>
  793. /// <param name="value">The currency value to convert.</param>
  794. /// <returns>The string representation of the specified value.</returns>
  795. public static string ToWordsFr(object value)
  796. {
  797. return ToWordsFr(value, "EUR");
  798. }
  799. /// <summary>
  800. /// Converts a currency value to a french string representation of that value,
  801. /// using the specified currency.
  802. /// </summary>
  803. /// <param name="value">The currency value to convert.</param>
  804. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  805. /// <returns>The string representation of the specified value.</returns>
  806. public static string ToWordsFr(object value, string currencyName)
  807. {
  808. return new NumToWordsFr().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  809. }
  810. /// <summary>
  811. /// Converts a numeric value to a french string representation of that value.
  812. /// </summary>
  813. /// <param name="value">The numeric value to convert.</param>
  814. /// <param name="one">The name in singular form, for example "page".</param>
  815. /// <param name="many">The name in plural form, for example "pages".</param>
  816. /// <returns>The string representation of the specified value.</returns>
  817. public static string ToWordsFr(object value, string one, string many)
  818. {
  819. return new NumToWordsFr().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  820. }
  821. /// <summary>
  822. /// Converts a currency value to a dutch string representation of that value.
  823. /// </summary>
  824. /// <param name="value">The currency value to convert.</param>
  825. /// <returns>The string representation of the specified value.</returns>
  826. public static string ToWordsNl(object value)
  827. {
  828. return ToWordsNl(value, "EUR");
  829. }
  830. /// <summary>
  831. /// Converts a currency value to a dutch string representation of that value,
  832. /// using the specified currency.
  833. /// </summary>
  834. /// <param name="value">The currency value to convert.</param>
  835. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  836. /// <returns>The string representation of the specified value.</returns>
  837. public static string ToWordsNl(object value, string currencyName)
  838. {
  839. return new NumToWordsNl().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  840. }
  841. /// <summary>
  842. /// Converts a numeric value to a dutch string representation of that value.
  843. /// </summary>
  844. /// <param name="value">The numeric value to convert.</param>
  845. /// <param name="one">The name in singular form, for example "page".</param>
  846. /// <param name="many">The name in plural form, for example "pages".</param>
  847. /// <returns>The string representation of the specified value.</returns>
  848. public static string ToWordsNl(object value, string one, string many)
  849. {
  850. return new NumToWordsNl().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  851. }
  852. /// <summary>
  853. /// Converts a numeric value to a indian numbering system string representation of that value.
  854. /// </summary>
  855. /// <param name="value">the currency value to convert</param>
  856. /// <returns>The string representation of the specified value.</returns>
  857. public static string ToWordsIn(object value)
  858. {
  859. return ToWordsIn(value, "INR");
  860. }
  861. /// <summary>
  862. /// Converts a numeric value to a indian numbering system string representation of that value.
  863. /// </summary>
  864. /// <param name="value">he numeric value to convert.</param>
  865. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "INR".</param>
  866. /// <returns></returns>
  867. public static string ToWordsIn(object value,string currencyName)
  868. {
  869. return new NumToWordsIn().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  870. }
  871. /// <summary>
  872. /// Converts a numeric value to a indian numbering system string representation of that value.
  873. /// </summary>
  874. /// <param name="value">The numeric value to convert.</param>
  875. /// <param name="one">The name in singular form, for example "page".</param>
  876. /// <param name="many">The name in plural form, for example "pages".</param>
  877. /// <returns>The string representation of the specified value.</returns>
  878. public static string ToWordsIn(object value, string one, string many)
  879. {
  880. return new NumToWordsIn().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  881. }
  882. /// <summary>
  883. /// Converts a numeric value to a ukrainian string representation of that value.
  884. /// </summary>
  885. /// <param name="value">The numeric value to convert.</param>
  886. /// <returns>The string representation of the specified value.</returns>
  887. public static string ToWordsUkr(object value)
  888. {
  889. return ToWordsUkr(value,"UAH");
  890. }
  891. /// <summary>
  892. /// Converts a currency value to a ukrainian string representation of that value,
  893. /// using the specified currency.
  894. /// </summary>
  895. /// <param name="value">The currency value to convert.</param>
  896. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "UAH".</param>
  897. /// <returns>The string representation of the specified value.</returns>
  898. public static string ToWordsUkr(object value, string currencyName)
  899. {
  900. return new NumToWordsUkr().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  901. }
  902. /// <summary>
  903. /// Converts a numeric value to a ukrainian string representation of that value.
  904. /// </summary>
  905. /// <param name="value">The numeric value to convert.</param>
  906. /// <param name="male">True if the name is of male gender.</param>
  907. /// <param name="one">The name in singular form, for example "сторінка".</param>
  908. /// <param name="two">The name in plural form, for example "сторінки".</param>
  909. /// <param name="many">The name in plural form, for example "сторінок".</param>
  910. /// <returns>The string representation of the specified value.</returns>
  911. public static string ToWordsUkr(object value, bool male, string one, string two, string many)
  912. {
  913. return new NumToWordsUkr().ConvertNumber(Convert.ToDecimal(value), male, one, two, many);
  914. }
  915. /// <summary>
  916. /// Converts a numeric value to a spanish string representation of that value.
  917. /// </summary>
  918. /// <param name="value">The numeric value to convert.</param>
  919. /// <returns>The string representation of the specified value.</returns>
  920. public static string ToWordsSp(object value)
  921. {
  922. return ToWordsSp(value, "EUR");
  923. }
  924. /// <summary>
  925. /// Converts a numeric value to a spanish representation of that value.
  926. /// </summary>
  927. /// <param name="value">he numeric value to convert.</param>
  928. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  929. /// <returns></returns>
  930. public static string ToWordsSp(object value, string currencyName)
  931. {
  932. return new NumToWordsSp().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  933. }
  934. /// <summary>
  935. /// Converts a numeric value to a spanish string representation of that value.
  936. /// </summary>
  937. /// <param name="value">The numeric value to convert.</param>
  938. /// <param name="male">True if the name is of male gender.</param>
  939. /// <param name="one">The name in singular form, for example "silla".</param>
  940. /// <param name="two">The name in plural form, for example "Sillas".</param>
  941. /// <param name="many">The name in plural form, for example "Sillas".</param>
  942. /// <returns>The string representation of the specified value.</returns>
  943. public static string ToWordsSp(object value, string one, string many)
  944. {
  945. return new NumToWordsSp().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  946. }
  947. /// <summary>
  948. /// Converts a numeric value to a persian string representation of that value.
  949. /// </summary>
  950. /// <param name="value">The numeric value to convert.</param>
  951. /// <returns>The string representation of the specified value.</returns>
  952. public static string ToWordsPersian(object value)
  953. {
  954. return ToWordsPersian(value, "EUR");
  955. }
  956. /// <summary>
  957. /// Converts a numeric value to a persian representation of that value.
  958. /// </summary>
  959. /// <param name="value">he numeric value to convert.</param>
  960. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  961. /// <returns></returns>
  962. public static string ToWordsPersian(object value, string currencyName)
  963. {
  964. return new NumToWordsPersian().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  965. }
  966. /// <summary>
  967. /// Converts a numeric value to a persian string representation of that value.
  968. /// </summary>
  969. /// <param name="value">The numeric value to convert.</param>
  970. /// <param name="male">True if the name is of male gender.</param>
  971. /// <param name="one">The name in singular form, for example "silla".</param>
  972. /// <param name="two">The name in plural form, for example "Sillas".</param>
  973. /// <param name="many">The name in plural form, for example "Sillas".</param>
  974. /// <returns>The string representation of the specified value.</returns>
  975. public static string ToWordsPersian(object value, string one, string many)
  976. {
  977. return new NumToWordsPersian().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  978. }
  979. /// <summary>
  980. /// Converts a numeric value to a polish string representation of that value.
  981. /// </summary>
  982. /// <param name="value">The numeric value to convert.</param>
  983. /// <returns>The string representation of the specified value.</returns>
  984. public static string ToWordsPl(object value)
  985. {
  986. return ToWordsPl(value, "PLN");
  987. }
  988. /// <summary>
  989. /// Converts a numeric value to a polish representation of that value.
  990. /// </summary>
  991. /// <param name="value">he numeric value to convert.</param>
  992. /// <param name="currencyName">The 3-digit ISO name of the currency, for example "EUR".</param>
  993. /// <returns></returns>
  994. public static string ToWordsPl(object value, string currencyName)
  995. {
  996. return new NumToWordsPl().ConvertCurrency(Convert.ToDecimal(value), currencyName);
  997. }
  998. /// <summary>
  999. /// Converts a numeric value to a polish string representation of that value.
  1000. /// </summary>
  1001. /// <param name="value">The numeric value to convert.</param>
  1002. /// <param name="male">True if the name is of male gender.</param>
  1003. /// <param name="one">The name in singular form, for example "silla".</param>
  1004. /// <param name="two">The name in plural form, for example "Sillas".</param>
  1005. /// <param name="many">The name in plural form, for example "Sillas".</param>
  1006. /// <returns>The string representation of the specified value.</returns>
  1007. public static string ToWordsPl(object value, string one, string many)
  1008. {
  1009. return new NumToWordsPl().ConvertNumber(Convert.ToDecimal(value), true, one, many, many);
  1010. }
  1011. /// <summary>
  1012. /// Converts a value to an english (US) alphabet string representation of that value.
  1013. /// </summary>
  1014. /// <param name="value">The value to convert.</param>
  1015. /// <returns>The alphabet string representation of the specified value.</returns>
  1016. public static string ToLetters(object value)
  1017. {
  1018. return ToLetters(value, false);
  1019. }
  1020. /// <summary>
  1021. /// Converts a value to an english (US) alphabet string representation of that value.
  1022. /// </summary>
  1023. /// <param name="value">The value to convert.</param>
  1024. /// <param name="isUpper">Bool indicating that letters should be in upper registry.</param>
  1025. /// <returns>The alphabet string representation of the specified value.</returns>
  1026. public static string ToLetters(object value, bool isUpper)
  1027. {
  1028. return new NumToLettersEn().ConvertNumber(Convert.ToInt32(value), isUpper);
  1029. }
  1030. /// <summary>
  1031. /// Converts a value to a russian alphabet string representation of that value.
  1032. /// </summary>
  1033. /// <param name="value">The value to convert.</param>
  1034. /// <returns>The alphabet string representation of the specified value.</returns>
  1035. public static string ToLettersRu(object value)
  1036. {
  1037. return ToLettersRu(value, false);
  1038. }
  1039. /// <summary>
  1040. /// Converts a value to a russian alphabet string representation of that value.
  1041. /// </summary>
  1042. /// <param name="value">The value to convert.</param>
  1043. /// <param name="isUpper">Bool indicating that letters should be in upper registry.</param>
  1044. /// <returns>The alphabet string representation of the specified value.</returns>
  1045. public static string ToLettersRu(object value, bool isUpper)
  1046. {
  1047. return new NumToLettersRu().ConvertNumber(Convert.ToInt32(value), isUpper);
  1048. }
  1049. #endregion
  1050. #region Program Flow
  1051. /// <summary>
  1052. /// Selects and returns a value from a list of arguments.
  1053. /// </summary>
  1054. /// <param name="index">A value between 1 and the number of elements passed in the "choice" argument.</param>
  1055. /// <param name="choice">Object parameter array.</param>
  1056. /// <returns>One of the values in the "choice" argument.</returns>
  1057. public static object Choose(double index, params object[] choice)
  1058. {
  1059. int ind = (int)index - 1;
  1060. if (ind < 0 || ind >= choice.Length)
  1061. return null;
  1062. return choice[ind];
  1063. }
  1064. /// <summary>
  1065. /// Returns one of two objects, depending on the evaluation of an expression.
  1066. /// </summary>
  1067. /// <param name="expression">The expression you want to evaluate.</param>
  1068. /// <param name="truePart">Returned if Expression evaluates to True.</param>
  1069. /// <param name="falsePart">Returned if Expression evaluates to False.</param>
  1070. /// <returns>Either truePart os falsePart.</returns>
  1071. public static object IIf(bool expression, object truePart, object falsePart)
  1072. {
  1073. return expression ? truePart : falsePart;
  1074. }
  1075. /// <summary>
  1076. /// Evaluates a list of expressions and returns a value corresponding to the first
  1077. /// expression in the list that is True.
  1078. /// </summary>
  1079. /// <param name="expressions">Parameter array consists of paired expressions and values.</param>
  1080. /// <returns>The value corresponding to an expression which returns true.</returns>
  1081. public static object Switch(params object[] expressions)
  1082. {
  1083. for (int i = 0; i + 1 < expressions.Length; i += 2)
  1084. {
  1085. if (Convert.ToBoolean(expressions[i]) == true)
  1086. return expressions[i + 1];
  1087. }
  1088. return null;
  1089. }
  1090. /// <summary>
  1091. /// Checks if the specified object is null.
  1092. /// </summary>
  1093. /// <param name="thisReport">The report instance.</param>
  1094. /// <param name="name">Either a name of DB column, or a parameter name, or a total name to check.</param>
  1095. /// <returns><b>true</b> if the object's value is null.</returns>
  1096. public static bool IsNull(Report thisReport, string name)
  1097. {
  1098. object value = null;
  1099. if (DataHelper.IsValidColumn(thisReport.Dictionary, name))
  1100. {
  1101. value = thisReport.GetColumnValueNullable(name);
  1102. }
  1103. else if (DataHelper.IsValidParameter(thisReport.Dictionary, name))
  1104. {
  1105. value = thisReport.GetParameterValue(name);
  1106. }
  1107. else if (DataHelper.IsValidTotal(thisReport.Dictionary, name))
  1108. {
  1109. value = thisReport.GetTotalValueNullable(name).Value;
  1110. }
  1111. return value == null || value == DBNull.Value;
  1112. }
  1113. #endregion
  1114. internal static void Register()
  1115. {
  1116. #region Math
  1117. RegisteredObjects.AddFunctionCategory("Math", "Functions,Math");
  1118. Type math = typeof(Math);
  1119. RegisteredObjects.AddFunction(math.GetMethod("Abs", new Type[] { typeof(sbyte) }), "Math,Abs");
  1120. RegisteredObjects.InternalAddFunction(math.GetMethod("Abs", new Type[] { typeof(short) }), "Math,Abs");
  1121. RegisteredObjects.InternalAddFunction(math.GetMethod("Abs", new Type[] { typeof(int) }), "Math,Abs");
  1122. RegisteredObjects.InternalAddFunction(math.GetMethod("Abs", new Type[] { typeof(long) }), "Math,Abs");
  1123. RegisteredObjects.InternalAddFunction(math.GetMethod("Abs", new Type[] { typeof(float) }), "Math,Abs");
  1124. RegisteredObjects.InternalAddFunction(math.GetMethod("Abs", new Type[] { typeof(double) }), "Math,Abs");
  1125. RegisteredObjects.InternalAddFunction(math.GetMethod("Abs", new Type[] { typeof(decimal) }), "Math,Abs");
  1126. RegisteredObjects.InternalAddFunction(math.GetMethod("Acos"), "Math");
  1127. RegisteredObjects.InternalAddFunction(math.GetMethod("Asin"), "Math");
  1128. RegisteredObjects.InternalAddFunction(math.GetMethod("Atan"), "Math");
  1129. RegisteredObjects.InternalAddFunction(math.GetMethod("Ceiling", new Type[] { typeof(double) }), "Math,Ceiling");
  1130. RegisteredObjects.InternalAddFunction(math.GetMethod("Ceiling", new Type[] { typeof(decimal) }), "Math,Ceiling");
  1131. RegisteredObjects.InternalAddFunction(math.GetMethod("Cos"), "Math");
  1132. RegisteredObjects.InternalAddFunction(math.GetMethod("Exp"), "Math");
  1133. RegisteredObjects.InternalAddFunction(math.GetMethod("Floor", new Type[] { typeof(double) }), "Math,Floor");
  1134. RegisteredObjects.InternalAddFunction(math.GetMethod("Floor", new Type[] { typeof(decimal) }), "Math,Floor");
  1135. RegisteredObjects.InternalAddFunction(math.GetMethod("Log", new Type[] { typeof(double) }), "Math");
  1136. Type myMath = typeof(StdFunctions);
  1137. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Maximum", new Type[] { typeof(int), typeof(int) }), "Math,Maximum");
  1138. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Maximum", new Type[] { typeof(long), typeof(long) }), "Math,Maximum");
  1139. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Maximum", new Type[] { typeof(float), typeof(float) }), "Math,Maximum");
  1140. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Maximum", new Type[] { typeof(double), typeof(double) }), "Math,Maximum");
  1141. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Maximum", new Type[] { typeof(decimal), typeof(decimal) }), "Math,Maximum");
  1142. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Minimum", new Type[] { typeof(int), typeof(int) }), "Math,Minimum");
  1143. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Minimum", new Type[] { typeof(long), typeof(long) }), "Math,Minimum");
  1144. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Minimum", new Type[] { typeof(float), typeof(float) }), "Math,Minimum");
  1145. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Minimum", new Type[] { typeof(double), typeof(double) }), "Math,Minimum");
  1146. RegisteredObjects.InternalAddFunction(myMath.GetMethod("Minimum", new Type[] { typeof(decimal), typeof(decimal) }), "Math,Minimum");
  1147. RegisteredObjects.InternalAddFunction(math.GetMethod("Round", new Type[] { typeof(double) }), "Math,Round");
  1148. RegisteredObjects.InternalAddFunction(math.GetMethod("Round", new Type[] { typeof(decimal) }), "Math,Round");
  1149. RegisteredObjects.InternalAddFunction(math.GetMethod("Round", new Type[] { typeof(double), typeof(int) }), "Math,Round");
  1150. RegisteredObjects.InternalAddFunction(math.GetMethod("Round", new Type[] { typeof(decimal), typeof(int) }), "Math,Round");
  1151. RegisteredObjects.InternalAddFunction(math.GetMethod("Sin"), "Math");
  1152. RegisteredObjects.InternalAddFunction(math.GetMethod("Sqrt"), "Math");
  1153. RegisteredObjects.InternalAddFunction(math.GetMethod("Tan"), "Math");
  1154. RegisteredObjects.InternalAddFunction(math.GetMethod("Truncate", new Type[] { typeof(double) }), "Math,Truncate");
  1155. RegisteredObjects.InternalAddFunction(math.GetMethod("Truncate", new Type[] { typeof(decimal) }), "Math,Truncate");
  1156. #endregion
  1157. #region Text
  1158. RegisteredObjects.AddFunctionCategory("Text", "Functions,Text");
  1159. Type str = typeof(StdFunctions);
  1160. RegisteredObjects.InternalAddFunction(str.GetMethod("Asc"), "Text");
  1161. RegisteredObjects.InternalAddFunction(str.GetMethod("Chr"), "Text");
  1162. RegisteredObjects.InternalAddFunction(str.GetMethod("Insert"), "Text");
  1163. RegisteredObjects.InternalAddFunction(str.GetMethod("Length"), "Text");
  1164. RegisteredObjects.InternalAddFunction(str.GetMethod("LowerCase"), "Text");
  1165. RegisteredObjects.InternalAddFunction(str.GetMethod("PadLeft", new Type[] { typeof(string), typeof(int) }), "Text,PadLeft");
  1166. RegisteredObjects.InternalAddFunction(str.GetMethod("PadLeft", new Type[] { typeof(string), typeof(int), typeof(char) }), "Text,PadLeft");
  1167. RegisteredObjects.InternalAddFunction(str.GetMethod("PadRight", new Type[] { typeof(string), typeof(int) }), "Text,PadRight");
  1168. RegisteredObjects.InternalAddFunction(str.GetMethod("PadRight", new Type[] { typeof(string), typeof(int), typeof(char) }), "Text,PadRight");
  1169. RegisteredObjects.InternalAddFunction(str.GetMethod("Remove", new Type[] { typeof(string), typeof(int) }), "Text,Remove");
  1170. RegisteredObjects.InternalAddFunction(str.GetMethod("Remove", new Type[] { typeof(string), typeof(int), typeof(int) }), "Text,Remove");
  1171. RegisteredObjects.InternalAddFunction(str.GetMethod("Replace"), "Text");
  1172. RegisteredObjects.InternalAddFunction(str.GetMethod("Substring", new Type[] { typeof(string), typeof(int) }), "Text,Substring");
  1173. RegisteredObjects.InternalAddFunction(str.GetMethod("Substring", new Type[] { typeof(string), typeof(int), typeof(int) }), "Text,Substring");
  1174. RegisteredObjects.InternalAddFunction(str.GetMethod("TitleCase"), "Text");
  1175. RegisteredObjects.InternalAddFunction(str.GetMethod("Trim"), "Text");
  1176. RegisteredObjects.InternalAddFunction(str.GetMethod("UpperCase"), "Text");
  1177. #endregion
  1178. #region Date & Time
  1179. RegisteredObjects.AddFunctionCategory("DateTime", "Functions,DateTime");
  1180. Type dt = typeof(StdFunctions);
  1181. RegisteredObjects.InternalAddFunction(dt.GetMethod("AddDays"), "DateTime");
  1182. RegisteredObjects.InternalAddFunction(dt.GetMethod("AddHours"), "DateTime");
  1183. RegisteredObjects.InternalAddFunction(dt.GetMethod("AddMinutes"), "DateTime");
  1184. RegisteredObjects.InternalAddFunction(dt.GetMethod("AddMonths"), "DateTime");
  1185. RegisteredObjects.InternalAddFunction(dt.GetMethod("AddSeconds"), "DateTime");
  1186. RegisteredObjects.InternalAddFunction(dt.GetMethod("AddYears"), "DateTime");
  1187. RegisteredObjects.InternalAddFunction(dt.GetMethod("DateDiff"), "DateTime");
  1188. RegisteredObjects.InternalAddFunction(dt.GetMethod("DateSerial"), "DateTime");
  1189. RegisteredObjects.InternalAddFunction(dt.GetMethod("Day"), "DateTime");
  1190. RegisteredObjects.InternalAddFunction(dt.GetMethod("DayOfWeek"), "DateTime");
  1191. RegisteredObjects.InternalAddFunction(dt.GetMethod("DayOfYear"), "DateTime");
  1192. RegisteredObjects.InternalAddFunction(dt.GetMethod("DaysInMonth"), "DateTime");
  1193. RegisteredObjects.InternalAddFunction(dt.GetMethod("Hour"), "DateTime");
  1194. RegisteredObjects.InternalAddFunction(dt.GetMethod("Minute"), "DateTime");
  1195. RegisteredObjects.InternalAddFunction(dt.GetMethod("Month"), "DateTime");
  1196. RegisteredObjects.InternalAddFunction(dt.GetMethod("MonthName"), "DateTime");
  1197. RegisteredObjects.InternalAddFunction(dt.GetMethod("Second"), "DateTime");
  1198. RegisteredObjects.InternalAddFunction(dt.GetMethod("WeekOfYear"), "DateTime");
  1199. RegisteredObjects.InternalAddFunction(dt.GetMethod("Year"), "DateTime");
  1200. #endregion
  1201. #region Formatting
  1202. RegisteredObjects.AddFunctionCategory("Formatting", "Functions,Formatting");
  1203. Type fmt = typeof(StdFunctions);
  1204. RegisteredObjects.InternalAddFunction(fmt.GetMethod("Format", new Type[] { typeof(string), typeof(object[]) }), "Formatting");
  1205. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatCurrency", new Type[] { typeof(object) }), "Formatting,FormatCurrency");
  1206. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatCurrency", new Type[] { typeof(object), typeof(int) }), "Formatting,FormatCurrency");
  1207. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatDateTime", new Type[] { typeof(DateTime) }), "Formatting,FormatDateTime");
  1208. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatDateTime", new Type[] { typeof(DateTime), typeof(string) }), "Formatting,FormatDateTime");
  1209. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatNumber", new Type[] { typeof(object) }), "Formatting,FormatNumber");
  1210. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatNumber", new Type[] { typeof(object), typeof(int) }), "Formatting,FormatNumber");
  1211. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatPercent", new Type[] { typeof(object) }), "Formatting,FormatPercent");
  1212. RegisteredObjects.InternalAddFunction(fmt.GetMethod("FormatPercent", new Type[] { typeof(object), typeof(int) }), "Formatting,FormatPercent");
  1213. #endregion
  1214. #region Conversion
  1215. RegisteredObjects.AddFunctionCategory("Conversion", "Functions,Conversion");
  1216. Type stdConv = typeof(Convert);
  1217. Type myConv = typeof(StdFunctions);
  1218. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToBoolean", new Type[] { typeof(object) }), "Conversion");
  1219. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToByte", new Type[] { typeof(object) }), "Conversion");
  1220. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToChar", new Type[] { typeof(object) }), "Conversion");
  1221. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToDateTime", new Type[] { typeof(object) }), "Conversion");
  1222. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToDecimal", new Type[] { typeof(object) }), "Conversion");
  1223. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToDouble", new Type[] { typeof(object) }), "Conversion");
  1224. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToInt32", new Type[] { typeof(object) }), "Conversion");
  1225. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToRoman"), "Conversion");
  1226. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToSingle", new Type[] { typeof(object) }), "Conversion");
  1227. RegisteredObjects.InternalAddFunction(stdConv.GetMethod("ToString", new Type[] { typeof(object) }), "Conversion");
  1228. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWords", new Type[] { typeof(object) }), "Conversion,ToWords");
  1229. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWords", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWords");
  1230. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWords", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWords");
  1231. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsIn", new Type[] { typeof(object) }), "Conversion,ToWordsIn");
  1232. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsIn", new Type[] { typeof(object),typeof(string) }), "Conversion,ToWordsIn");
  1233. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsIn", new Type[] { typeof(object), typeof(string),typeof(string) }), "Conversion,ToWordsIn");
  1234. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsDe", new Type[] { typeof(object) }), "Conversion,ToWordsDe");
  1235. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsDe", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsDe");
  1236. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsDe", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsDe");
  1237. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsEnGb", new Type[] { typeof(object) }), "Conversion,ToWordsEnGb");
  1238. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsEnGb", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsEnGb");
  1239. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsEnGb", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsEnGb");
  1240. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsEs", new Type[] { typeof(object) }), "Conversion,ToWordsEs");
  1241. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsEs", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsEs");
  1242. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsEs", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsEs");
  1243. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsFr", new Type[] { typeof(object) }), "Conversion,ToWordsFr");
  1244. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsFr", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsFr");
  1245. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsFr", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsFr");
  1246. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsNl", new Type[] { typeof(object) }), "Conversion,ToWordsNl");
  1247. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsNl", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsNl");
  1248. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsNl", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsNl");
  1249. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsRu", new Type[] { typeof(object) }), "Conversion,ToWordsRu");
  1250. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsRu", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsRu");
  1251. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsRu", new Type[] { typeof(object), typeof(bool), typeof(string), typeof(string), typeof(string) }), "Conversion,ToWordsRu");
  1252. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsUkr",new Type[]{typeof(object)}),"Conversion,ToWordsUkr");
  1253. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsUkr", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsUkr");
  1254. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsUkr", new Type[] { typeof(object), typeof(bool), typeof(string), typeof(string), typeof(string) }), "Conversion,ToWordsUkr");
  1255. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsSp", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsSp");
  1256. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsSp", new Type[] { typeof(object) }), "Conversion,ToWordsSp");
  1257. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsSp", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsSp");
  1258. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsPersian", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsPersian");
  1259. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsPersian", new Type[] { typeof(object) }), "Conversion,ToWordsPersian");
  1260. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsPersian", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsPersian");
  1261. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToLetters", new Type[] { typeof(object) }), "Conversion,ToLetters");
  1262. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToLetters", new Type[] { typeof(object), typeof(bool) }), "Conversion,ToLetters");
  1263. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToLettersRu", new Type[] { typeof(object) }), "Conversion,ToLettersRu");
  1264. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToLettersRu", new Type[] { typeof(object), typeof(bool) }), "Conversion,ToLettersRu");
  1265. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsPl", new Type[] { typeof(object), typeof(string) }), "Conversion,ToWordsPl");
  1266. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsPl", new Type[] { typeof(object) }), "Conversion,ToWordsPl");
  1267. RegisteredObjects.InternalAddFunction(myConv.GetMethod("ToWordsPl", new Type[] { typeof(object), typeof(string), typeof(string) }), "Conversion,ToWordsPl");
  1268. #endregion
  1269. #region Program Flow
  1270. RegisteredObjects.AddFunctionCategory("ProgramFlow", "Functions,ProgramFlow");
  1271. Type misc = typeof(StdFunctions);
  1272. RegisteredObjects.InternalAddFunction(misc.GetMethod("Choose"), "ProgramFlow");
  1273. RegisteredObjects.InternalAddFunction(misc.GetMethod("IIf"), "ProgramFlow");
  1274. RegisteredObjects.InternalAddFunction(misc.GetMethod("Switch"), "ProgramFlow");
  1275. RegisteredObjects.InternalAddFunction(misc.GetMethod("IsNull"), "ProgramFlow");
  1276. #endregion
  1277. }
  1278. }
  1279. }