PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/v41/Source/Widgetsphere.Generator.DAL/ProjectItemGenerators/BusinessViewCollection/BusinessViewCollectionGeneratedTemplate.cs

#
C# | 1300 lines | 1173 code | 78 blank | 49 comment | 32 complexity | 27b2984b9e1a2821cc42ed3896c8995e MD5 | raw file
Possible License(s): JSON, CC-BY-SA-3.0

Large files files are truncated, but you can click here to view the full file

  1. #region Copyright (c) 2006-2011 Widgetsphere LLC, All Rights Reserved
  2. //--------------------------------------------------------------------- *
  3. // Widgetsphere LLC *
  4. // Copyright (c) 2006-2011 All Rights reserved *
  5. // *
  6. // *
  7. //This file and its contents are protected by United States and *
  8. //International copyright laws. Unauthorized reproduction and/or *
  9. //distribution of all or any portion of the code contained herein *
  10. //is strictly prohibited and will result in severe civil and criminal *
  11. //penalties. Any violations of this copyright will be prosecuted *
  12. //to the fullest extent possible under law. *
  13. // *
  14. //THE SOURCE CODE CONTAINED HEREIN AND IN RELATED FILES IS PROVIDED *
  15. //TO THE REGISTERED DEVELOPER FOR THE PURPOSES OF EDUCATION AND *
  16. //TROUBLESHOOTING. UNDER NO CIRCUMSTANCES MAY ANY PORTION OF THE SOURCE *
  17. //CODE BE DISTRIBUTED, DISCLOSED OR OTHERWISE MADE AVAILABLE TO ANY *
  18. //THIRD PARTY WITHOUT THE EXPRESS WRITTEN CONSENT OF WIDGETSPHERE LLC *
  19. // *
  20. //UNDER NO CIRCUMSTANCES MAY THE SOURCE CODE BE USED IN WHOLE OR IN *
  21. //PART, AS THE BASIS FOR CREATING A PRODUCT THAT PROVIDES THE SAME, OR *
  22. //SUBSTANTIALLY THE SAME, FUNCTIONALITY AS ANY WIDGETSPHERE PRODUCT. *
  23. // *
  24. //THE REGISTERED DEVELOPER ACKNOWLEDGES THAT THIS SOURCE CODE *
  25. //CONTAINS VALUABLE AND PROPRIETARY TRADE SECRETS OF WIDGETSPHERE, *
  26. //INC. THE REGISTERED DEVELOPER AGREES TO EXPEND EVERY EFFORT TO *
  27. //INSURE ITS CONFIDENTIALITY. *
  28. // *
  29. //THE END USER LICENSE AGREEMENT (EULA) ACCOMPANYING THE PRODUCT *
  30. //PERMITS THE REGISTERED DEVELOPER TO REDISTRIBUTE THE PRODUCT IN *
  31. //EXECUTABLE FORM ONLY IN SUPPORT OF APPLICATIONS WRITTEN USING *
  32. //THE PRODUCT. IT DOES NOT PROVIDE ANY RIGHTS REGARDING THE *
  33. //SOURCE CODE CONTAINED HEREIN. *
  34. // *
  35. //THIS COPYRIGHT NOTICE MAY NOT BE REMOVED FROM THIS FILE. *
  36. //--------------------------------------------------------------------- *
  37. #endregion
  38. using System;
  39. using System.Collections;
  40. using System.Collections.Generic;
  41. using System.Linq;
  42. using System.Text;
  43. using Widgetsphere.Generator.Common.Util;
  44. using Widgetsphere.Generator.Models;
  45. namespace Widgetsphere.Generator.DAL.ProjectItemGenerators.BusinessViewCollection
  46. {
  47. class BusinessViewCollectionGeneratedTemplate : DomainProjectTemplate
  48. {
  49. private readonly StringBuilder sb = new StringBuilder();
  50. private readonly CustomView _currentView;
  51. public BusinessViewCollectionGeneratedTemplate(ModelRoot model, CustomView currentView)
  52. {
  53. _model = model;
  54. _currentView = currentView;
  55. }
  56. #region BaseClassTemplate overrides
  57. public override string FileName
  58. {
  59. get { return string.Format("{0}Collection.Generated.cs", _currentView.PascalName); }
  60. }
  61. public string ParentItemName
  62. {
  63. get { return string.Format("{0}Collection.cs", _currentView.PascalName); }
  64. }
  65. public override string FileContent
  66. {
  67. get
  68. {
  69. GenerateContent();
  70. return sb.ToString();
  71. }
  72. }
  73. #endregion
  74. #region GenerateContent
  75. private void GenerateContent()
  76. {
  77. try
  78. {
  79. Widgetsphere.Generator.GenerationHelper.AppendCopyrightInCode(sb, _model);
  80. this.AppendUsingStatements();
  81. sb.AppendLine("namespace " + this.GetLocalNamespace() + ".Business.Views");
  82. sb.AppendLine("{");
  83. this.AppendClass();
  84. this.AppendSearchClass();
  85. sb.AppendLine("}");
  86. }
  87. catch (Exception ex)
  88. {
  89. throw;
  90. }
  91. }
  92. #endregion
  93. #region namespace / objects
  94. public void AppendUsingStatements()
  95. {
  96. sb.AppendLine("using System;");
  97. sb.AppendLine("using System.Linq;");
  98. sb.AppendLine("using System.Data;");
  99. sb.AppendLine("using System.Xml;");
  100. sb.AppendLine("using System.Collections.Generic;");
  101. sb.AppendLine("using System.Collections;");
  102. sb.AppendLine("using System.Runtime.Serialization;");
  103. sb.AppendLine("using System.ComponentModel;");
  104. sb.AppendLine("using " + this.GetLocalNamespace() + ".Business.Rules;");
  105. sb.AppendLine("using " + this.GetLocalNamespace() + ".Business.SelectCommands;");
  106. sb.AppendLine("using " + this.GetLocalNamespace() + ".Domain.Objects;");
  107. sb.AppendLine("using " + this.GetLocalNamespace() + ".Domain.Views;");
  108. sb.AppendLine("using Widgetsphere.Core.DataAccess;");
  109. sb.AppendLine("using Widgetsphere.Core.Util;");
  110. sb.AppendLine("using Widgetsphere.Core.Logging;");
  111. sb.AppendLine("using Widgetsphere.Core.Exceptions;");
  112. sb.AppendLine("using System.IO;");
  113. sb.AppendLine("using System.Linq.Expressions;");
  114. sb.AppendLine("using " + this.GetLocalNamespace() + ".Business.Objects;");
  115. sb.AppendLine("using System.Data.Linq;");
  116. sb.AppendLine("using " + this.GetLocalNamespace() + ".Business.LINQ;");
  117. sb.AppendLine("using System.Text.RegularExpressions;");
  118. sb.AppendLine("using System.Text;");
  119. sb.AppendLine();
  120. }
  121. private void AppendClass()
  122. {
  123. sb.AppendLine();
  124. sb.AppendLine(" /// <summary>");
  125. sb.AppendLine(" /// The class representing the '" + _currentView.PascalName + "' virtual database table");
  126. sb.AppendLine(" /// </summary>");
  127. sb.AppendLine(" [Serializable()]");
  128. sb.AppendLine(" public partial class " + _currentView.PascalName + "Collection : Widgetsphere.Core.DataAccess.BusinessCollectionBase, Widgetsphere.Core.DataAccess.IReadOnlyBusinessCollection, System.Collections.Generic.IEnumerable<" + _currentView.PascalName + ">, System.ComponentModel.IListSource, System.Collections.IList");
  129. sb.AppendLine(" {");
  130. this.AppendMemberVariables();
  131. this.AppendConstructors();
  132. this.AppendProperties();
  133. this.AppendOperatorIndexer();
  134. this.AppendMethods();
  135. this.AppendAggregateMethods();
  136. this.AppendMethodContainsIndexOf();
  137. this.AppendMethodIListInterface();
  138. this.AppendClassEnumerator();
  139. this.AppendIBusinessCollectionRegion();
  140. sb.AppendLine(" }");
  141. sb.AppendLine();
  142. this.AppendPagingClass();
  143. }
  144. #region Aggregate Methods
  145. private void AppendAggregateMethods()
  146. {
  147. var scope = string.Empty;
  148. //List<Table> tableList = _currentView.GetTableHierarchy();
  149. //tableList.Remove(_currentView);
  150. var columnList = new Dictionary<string, CustomViewColumn>();
  151. //Need the colums in order from base UP
  152. foreach (var column in _currentView.GetColumns().OrderBy(x => x.PascalName))
  153. {
  154. if (column.Generated)
  155. {
  156. columnList.Add(column.DatabaseName.ToLower(), column);
  157. }
  158. }
  159. //All types that are valid for these operations
  160. var typeList = new List<string>();
  161. typeList.Add("int");
  162. typeList.Add("Single");
  163. typeList.Add("double");
  164. typeList.Add("decimal");
  165. typeList.Add("string");
  166. typeList.Add("DateTime");
  167. //Max
  168. this.AppendAggregateMax(scope, columnList, typeList);
  169. //Min
  170. this.AppendAggregateMin(scope, columnList, typeList);
  171. typeList = new List<string>();
  172. typeList.Add("int");
  173. typeList.Add("Single");
  174. typeList.Add("double");
  175. typeList.Add("decimal");
  176. //Average
  177. this.AppendAggregateAverage(scope, columnList, typeList);
  178. //Sum
  179. this.AppendAggregateSum(scope, columnList, typeList);
  180. typeList = new List<string>();
  181. typeList.Add("int");
  182. typeList.Add("Single");
  183. typeList.Add("double");
  184. typeList.Add("decimal");
  185. typeList.Add("string");
  186. typeList.Add("DateTime");
  187. typeList.Add("Guid");
  188. //Count
  189. this.AppendAggregateCount(scope, columnList);
  190. //Distinct
  191. this.AppendAggregateDistinct(scope, columnList, typeList);
  192. }
  193. private void AppendAggregateSum(string scope, Dictionary<string, CustomViewColumn> columnList, List<string> typeList)
  194. {
  195. foreach (var typeName in typeList)
  196. {
  197. AppendAggregateSumBody(scope, columnList, typeName);
  198. if (typeName != "string")
  199. AppendAggregateSumBody(scope, columnList, typeName + "?");
  200. }
  201. }
  202. private void AppendAggregateSumBody(string scope, Dictionary<string, CustomViewColumn> columnList, string typeName)
  203. {
  204. var returnType = "double";
  205. if (typeName.StartsWith("decimal")) returnType = "decimal";
  206. sb.AppendLine(" /// <summary>");
  207. sb.AppendLine(" /// Get the summary value of the field for all objects");
  208. sb.AppendLine(" /// </summary>");
  209. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  210. sb.AppendLine(" public static " + scope + returnType + "? GetSum(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select)");
  211. sb.AppendLine(" {");
  212. sb.AppendLine(" return GetSum(select, x => true);");
  213. sb.AppendLine(" }");
  214. sb.AppendLine();
  215. sb.AppendLine(" /// <summary>");
  216. sb.AppendLine(" /// Get the summary value of the field for all objects");
  217. sb.AppendLine(" /// </summary>");
  218. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  219. sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
  220. sb.AppendLine(" public static " + scope + returnType + "? GetSum(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentView.PascalName + "Query, bool>> where)");
  221. sb.AppendLine(" {");
  222. sb.AppendLine(" return GetSum(select, where, new QueryOptimizer());");
  223. sb.AppendLine(" }");
  224. sb.AppendLine();
  225. sb.AppendLine(" /// <summary>");
  226. sb.AppendLine(" /// Get the summary value of the field in the set of records that match the Where condition");
  227. sb.AppendLine(" /// </summary>");
  228. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  229. sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
  230. sb.AppendLine(" /// <param name=\"optimizer\">An object to specify querying parameters and return profiling information</param>");
  231. sb.AppendLine(" public static " + scope + returnType + "? GetSum(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentView.PascalName + "Query, bool>> where, QueryOptimizer optimizer)");
  232. sb.AppendLine(" {");
  233. sb.AppendLine(" var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);");
  234. sb.AppendLine(" var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);");
  235. sb.AppendLine(" Table<" + _currentView.PascalName + "Query> template = dc.GetTable<" + _currentView.PascalName + "Query>();");
  236. sb.AppendLine(" var cmd = BusinessCollectionPersistableBase.GetCommand<" + _currentView.PascalName + "Query>(dc, template, where);");
  237. sb.AppendLine(" cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;");
  238. sb.AppendLine(" string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;");
  239. sb.AppendLine(" switch (fieldName.ToLower())");
  240. sb.AppendLine(" {");
  241. foreach (var column in _currentView.GetColumns().Where(x => x.Generated))
  242. {
  243. sb.AppendLine(" case \"" + column.PascalName.ToLower() + "\": fieldName = \"" + column.DatabaseName + "\"; break;");
  244. }
  245. sb.AppendLine(" default: throw new Exception(\"The select clause is not valid.\");");
  246. sb.AppendLine(" }");
  247. sb.AppendLine();
  248. sb.AppendLine(" var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);");
  249. sb.AppendLine(" cmd.CommandText = \"SELECT SUM([\" + parser.GetTableAlias(fieldName, \"" + _currentView.DatabaseName + "\") + \"].\" + fieldName + \") \" + parser.GetFromClause(optimizer) + \" \" + parser.GetWhereClause() + string.Empty;");
  250. sb.AppendLine(" dc.Connection.Open();");
  251. sb.AppendLine(" object p = cmd.ExecuteScalar();");
  252. sb.AppendLine(" dc.Connection.Close();");
  253. sb.AppendLine(" if (p == System.DBNull.Value)");
  254. sb.AppendLine(" return null;");
  255. sb.AppendLine(" else");
  256. sb.AppendLine(" return (" + typeName + ")p;");
  257. sb.AppendLine(" }");
  258. sb.AppendLine();
  259. }
  260. private void AppendAggregateAverage(string scope, Dictionary<string, CustomViewColumn> columnList, List<string> typeList)
  261. {
  262. foreach (var typeName in typeList)
  263. {
  264. AppendAggregateAverageBody(scope, columnList, typeName);
  265. if (typeName != "string")
  266. AppendAggregateAverageBody(scope, columnList, typeName + "?");
  267. }
  268. }
  269. private void AppendAggregateAverageBody(string scope, Dictionary<string, CustomViewColumn> columnList, string typeName)
  270. {
  271. var returnType = "double";
  272. if (typeName.StartsWith("decimal")) returnType = "decimal";
  273. sb.AppendLine(" /// <summary>");
  274. sb.AppendLine(" /// Get the average value of the field for all objects");
  275. sb.AppendLine(" /// </summary>");
  276. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  277. sb.AppendLine(" public static " + scope + returnType + "? GetAverage(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select)");
  278. sb.AppendLine(" {");
  279. sb.AppendLine(" return GetAverage(select, x => true);");
  280. sb.AppendLine(" }");
  281. sb.AppendLine();
  282. sb.AppendLine(" /// <summary>");
  283. sb.AppendLine(" /// Get the average value of the field in the set of records that match the Where condition");
  284. sb.AppendLine(" /// </summary>");
  285. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  286. sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
  287. sb.AppendLine(" public static " + scope + returnType + "? GetAverage(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentView.PascalName + "Query, bool>> where)");
  288. sb.AppendLine(" {");
  289. sb.AppendLine(" return GetAverage(select, where, new QueryOptimizer());");
  290. sb.AppendLine(" }");
  291. sb.AppendLine();
  292. sb.AppendLine(" /// <summary>");
  293. sb.AppendLine(" /// Get the average value of the field in the set of records that match the Where condition");
  294. sb.AppendLine(" /// </summary>");
  295. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  296. sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
  297. sb.AppendLine(" /// <param name=\"optimizer\">An object to specify querying parameters and return profiling information</param>");
  298. sb.AppendLine(" public static " + scope + returnType + "? GetAverage(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentView.PascalName + "Query, bool>> where, QueryOptimizer optimizer)");
  299. sb.AppendLine(" {");
  300. sb.AppendLine(" var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);");
  301. sb.AppendLine(" var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);");
  302. sb.AppendLine(" Table<" + _currentView.PascalName + "Query> template = dc.GetTable<" + _currentView.PascalName + "Query>();");
  303. sb.AppendLine(" var cmd = BusinessCollectionPersistableBase.GetCommand<" + _currentView.PascalName + "Query>(dc, template, where);");
  304. sb.AppendLine(" cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;");
  305. sb.AppendLine(" string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;");
  306. sb.AppendLine(" switch (fieldName.ToLower())");
  307. sb.AppendLine(" {");
  308. foreach (var column in _currentView.GetColumns().Where(x => x.Generated))
  309. {
  310. sb.AppendLine(" case \"" + column.PascalName.ToLower() + "\": fieldName = \"" + column.DatabaseName + "\"; break;");
  311. }
  312. sb.AppendLine(" default: throw new Exception(\"The select clause is not valid.\");");
  313. sb.AppendLine(" }");
  314. sb.AppendLine();
  315. sb.AppendLine(" var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);");
  316. sb.AppendLine(" cmd.CommandText = \"SELECT AVG([\" + parser.GetTableAlias(fieldName, \"" + _currentView.DatabaseName + "\") + \"].\" + fieldName + \") \" + parser.GetFromClause(optimizer) + \" \" + parser.GetWhereClause() + string.Empty;");
  317. sb.AppendLine(" dc.Connection.Open();");
  318. sb.AppendLine(" object p = cmd.ExecuteScalar();");
  319. sb.AppendLine(" dc.Connection.Close();");
  320. sb.AppendLine(" if (p == System.DBNull.Value)");
  321. sb.AppendLine(" return null;");
  322. sb.AppendLine(" else");
  323. sb.AppendLine(" return (" + typeName + ")p;");
  324. sb.AppendLine(" }");
  325. sb.AppendLine();
  326. }
  327. private void AppendAggregateDistinct(string scope, Dictionary<string, CustomViewColumn> columnList, List<string> typeList)
  328. {
  329. foreach (var typeName in typeList)
  330. {
  331. AppendAggregateDistinctBody(scope, columnList, typeName);
  332. if (typeName != "string")
  333. AppendAggregateDistinctBody(scope, columnList, typeName + "?");
  334. }
  335. }
  336. private void AppendAggregateDistinctBody(string scope, Dictionary<string, CustomViewColumn> columnList, string typeName)
  337. {
  338. sb.AppendLine(" /// <summary>");
  339. sb.AppendLine(" /// Get a list of distinct values of the field for all objects");
  340. sb.AppendLine(" /// </summary>");
  341. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  342. sb.AppendLine(" public static " + scope + "IEnumerable<" + typeName + "> GetDistinct(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select)");
  343. sb.AppendLine(" {");
  344. sb.AppendLine(" return GetDistinct(select, x => true);");
  345. sb.AppendLine(" }");
  346. sb.AppendLine();
  347. sb.AppendLine(" /// <summary>");
  348. sb.AppendLine(" /// Get a list of distinct values of the field in the set of records that match the Where condition");
  349. sb.AppendLine(" /// </summary>");
  350. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  351. sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
  352. sb.AppendLine(" public static " + scope + "IEnumerable<" + typeName + "> GetDistinct(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentView.PascalName + "Query, bool>> where)");
  353. sb.AppendLine(" {");
  354. sb.AppendLine(" return GetDistinct(select, where, new QueryOptimizer());");
  355. sb.AppendLine(" }");
  356. sb.AppendLine();
  357. sb.AppendLine(" /// <summary>");
  358. sb.AppendLine(" /// Get a list of distinct values of the field in the set of records that match the Where condition");
  359. sb.AppendLine(" /// </summary>");
  360. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  361. sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
  362. sb.AppendLine(" /// <param name=\"optimizer\">An object to specify querying parameters and return profiling information</param>");
  363. sb.AppendLine(" public static " + scope + "IEnumerable<" + typeName + "> GetDistinct(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentView.PascalName + "Query, bool>> where, QueryOptimizer optimizer)");
  364. sb.AppendLine(" {");
  365. sb.AppendLine(" var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);");
  366. sb.AppendLine(" var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);");
  367. sb.AppendLine(" Table<" + _currentView.PascalName + "Query> template = dc.GetTable<" + _currentView.PascalName + "Query>();");
  368. sb.AppendLine(" var cmd = BusinessCollectionPersistableBase.GetCommand<" + _currentView.PascalName + "Query>(dc, template, where);");
  369. sb.AppendLine(" cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;");
  370. sb.AppendLine(" string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;");
  371. sb.AppendLine(" switch (fieldName.ToLower())");
  372. sb.AppendLine(" {");
  373. foreach (var column in _currentView.GetColumns().Where(x => x.Generated))
  374. {
  375. sb.AppendLine(" case \"" + column.PascalName.ToLower() + "\": fieldName = \"" + column.DatabaseName + "\"; break;");
  376. }
  377. sb.AppendLine(" default: throw new Exception(\"The select clause is not valid.\");");
  378. sb.AppendLine(" }");
  379. sb.AppendLine();
  380. sb.AppendLine(" var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);");
  381. sb.AppendLine(" cmd.CommandText = \"SELECT DISTINCT([\" + parser.GetTableAlias(fieldName, \"" + _currentView.DatabaseName + "\") + \"].\" + fieldName + \") \" + parser.GetFromClause(optimizer) + \" \" + parser.GetWhereClause() + string.Empty;");
  382. sb.AppendLine(" dc.Connection.Open();");
  383. sb.AppendLine(" System.Data.Common.DbDataReader dr = cmd.ExecuteReader();");
  384. sb.AppendLine();
  385. sb.AppendLine(" var retval = new List<" + typeName + ">();");
  386. sb.AppendLine(" while (dr.Read())");
  387. sb.AppendLine(" {");
  388. sb.AppendLine(" if (!dr.IsDBNull(0))");
  389. sb.AppendLine(" {");
  390. sb.AppendLine(" object o = dr[0];");
  391. sb.AppendLine(" retval.Add((" + typeName + ")o);");
  392. sb.AppendLine(" }");
  393. sb.AppendLine(" }");
  394. sb.AppendLine();
  395. sb.AppendLine(" dc.Connection.Close();");
  396. sb.AppendLine();
  397. sb.AppendLine(" return retval;");
  398. sb.AppendLine();
  399. sb.AppendLine(" }");
  400. sb.AppendLine();
  401. }
  402. private void AppendAggregateMin(string scope, Dictionary<string, CustomViewColumn> columnList, List<string> typeList)
  403. {
  404. foreach (var typeName in typeList)
  405. {
  406. AppendAggregateMinBody(scope, columnList, typeName);
  407. if (typeName != "string")
  408. AppendAggregateMinBody(scope, columnList, typeName + "?");
  409. }
  410. }
  411. private void AppendAggregateMinBody(string scope, Dictionary<string, CustomViewColumn> columnList, string typeName)
  412. {
  413. sb.AppendLine(" /// <summary>");
  414. sb.AppendLine(" /// Get the minimum value of the field for all objects");
  415. sb.AppendLine(" /// </summary>");
  416. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  417. sb.AppendLine(" public static " + scope + typeName.Replace("?", "") + ((typeName == "string") ? "" : "?") + " GetMin(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select)");
  418. sb.AppendLine(" {");
  419. sb.AppendLine(" return GetMin(select, x => true);");
  420. sb.AppendLine(" }");
  421. sb.AppendLine();
  422. sb.AppendLine(" /// <summary>");
  423. sb.AppendLine(" /// Get the minimum value of the field in the set of records that match the Where condition");
  424. sb.AppendLine(" /// </summary>");
  425. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  426. sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
  427. sb.AppendLine(" public static " + scope + typeName.Replace("?", "") + ((typeName == "string") ? "" : "?") + " GetMin(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentView.PascalName + "Query, bool>> where)");
  428. sb.AppendLine(" {");
  429. sb.AppendLine(" return GetMin(select, where, new QueryOptimizer());");
  430. sb.AppendLine(" }");
  431. sb.AppendLine();
  432. sb.AppendLine(" /// <summary>");
  433. sb.AppendLine(" /// Get the minimum value of the field in the set of records that match the Where condition");
  434. sb.AppendLine(" /// </summary>");
  435. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  436. sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
  437. sb.AppendLine(" /// <param name=\"optimizer\">An object to specify querying parameters and return profiling information</param>");
  438. sb.AppendLine(" public static " + scope + typeName.Replace("?", "") + ((typeName == "string") ? "" : "?") + " GetMin(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentView.PascalName + "Query, bool>> where, QueryOptimizer optimizer)");
  439. sb.AppendLine(" {");
  440. sb.AppendLine(" var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);");
  441. sb.AppendLine(" var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);");
  442. sb.AppendLine(" Table<" + _currentView.PascalName + "Query> template = dc.GetTable<" + _currentView.PascalName + "Query>();");
  443. sb.AppendLine(" var cmd = BusinessCollectionPersistableBase.GetCommand<" + _currentView.PascalName + "Query>(dc, template, where);");
  444. sb.AppendLine(" cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;");
  445. sb.AppendLine(" string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;");
  446. sb.AppendLine(" switch (fieldName.ToLower())");
  447. sb.AppendLine(" {");
  448. foreach (var column in _currentView.GetColumns().Where(x => x.Generated))
  449. {
  450. sb.AppendLine(" case \"" + column.PascalName.ToLower() + "\": fieldName = \"" + column.DatabaseName + "\"; break;");
  451. }
  452. sb.AppendLine(" default: throw new Exception(\"The select clause is not valid.\");");
  453. sb.AppendLine(" }");
  454. sb.AppendLine();
  455. sb.AppendLine(" var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);");
  456. sb.AppendLine(" cmd.CommandText = \"SELECT MIN([\" + parser.GetTableAlias(fieldName, \"" + _currentView.DatabaseName + "\") + \"].\" + fieldName + \") \" + parser.GetFromClause(optimizer) + \" \" + parser.GetWhereClause() + string.Empty;");
  457. sb.AppendLine(" dc.Connection.Open();");
  458. sb.AppendLine(" object p = cmd.ExecuteScalar();");
  459. sb.AppendLine(" dc.Connection.Close();");
  460. sb.AppendLine(" if (p == System.DBNull.Value)");
  461. sb.AppendLine(" return null;");
  462. sb.AppendLine(" else");
  463. sb.AppendLine(" return (" + typeName + ")p;");
  464. sb.AppendLine(" }");
  465. sb.AppendLine();
  466. }
  467. private void AppendAggregateMax(string scope, Dictionary<string, CustomViewColumn> columnList, List<string> typeList)
  468. {
  469. foreach (var typeName in typeList)
  470. {
  471. AppendAggregateMaxBody(scope, columnList, typeName);
  472. if (typeName != "string")
  473. AppendAggregateMaxBody(scope, columnList, typeName + "?");
  474. }
  475. }
  476. private void AppendAggregateMaxBody(string scope, Dictionary<string, CustomViewColumn> columnList, string typeName)
  477. {
  478. sb.AppendLine(" /// <summary>");
  479. sb.AppendLine(" /// Get the maximum value of the field for all objects");
  480. sb.AppendLine(" /// </summary>");
  481. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  482. sb.AppendLine(" public static " + scope + typeName.Replace("?", "") + ((typeName == "string") ? "" : "?") + " GetMax(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select)");
  483. sb.AppendLine(" {");
  484. sb.AppendLine(" return GetMax(select, x => true);");
  485. sb.AppendLine(" }");
  486. sb.AppendLine();
  487. sb.AppendLine(" /// <summary>");
  488. sb.AppendLine(" /// Get the maximum value of the field in the set of records that match the Where condition");
  489. sb.AppendLine(" /// </summary>");
  490. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  491. sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
  492. sb.AppendLine(" public static " + scope + typeName.Replace("?", "") + ((typeName == "string") ? "" : "?") + " GetMax(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentView.PascalName + "Query, bool>> where)");
  493. sb.AppendLine(" {");
  494. sb.AppendLine(" return GetMax(select, where, new QueryOptimizer());");
  495. sb.AppendLine(" }");
  496. sb.AppendLine();
  497. sb.AppendLine(" /// <summary>");
  498. sb.AppendLine(" /// Get the maximum value of the field in the set of records that match the Where condition");
  499. sb.AppendLine(" /// </summary>");
  500. sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
  501. sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
  502. sb.AppendLine(" /// <param name=\"optimizer\">An object to specify querying parameters and return profiling information</param>");
  503. sb.AppendLine(" public static " + scope + typeName.Replace("?", "") + ((typeName == "string") ? "" : "?") + " GetMax(Expression<Func<" + _currentView.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentView.PascalName + "Query, bool>> where, QueryOptimizer optimizer)");
  504. sb.AppendLine(" {");
  505. sb.AppendLine(" var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);");
  506. sb.AppendLine(" var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);");
  507. sb.AppendLine(" Table<" + _currentView.PascalName + "Query> template = dc.GetTable<" + _currentView.PascalName + "Query>();");
  508. sb.AppendLine(" var cmd = BusinessCollectionPersistableBase.GetCommand<" + _currentView.PascalName + "Query>(dc, template, where);");
  509. sb.AppendLine(" cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;");
  510. sb.AppendLine(" string fieldName = ((System.Linq.Expressions.MemberExpression)(select.Body)).Member.Name;");
  511. sb.AppendLine(" switch (fieldName.ToLower())");
  512. sb.AppendLine(" {");
  513. foreach (var column in _currentView.GetColumns().Where(x => x.Generated))
  514. {
  515. sb.AppendLine(" case \"" + column.PascalName.ToLower() + "\": fieldName = \"" + column.DatabaseName + "\"; break;");
  516. }
  517. sb.AppendLine(" default: throw new Exception(\"The select clause is not valid.\");");
  518. sb.AppendLine(" }");
  519. sb.AppendLine();
  520. sb.AppendLine(" var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);");
  521. sb.AppendLine(" cmd.CommandText = \"SELECT MAX([\" + parser.GetTableAlias(fieldName, \"" + _currentView.DatabaseName + "\") + \"].\" + fieldName + \") \" + parser.GetFromClause(optimizer) + \" \" + parser.GetWhereClause() + string.Empty;");
  522. sb.AppendLine(" dc.Connection.Open();");
  523. sb.AppendLine(" object p = cmd.ExecuteScalar();");
  524. sb.AppendLine(" dc.Connection.Close();");
  525. sb.AppendLine(" if (p == System.DBNull.Value)");
  526. sb.AppendLine(" return null;");
  527. sb.AppendLine(" else");
  528. sb.AppendLine(" return (" + typeName + ")p;");
  529. sb.AppendLine(" }");
  530. sb.AppendLine();
  531. }
  532. private void AppendAggregateCount(string scope, Dictionary<string, CustomViewColumn> columnList)
  533. {
  534. sb.AppendLine(" /// <summary>");
  535. sb.AppendLine(" /// Get the count of all objects");
  536. sb.AppendLine(" /// </summary>");
  537. sb.AppendLine(" public static " + scope + "int GetCount()");
  538. sb.AppendLine(" {");
  539. sb.AppendLine(" return GetCount(x => true, new QueryOptimizer());");
  540. sb.AppendLine(" }");
  541. sb.AppendLine();
  542. sb.AppendLine(" /// <summary>");
  543. sb.AppendLine(" /// Get the count of all objects");
  544. sb.AppendLine(" /// </summary>");
  545. sb.AppendLine(" public static " + scope + "int GetCount(QueryOptimizer optimizer)");
  546. sb.AppendLine(" {");
  547. sb.AppendLine(" return GetCount(x => true, optimizer);");
  548. sb.AppendLine(" }");
  549. sb.AppendLine();
  550. sb.AppendLine(" /// <summary>");
  551. sb.AppendLine(" /// Get the count of objects that match the Where condition");
  552. sb.AppendLine(" /// </summary>");
  553. sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
  554. sb.AppendLine(" public static " + scope + "int GetCount(Expression<Func<" + _currentView.PascalName + "Query, bool>> where)");
  555. sb.AppendLine(" {");
  556. sb.AppendLine(" return GetCount(where, new QueryOptimizer());");
  557. sb.AppendLine(" }");
  558. sb.AppendLine();
  559. sb.AppendLine(" /// <summary>");
  560. sb.AppendLine(" /// Get the count of objects that match the Where condition");
  561. sb.AppendLine(" /// </summary>");
  562. sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
  563. sb.AppendLine(" /// <param name=\"optimizer\">An object to specify querying parameters and return profiling information</param>");
  564. sb.AppendLine(" public static " + scope + "int GetCount(Expression<Func<" + _currentView.PascalName + "Query, bool>> where, QueryOptimizer optimizer)");
  565. sb.AppendLine(" {");
  566. sb.AppendLine(" var subDomain = new SubDomain(ConfigurationValues.GetInstance().Modifier);");
  567. sb.AppendLine(" var dc = new DataContext(ConfigurationValues.GetInstance().ConnectionString);");
  568. sb.AppendLine(" Table<" + _currentView.PascalName + "Query> template = dc.GetTable<" + _currentView.PascalName + "Query>();");
  569. sb.AppendLine();
  570. sb.AppendLine(" var cmd = BusinessCollectionPersistableBase.GetCommand<" + _currentView.PascalName + "Query>(dc, template, where);");
  571. sb.AppendLine(" cmd.CommandTimeout = ConfigurationValues.GetInstance().DefaultTimeOut;");
  572. sb.AppendLine(" var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.View);");
  573. sb.AppendLine(" cmd.CommandText = \"select count(*) \" + parser.GetFromClause(optimizer) + \" \" + parser.GetWhereClause() + string.Empty;");
  574. sb.AppendLine(" dc.Connection.Open();");
  575. sb.AppendLine(" object p = cmd.ExecuteScalar();");
  576. sb.AppendLine(" dc.Connection.Close();");
  577. sb.AppendLine(" return (int)p;");
  578. sb.AppendLine(" }");
  579. sb.AppendLine();
  580. }
  581. #endregion
  582. private void AppendIBusinessCollectionRegion()
  583. {
  584. sb.AppendLine(" #region IBusinessCollection Explicit Members");
  585. sb.AppendLine();
  586. sb.AppendLine(" /// <summary>");
  587. sb.AppendLine(" /// Returns an item in this collection by index.");
  588. sb.AppendLine(" /// </summary>");
  589. sb.AppendLine(" /// <param name=\"index\">The zero-based index of the element to get or set. </param>");
  590. sb.AppendLine(" /// <returns>The element at the specified index.</returns>");
  591. sb.AppendLine(" IBusinessObject IBusinessCollection.this[int index]");
  592. sb.AppendLine(" {");
  593. sb.AppendLine(" get { return this[index]; }");
  594. sb.AppendLine(" }");
  595. sb.AppendLine();
  596. sb.AppendLine(" Enum IBusinessCollection.Collection");
  597. sb.AppendLine(" {");
  598. sb.AppendLine(" get { return this.Collection; }");
  599. sb.AppendLine(" }");
  600. sb.AppendLine();
  601. sb.AppendLine(" Type IBusinessCollection.ContainedType");
  602. sb.AppendLine(" {");
  603. sb.AppendLine(" get { return this.ContainedType; }");
  604. sb.AppendLine(" }");
  605. sb.AppendLine();
  606. sb.AppendLine(" SubDomainBase IBusinessCollection.SubDomain");
  607. sb.AppendLine(" {");
  608. sb.AppendLine(" get { return this.SubDomain; }");
  609. sb.AppendLine(" }");
  610. sb.AppendLine();
  611. sb.AppendLine(" Type ITyped.GetContainedType()");
  612. sb.AppendLine(" {");
  613. sb.AppendLine(" return typeof(" + _currentView.PascalName + ");");
  614. sb.AppendLine(" }");
  615. sb.AppendLine();
  616. sb.AppendLine(" #endregion");
  617. sb.AppendLine();
  618. }
  619. private void AppendSearchClass()
  620. {
  621. var validColumns = GetValidSearchColumns();
  622. if (validColumns.Count != 0)
  623. {
  624. sb.AppendLine(" #region " + _currentView.PascalName + "Search");
  625. sb.AppendLine();
  626. sb.AppendLine(" /// <summary>");
  627. sb.AppendLine(" /// The search object for the " + _currentView.PascalName + "Collection.");
  628. sb.AppendLine(" /// </summary>");
  629. sb.AppendLine(" [Serializable]");
  630. sb.AppendLine(" public class " + _currentView.PascalName + "Search : IBusinessObjectSearch");
  631. sb.AppendLine(" {");
  632. sb.AppendLine();
  633. sb.AppendLine(" private int _maxRowCount = 0;");
  634. foreach (CustomViewColumn dc in validColumns)
  635. {
  636. sb.AppendFormat(" private " + dc.GetCodeType(true, true) + " _{0};", dc.CamelName).AppendLine();
  637. }
  638. sb.AppendLine(" private SearchType _searchType;");
  639. sb.AppendLine();
  640. sb.AppendLine(" /// <summary>");
  641. sb.AppendLine(" /// Determines the maximum number of rows that are returned. Use 0 for no limit.");
  642. sb.AppendLine(" /// </summary>");
  643. sb.AppendLine(" public int MaxRowCount");
  644. sb.AppendLine(" {");
  645. sb.AppendLine(" get { return _maxRowCount; }");
  646. sb.AppendLine(" set { _maxRowCount = value; }");
  647. sb.AppendLine(" }");
  648. sb.AppendLine();
  649. sb.AppendLine(" int IBusinessObjectSearch.MaxRowCount");
  650. sb.AppendLine(" {");
  651. sb.AppendLine(" get { return this.MaxRowCount; }");
  652. sb.AppendLine(" set { this.MaxRowCount = value; }");
  653. sb.AppendLine(" }");
  654. sb.AppendLine();
  655. sb.AppendLine(" /// <summary>");
  656. sb.AppendLine(" /// Determines the type of search to be performed.");
  657. sb.AppendLine(" /// </summary>");
  658. sb.AppendLine(" public SearchType SearchType");
  659. sb.AppendLine(" {");
  660. sb.AppendLine(" get { return _searchType; }");
  661. sb.AppendLine(" }");
  662. sb.AppendLine();
  663. sb.AppendLine(" /// <summary>");
  664. sb.AppendLine(" /// A search object for the '" + _currentView.PascalName + "' collection.");
  665. sb.AppendLine(" /// </summary>");
  666. sb.AppendLine(" public " + _currentView.PascalName + "Search(SearchType searchType) ");
  667. sb.AppendLine(" {");
  668. sb.AppendLine(" _searchType = searchType;");
  669. sb.AppendLine(" }");
  670. sb.AppendLine();
  671. sb.AppendLine(" void IBusinessObjectSearch.SetValue(Enum field, object value)");
  672. sb.AppendLine(" {");
  673. sb.AppendLine(" this.SetValue((" + _currentView.PascalName + ".FieldNameConstants)field, value);");
  674. sb.AppendLine(" }");
  675. sb.AppendLine();
  676. sb.AppendLine(" /// <summary>");
  677. sb.AppendLine(" /// Set the specified value on this object.");
  678. sb.AppendLine(" /// </summary>");
  679. sb.AppendLine(" public void SetValue(" + _currentView.PascalName + ".FieldNameConstants field, object value)");
  680. sb.AppendLine(" {");
  681. foreach (CustomViewColumn dc in validColumns)
  682. {
  683. sb.AppendLine(" if (field == " + _currentView.PascalName + ".FieldNameConstants." + dc.PascalName + ")");
  684. sb.AppendLine(" this." + dc.PascalName + " = (" + dc.GetCodeType(false) + ")value;");
  685. }
  686. sb.AppendLine(" }");
  687. sb.AppendLine();
  688. foreach (CustomViewColumn dc in validColumns)
  689. {
  690. sb.AppendLine(" /// <summary>");
  691. sb.AppendLine(" /// This field determines the value of the '" + dc.PascalName + "' field on the '" + _currentView.PascalName + "' object when this search object is applied.");
  692. sb.AppendLine(" /// </summary>");
  693. sb.AppendFormat(" public " + dc.GetCodeType(true, true) + " {0}", dc.PascalName).AppendLine();
  694. sb.AppendLine(" {");
  695. sb.AppendFormat(" get {{ return _{0}; }}", dc.CamelName).AppendLine();
  696. sb.AppendFormat(" set {{ _{0} = value; }}", dc.CamelName).AppendLine();
  697. sb.AppendLine(" }");
  698. sb.AppendLine();
  699. }
  700. sb.AppendLine(" }");
  701. sb.AppendLine();
  702. sb.AppendLine(" #endregion ");
  703. sb.AppendLine();
  704. }
  705. }
  706. private ArrayList GetValidSearchColumns()
  707. {
  708. var validColumns = new ArrayList();
  709. foreach (var column in _currentView.GeneratedColumns)
  710. {
  711. if (!(column.DataType == System.Data.SqlDbType.Binary ||
  712. column.DataType == System.Data.SqlDbType.Image ||
  713. column.DataType == System.Data.SqlDbType.NText ||
  714. column.DataType == System.Data.SqlDbType.Text ||
  715. column.DataType == System.Data.SqlDbType.Timestamp ||
  716. column.DataType == System.Data.SqlDbType.Udt ||
  717. column.DataType == System.Data.SqlDbType.VarBinary ||
  718. column.DataType == System.Data.SqlDbType.Variant ||
  719. column.DataType == System.Data.SqlDbType.Money))
  720. {
  721. validColumns.Add(column);
  722. }
  723. }
  724. return validColumns;
  725. }
  726. private void AppendClassEnumerator()
  727. {
  728. sb.AppendLine(" #region IEnumerator");
  729. sb.AppendLine();
  730. sb.AppendLine(" /// <summary>");
  731. sb.AppendLine(" /// An strongly-typed enumerator for the '" + _currentView.PascalName + "' object collection");
  732. sb.AppendLine(" /// </summary>");
  733. sb.AppendLine(" public partial class " + _currentView.PascalName + "Enumerator: System.Collections.IEnumerator ");
  734. sb.AppendLine(" {");
  735. sb.AppendLine(" private System.Collections.IEnumerator internalEnumerator;");
  736. sb.AppendLine(" internal " + _currentView.PascalName + "Enumerator(IEnumerator icg)");
  737. sb.AppendLine(" {");
  738. sb.AppendLine(" internalEnumerator = icg;");
  739. sb.AppendLine(" }");
  740. sb.AppendLine();
  741. sb.AppendLine(" #region IEnumerator Members");
  742. sb.AppendLine();
  743. sb.AppendLine(" /// <summary>");
  744. sb.AppendLine(" /// Reset the enumerator to the first object in this collection");
  745. sb.AppendLine(" /// </summary>");
  746. sb.AppendLine(" public void Reset()");
  747. sb.AppendLine(" {");
  748. sb.AppendLine(" try");
  749. sb.AppendLine(" {");
  750. sb.AppendLine(" internalEnumerator.Reset();");
  751. sb.AppendLine(" }");
  752. Globals.AppendBusinessEntryCatch(sb);
  753. sb.AppendLine(" }");
  754. sb.AppendLine();
  755. sb.AppendLine(" /// <summary>");
  756. sb.AppendLine(" /// Gets the current element in the collection.");
  757. sb.AppendLine(" /// </summary>");
  758. sb.AppendLine(" /// <returns>The current element in the collection.</returns>");
  759. sb.AppendLine(" public object Current");
  760. sb.AppendLine(" {");
  761. sb.AppendLine(" get");
  762. sb.AppendLine(" {");
  763. sb.AppendLine(" try");
  764. sb.AppendLine(" {");
  765. sb.AppendLine(" return new " + _currentView.PascalName + "((" + this.GetLocalNamespace() + ".Domain.Views.Domain" + _currentView.PascalName + ")internalEnumerator.Current);");
  766. sb.AppendLine(" }");
  767. Globals.AppendBusinessEntryCatch(sb, true);
  768. sb.AppendLine(" }");
  769. sb.AppendLine(" }");
  770. sb.AppendLine();
  771. sb.AppendLine(" /// <summary>");
  772. sb.AppendLine(" /// Advances the enumerator to the next element of the collection.");
  773. sb.AppendLine(" /// </summary>");
  774. sb.AppendLine(" public bool MoveNext()");
  775. sb.AppendLine(" {");
  776. sb.AppendLine(" try");
  777. sb.AppendLine(" {");
  778. sb.AppendLine(" bool movedNext = internalEnumerator.MoveNext();");
  779. sb.AppendLine(" if (movedNext)");
  780. sb.AppendLine(" {");
  781. sb.AppendLine(" " + this.GetLocalNamespace() + ".Domain.Views.Domain" + _currentView.PascalName + " currentRow = (" + this.GetLocalNamespace() + ".Domain.Views.Domain" + _currentView.PascalName + ")internalEnumerator.Current;");
  782. sb.AppendLine(" while (currentRow.RowState == System.Data.DataRowState.Deleted || currentRow.RowState == System.Data.DataRowState.Detached)");
  783. sb.AppendLine(" {");
  784. sb.AppendLine(" movedNext = internalEnumerator.MoveNext();");
  785. sb.AppendLine(" if (!movedNext) break;");
  786. sb.AppendLine(" currentRow = (Domain" + _currentView.PascalName + ")internalEnumerator.Current;");
  787. sb.AppendLine(" }");
  788. sb.AppendLine(" }");
  789. sb.AppendLine(" return movedNext;");
  790. sb.AppendLine(" }");
  791. Globals.AppendBusinessEntryCatch(sb);
  792. sb.AppendLine(" }");
  793. sb.AppendLine();
  794. sb.AppendLine(" #endregion");
  795. sb.AppendLine();
  796. sb.AppendLine(" }");
  797. sb.AppendLine(" #endregion");
  798. sb.AppendLine();
  799. }
  800. private void AppendPagingClass()
  801. {
  802. sb.AppendLine(" #region " + _currentView.PascalName + "Paging");
  803. sb.AppendLine();
  804. sb.AppendLine(" /// <summary>");
  805. sb.AppendLine(" /// A field sort object for the " + _currentView.PascalName + "Paging object.");
  806. sb.AppendLine(" /// </summary>");
  807. sb.AppendLine(" [Serializable]");
  808. sb.AppendLine(" public class " + _currentView.PascalName + "PagingFieldItem : IPagingFieldItem");
  809. sb.AppendLine(" {");
  810. sb.AppendLine(" /// <summary>");
  811. sb.AppendLine(" /// Determines the direction of the sort.");
  812. sb.AppendLine(" /// </summary>");
  813. sb.AppendLine(" public bool Ascending { get; set; }");
  814. sb.AppendLine();
  815. sb.AppendLine(" /// <summary>");
  816. sb.AppendLine(" /// Determines the field on which to sort.");
  817. sb.AppendLine(" /// </summary>");
  818. sb.AppendLine(" public " + this.GetLocalNamespace() + ".Business.Views." + _currentView.PascalName + ".FieldNameConstants Field { get; set; }");
  819. sb.AppendLine();
  820. sb.AppendLine(" /// <summary>");
  821. sb.AppendLine(" /// Create a sorting field object for the " + _currentView.PascalName + "Paging object.");
  822. sb.AppendLine(" /// </summary>");
  823. sb.AppendLine(" /// <param name=\"field\">The field on which to sort.</param>");
  824. sb.AppendLine(" public " + _currentView.PascalName + "PagingFieldItem(" + this.GetLocalNamespace() + ".Business.Views." + _currentView.PascalName + ".FieldNameConstants field)");
  825. sb.AppendLine(" {");
  826. sb.AppendLine(" this.Field = field;");
  827. sb.AppendLine(" }");
  828. sb.AppendLine();
  829. sb.AppendLine(" /// <summary>");
  830. sb.AppendLine(" /// Create a sorting field object for the " + _currentView.PascalName + "Paging object.");
  831. sb.AppendLine(" /// </summary>");
  832. sb.AppendLine(" /// <param name=\"field\">The field on which to sort.</param>");
  833. sb.AppendLine(" /// <param name=\"ascending\">Determines the direction of the sort.</param>");
  834. sb.AppendLine(" public " + _currentView.PascalName + "PagingFieldItem(" + this.GetLocalNamespace() + ".Business.Views." + _currentView.PascalName + ".FieldNameConstants field, bool ascending)");
  835. sb.AppendLine(" : this(field)");
  836. sb.AppendLine(" {");
  837. sb.AppendLine(" this.Ascending = ascending;");
  838. sb.AppendLine(" }");
  839. sb.AppendLine();
  840. sb.AppendLine(" #region IPagingFieldItem Members");
  841. sb.AppendLine();
  842. sb.AppendLine(" System.Enum IPagingFieldItem.GetField()");
  843. sb.AppendLine(" {");
  844. sb.AppendLine(" return this.Field;");
  845. sb.AppendLine(" }");
  846. sb.AppendLine();
  847. sb.AppendLine(" #endregion");
  848. sb.AppendLine();
  849. sb.AppendLine(" }");
  850. sb.AppendLine();
  851. sb.AppendLine(" /// <summary>");
  852. sb.AppendLine(" /// The paging object for the " + _currentView.PascalName + " collection");
  853. sb.AppendLine(" /// </summary>");
  854. sb.AppendLine(" [Serializable]");
  855. sb.AppendLine(" public class " + _currentView.PascalName + "Paging : PagingBase<" + _currentView.PascalName + "PagingFieldItem, " + this.GetLocalNamespace() + ".Business.Views." + _currentView.PascalName + ".FieldNameConstants> { }");
  856. sb.AppendLine();
  857. sb.AppendLine(" #endregion");
  858. sb.AppendLine();
  859. }
  860. #endregion
  861. #region append regions
  862. #endregion
  863. #region append member variables
  864. public void AppendMemberVariables()
  865. {
  866. sb.AppendLine(" #region Member Variables");
  867. sb.AppendLine();
  868. sb.AppendLine(" internal Domain" + _currentView.PascalName + "Collection wrappedClass;");
  869. sb.AppendLine();
  870. sb.AppendLine(" #endregion");
  871. sb.AppendLine();
  872. }
  873. #endregion
  874. #region append constructors
  875. public void AppendConstructors()
  876. {
  877. sb.AppendLine(" #region Constructor / Initialize");
  878. sb.AppendLine();
  879. AppendConstructorDomainClass();
  880. AppendConstructorDefault();
  881. sb.AppendLine(" #endregion");
  882. sb.AppendLine();
  883. }
  884. private void AppendConstructorDomainClass()
  885. {
  886. sb.AppendLine(" internal " + _currentView.PascalName + "Collection(Domain" + _currentView.PascalName + "Collection classToWrap)");
  887. sb.AppendLine(" {");
  888. sb.AppendLine(" wrappedClass = classToWrap;");
  889. sb.AppendLine(" }");
  890. sb.AppendLine();
  891. }
  892. private void AppendConstructorDefault()
  893. {
  894. sb.AppendLine(" /// <summary>");
  895. sb.AppendLine(" /// The default constructor");
  896. sb.AppendLine(" /// </summary>");
  897. sb.AppendLine(" public " + _currentView.PascalName + "Collection() ");
  898. sb.AppendLine(" {");
  899. //sb.AppendLine(" var sd = new SubDomain(\"Default Contructor Called\");");
  900. sb.AppendLine(" var sd = new SubDomain(ConfigurationValues.GetInstance().Modifier);");
  901. sb.AppendLine(" wrappedClass = (Domain" + _currentView.PascalName + "Collection)sd.GetDomainCollection(Collections." + _currentView.PascalName + "Collection);");
  902. sb.AppendLine(" }");
  903. sb.AppendLine();
  904. }
  905. #endregion
  906. #region append properties
  907. private void AppendProperties()
  908. {
  909. sb.AppendLine(" #region Property Implementations");
  910. sb.AppendLine();
  911. AppendPropertyWrappedClass();
  912. AppendPropertySubDomain();
  913. AppendPropertyCount();
  914. AppendPropertyContainedType();
  915. AppendPropertyCollection();
  916. sb.AppendLine(" #endregion");
  917. sb.AppendLine();
  918. }
  919. private void AppendPropertyWrappedClass()
  920. {
  921. sb.AppendLine(" /// <summary>");
  922. sb.AppendLine(" /// Returns the internal object that this object wraps");
  923. sb.AppendLine(" /// </summary>");
  924. sb.AppendLine(" [System.ComponentModel.Browsable(false)]");
  925. sb.AppendLine(" public object WrappedClass");
  926. sb.AppendLine(" {");
  927. sb.AppendLine(" get { return wrappedClass; }");
  928. sb.AppendLine(" set { wrappedClass = (Domain" + _currentView.PascalName + "Collection)value; }");
  929. sb.Ap

Large files files are truncated, but you can click here to view the full file