You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
7.4 KiB

2 years ago
  1. using System;
  2. using System.Linq;
  3. namespace SqlSugar
  4. {
  5. public partial class SqlFunc
  6. {
  7. public static bool HasNumber(object thisValue)
  8. {
  9. return thisValue.ObjToInt() > 0;
  10. }
  11. public static bool HasValue(object thisValue)
  12. {
  13. return thisValue.HasValue();
  14. }
  15. public static bool IsNullOrEmpty(object thisValue)
  16. {
  17. return thisValue.IsNullOrEmpty();
  18. }
  19. public static string ToLower(object thisValue)
  20. {
  21. return thisValue?.ToString().ToLower();
  22. }
  23. public static string ToUpper(object thisValue)
  24. {
  25. return thisValue?.ToString().ToUpper();
  26. }
  27. public static string Trim(object thisValue)
  28. {
  29. return thisValue?.ToString().Trim();
  30. }
  31. public static bool Contains(string thisValue, string parameterValue)
  32. {
  33. return thisValue.Contains(parameterValue);
  34. }
  35. public static bool ContainsArray<T>(T[] thisValue, object parameterValue)
  36. {
  37. return thisValue.Contains((T)parameterValue);
  38. }
  39. public static bool StartsWith(string thisValue, string parameterValue)
  40. {
  41. return thisValue.StartsWith(parameterValue);
  42. }
  43. public static bool EndsWith(string thisValue, string parameterValue)
  44. {
  45. return thisValue.EndsWith(parameterValue);
  46. }
  47. public new static bool Equals(object thisValue, object parameterValue)
  48. {
  49. return thisValue.Equals(parameterValue);
  50. }
  51. public static bool DateIsSame(DateTime date1, DateTime date2)
  52. {
  53. return date1.ToString("yyyy-MM-dd") == date2.ToString("yyyy-MM-dd");
  54. }
  55. public static bool DateIsSame(DateTime? date1, DateTime? date2)
  56. {
  57. return ((DateTime)date1).ToString("yyyy-MM-dd") == ((DateTime)date2).ToString("yyyy-MM-dd");
  58. }
  59. public static string DateFullYear(DateTime? date)
  60. {
  61. return ((DateTime)date).ToString("yyyy");
  62. }
  63. public static bool DateIsSame(DateTime date1, DateTime date2, DateType dataType) { throw new NotSupportedException("Can only be used in expressions"); }
  64. public static DateTime DateAdd(DateTime date, int addValue, DateType dataType) { throw new NotSupportedException("Can only be used in expressions"); }
  65. public static DateTime DateAdd(DateTime date, int addValue) { throw new NotSupportedException("Can only be used in expressions"); }
  66. public static int DateValue(DateTime date, DateType dataType) { throw new NotSupportedException("Can only be used in expressions"); }
  67. public static bool Between(object value, object start, object end) { throw new NotSupportedException("Can only be used in expressions"); }
  68. public static TResult IIF<TResult>(bool Expression, TResult thenValue, TResult elseValue) { throw new NotSupportedException("Can only be used in expressions"); }
  69. public static TResult IsNull<TResult>(TResult thisValue, TResult ifNullValue) { throw new NotSupportedException("Can only be used in expressions"); }
  70. public static string MergeString(string value1, string value2) { throw new NotSupportedException("Can only be used in expressions"); }
  71. public static string MergeString(string value1, string value2, string value3) { throw new NotSupportedException("Can only be used in expressions"); }
  72. public static string MergeString(string value1, string value2, string value3, string value4) { throw new NotSupportedException("Can only be used in expressions"); }
  73. public static string MergeString(string value1, string value2, string value3, string value4, string value5) { throw new NotSupportedException("Can only be used in expressions"); }
  74. public static string MergeString(string value1, string value2, string value3, string value4, string value5, string value6) { throw new NotSupportedException("Can only be used in expressions"); }
  75. public static string MergeString(string value1, string value2, string value3, string value4, string value5, string value6, string value7) { throw new NotSupportedException("Can only be used in expressions"); }
  76. public static int ToInt32(object value) { return value.ObjToInt(); }
  77. public static long ToInt64(object value) { return Convert.ToInt64(value); }
  78. /// <summary>
  79. /// yyyy-MM-dd HH:mm:ss.fff
  80. /// </summary>
  81. /// <param name="value"></param>
  82. /// <returns></returns>
  83. public static DateTime ToDate(object value) { return value.ObjToDate(); }
  84. /// <summary>
  85. ///HH:mm:ss
  86. /// </summary>
  87. /// <param name="value"></param>
  88. /// <returns></returns>
  89. public static TimeSpan ToTime(object value) { throw new NotSupportedException("Can only be used in expressions"); }
  90. public static string ToString(object value) { return value.ObjToString(); }
  91. public static decimal ToDecimal(object value) { return value.ObjToDecimal(); }
  92. public static Guid ToGuid(object value) { return Guid.Parse(value.ObjToString()); }
  93. public static double ToDouble(object value) { return value.ObjToMoney(); }
  94. public static bool ToBool(object value) { return value.ObjToBool(); }
  95. public static string Substring(object value, int index, int length) { return value.ObjToString().Substring(index, length); }
  96. public static string Replace(object value, string oldChar, string newChar) { return value.ObjToString().Replace(oldChar, newChar); }
  97. public static int Length(object value) { return value.ObjToString().Length; }
  98. public static TResult AggregateSum<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
  99. public static TResult AggregateAvg<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
  100. public static TResult AggregateMin<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
  101. public static TResult AggregateMax<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
  102. public static TResult AggregateCount<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
  103. public static TResult MappingColumn<TResult>(TResult oldColumnName, string newColumnName) { throw new NotSupportedException("Can only be used in expressions"); }
  104. /// <summary>
  105. ///Example: new NewT(){name=SqlFunc.GetSelfAndAutoFill(it)} Generated SQL it.*
  106. /// </summary>
  107. /// <typeparam name="TResult"></typeparam>
  108. /// <param name="value"></param>
  109. /// <returns></returns>
  110. public static TResult GetSelfAndAutoFill<TResult>(TResult value) { throw new NotSupportedException("Can only be used in expressions"); }
  111. public static DateTime GetDate() { throw new NotSupportedException("Can only be used in expressions"); }
  112. /// <summary>
  113. /// Subquery
  114. /// </summary>
  115. /// <typeparam name="T"></typeparam>
  116. /// <returns></returns>
  117. public static Subqueryable<T> Subqueryable<T>() where T : class, new() { throw new NotSupportedException("Can only be used in expressions"); }
  118. public static CaseThen IF(bool condition) { throw new NotSupportedException("Can only be used in expressions"); }
  119. }
  120. }