PageRenderTime 92ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 1ms

/tags/Last2008/Source/Widgetsphere.Generator.DAL/ProjectItemGenerators/BusinessCollection/BusinessCollectionGeneratedTemplate.cs

#
C# | 1487 lines | 1226 code | 114 blank | 147 comment | 80 complexity | 3b3c46ae481b89c42fc90aa080c0af4d 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-2010 Widgetsphere LLC, All Rights Reserved
  2. //--------------------------------------------------------------------- *
  3. // Widgetsphere LLC *
  4. // Copyright (c) 2006-2010 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.Linq;
  40. using System.Collections.Generic;
  41. using System.Text;
  42. using Widgetsphere.Generator.Common.Util;
  43. using Widgetsphere.Generator.Models;
  44. using Widgetsphere.Generator.ProjectItemGenerators;
  45. using System.Collections;
  46. namespace Widgetsphere.Generator.DAL.ProjectItemGenerators.BusinessCollection
  47. {
  48. class BusinessCollectionGeneratedTemplate : BaseClassTemplate
  49. {
  50. private StringBuilder sb = new StringBuilder();
  51. private Table _currentTable;
  52. public BusinessCollectionGeneratedTemplate(ModelRoot model, Table currentTable)
  53. {
  54. _model = model;
  55. _currentTable = currentTable;
  56. }
  57. #region BaseClassTemplate overrides
  58. public override string FileName
  59. {
  60. get { return string.Format("{0}Collection.Generated.cs", _currentTable.PascalName); }
  61. }
  62. public string ParentItemName
  63. {
  64. get { return string.Format("{0}Collection.cs", _currentTable.PascalName); }
  65. }
  66. public override string FileContent
  67. {
  68. get
  69. {
  70. GenerateContent();
  71. return sb.ToString();
  72. }
  73. }
  74. #endregion
  75. #region GenerateContent
  76. private void GenerateContent()
  77. {
  78. try
  79. {
  80. ValidationHelper.AppendCopyrightInCode(sb, _model);
  81. this.AppendUsingStatements();
  82. sb.AppendLine("namespace " + DefaultNamespace + ".Business.Objects");
  83. sb.AppendLine("{");
  84. this.AppendClass();
  85. this.AppendSearchClass();
  86. this.AppendPagingClass();
  87. sb.AppendLine("}");
  88. }
  89. catch (Exception ex)
  90. {
  91. throw;
  92. }
  93. }
  94. #endregion
  95. #region namespace / objects
  96. public void AppendUsingStatements()
  97. {
  98. sb.AppendLine("using System;");
  99. sb.AppendLine("using System.Data;");
  100. sb.AppendLine("using System.Xml;");
  101. sb.AppendLine("using System.Collections;");
  102. sb.AppendLine("using System.Runtime.Serialization;");
  103. sb.AppendLine("using System.ComponentModel;");
  104. sb.AppendLine("using " + DefaultNamespace + ".Business.Rules;");
  105. sb.AppendLine("using " + DefaultNamespace + ".Business.SelectCommands;");
  106. sb.AppendLine("using " + DefaultNamespace + ".Domain.Objects;");
  107. sb.AppendLine("using Widgetsphere.Core.DataAccess;");
  108. sb.AppendLine("using Widgetsphere.Core.Util;");
  109. sb.AppendLine("using Widgetsphere.Core.Logging;");
  110. sb.AppendLine("using Widgetsphere.Core.Exceptions;");
  111. sb.AppendLine("using " + DefaultNamespace + ".Business.LINQ;");
  112. sb.AppendLine("using System.IO;");
  113. sb.AppendLine("using System.Collections.Generic;");
  114. sb.AppendLine("using System.Linq.Expressions;");
  115. sb.AppendLine("using System.Data.Linq;");
  116. sb.AppendLine("using System.Linq;");
  117. sb.AppendLine("using System.Text;");
  118. sb.AppendLine("using Widgetsphere.Core.EventArgs;");
  119. sb.AppendLine("using System.Text.RegularExpressions;");
  120. sb.AppendLine();
  121. }
  122. private void AppendClass()
  123. {
  124. string baseClass = "BusinessCollectionPersistableBase";
  125. string baseInterface = "IPersistableBusinessCollection";
  126. if (_currentTable.Immutable)
  127. {
  128. baseClass = "BusinessCollectionBase";
  129. baseInterface = "IBusinessCollection";
  130. }
  131. if (_currentTable.ParentTable != null)
  132. baseClass = _currentTable.ParentTable.PascalName + "Collection";
  133. sb.AppendLine(" /// <summary>");
  134. sb.AppendLine(" /// The collection to hold '" + _currentTable.PascalName + "' entities");
  135. if (_currentTable.Description != "")
  136. sb.AppendLine(" /// " + _currentTable.Description);
  137. sb.AppendLine(" /// </summary>");
  138. sb.AppendLine(" [Serializable()]");
  139. sb.AppendLine(" public partial class " + _currentTable.PascalName + "Collection : " + baseClass + ", " + baseInterface + ", IDisposable, IEnumerator, IEnumerable<" + _currentTable.PascalName + ">, IWrappingClass");
  140. sb.AppendLine(" {");
  141. this.AppendMemberVariables();
  142. this.AppendConstructors();
  143. this.AppendProperties();
  144. this.AppendOperatorIndexer();
  145. this.AppendMethods();
  146. //this.AppendIListImplementation();
  147. this.AppendRegionIBusinessCollectionExplicit();
  148. //this.AppendRegionGetFilteredList();
  149. this.AppendRegionGetDatabaseFieldName();
  150. this.AppendClassEnumerator();
  151. this.AppendRegionSearch();
  152. this.AppendRegionCustomSelectByRules();
  153. this.AppendRegionSelectByDates();
  154. this.AppendRegionEnumerator();
  155. this.AppendInterfaces();
  156. sb.AppendLine(" }");
  157. sb.AppendLine();
  158. }
  159. private void AppendRegionSearch()
  160. {
  161. if (!_model.SupportLegacySearchObject)
  162. {
  163. sb.AppendLine(" #region Search Members");
  164. sb.AppendLine();
  165. sb.AppendLine(" /// <summary>");
  166. sb.AppendLine(" /// Creates a search object to query this collection.");
  167. sb.AppendLine(" /// </summary>");
  168. sb.AppendLine(" IBusinessObjectSearch IBusinessCollection.CreateSearchObject(SearchType searchType)");
  169. sb.AppendLine(" {");
  170. sb.AppendLine(" throw new Exception(\"This functoinality is not supported because the model did not support legacy search objects.\");");
  171. sb.AppendLine(" }");
  172. sb.AppendLine();
  173. sb.AppendLine(" #endregion");
  174. sb.AppendLine();
  175. }
  176. else
  177. {
  178. sb.AppendLine(" #region Search Members");
  179. sb.AppendLine();
  180. sb.AppendLine(" /// <summary>");
  181. sb.AppendLine(" /// Creates a search object to query this collection.");
  182. sb.AppendLine(" /// </summary>");
  183. sb.AppendLine(" IBusinessObjectSearch IBusinessCollection.CreateSearchObject(SearchType searchType)");
  184. sb.AppendLine(" {");
  185. sb.AppendLine(" return (IBusinessObjectSearch)this.CreateSearchObject(searchType);");
  186. sb.AppendLine(" }");
  187. sb.AppendLine();
  188. sb.AppendLine(" /// <summary>");
  189. sb.AppendLine(" /// Creates a search object to query this collection.");
  190. sb.AppendLine(" /// </summary>");
  191. if (_model.Database.AllowZeroTouch)
  192. {
  193. if (_currentTable.ParentTable == null)
  194. sb.AppendLine(" public virtual IBusinessObjectSearch CreateSearchObject(SearchType searchType)");
  195. else
  196. sb.AppendLine(" public new IBusinessObjectSearch CreateSearchObject(SearchType searchType)");
  197. sb.AppendLine(" {");
  198. sb.AppendLine(" return null;");
  199. sb.AppendLine(" }");
  200. }
  201. else
  202. {
  203. if (_currentTable.ParentTable == null)
  204. sb.AppendLine(" public virtual " + _currentTable.PascalName + "Search CreateSearchObject(SearchType searchType)");
  205. else
  206. sb.AppendLine(" public new " + _currentTable.PascalName + "Search CreateSearchObject(SearchType searchType)");
  207. sb.AppendLine(" {");
  208. sb.AppendLine(" return new " + _currentTable.PascalName + "Search(searchType);");
  209. sb.AppendLine(" }");
  210. }
  211. sb.AppendLine();
  212. sb.AppendLine(" #endregion");
  213. sb.AppendLine();
  214. }
  215. }
  216. private void AppendRegionSelectByDates()
  217. {
  218. sb.AppendLine(" #region Select By Dates");
  219. sb.AppendLine();
  220. if (_currentTable.Generated && _currentTable.AllowCreateAudit)
  221. {
  222. sb.AppendLine(" /// <summary>");
  223. sb.AppendLine(" /// Select objects by their created date.");
  224. sb.AppendLine(" /// </summary>");
  225. sb.AppendLine(" /// <param name=\"startDate\">The inclusive date on which to start the search.</param>");
  226. sb.AppendLine(" /// <param name=\"endDate\">The inclusive date on which to end the search.</param>");
  227. sb.AppendLine(" /// <param name=\"modifier\">The identifier used for the create and modify audits.</param>");
  228. if (_currentTable.ParentTable == null)
  229. sb.AppendLine(" public static " + _currentTable.PascalName + "Collection SelectByCreatedDateRange(DateTime? startDate, DateTime? endDate, string modifier)");
  230. else
  231. sb.AppendLine(" public new static " + _currentTable.PascalName + "Collection SelectByCreatedDateRange(DateTime? startDate, DateTime? endDate, string modifier)");
  232. sb.AppendLine(" {");
  233. sb.AppendLine(" SubDomain subDomain = new SubDomain(modifier);");
  234. sb.AppendLine(" " + _currentTable.PascalName + "SelectByCreatedDateRange selectCommand = new " + _currentTable.PascalName + "SelectByCreatedDateRange(startDate, endDate);");
  235. sb.AppendLine(" subDomain.AddSelectCommand(selectCommand);");
  236. sb.AppendLine(" subDomain.RunSelectCommands();");
  237. sb.AppendLine(" return subDomain.GetCollection<" + _currentTable.PascalName + "Collection>();");
  238. sb.AppendLine(" }");
  239. sb.AppendLine();
  240. }
  241. if (_currentTable.Generated && _currentTable.AllowModifiedAudit)
  242. {
  243. sb.AppendLine(" /// <summary>");
  244. sb.AppendLine(" /// Select objects by their modified date.");
  245. sb.AppendLine(" /// </summary>");
  246. sb.AppendLine(" /// <param name=\"startDate\">The inclusive date on which to start the search.</param>");
  247. sb.AppendLine(" /// <param name=\"endDate\">The inclusive date on which to end the search.</param>");
  248. sb.AppendLine(" /// <param name=\"modifier\">The identifier used for the create and modify audits.</param>");
  249. if (_currentTable.ParentTable == null)
  250. sb.AppendLine(" public static " + _currentTable.PascalName + "Collection SelectByModifiedDateRange(DateTime? startDate, DateTime? endDate, string modifier)");
  251. else
  252. sb.AppendLine(" public new static " + _currentTable.PascalName + "Collection SelectByModifiedDateRange(DateTime? startDate, DateTime? endDate, string modifier)");
  253. sb.AppendLine(" {");
  254. sb.AppendLine(" SubDomain subDomain = new SubDomain(modifier);");
  255. sb.AppendLine(" " + _currentTable.PascalName + "SelectByModifiedDateRange selectCommand = new " + _currentTable.PascalName + "SelectByModifiedDateRange(startDate, endDate);");
  256. sb.AppendLine(" subDomain.AddSelectCommand(selectCommand);");
  257. sb.AppendLine(" subDomain.RunSelectCommands();");
  258. sb.AppendLine(" return subDomain.GetCollection<" + _currentTable.PascalName + "Collection>();");
  259. sb.AppendLine(" }");
  260. sb.AppendLine();
  261. }
  262. sb.AppendLine(" #endregion");
  263. sb.AppendLine();
  264. }
  265. private void AppendRegionCustomSelectByRules()
  266. {
  267. if (_model.Database.AllowZeroTouch) return;
  268. if (_currentTable.CustomRetrieveRules.Count == 0)
  269. return;
  270. sb.AppendLine(" #region CustomSelectBy CustomRules");
  271. sb.AppendLine();
  272. //Create a method for all custom retrieve rules
  273. foreach (Reference reference in _currentTable.CustomRetrieveRules)
  274. {
  275. CustomRetrieveRule rule = (CustomRetrieveRule)reference.Object;
  276. if (rule.Generated)
  277. {
  278. sb.AppendLine(" /// <summary>");
  279. sb.AppendLine(" /// Select rows based on the '" + rule.PascalName + "' custom retrieve rule for the '" + _currentTable.DatabaseName + "' table.");
  280. sb.AppendLine(" /// </summary>");
  281. //sb.AppendLine(" /// <param name=\"modifier\">The identifier used for the create and modify audits.</param>");
  282. sb.Append(" public static " + _currentTable.PascalName + "Collection SelectBy" + rule.PascalName + "(");
  283. if (rule.UseSearchObject)
  284. {
  285. sb.Append(_currentTable.PascalName + "Search " + _currentTable.CamelName);
  286. if (rule.Parameters.Count > 0)
  287. sb.Append(", ");
  288. }
  289. foreach (Parameter parameter in rule.GeneratedParameters)
  290. {
  291. if (parameter.IsOutputParameter)
  292. sb.Append("out ");
  293. sb.Append(parameter.GetCodeType() + " " + parameter.CamelName + ", ");
  294. }
  295. sb.AppendLine("string modifier)");
  296. sb.AppendLine(" {");
  297. sb.AppendLine(" SubDomain subDomain = new SubDomain(modifier);");
  298. sb.Append(" " + _currentTable.PascalName + "CustomSelectBy" + rule.PascalName + " selectCommand = new " + _currentTable.PascalName + "CustomSelectBy" + rule.PascalName + "(");
  299. if (rule.UseSearchObject)
  300. {
  301. sb.Append(_currentTable.CamelName);
  302. if (rule.Parameters.Count > 0)
  303. sb.Append(", ");
  304. }
  305. foreach (Parameter parameter in rule.GeneratedParameters)
  306. {
  307. if (!parameter.IsOutputParameter)
  308. {
  309. sb.Append(parameter.CamelName + ", ");
  310. }
  311. }
  312. if (sb.ToString().EndsWith(", ")) sb.Remove(sb.ToString().Length - 2, 2);
  313. sb.AppendLine(");");
  314. sb.AppendLine(" subDomain.AddSelectCommand(selectCommand);");
  315. sb.AppendLine(" subDomain.RunSelectCommands();");
  316. foreach (Parameter parameter in rule.GeneratedParameters)
  317. {
  318. if (parameter.IsOutputParameter)
  319. {
  320. sb.AppendLine(" " + parameter.CamelName + " = selectCommand." + parameter.PascalName + ";");
  321. }
  322. }
  323. sb.AppendLine(" return subDomain.GetCollection<" + _currentTable.PascalName + "Collection>();");
  324. sb.AppendLine(" }");
  325. sb.AppendLine();
  326. }
  327. }
  328. sb.AppendLine(" #endregion");
  329. sb.AppendLine();
  330. }
  331. private void AppendInterfaces()
  332. {
  333. sb.AppendLine(" #region IDisposable Members");
  334. sb.AppendLine();
  335. sb.AppendLine(" void IDisposable.Dispose()");
  336. sb.AppendLine(" {");
  337. sb.AppendLine();
  338. sb.AppendLine(" }");
  339. sb.AppendLine();
  340. sb.AppendLine(" #endregion");
  341. sb.AppendLine();
  342. }
  343. private void AppendRegionEnumerator()
  344. {
  345. sb.AppendLine(" #region IEnumerator Members");
  346. sb.AppendLine();
  347. sb.AppendLine(" object IEnumerator.Current");
  348. sb.AppendLine(" {");
  349. sb.AppendLine(" get { return this.GetEnumerator().Current; }");
  350. sb.AppendLine(" }");
  351. sb.AppendLine();
  352. sb.AppendLine(" bool IEnumerator.MoveNext()");
  353. sb.AppendLine(" {");
  354. sb.AppendLine(" return this.GetEnumerator().MoveNext();");
  355. sb.AppendLine(" }");
  356. sb.AppendLine();
  357. sb.AppendLine(" void IEnumerator.Reset()");
  358. sb.AppendLine(" {");
  359. sb.AppendLine(" this.GetEnumerator().Reset();");
  360. sb.AppendLine(" }");
  361. sb.AppendLine();
  362. sb.AppendLine(" #endregion");
  363. sb.AppendLine();
  364. sb.AppendLine(" #region IEnumerable<" + _currentTable.PascalName + "> Members");
  365. sb.AppendLine();
  366. sb.AppendLine(" IEnumerator<" + _currentTable.PascalName + "> IEnumerable<" + _currentTable.PascalName + ">.GetEnumerator()");
  367. sb.AppendLine(" {");
  368. sb.AppendLine(" List<" + _currentTable.PascalName + "> retval = new List<" + _currentTable.PascalName + ">();");
  369. sb.AppendLine(" foreach (" + _currentTable.PascalName + " item in this)");
  370. sb.AppendLine(" {");
  371. sb.AppendLine(" retval.Add(item);");
  372. sb.AppendLine(" }");
  373. sb.AppendLine(" return retval.GetEnumerator();");
  374. sb.AppendLine(" }");
  375. sb.AppendLine();
  376. sb.AppendLine(" #endregion");
  377. sb.AppendLine();
  378. }
  379. private void AppendRegionIBusinessCollectionExplicit()
  380. {
  381. if (!_currentTable.Immutable)
  382. {
  383. sb.AppendLine(" #region IPersistableBusinessCollection Explicit Members");
  384. sb.AppendLine();
  385. sb.AppendLine(" /// <summary>");
  386. sb.AppendLine(" /// Returns an item in this collection by index.");
  387. sb.AppendLine(" /// </summary>");
  388. sb.AppendLine(" /// <param name=\"index\">The zero-based index of the element to get or set. </param>");
  389. sb.AppendLine(" /// <returns>The element at the specified index.</returns>");
  390. sb.AppendLine(" IPersistableBusinessObject IPersistableBusinessCollection.this[int index]");
  391. sb.AppendLine(" {");
  392. sb.AppendLine(" get { return this[index]; }");
  393. sb.AppendLine(" }");
  394. sb.AppendLine();
  395. sb.AppendLine(" void IPersistableBusinessCollection.AddItem(IPersistableBusinessObject newItem)");
  396. sb.AppendLine(" {");
  397. sb.AppendLine(" this.AddItem((" + _currentTable.PascalName + ")newItem);");
  398. sb.AppendLine(" }");
  399. sb.AppendLine();
  400. sb.AppendLine(" IPersistableBusinessObject IPersistableBusinessCollection.NewItem()");
  401. sb.AppendLine(" {");
  402. sb.AppendLine(" return this.NewItem();");
  403. sb.AppendLine(" }");
  404. sb.AppendLine();
  405. sb.AppendLine(" #endregion");
  406. sb.AppendLine();
  407. }
  408. sb.AppendLine(" #region IBusinessCollection Explicit Members");
  409. sb.AppendLine();
  410. sb.AppendLine(" /// <summary>");
  411. sb.AppendLine(" /// Returns an item in this collection by index.");
  412. sb.AppendLine(" /// </summary>");
  413. sb.AppendLine(" /// <param name=\"index\">The zero-based index of the element to get or set. </param>");
  414. sb.AppendLine(" /// <returns>The element at the specified index.</returns>");
  415. sb.AppendLine(" IBusinessObject IBusinessCollection.this[int index]");
  416. sb.AppendLine(" {");
  417. sb.AppendLine(" get { return this[index]; }");
  418. sb.AppendLine(" }");
  419. sb.AppendLine();
  420. sb.AppendLine(" Enum IBusinessCollection.Collection");
  421. sb.AppendLine(" {");
  422. sb.AppendLine(" get { return this.Collection; }");
  423. sb.AppendLine(" }");
  424. sb.AppendLine();
  425. sb.AppendLine(" Type IBusinessCollection.ContainedType");
  426. sb.AppendLine(" {");
  427. sb.AppendLine(" get { return this.ContainedType; }");
  428. sb.AppendLine(" }");
  429. sb.AppendLine();
  430. sb.AppendLine(" SubDomainBase IBusinessCollection.SubDomain");
  431. sb.AppendLine(" {");
  432. sb.AppendLine(" get { return this.SubDomain; }");
  433. sb.AppendLine(" }");
  434. sb.AppendLine();
  435. sb.AppendLine(" Type ITyped.GetContainedType()");
  436. sb.AppendLine(" {");
  437. sb.AppendLine(" return typeof(" + _currentTable.PascalName + ");");
  438. sb.AppendLine(" }");
  439. sb.AppendLine();
  440. sb.AppendLine(" #endregion");
  441. sb.AppendLine();
  442. }
  443. private void AppendRegionGetFilteredList()
  444. {
  445. sb.AppendLine(" #region GetFilteredList");
  446. sb.AppendLine();
  447. sb.AppendLine(" /// <summary>");
  448. sb.AppendLine(" /// Returns a list filtered on the specified field with the specified value.");
  449. sb.AppendLine(" /// </summary>");
  450. sb.AppendLine(" [Obsolete(\"Use a LINQ query for more robust functionality\")]");
  451. sb.AppendLine(" public BusinessObjectList<" + _currentTable.PascalName + "> GetFilteredList(" + _currentTable.PascalName + ".FieldNameConstants field, object value)");
  452. sb.AppendLine(" {");
  453. sb.AppendLine(" BusinessObjectList<" + _currentTable.PascalName + "> retval = new BusinessObjectList<" + _currentTable.PascalName + ">();");
  454. sb.AppendLine(" if (value == null)");
  455. sb.AppendLine(" return retval;");
  456. sb.AppendLine();
  457. sb.AppendLine(" string fieldName = \"\";");
  458. sb.AppendLine(" switch (field)");
  459. sb.AppendLine(" {");
  460. foreach (Column column in _currentTable.GeneratedColumns)
  461. {
  462. sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + column.PascalName + ": fieldName = \"" + column.DatabaseName + "\"; break;");
  463. }
  464. if (_currentTable.AllowCreateAudit)
  465. {
  466. sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedByColumnName) + ": fieldName = \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedByColumnName) + "\"; break;");
  467. sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedDateColumnName) + ": fieldName = \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedDateColumnName) + "\"; break;");
  468. }
  469. if (_currentTable.AllowModifiedAudit)
  470. {
  471. sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedByColumnName) + ": fieldName = \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedByColumnName) + "\"; break;");
  472. sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedDateColumnName) + ": fieldName = \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedDateColumnName) + "\"; break;");
  473. }
  474. sb.AppendLine(" }");
  475. sb.AppendLine();
  476. sb.AppendLine(" DataRow[] rows = null;");
  477. sb.AppendLine(" if (value == null)");
  478. sb.AppendLine(" {");
  479. sb.AppendLine(" rows = this.wrappedClass.Select(fieldName + \" IS NULL\");");
  480. sb.AppendLine(" }");
  481. sb.AppendLine(" else");
  482. sb.AppendLine(" {");
  483. sb.AppendLine(" string tick = \"\";");
  484. sb.AppendLine(" if ((this.wrappedClass.Columns[fieldName].DataType == typeof(string)) || (this.wrappedClass.Columns[fieldName].DataType == typeof(Guid)))");
  485. sb.AppendLine(" tick = \"'\";");
  486. sb.AppendLine();
  487. sb.AppendLine(" rows = this.wrappedClass.Select(fieldName + \" = \" + tick + value.ToString().Replace(\"'\", \"''\") + tick);");
  488. sb.AppendLine(" }");
  489. sb.AppendLine();
  490. sb.AppendLine(" foreach (DataRow dr in rows)");
  491. sb.AppendLine(" retval.Add(new " + _currentTable.PascalName + "((Domain" + _currentTable.PascalName + ")dr));");
  492. sb.AppendLine();
  493. sb.AppendLine(" return retval;");
  494. sb.AppendLine(" }");
  495. sb.AppendLine();
  496. sb.AppendLine(" #endregion");
  497. sb.AppendLine();
  498. }
  499. private void AppendRegionGetDatabaseFieldName()
  500. {
  501. sb.AppendLine(" #region GetDatabaseFieldName");
  502. sb.AppendLine();
  503. sb.AppendLine(" /// <summary>");
  504. sb.AppendLine(" /// Returns the actual database name of the specified field.");
  505. sb.AppendLine(" /// </summary>");
  506. sb.AppendLine(" internal static string GetDatabaseFieldName(" + _currentTable.PascalName + ".FieldNameConstants field)");
  507. sb.AppendLine(" {");
  508. sb.AppendLine(" return GetDatabaseFieldName(field.ToString());");
  509. //sb.AppendLine(" switch (field)");
  510. //sb.AppendLine(" {");
  511. //foreach (Column column in _currentTable.GeneratedColumns)
  512. //{
  513. // if (column.Generated)
  514. // sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + column.PascalName + ": return \"" + column.Name + "\";");
  515. //}
  516. //if (_currentTable.AllowCreateAudit)
  517. //{
  518. // sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedByColumnName) + ": return \"" + _model.Database.CreatedByColumnName + "\";");
  519. // sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedDateColumnName) + ": return \"" + _model.Database.CreatedDateColumnName + "\";");
  520. //}
  521. //if (_currentTable.AllowModifiedAudit)
  522. //{
  523. // sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedByColumnName) + ": return \"" + _model.Database.ModifiedByColumnName + "\";");
  524. // sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedDateColumnName) + ": return \"" + _model.Database.ModifiedDateColumnName + "\";");
  525. //}
  526. //sb.AppendLine(" }");
  527. //sb.AppendLine(" return \"\";");
  528. sb.AppendLine(" }");
  529. sb.AppendLine();
  530. sb.AppendLine(" /// <summary>");
  531. sb.AppendLine(" /// Returns the actual database name of the specified field.");
  532. sb.AppendLine(" /// </summary>");
  533. sb.AppendLine(" internal " + (_currentTable.ParentTable == null ? "" : "new ") + "static string GetDatabaseFieldName(string field)");
  534. sb.AppendLine(" {");
  535. sb.AppendLine(" switch (field)");
  536. sb.AppendLine(" {");
  537. foreach (Column column in _currentTable.GeneratedColumns)
  538. {
  539. if (column.Generated)
  540. sb.AppendLine(" case \"" + column.PascalName + "\": return \"" + column.Name + "\";");
  541. }
  542. if (_currentTable.AllowCreateAudit)
  543. {
  544. sb.AppendLine(" case \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedByColumnName) + "\": return \"" + _model.Database.CreatedByColumnName + "\";");
  545. sb.AppendLine(" case \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedDateColumnName) + "\": return \"" + _model.Database.CreatedDateColumnName + "\";");
  546. }
  547. if (_currentTable.AllowModifiedAudit)
  548. {
  549. sb.AppendLine(" case \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedByColumnName) + "\": return \"" + _model.Database.ModifiedByColumnName + "\";");
  550. sb.AppendLine(" case \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedDateColumnName) + "\": return \"" + _model.Database.ModifiedDateColumnName + "\";");
  551. }
  552. sb.AppendLine(" }");
  553. sb.AppendLine(" return \"\";");
  554. sb.AppendLine(" }");
  555. sb.AppendLine();
  556. sb.AppendLine(" #endregion");
  557. sb.AppendLine();
  558. }
  559. private void AppendSearchClass()
  560. {
  561. if (_model.Database.AllowZeroTouch) return;
  562. if (!_model.SupportLegacySearchObject) return;
  563. IEnumerable<Column> validColumns = GetValidSearchColumns();
  564. if (validColumns.Count() != 0)
  565. {
  566. sb.AppendLine(" #region " + _currentTable.PascalName + "Search");
  567. sb.AppendLine();
  568. sb.AppendLine(" /// <summary>");
  569. sb.AppendLine(" /// The search object for the " + _currentTable.PascalName + "Collection.");
  570. sb.AppendLine(" /// </summary>");
  571. sb.AppendLine(" [Serializable]");
  572. sb.AppendLine(" public class " + _currentTable.PascalName + "Search : IBusinessObjectSearch");
  573. sb.AppendLine(" {");
  574. sb.AppendLine();
  575. sb.AppendLine(" private int _maxRowCount = 0;");
  576. //foreach (Column column in validColumns.OrderBy(x => x.Name))
  577. //{
  578. // sb.AppendLine(" private " + column.GetCodeType(true, true) + " _" + column.CamelName + ";");
  579. //}
  580. sb.AppendLine(" private SearchType _searchType;");
  581. sb.AppendLine();
  582. sb.AppendLine(" /// <summary>");
  583. sb.AppendLine(" /// Determines the maximum number of rows that are returned. Use 0 for no limit.");
  584. sb.AppendLine(" /// </summary>");
  585. sb.AppendLine(" public int MaxRowCount");
  586. sb.AppendLine(" {");
  587. sb.AppendLine(" get { return _maxRowCount; }");
  588. sb.AppendLine(" set { _maxRowCount = value; }");
  589. sb.AppendLine(" }");
  590. sb.AppendLine();
  591. sb.AppendLine(" /// <summary>");
  592. sb.AppendLine(" /// Determines the maximum number of rows that are returned. Use 0 for no limit.");
  593. sb.AppendLine(" /// </summary>");
  594. sb.AppendLine(" int IBusinessObjectSearch.MaxRowCount");
  595. sb.AppendLine(" {");
  596. sb.AppendLine(" get { return this.MaxRowCount; }");
  597. sb.AppendLine(" set { this.MaxRowCount = value; }");
  598. sb.AppendLine(" }");
  599. sb.AppendLine();
  600. sb.AppendLine(" /// <summary>");
  601. sb.AppendLine(" /// Determines the type of search to be performed.");
  602. sb.AppendLine(" /// </summary>");
  603. sb.AppendLine(" public SearchType SearchType");
  604. sb.AppendLine(" {");
  605. sb.AppendLine(" get { return _searchType; }");
  606. sb.AppendLine(" }");
  607. sb.AppendLine();
  608. sb.AppendLine(" /// <summary>");
  609. sb.AppendLine(" /// A search object for the '" + _currentTable.PascalName + "' collection.");
  610. sb.AppendLine(" /// </summary>");
  611. sb.AppendLine(" public " + _currentTable.PascalName + "Search(SearchType searchType) ");
  612. sb.AppendLine(" {");
  613. sb.AppendLine(" _searchType = searchType;");
  614. sb.AppendLine(" }");
  615. sb.AppendLine();
  616. sb.AppendLine(" void IBusinessObjectSearch.SetValue(Enum field, object value)");
  617. sb.AppendLine(" {");
  618. sb.AppendLine(" this.SetValue((" + _currentTable.PascalName + ".FieldNameConstants)field, value);");
  619. sb.AppendLine(" }");
  620. sb.AppendLine();
  621. sb.AppendLine(" /// <summary>");
  622. sb.AppendLine(" /// Set the specified value on this object.");
  623. sb.AppendLine(" /// </summary>");
  624. sb.AppendLine(" public void SetValue(" + _currentTable.PascalName + ".FieldNameConstants field, object value)");
  625. sb.AppendLine(" {");
  626. foreach (Column column in validColumns.OrderBy(x => x.Name))
  627. {
  628. sb.AppendLine(" if (field == " + _currentTable.PascalName + ".FieldNameConstants." + column.PascalName + ") this." + column.PascalName + " = (" + column.GetCodeType(false) + ")value;");
  629. }
  630. sb.AppendLine(" }");
  631. sb.AppendLine();
  632. foreach (Column column in validColumns.OrderBy(x => x.Name))
  633. {
  634. sb.AppendLine(" /// <summary>");
  635. sb.AppendLine(" /// This field determines the value of the '" + column.PascalName + "' field on the '" + _currentTable.PascalName + "' object when this search object is applied.");
  636. sb.AppendLine(" /// </summary>");
  637. sb.AppendLine(" public " + column.GetCodeType(true, true) + " " + column.PascalName + " { get; set; }");
  638. sb.AppendLine();
  639. }
  640. sb.AppendLine(" }");
  641. sb.AppendLine();
  642. sb.AppendLine(" #endregion ");
  643. sb.AppendLine();
  644. }
  645. }
  646. private void AppendPagingClass()
  647. {
  648. sb.AppendLine(" #region " + _currentTable.PascalName + "Paging");
  649. sb.AppendLine();
  650. sb.AppendLine(" /// <summary>");
  651. sb.AppendLine(" /// A field sort object for the " + _currentTable.PascalName + "Paging object.");
  652. sb.AppendLine(" /// </summary>");
  653. sb.AppendLine(" [Serializable]");
  654. sb.AppendLine(" public class " + _currentTable.PascalName + "PagingFieldItem : IPagingFieldItem");
  655. sb.AppendLine(" {");
  656. sb.AppendLine(" /// <summary>");
  657. sb.AppendLine(" /// Determines the direction of the sort.");
  658. sb.AppendLine(" /// </summary>");
  659. sb.AppendLine(" public bool Ascending { get; set; }");
  660. sb.AppendLine();
  661. sb.AppendLine(" /// <summary>");
  662. sb.AppendLine(" /// Determines the field on which to sort.");
  663. sb.AppendLine(" /// </summary>");
  664. sb.AppendLine(" public " + DefaultNamespace + ".Business.Objects." + _currentTable.PascalName + ".FieldNameConstants Field { get; set; }");
  665. sb.AppendLine();
  666. sb.AppendLine(" /// <summary>");
  667. sb.AppendLine(" /// Create a sorting field object for the " + _currentTable.PascalName + "Paging object.");
  668. sb.AppendLine(" /// </summary>");
  669. sb.AppendLine(" /// <param name=\"field\">The field on which to sort.</param>");
  670. sb.AppendLine(" public " + _currentTable.PascalName + "PagingFieldItem(" + DefaultNamespace + ".Business.Objects." + _currentTable.PascalName + ".FieldNameConstants field)");
  671. sb.AppendLine(" {");
  672. sb.AppendLine(" this.Field = field;");
  673. sb.AppendLine(" }");
  674. sb.AppendLine();
  675. sb.AppendLine(" /// <summary>");
  676. sb.AppendLine(" /// Create a sorting field object for the " + _currentTable.PascalName + "Paging object.");
  677. sb.AppendLine(" /// </summary>");
  678. sb.AppendLine(" /// <param name=\"field\">The field on which to sort.</param>");
  679. sb.AppendLine(" /// <param name=\"ascending\">Determines the direction of the sort.</param>");
  680. sb.AppendLine(" public " + _currentTable.PascalName + "PagingFieldItem(" + DefaultNamespace + ".Business.Objects." + _currentTable.PascalName + ".FieldNameConstants field, bool ascending)");
  681. sb.AppendLine(" : this(field)");
  682. sb.AppendLine(" {");
  683. sb.AppendLine(" this.Ascending = ascending;");
  684. sb.AppendLine(" }");
  685. sb.AppendLine();
  686. sb.AppendLine(" #region IPagingFieldItem Members");
  687. sb.AppendLine();
  688. sb.AppendLine(" Enum IPagingFieldItem.GetField()");
  689. sb.AppendLine(" {");
  690. sb.AppendLine(" return this.Field;");
  691. sb.AppendLine(" }");
  692. sb.AppendLine();
  693. sb.AppendLine(" #endregion");
  694. sb.AppendLine();
  695. sb.AppendLine(" }");
  696. sb.AppendLine();
  697. sb.AppendLine(" /// <summary>");
  698. sb.AppendLine(" /// The paging object for the " + _currentTable.PascalName + " collection");
  699. sb.AppendLine(" /// </summary>");
  700. sb.AppendLine(" [Serializable]");
  701. sb.AppendLine(" public class " + _currentTable.PascalName + "Paging : PagingBase<" + _currentTable.PascalName + "PagingFieldItem>");
  702. //sb.AppendLine(" public class " + _currentTable.PascalName + "Paging : IPagingObject");
  703. sb.AppendLine(" {");
  704. //sb.AppendLine(" #region Class Members");
  705. //sb.AppendLine();
  706. //sb.AppendLine(" private int _pageIndex = 1;");
  707. //sb.AppendLine(" private int _recordsperPage = 10;");
  708. //sb.AppendLine(" private List<" + _currentTable.PascalName + "PagingFieldItem> _orderByList = new List<" + _currentTable.PascalName + "PagingFieldItem>(); ");
  709. //sb.AppendLine(" private int _recordCount = 0;");
  710. //sb.AppendLine();
  711. //sb.AppendLine(" #endregion");
  712. sb.AppendLine();
  713. sb.AppendLine(" #region Constructors");
  714. sb.AppendLine();
  715. sb.AppendLine(" /// <summary>");
  716. sb.AppendLine(" /// Creates a paging object");
  717. sb.AppendLine(" /// </summary>");
  718. sb.AppendLine(" public " + _currentTable.PascalName + "Paging()");
  719. sb.AppendLine(" : this(1, 10, null)");
  720. sb.AppendLine(" {");
  721. sb.AppendLine(" }");
  722. sb.AppendLine();
  723. sb.AppendLine(" /// <summary>");
  724. sb.AppendLine(" /// Creates a paging object");
  725. sb.AppendLine(" /// </summary>");
  726. sb.AppendLine(" /// <param name=\"pageIndex\">The page number to load</param>");
  727. sb.AppendLine(" /// <param name=\"recordsperPage\">The number of records per page.</param>");
  728. sb.AppendLine(" public " + _currentTable.PascalName + "Paging(int pageIndex, int recordsperPage)");
  729. sb.AppendLine(" : this(pageIndex, recordsperPage, null)");
  730. sb.AppendLine(" {");
  731. sb.AppendLine(" }");
  732. sb.AppendLine();
  733. sb.AppendLine(" /// <summary>");
  734. sb.AppendLine(" /// Creates a paging object");
  735. sb.AppendLine(" /// </summary>");
  736. sb.AppendLine(" /// <param name=\"pageIndex\">The page number to load</param>");
  737. sb.AppendLine(" /// <param name=\"recordsperPage\">The number of records per page.</param>");
  738. sb.AppendLine(" /// <param name=\"field\">The field on which to sort.</param>");
  739. sb.AppendLine(" /// <param name=\"ascending\">Determines the sorted direction.</param>");
  740. sb.AppendLine(" public " + _currentTable.PascalName + "Paging(int pageIndex, int recordsperPage, " + DefaultNamespace + ".Business.Objects." + _currentTable.PascalName + ".FieldNameConstants field, bool ascending)");
  741. sb.AppendLine(" : this(pageIndex, recordsperPage, new " + _currentTable.PascalName + "PagingFieldItem(field, ascending))");
  742. sb.AppendLine(" {");
  743. sb.AppendLine(" }");
  744. sb.AppendLine();
  745. sb.AppendLine(" /// <summary>");
  746. sb.AppendLine(" /// Creates a paging object");
  747. sb.AppendLine(" /// </summary>");
  748. sb.AppendLine(" /// <param name=\"pageIndex\">The page number to load</param>");
  749. sb.AppendLine(" /// <param name=\"recordsperPage\">The number of items per page.</param>");
  750. sb.AppendLine(" /// <param name=\"orderByField\">The field on which to sort.</param>");
  751. sb.AppendLine(" public " + _currentTable.PascalName + "Paging(int pageIndex, int recordsperPage, " + _currentTable.PascalName + "PagingFieldItem orderByField)");
  752. sb.AppendLine(" : base(pageIndex, recordsperPage, orderByField)");
  753. sb.AppendLine(" {");
  754. sb.AppendLine(" }");
  755. sb.AppendLine();
  756. sb.AppendLine(" #endregion");
  757. //sb.AppendLine();
  758. //sb.AppendLine(" #region Property Implementations");
  759. //sb.AppendLine();
  760. //sb.AppendLine(" /// <summary>");
  761. //sb.AppendLine(" /// The page number of load.");
  762. //sb.AppendLine(" /// </summary>");
  763. //sb.AppendLine(" public int PageIndex");
  764. //sb.AppendLine(" {");
  765. //sb.AppendLine(" get { return _pageIndex; }");
  766. //sb.AppendLine(" set");
  767. //sb.AppendLine(" {");
  768. //sb.AppendLine(" if (value < 1) throw new Exception(\"The PageIndex must be 1 or greater.\");");
  769. //sb.AppendLine(" _pageIndex = value;");
  770. //sb.AppendLine(" }");
  771. //sb.AppendLine(" }");
  772. //sb.AppendLine();
  773. //sb.AppendLine(" /// <summary>");
  774. //sb.AppendLine(" /// The number of items per page.");
  775. //sb.AppendLine(" /// </summary>");
  776. //sb.AppendLine(" public int RecordsperPage");
  777. //sb.AppendLine(" {");
  778. //sb.AppendLine(" get { return _recordsperPage; }");
  779. //sb.AppendLine(" set");
  780. //sb.AppendLine(" {");
  781. //sb.AppendLine(" if (value < 1) throw new Exception(\"The RecordsperPage must be 1 or greater.\");");
  782. //sb.AppendLine(" _recordsperPage = value;");
  783. //sb.AppendLine(" }");
  784. //sb.AppendLine(" }");
  785. //sb.AppendLine();
  786. //sb.AppendLine(" /// <summary>");
  787. //sb.AppendLine(" /// A list of fields on which to sort.");
  788. //sb.AppendLine(" /// </summary>");
  789. //sb.AppendLine(" public List<" + _currentTable.PascalName + "PagingFieldItem> OrderByList");
  790. //sb.AppendLine(" {");
  791. //sb.AppendLine(" get { return _orderByList; } ");
  792. //sb.AppendLine(" }");
  793. //sb.AppendLine();
  794. //sb.AppendLine(" /// <summary>");
  795. //sb.AppendLine(" /// The total number of non-paged items returned for the search.");
  796. //sb.AppendLine(" /// </summary>");
  797. //sb.AppendLine(" public int RecordCount");
  798. //sb.AppendLine(" {");
  799. //sb.AppendLine(" get { return _recordCount; }");
  800. //sb.AppendLine(" set { _recordCount = value; }");
  801. //sb.AppendLine(" }");
  802. //sb.AppendLine();
  803. //sb.AppendLine(" #endregion");
  804. //sb.AppendLine();
  805. //sb.AppendLine(" #region IPagingObject Members");
  806. //sb.AppendLine();
  807. //sb.AppendLine(" IEnumerable<IPagingFieldItem> IPagingObject.GetOrderByList()");
  808. //sb.AppendLine(" {");
  809. //sb.AppendLine(" List<IPagingFieldItem> retval = new List<IPagingFieldItem>();");
  810. //sb.AppendLine(" foreach (IPagingFieldItem item in this.OrderByList)");
  811. //sb.AppendLine(" {");
  812. //sb.AppendLine(" retval.Add(item);");
  813. //sb.AppendLine(" }");
  814. //sb.AppendLine(" return retval.AsEnumerable();");
  815. //sb.AppendLine(" }");
  816. //sb.AppendLine();
  817. //sb.AppendLine(" #endregion");
  818. sb.AppendLine();
  819. sb.AppendLine(" }");
  820. sb.AppendLine();
  821. sb.AppendLine(" #endregion");
  822. sb.AppendLine();
  823. }
  824. private IEnumerable<Column> GetValidSearchColumns()
  825. {
  826. List<Column> allColumns = _currentTable.GetColumnsFullHierarchy().Where(x => x.Generated).ToList();
  827. List<Column> validColumns = new List<Column>();
  828. foreach (Column column in allColumns.OrderBy(x => x.Name))
  829. {
  830. if (!(column.DataType == System.Data.SqlDbType.Binary ||
  831. column.DataType == System.Data.SqlDbType.Image ||
  832. column.DataType == System.Data.SqlDbType.NText ||
  833. column.DataType == System.Data.SqlDbType.Text ||
  834. column.DataType == System.Data.SqlDbType.Timestamp ||
  835. column.DataType == System.Data.SqlDbType.Udt ||
  836. column.DataType == System.Data.SqlDbType.VarBinary ||
  837. column.DataType == System.Data.SqlDbType.Variant ||
  838. column.DataType == System.Data.SqlDbType.Money))
  839. {
  840. validColumns.Add(column);
  841. }
  842. }
  843. return validColumns;
  844. }
  845. private void AppendClassEnumerator()
  846. {
  847. sb.AppendLine(" #region IEnumerator");
  848. sb.AppendLine();
  849. sb.AppendLine(" /// <summary>");
  850. sb.AppendLine(" /// An strongly-typed enumerator for the '" + _currentTable.PascalName + "' object collection");
  851. sb.AppendLine(" /// </summary>");
  852. sb.AppendLine(" public class " + _currentTable.PascalName + "Enumerator : IEnumerator ");
  853. sb.AppendLine(" {");
  854. sb.AppendLine(" private IEnumerator internalEnumerator;");
  855. sb.AppendLine(" internal " + _currentTable.PascalName + "Enumerator(IEnumerator icg)");
  856. sb.AppendLine(" {");
  857. sb.AppendLine(" internalEnumerator = icg;");
  858. sb.AppendLine(" }");
  859. sb.AppendLine();
  860. sb.AppendLine(" #region IEnumerator Members");
  861. sb.AppendLine();
  862. sb.AppendLine(" /// <summary>");
  863. sb.AppendLine(" /// Reset the enumerator to the first object in this collection");
  864. sb.AppendLine(" /// </summary>");
  865. sb.AppendLine(" public void Reset()");
  866. sb.AppendLine(" {");
  867. sb.AppendLine(" try");
  868. sb.AppendLine(" {");
  869. sb.AppendLine(" internalEnumerator.Reset();");
  870. sb.AppendLine(" }");
  871. Globals.AppendBusinessEntryCatch(sb);
  872. sb.AppendLine(" }");
  873. sb.AppendLine();
  874. sb.AppendLine(" /// <summary>");
  875. sb.AppendLine(" /// Gets the current element in the collection.");
  876. sb.AppendLine(" /// </summary>");
  877. sb.AppendLine(" /// <returns>The current element in the collection.</returns>");
  878. sb.AppendLine(" public object Current");
  879. sb.AppendLine(" {");
  880. sb.AppendLine(" get");
  881. sb.AppendLine(" {");
  882. sb.AppendLine(" try");
  883. sb.AppendLine(" {");
  884. sb.AppendLine(" return new " + _currentTable.PascalName + "((Domain" + _currentTable.PascalName + ")internalEnumerator.Current);");
  885. sb.AppendLine(" }");
  886. Globals.AppendBusinessEntryCatch(sb, true);
  887. sb.AppendLine(" }");
  888. sb.AppendLine(" }");
  889. sb.AppendLine();
  890. sb.AppendLine(" /// <summary>");
  891. sb.AppendLine(" /// Advances the enumerator to the next element of the collection.");
  892. sb.AppendLine(" /// </summary>");
  893. sb.AppendLine(" public bool MoveNext()");
  894. sb.AppendLine(" {");
  895. sb.AppendLine(" try");
  896. sb.AppendLine(" {");
  897. sb.AppendLine(" bool movedNext = internalEnumerator.MoveNext();");
  898. sb.AppendLine(" if(movedNext)");
  899. sb.AppendLine(" {");
  900. sb.AppendLine(" Domain" + _currentTable.PascalName + " currentRow = (Domain" + _currentTable.PascalName + ")internalEnumerator.Current;");
  901. sb.AppendLine(" while(currentRow.RowState == System.Data.DataRowState.Deleted || currentRow.RowState == System.Data.DataRowState.Detached)");
  902. sb.AppendLine(" {");
  903. sb.AppendLine(" movedNext = internalEnumerator.MoveNext();");
  904. sb.AppendLine(" if(!movedNext)");
  905. sb.AppendLine(" break;");
  906. sb.AppendLine(" currentRow = (Domain" + _currentTable.PascalName + ")internalEnumerator.Current;");
  907. sb.AppendLine(" }");
  908. sb.AppendLine(" }");
  909. sb.AppendLine(" return movedNext;");
  910. sb.AppendLine(" }");
  911. Globals.AppendBusinessEntryCatch(sb);
  912. sb.AppendLine(" }");
  913. sb.AppendLine();
  914. sb.AppendLine(" #endregion");
  915. sb.AppendLine();
  916. sb.AppendLine(" }");
  917. sb.AppendLine();
  918. sb.AppendLine(" #endregion");
  919. sb.AppendLine();
  920. }
  921. #endregion
  922. #region append member variables
  923. public void AppendMemberVariables()
  924. {
  925. sb.AppendLine(" #region Member Variables");
  926. sb.AppendLine();
  927. if (_currentTable.ParentTable == null)
  928. {
  929. sb.AppendLine(" internal Domain" + _currentTable.PascalName + "Collection wrappedClass;");
  930. sb.AppendLine();
  931. sb.AppendLine(" /// <summary>");
  932. sb.AppendLine(" /// The parent subdomain object");
  933. sb.AppendLine(" /// </summary>");
  934. sb.AppendLine(" protected SubDomain _subDomain = null;");
  935. }
  936. else
  937. {
  938. sb.AppendLine(" internal new Domain" + _currentTable.PascalName + "Collection wrappedClass;");
  939. }
  940. sb.AppendLine();
  941. sb.AppendLine(" #endregion");
  942. sb.AppendLine();
  943. }
  944. #endregion
  945. #region append constructors
  946. public void AppendConstructors()
  947. {
  948. sb.AppendLine(" #region Constructor / Initialize");
  949. sb.AppendLine();
  950. AppendConstructorDomainClass();
  951. AppendConstructorModifier();
  952. AppendConstructorDefault();
  953. sb.AppendLine(" #endregion");
  954. sb.AppendLine();
  955. }
  956. private void AppendConstructorDomainClass()
  957. {
  958. if (_currentTable.ParentTable == null)
  959. {
  960. sb.AppendLine(" internal " + _currentTable.PascalName + "Collection(Domain" + _currentTable.PascalName + "Collection classToWrap)");
  961. sb.AppendLine(" {");
  962. sb.AppendLine(" _subDomain = classToWrap.SubDomain;");
  963. sb.AppendLine(" wrappedClass = classToWrap;");
  964. sb.AppendLine(" }");
  965. }
  966. else
  967. {
  968. sb.AppendLine(" internal " + _currentTable.PascalName + "Collection(Domain" + _currentTable.PascalName + "Collection classToWrap):base(classToWrap)");
  969. sb.AppendLine(" {");
  970. sb.AppendLine(" wrappedClass = classToWrap;");
  971. sb.AppendLine(" base.wrappedClass = wrappedClass;");
  972. sb.AppendLine(" }");
  973. }
  974. sb.AppendLine();
  975. }
  976. private void AppendConstructorModifier()
  977. {
  978. sb.AppendLine(" /// <summary>");
  979. sb.AppendLine(" /// Constructor that enables you to specify a modifier");
  980. sb.AppendLine(" /// </summary>");
  981. sb.AppendLine(" /// <param name=\"modifier\">Used in audit operations to track changes</param>");
  982. sb.AppendLine(" public " + _currentTable.PascalName + "Collection(string modifier)");
  983. sb.AppendLine(" {");
  984. sb.AppendLine(" _subDomain = new SubDomain(modifier);");
  985. sb.AppendLine(" ResetWrappedClass((Domain" + _currentTable.PascalName + "Collection)_subDomain.GetDomainCollection(Collections." + _currentTable.PascalName + "Collection));");
  986. sb.AppendLine(" }");
  987. sb.AppendLine();
  988. }
  989. private void AppendConstructorDefault()
  990. {
  991. sb.AppendLine(" /// <summary>");
  992. sb.AppendLine(" /// The default constructor");
  993. sb.AppendLine(" /// </summary>");
  994. sb.AppendLine(" public " + _currentTable.PascalName + "Collection() ");
  995. sb.AppendLine(" {");
  996. sb.AppendLine(" _subDomain = new SubDomain(\"\");");
  997. sb.AppendLine(" ResetWrappedClass((Domain" + _currentTable.PascalName + "Collection)_subDomain.GetDomainCollection(Collections." + _currentTable.PascalName + "Collection));");
  998. sb.AppendLine(" }");
  999. sb.AppendLine();
  1000. }
  1001. #endregion
  1002. #region append properties
  1003. private void AppendProperties()
  1004. {
  1005. sb.AppendLine(" #region Property Implementations");
  1006. sb.AppendLine();
  1007. AppendPropertyWrappedClass();
  1008. AppendPropertyModifier();
  1009. AppendPropertySubDomain();
  1010. AppendPropertyCount();
  1011. AppendPropertyContainedType();
  1012. AppendPropertyCollection();
  1013. sb.AppendLine();
  1014. sb.AppendLine(" #endregion");
  1015. sb.AppendLine();
  1016. }
  1017. private void AppendPropertyWrappedClass()
  1018. {
  1019. sb.AppendLine(" /// <summary>");
  1020. sb.AppendLine(" /// Returns the internal object that this object wraps");
  1021. sb.AppendLine(" /// </summary>");
  1022. sb.AppendLine(" [System.ComponentModel.Browsable(false)]");
  1023. if (_currentTable.ParentTable == null)
  1024. sb.AppendLine(" internal virtual object WrappedClass");
  1025. else
  1026. sb.AppendLine(" internal override object WrappedClass");
  1027. sb.AppendLine(" {");
  1028. sb.AppendLine(" get { return wrappedClass ; }");
  1029. sb.AppendLine(" set { wrappedClass = (Domain" + _currentTable.PascalName + "Collection)value ; }");
  1030. sb.AppendLine(" }");
  1031. sb.AppendLine();
  1032. sb.AppendLine(" //WrappingClass Interface");
  1033. sb.AppendLine(" object IWrappingClass.WrappedClass");
  1034. sb.AppendLine(" {");
  1035. sb.AppendLine(" get { return this.WrappedClass; }");
  1036. sb.AppendLine(" set { this.WrappedClass = value; }");
  1037. sb.AppendLine(" }");
  1038. sb.AppendLine();
  1039. }
  1040. private void AppendPropertySubDomain()
  1041. {
  1042. if (_currentTable.ParentTable != null)
  1043. return;
  1044. sb.AppendLine(" /// <summary>");
  1045. sb.AppendLine(" /// A reference to the SubDomain that holds this collection");
  1046. sb.AppendLine(" /// </summary>");
  1047. sb.AppendLine(" public SubDomain SubDomain");
  1048. sb.AppendLine(" {");
  1049. sb.AppendLine(" get");
  1050. sb.AppendLine(" {");
  1051. sb.AppendLine(" try");
  1052. sb.AppendLine(" {");
  1053. sb.AppendLine(" return wrappedClass.SubDomain;");
  1054. sb.AppendLine(" }");
  1055. Globals.AppendBusinessEntryCatch(sb, true);
  1056. sb.AppendLine(" }");
  1057. sb.AppendLine(" }");
  1058. sb.AppendLine();
  1059. }

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