PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/SeaQuail/Data/SQConditionBase.cs

#
C# | 239 lines | 101 code | 5 blank | 133 comment | 2 complexity | 58321f73764d742a36fd580e360c7644 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace SeaQuail.Data
  6. {
  7. public enum SQLogicOperators { AND, OR }
  8. public enum SQRelationOperators { Equal, GreaterThan, LessThan, GreaterThanOrEqual, LessThanOrEqual, StartsWith, Like, EndsWith, Contains, Before, After, In, Is }
  9. public abstract class SQConditionBase
  10. {
  11. /// <summary>
  12. /// The And or Or logic operator
  13. /// </summary>
  14. public SQLogicOperators Connective { get; private set; }
  15. /// <summary>
  16. /// The subsequent condition
  17. /// </summary>
  18. public SQConditionBase NextCondition { get; private set; }
  19. /// <summary>
  20. /// Set to true to invert the meaning of the condition. For
  21. /// example, if the condition is a == b, then when set to
  22. /// true the condition becomes a != b
  23. /// </summary>
  24. public bool InvertMeaning { get; set; }
  25. /// <summary>
  26. /// Append a condition with a connective "or" to this condition chain and return this.
  27. /// </summary>
  28. /// <param name="nextCondition"></param>
  29. /// <returns>The current condition</returns>
  30. public SQConditionBase Or(SQConditionBase nextCondition)
  31. {
  32. AppendCondition(nextCondition, SQLogicOperators.OR);
  33. return this;
  34. }
  35. /// <summary>
  36. /// Append an "or" condition. Pass the settings for a SQCondition
  37. /// </summary>
  38. /// <param name="operandA"></param>
  39. /// <param name="op"></param>
  40. /// <param name="operandB"></param>
  41. /// <returns>The current condition</returns>
  42. public SQConditionBase Or(string operandA, SQRelationOperators op, string operandB)
  43. {
  44. return Or(new SQCondition(operandA, op, operandB, false));
  45. }
  46. /// <summary>
  47. /// Append an "or" condition. Pass the settings for a SQCondition
  48. /// </summary>
  49. /// <param name="operandA"></param>
  50. /// <param name="op"></param>
  51. /// <param name="operandB"></param>
  52. /// <returns>The current condition</returns>
  53. public SQConditionBase Or(string operandA, SQRelationOperators op, string operandB, bool invert)
  54. {
  55. return Or(new SQCondition(operandA, op, operandB, invert));
  56. }
  57. /// <summary>
  58. /// Append an "or" condition. Pass the settings for a SQCondition
  59. /// </summary>
  60. /// <param name="operandA"></param>
  61. /// <param name="op"></param>
  62. /// <param name="operandB"></param>
  63. /// <returns>The current condition</returns>
  64. public SQConditionBase Or(string operandA, SQRelationOperators op, object operandB)
  65. {
  66. return Or(new SQCondition(operandA, op, operandB, false));
  67. }
  68. /// <summary>
  69. /// Append an "or" condition. Pass the settings for a SQCondition
  70. /// </summary>
  71. /// <param name="operandA"></param>
  72. /// <param name="op"></param>
  73. /// <param name="operandB"></param>
  74. /// <returns>The current condition</returns>
  75. public SQConditionBase Or(string operandA, SQRelationOperators op, object operandB, bool invert)
  76. {
  77. return Or(new SQCondition(operandA, op, operandB, invert));
  78. }
  79. /// <summary>
  80. /// Append an "or" condition. Pass the settings for a SQCondition
  81. /// </summary>
  82. /// <param name="operandA"></param>
  83. /// <param name="op"></param>
  84. /// <param name="operandB"></param>
  85. /// <returns>The current condition</returns>
  86. public SQConditionBase Or(object operandA, SQRelationOperators op, object operandB)
  87. {
  88. return Or(new SQCondition(operandA, op, operandB, false));
  89. }
  90. /// <summary>
  91. /// Append an "or" condition. Pass the settings for a SQCondition
  92. /// </summary>
  93. /// <param name="operandA"></param>
  94. /// <param name="op"></param>
  95. /// <param name="operandB"></param>
  96. /// <returns>The current condition</returns>
  97. public SQConditionBase Or(object operandA, SQRelationOperators op, object operandB, bool invert)
  98. {
  99. return Or(new SQCondition(operandA, op, operandB, invert));
  100. }
  101. /// <summary>
  102. /// Append an "or" condition. Pass the settings for a SQCondition
  103. /// </summary>
  104. /// <param name="operandA"></param>
  105. /// <param name="op"></param>
  106. /// <param name="operandB"></param>
  107. /// <returns>The current condition</returns>
  108. public SQConditionBase Or(IWriteSQL operandA, SQRelationOperators op, IWriteSQL operandB)
  109. {
  110. return Or(new SQCondition(operandA, op, operandB, false));
  111. }
  112. /// <summary>
  113. /// Append an "or" condition. Pass the settings for a SQCondition
  114. /// </summary>
  115. /// <param name="operandA"></param>
  116. /// <param name="op"></param>
  117. /// <param name="operandB"></param>
  118. /// <returns>The current condition</returns>
  119. public SQConditionBase Or(IWriteSQL operandA, SQRelationOperators op, IWriteSQL operandB, bool invert)
  120. {
  121. return Or(new SQCondition(operandA, op, operandB, invert));
  122. }
  123. /// <summary>
  124. /// Append a condition with a connective "and" to this condition chain and return this.
  125. /// </summary>
  126. /// <param name="nextCondition"></param>
  127. /// <returns>The current condition</returns>
  128. public SQConditionBase And(SQConditionBase nextCondition)
  129. {
  130. AppendCondition(nextCondition, SQLogicOperators.AND);
  131. return this;
  132. }
  133. /// <summary>
  134. /// Append an "and" condition. Pass the settings for a SQCondition
  135. /// </summary>
  136. /// <param name="operandA"></param>
  137. /// <param name="op"></param>
  138. /// <param name="operandB"></param>
  139. /// <returns>The current condition</returns>
  140. public SQConditionBase And(string operandA, SQRelationOperators op, string operandB)
  141. {
  142. return And(operandA, op, operandB, false);
  143. }
  144. /// <summary>
  145. /// Append an "and" condition. Pass the settings for a SQCondition
  146. /// </summary>
  147. /// <param name="operandA"></param>
  148. /// <param name="op"></param>
  149. /// <param name="operandB"></param>
  150. /// <returns>The current condition</returns>
  151. public SQConditionBase And(string operandA, SQRelationOperators op, string operandB, bool invert)
  152. {
  153. return And(new SQCondition(operandA, op, operandB, invert));
  154. }
  155. /// <summary>
  156. /// Append an "and" condition. Pass the settings for a SQCondition
  157. /// </summary>
  158. /// <param name="operandA"></param>
  159. /// <param name="op"></param>
  160. /// <param name="operandB"></param>
  161. /// <returns>The current condition</returns>
  162. public SQConditionBase And(string operandA, SQRelationOperators op, object operandB)
  163. {
  164. return And(operandA, op, operandB, false);
  165. }
  166. /// <summary>
  167. /// Append an "and" condition. Pass the settings for a SQCondition
  168. /// </summary>
  169. /// <param name="operandA"></param>
  170. /// <param name="op"></param>
  171. /// <param name="operandB"></param>
  172. /// <returns>The current condition</returns>
  173. public SQConditionBase And(string operandA, SQRelationOperators op, object operandB, bool invert)
  174. {
  175. return And(new SQCondition(operandA, op, operandB, invert));
  176. }
  177. /// <summary>
  178. /// Append an "and" condition. Pass the settings for a SQCondition
  179. /// </summary>
  180. /// <param name="operandA"></param>
  181. /// <param name="op"></param>
  182. /// <param name="operandB"></param>
  183. /// <returns>The current condition</returns>
  184. public SQConditionBase And(object operandA, SQRelationOperators op, object operandB)
  185. {
  186. return And(operandA, op, operandB, false);
  187. }
  188. /// <summary>
  189. /// Append an "and" condition. Pass the settings for a SQCondition
  190. /// </summary>
  191. /// <param name="operandA"></param>
  192. /// <param name="op"></param>
  193. /// <param name="operandB"></param>
  194. /// <returns>The current condition</returns>
  195. public SQConditionBase And(object operandA, SQRelationOperators op, object operandB, bool invert)
  196. {
  197. return And(new SQCondition(operandA, op, operandB, invert));
  198. }
  199. /// <summary>
  200. /// Append an "and" condition. Pass the settings for a SQCondition
  201. /// </summary>
  202. /// <param name="operandA"></param>
  203. /// <param name="op"></param>
  204. /// <param name="operandB"></param>
  205. /// <returns>The current condition</returns>
  206. public SQConditionBase And(ISQLWriter operandA, SQRelationOperators op, ISQLWriter operandB)
  207. {
  208. return And(operandA, op, operandB, false);
  209. }
  210. /// <summary>
  211. /// Append an "and" condition. Pass the settings for a SQCondition
  212. /// </summary>
  213. /// <param name="operandA"></param>
  214. /// <param name="op"></param>
  215. /// <param name="operandB"></param>
  216. /// <returns>The current condition</returns>
  217. public SQConditionBase And(ISQLWriter operandA, SQRelationOperators op, ISQLWriter operandB, bool invert)
  218. {
  219. return And(new SQCondition(operandA, op, operandB, invert));
  220. }
  221. private void AppendCondition(SQConditionBase condition, SQLogicOperators connective)
  222. {
  223. if (NextCondition == null)
  224. {
  225. NextCondition = condition;
  226. Connective = connective;
  227. }
  228. else
  229. {
  230. NextCondition.AppendCondition(condition, connective);
  231. }
  232. }
  233. }
  234. }