PageRenderTime 46ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/Last2008/Source/Widgetsphere.Generators/ProjectItemGenerators/BusinessCollection/BusinessCollectionGeneratedTemplate.cs

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

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