/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
- #region Copyright (c) 2006-2010 Widgetsphere LLC, All Rights Reserved
- //--------------------------------------------------------------------- *
- // Widgetsphere LLC *
- // Copyright (c) 2006-2010 All Rights reserved *
- // *
- // *
- //This file and its contents are protected by United States and *
- //International copyright laws. Unauthorized reproduction and/or *
- //distribution of all or any portion of the code contained herein *
- //is strictly prohibited and will result in severe civil and criminal *
- //penalties. Any violations of this copyright will be prosecuted *
- //to the fullest extent possible under law. *
- // *
- //THE SOURCE CODE CONTAINED HEREIN AND IN RELATED FILES IS PROVIDED *
- //TO THE REGISTERED DEVELOPER FOR THE PURPOSES OF EDUCATION AND *
- //TROUBLESHOOTING. UNDER NO CIRCUMSTANCES MAY ANY PORTION OF THE SOURCE *
- //CODE BE DISTRIBUTED, DISCLOSED OR OTHERWISE MADE AVAILABLE TO ANY *
- //THIRD PARTY WITHOUT THE EXPRESS WRITTEN CONSENT OF WIDGETSPHERE LLC *
- // *
- //UNDER NO CIRCUMSTANCES MAY THE SOURCE CODE BE USED IN WHOLE OR IN *
- //PART, AS THE BASIS FOR CREATING A PRODUCT THAT PROVIDES THE SAME, OR *
- //SUBSTANTIALLY THE SAME, FUNCTIONALITY AS ANY WIDGETSPHERE PRODUCT. *
- // *
- //THE REGISTERED DEVELOPER ACKNOWLEDGES THAT THIS SOURCE CODE *
- //CONTAINS VALUABLE AND PROPRIETARY TRADE SECRETS OF WIDGETSPHERE, *
- //INC. THE REGISTERED DEVELOPER AGREES TO EXPEND EVERY EFFORT TO *
- //INSURE ITS CONFIDENTIALITY. *
- // *
- //THE END USER LICENSE AGREEMENT (EULA) ACCOMPANYING THE PRODUCT *
- //PERMITS THE REGISTERED DEVELOPER TO REDISTRIBUTE THE PRODUCT IN *
- //EXECUTABLE FORM ONLY IN SUPPORT OF APPLICATIONS WRITTEN USING *
- //THE PRODUCT. IT DOES NOT PROVIDE ANY RIGHTS REGARDING THE *
- //SOURCE CODE CONTAINED HEREIN. *
- // *
- //THIS COPYRIGHT NOTICE MAY NOT BE REMOVED FROM THIS FILE. *
- //--------------------------------------------------------------------- *
- #endregion
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- using Widgetsphere.Generator.Common.Util;
- using Widgetsphere.Generator.Models;
- using Widgetsphere.Generator.ProjectItemGenerators;
- using System.Collections;
-
- namespace Widgetsphere.Generator.DAL.ProjectItemGenerators.BusinessCollection
- {
- class BusinessCollectionGeneratedTemplate : BaseClassTemplate
- {
- private StringBuilder sb = new StringBuilder();
- private Table _currentTable;
-
- public BusinessCollectionGeneratedTemplate(ModelRoot model, Table currentTable)
- {
- _model = model;
- _currentTable = currentTable;
- }
-
- #region BaseClassTemplate overrides
-
- public override string FileName
- {
- get { return string.Format("{0}Collection.Generated.cs", _currentTable.PascalName); }
- }
-
- public string ParentItemName
- {
- get { return string.Format("{0}Collection.cs", _currentTable.PascalName); }
- }
-
- public override string FileContent
- {
- get
- {
- GenerateContent();
- return sb.ToString();
- }
- }
-
- #endregion
-
- #region GenerateContent
-
- private void GenerateContent()
- {
- try
- {
- ValidationHelper.AppendCopyrightInCode(sb, _model);
- this.AppendUsingStatements();
- sb.AppendLine("namespace " + DefaultNamespace + ".Business.Objects");
- sb.AppendLine("{");
- this.AppendClass();
- this.AppendSearchClass();
- this.AppendPagingClass();
- sb.AppendLine("}");
- }
- catch (Exception ex)
- {
- throw;
- }
- }
-
- #endregion
-
- #region namespace / objects
-
- public void AppendUsingStatements()
- {
- sb.AppendLine("using System;");
- sb.AppendLine("using System.Data;");
- sb.AppendLine("using System.Xml;");
- sb.AppendLine("using System.Collections;");
- sb.AppendLine("using System.Runtime.Serialization;");
- sb.AppendLine("using System.ComponentModel;");
- sb.AppendLine("using " + DefaultNamespace + ".Business.Rules;");
- sb.AppendLine("using " + DefaultNamespace + ".Business.SelectCommands;");
- sb.AppendLine("using " + DefaultNamespace + ".Domain.Objects;");
- sb.AppendLine("using Widgetsphere.Core.DataAccess;");
- sb.AppendLine("using Widgetsphere.Core.Util;");
- sb.AppendLine("using Widgetsphere.Core.Logging;");
- sb.AppendLine("using Widgetsphere.Core.Exceptions;");
- sb.AppendLine("using " + DefaultNamespace + ".Business.LINQ;");
- sb.AppendLine("using System.IO;");
- sb.AppendLine("using System.Collections.Generic;");
- sb.AppendLine("using System.Linq.Expressions;");
- sb.AppendLine("using System.Data.Linq;");
- sb.AppendLine("using System.Linq;");
- sb.AppendLine("using System.Text;");
- sb.AppendLine("using Widgetsphere.Core.EventArgs;");
- sb.AppendLine("using System.Text.RegularExpressions;");
- sb.AppendLine();
- }
-
- private void AppendClass()
- {
-
- string baseClass = "BusinessCollectionPersistableBase";
- string baseInterface = "IPersistableBusinessCollection";
-
- if (_currentTable.Immutable)
- {
- baseClass = "BusinessCollectionBase";
- baseInterface = "IBusinessCollection";
- }
-
- if (_currentTable.ParentTable != null)
- baseClass = _currentTable.ParentTable.PascalName + "Collection";
-
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// The collection to hold '" + _currentTable.PascalName + "' entities");
- if (_currentTable.Description != "")
- sb.AppendLine(" /// " + _currentTable.Description);
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" [Serializable()]");
- sb.AppendLine(" public partial class " + _currentTable.PascalName + "Collection : " + baseClass + ", " + baseInterface + ", IDisposable, IEnumerator, IEnumerable<" + _currentTable.PascalName + ">, IWrappingClass");
- sb.AppendLine(" {");
- this.AppendMemberVariables();
- this.AppendConstructors();
- this.AppendProperties();
- this.AppendOperatorIndexer();
- this.AppendMethods();
- //this.AppendIListImplementation();
- this.AppendRegionIBusinessCollectionExplicit();
- //this.AppendRegionGetFilteredList();
- this.AppendRegionGetDatabaseFieldName();
- this.AppendClassEnumerator();
- this.AppendRegionSearch();
- this.AppendRegionCustomSelectByRules();
- this.AppendRegionSelectByDates();
- this.AppendRegionEnumerator();
- this.AppendInterfaces();
-
- sb.AppendLine(" }");
- sb.AppendLine();
- }
-
- private void AppendRegionSearch()
- {
- if (!_model.SupportLegacySearchObject)
- {
- sb.AppendLine(" #region Search Members");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Creates a search object to query this collection.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" IBusinessObjectSearch IBusinessCollection.CreateSearchObject(SearchType searchType)");
- sb.AppendLine(" {");
- sb.AppendLine(" throw new Exception(\"This functoinality is not supported because the model did not support legacy search objects.\");");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
- else
- {
- sb.AppendLine(" #region Search Members");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Creates a search object to query this collection.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" IBusinessObjectSearch IBusinessCollection.CreateSearchObject(SearchType searchType)");
- sb.AppendLine(" {");
- sb.AppendLine(" return (IBusinessObjectSearch)this.CreateSearchObject(searchType);");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Creates a search object to query this collection.");
- sb.AppendLine(" /// </summary>");
- if (_model.Database.AllowZeroTouch)
- {
- if (_currentTable.ParentTable == null)
- sb.AppendLine(" public virtual IBusinessObjectSearch CreateSearchObject(SearchType searchType)");
- else
- sb.AppendLine(" public new IBusinessObjectSearch CreateSearchObject(SearchType searchType)");
-
- sb.AppendLine(" {");
- sb.AppendLine(" return null;");
- sb.AppendLine(" }");
- }
- else
- {
- if (_currentTable.ParentTable == null)
- sb.AppendLine(" public virtual " + _currentTable.PascalName + "Search CreateSearchObject(SearchType searchType)");
- else
- sb.AppendLine(" public new " + _currentTable.PascalName + "Search CreateSearchObject(SearchType searchType)");
-
- sb.AppendLine(" {");
- sb.AppendLine(" return new " + _currentTable.PascalName + "Search(searchType);");
- sb.AppendLine(" }");
- }
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
-
- }
-
- private void AppendRegionSelectByDates()
- {
- sb.AppendLine(" #region Select By Dates");
- sb.AppendLine();
- if (_currentTable.Generated && _currentTable.AllowCreateAudit)
- {
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Select objects by their created date.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"startDate\">The inclusive date on which to start the search.</param>");
- sb.AppendLine(" /// <param name=\"endDate\">The inclusive date on which to end the search.</param>");
- sb.AppendLine(" /// <param name=\"modifier\">The identifier used for the create and modify audits.</param>");
- if (_currentTable.ParentTable == null)
- sb.AppendLine(" public static " + _currentTable.PascalName + "Collection SelectByCreatedDateRange(DateTime? startDate, DateTime? endDate, string modifier)");
- else
- sb.AppendLine(" public new static " + _currentTable.PascalName + "Collection SelectByCreatedDateRange(DateTime? startDate, DateTime? endDate, string modifier)");
- sb.AppendLine(" {");
- sb.AppendLine(" SubDomain subDomain = new SubDomain(modifier);");
- sb.AppendLine(" " + _currentTable.PascalName + "SelectByCreatedDateRange selectCommand = new " + _currentTable.PascalName + "SelectByCreatedDateRange(startDate, endDate);");
- sb.AppendLine(" subDomain.AddSelectCommand(selectCommand);");
- sb.AppendLine(" subDomain.RunSelectCommands();");
- sb.AppendLine(" return subDomain.GetCollection<" + _currentTable.PascalName + "Collection>();");
- sb.AppendLine(" }");
- sb.AppendLine();
- }
-
- if (_currentTable.Generated && _currentTable.AllowModifiedAudit)
- {
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Select objects by their modified date.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"startDate\">The inclusive date on which to start the search.</param>");
- sb.AppendLine(" /// <param name=\"endDate\">The inclusive date on which to end the search.</param>");
- sb.AppendLine(" /// <param name=\"modifier\">The identifier used for the create and modify audits.</param>");
- if (_currentTable.ParentTable == null)
- sb.AppendLine(" public static " + _currentTable.PascalName + "Collection SelectByModifiedDateRange(DateTime? startDate, DateTime? endDate, string modifier)");
- else
- sb.AppendLine(" public new static " + _currentTable.PascalName + "Collection SelectByModifiedDateRange(DateTime? startDate, DateTime? endDate, string modifier)");
- sb.AppendLine(" {");
- sb.AppendLine(" SubDomain subDomain = new SubDomain(modifier);");
- sb.AppendLine(" " + _currentTable.PascalName + "SelectByModifiedDateRange selectCommand = new " + _currentTable.PascalName + "SelectByModifiedDateRange(startDate, endDate);");
- sb.AppendLine(" subDomain.AddSelectCommand(selectCommand);");
- sb.AppendLine(" subDomain.RunSelectCommands();");
- sb.AppendLine(" return subDomain.GetCollection<" + _currentTable.PascalName + "Collection>();");
- sb.AppendLine(" }");
- sb.AppendLine();
- }
-
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
-
- private void AppendRegionCustomSelectByRules()
- {
- if (_model.Database.AllowZeroTouch) return;
-
- if (_currentTable.CustomRetrieveRules.Count == 0)
- return;
-
- sb.AppendLine(" #region CustomSelectBy CustomRules");
- sb.AppendLine();
-
- //Create a method for all custom retrieve rules
- foreach (Reference reference in _currentTable.CustomRetrieveRules)
- {
- CustomRetrieveRule rule = (CustomRetrieveRule)reference.Object;
- if (rule.Generated)
- {
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Select rows based on the '" + rule.PascalName + "' custom retrieve rule for the '" + _currentTable.DatabaseName + "' table.");
- sb.AppendLine(" /// </summary>");
- //sb.AppendLine(" /// <param name=\"modifier\">The identifier used for the create and modify audits.</param>");
- sb.Append(" public static " + _currentTable.PascalName + "Collection SelectBy" + rule.PascalName + "(");
- if (rule.UseSearchObject)
- {
- sb.Append(_currentTable.PascalName + "Search " + _currentTable.CamelName);
- if (rule.Parameters.Count > 0)
- sb.Append(", ");
- }
- foreach (Parameter parameter in rule.GeneratedParameters)
- {
- if (parameter.IsOutputParameter)
- sb.Append("out ");
- sb.Append(parameter.GetCodeType() + " " + parameter.CamelName + ", ");
- }
- sb.AppendLine("string modifier)");
-
- sb.AppendLine(" {");
- sb.AppendLine(" SubDomain subDomain = new SubDomain(modifier);");
- sb.Append(" " + _currentTable.PascalName + "CustomSelectBy" + rule.PascalName + " selectCommand = new " + _currentTable.PascalName + "CustomSelectBy" + rule.PascalName + "(");
- if (rule.UseSearchObject)
- {
- sb.Append(_currentTable.CamelName);
- if (rule.Parameters.Count > 0)
- sb.Append(", ");
- }
- foreach (Parameter parameter in rule.GeneratedParameters)
- {
- if (!parameter.IsOutputParameter)
- {
- sb.Append(parameter.CamelName + ", ");
- }
- }
- if (sb.ToString().EndsWith(", ")) sb.Remove(sb.ToString().Length - 2, 2);
- sb.AppendLine(");");
-
- sb.AppendLine(" subDomain.AddSelectCommand(selectCommand);");
- sb.AppendLine(" subDomain.RunSelectCommands();");
-
- foreach (Parameter parameter in rule.GeneratedParameters)
- {
- if (parameter.IsOutputParameter)
- {
- sb.AppendLine(" " + parameter.CamelName + " = selectCommand." + parameter.PascalName + ";");
- }
- }
-
- sb.AppendLine(" return subDomain.GetCollection<" + _currentTable.PascalName + "Collection>();");
- sb.AppendLine(" }");
- sb.AppendLine();
- }
-
- }
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
-
- private void AppendInterfaces()
- {
- sb.AppendLine(" #region IDisposable Members");
- sb.AppendLine();
- sb.AppendLine(" void IDisposable.Dispose()");
- sb.AppendLine(" {");
- sb.AppendLine();
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
-
- private void AppendRegionEnumerator()
- {
- sb.AppendLine(" #region IEnumerator Members");
- sb.AppendLine();
- sb.AppendLine(" object IEnumerator.Current");
- sb.AppendLine(" {");
- sb.AppendLine(" get { return this.GetEnumerator().Current; }");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" bool IEnumerator.MoveNext()");
- sb.AppendLine(" {");
- sb.AppendLine(" return this.GetEnumerator().MoveNext();");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" void IEnumerator.Reset()");
- sb.AppendLine(" {");
- sb.AppendLine(" this.GetEnumerator().Reset();");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
-
- sb.AppendLine(" #region IEnumerable<" + _currentTable.PascalName + "> Members");
- sb.AppendLine();
- sb.AppendLine(" IEnumerator<" + _currentTable.PascalName + "> IEnumerable<" + _currentTable.PascalName + ">.GetEnumerator()");
- sb.AppendLine(" {");
- sb.AppendLine(" List<" + _currentTable.PascalName + "> retval = new List<" + _currentTable.PascalName + ">();");
- sb.AppendLine(" foreach (" + _currentTable.PascalName + " item in this)");
- sb.AppendLine(" {");
- sb.AppendLine(" retval.Add(item);");
- sb.AppendLine(" }");
- sb.AppendLine(" return retval.GetEnumerator();");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
-
- }
-
- private void AppendRegionIBusinessCollectionExplicit()
- {
- if (!_currentTable.Immutable)
- {
- sb.AppendLine(" #region IPersistableBusinessCollection Explicit Members");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Returns an item in this collection by index.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"index\">The zero-based index of the element to get or set. </param>");
- sb.AppendLine(" /// <returns>The element at the specified index.</returns>");
- sb.AppendLine(" IPersistableBusinessObject IPersistableBusinessCollection.this[int index]");
- sb.AppendLine(" {");
- sb.AppendLine(" get { return this[index]; }");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" void IPersistableBusinessCollection.AddItem(IPersistableBusinessObject newItem)");
- sb.AppendLine(" {");
- sb.AppendLine(" this.AddItem((" + _currentTable.PascalName + ")newItem);");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" IPersistableBusinessObject IPersistableBusinessCollection.NewItem()");
- sb.AppendLine(" {");
- sb.AppendLine(" return this.NewItem();");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
-
- sb.AppendLine(" #region IBusinessCollection Explicit Members");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Returns an item in this collection by index.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"index\">The zero-based index of the element to get or set. </param>");
- sb.AppendLine(" /// <returns>The element at the specified index.</returns>");
- sb.AppendLine(" IBusinessObject IBusinessCollection.this[int index]");
- sb.AppendLine(" {");
- sb.AppendLine(" get { return this[index]; }");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" Enum IBusinessCollection.Collection");
- sb.AppendLine(" {");
- sb.AppendLine(" get { return this.Collection; }");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" Type IBusinessCollection.ContainedType");
- sb.AppendLine(" {");
- sb.AppendLine(" get { return this.ContainedType; }");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" SubDomainBase IBusinessCollection.SubDomain");
- sb.AppendLine(" {");
- sb.AppendLine(" get { return this.SubDomain; }");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" Type ITyped.GetContainedType()");
- sb.AppendLine(" {");
- sb.AppendLine(" return typeof(" + _currentTable.PascalName + ");");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
-
- private void AppendRegionGetFilteredList()
- {
- sb.AppendLine(" #region GetFilteredList");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Returns a list filtered on the specified field with the specified value.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" [Obsolete(\"Use a LINQ query for more robust functionality\")]");
- sb.AppendLine(" public BusinessObjectList<" + _currentTable.PascalName + "> GetFilteredList(" + _currentTable.PascalName + ".FieldNameConstants field, object value)");
- sb.AppendLine(" {");
- sb.AppendLine(" BusinessObjectList<" + _currentTable.PascalName + "> retval = new BusinessObjectList<" + _currentTable.PascalName + ">();");
- sb.AppendLine(" if (value == null)");
- sb.AppendLine(" return retval;");
- sb.AppendLine();
- sb.AppendLine(" string fieldName = \"\";");
- sb.AppendLine(" switch (field)");
- sb.AppendLine(" {");
- foreach (Column column in _currentTable.GeneratedColumns)
- {
- sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + column.PascalName + ": fieldName = \"" + column.DatabaseName + "\"; break;");
- }
-
- if (_currentTable.AllowCreateAudit)
- {
- sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedByColumnName) + ": fieldName = \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedByColumnName) + "\"; break;");
- sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedDateColumnName) + ": fieldName = \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedDateColumnName) + "\"; break;");
- }
-
- if (_currentTable.AllowModifiedAudit)
- {
- sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedByColumnName) + ": fieldName = \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedByColumnName) + "\"; break;");
- sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedDateColumnName) + ": fieldName = \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedDateColumnName) + "\"; break;");
- }
-
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" DataRow[] rows = null;");
- sb.AppendLine(" if (value == null)");
- sb.AppendLine(" {");
- sb.AppendLine(" rows = this.wrappedClass.Select(fieldName + \" IS NULL\");");
- sb.AppendLine(" }");
- sb.AppendLine(" else");
- sb.AppendLine(" {");
- sb.AppendLine(" string tick = \"\";");
- sb.AppendLine(" if ((this.wrappedClass.Columns[fieldName].DataType == typeof(string)) || (this.wrappedClass.Columns[fieldName].DataType == typeof(Guid)))");
- sb.AppendLine(" tick = \"'\";");
- sb.AppendLine();
- sb.AppendLine(" rows = this.wrappedClass.Select(fieldName + \" = \" + tick + value.ToString().Replace(\"'\", \"''\") + tick);");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" foreach (DataRow dr in rows)");
- sb.AppendLine(" retval.Add(new " + _currentTable.PascalName + "((Domain" + _currentTable.PascalName + ")dr));");
- sb.AppendLine();
- sb.AppendLine(" return retval;");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
-
- private void AppendRegionGetDatabaseFieldName()
- {
- sb.AppendLine(" #region GetDatabaseFieldName");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Returns the actual database name of the specified field.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" internal static string GetDatabaseFieldName(" + _currentTable.PascalName + ".FieldNameConstants field)");
- sb.AppendLine(" {");
- sb.AppendLine(" return GetDatabaseFieldName(field.ToString());");
- //sb.AppendLine(" switch (field)");
- //sb.AppendLine(" {");
- //foreach (Column column in _currentTable.GeneratedColumns)
- //{
- // if (column.Generated)
- // sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + column.PascalName + ": return \"" + column.Name + "\";");
- //}
-
- //if (_currentTable.AllowCreateAudit)
- //{
- // sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedByColumnName) + ": return \"" + _model.Database.CreatedByColumnName + "\";");
- // sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedDateColumnName) + ": return \"" + _model.Database.CreatedDateColumnName + "\";");
- //}
-
- //if (_currentTable.AllowModifiedAudit)
- //{
- // sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedByColumnName) + ": return \"" + _model.Database.ModifiedByColumnName + "\";");
- // sb.AppendLine(" case " + _currentTable.PascalName + ".FieldNameConstants." + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedDateColumnName) + ": return \"" + _model.Database.ModifiedDateColumnName + "\";");
- //}
-
- //sb.AppendLine(" }");
- //sb.AppendLine(" return \"\";");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Returns the actual database name of the specified field.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" internal " + (_currentTable.ParentTable == null ? "" : "new ") + "static string GetDatabaseFieldName(string field)");
- sb.AppendLine(" {");
- sb.AppendLine(" switch (field)");
- sb.AppendLine(" {");
- foreach (Column column in _currentTable.GeneratedColumns)
- {
- if (column.Generated)
- sb.AppendLine(" case \"" + column.PascalName + "\": return \"" + column.Name + "\";");
- }
-
- if (_currentTable.AllowCreateAudit)
- {
- sb.AppendLine(" case \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedByColumnName) + "\": return \"" + _model.Database.CreatedByColumnName + "\";");
- sb.AppendLine(" case \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.CreatedDateColumnName) + "\": return \"" + _model.Database.CreatedDateColumnName + "\";");
- }
-
- if (_currentTable.AllowModifiedAudit)
- {
- sb.AppendLine(" case \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedByColumnName) + "\": return \"" + _model.Database.ModifiedByColumnName + "\";");
- sb.AppendLine(" case \"" + StringHelper.DatabaseNameToPascalCase(_model.Database.ModifiedDateColumnName) + "\": return \"" + _model.Database.ModifiedDateColumnName + "\";");
- }
-
- sb.AppendLine(" }");
- sb.AppendLine(" return \"\";");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
-
- private void AppendSearchClass()
- {
- if (_model.Database.AllowZeroTouch) return;
- if (!_model.SupportLegacySearchObject) return;
-
- IEnumerable<Column> validColumns = GetValidSearchColumns();
- if (validColumns.Count() != 0)
- {
- sb.AppendLine(" #region " + _currentTable.PascalName + "Search");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// The search object for the " + _currentTable.PascalName + "Collection.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" [Serializable]");
- sb.AppendLine(" public class " + _currentTable.PascalName + "Search : IBusinessObjectSearch");
- sb.AppendLine(" {");
- sb.AppendLine();
- sb.AppendLine(" private int _maxRowCount = 0;");
- //foreach (Column column in validColumns.OrderBy(x => x.Name))
- //{
- // sb.AppendLine(" private " + column.GetCodeType(true, true) + " _" + column.CamelName + ";");
- //}
- sb.AppendLine(" private SearchType _searchType;");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Determines the maximum number of rows that are returned. Use 0 for no limit.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public int MaxRowCount");
- sb.AppendLine(" {");
- sb.AppendLine(" get { return _maxRowCount; }");
- sb.AppendLine(" set { _maxRowCount = value; }");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Determines the maximum number of rows that are returned. Use 0 for no limit.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" int IBusinessObjectSearch.MaxRowCount");
- sb.AppendLine(" {");
- sb.AppendLine(" get { return this.MaxRowCount; }");
- sb.AppendLine(" set { this.MaxRowCount = value; }");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Determines the type of search to be performed.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public SearchType SearchType");
- sb.AppendLine(" {");
- sb.AppendLine(" get { return _searchType; }");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// A search object for the '" + _currentTable.PascalName + "' collection.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public " + _currentTable.PascalName + "Search(SearchType searchType) ");
- sb.AppendLine(" {");
- sb.AppendLine(" _searchType = searchType;");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" void IBusinessObjectSearch.SetValue(Enum field, object value)");
- sb.AppendLine(" {");
- sb.AppendLine(" this.SetValue((" + _currentTable.PascalName + ".FieldNameConstants)field, value);");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Set the specified value on this object.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public void SetValue(" + _currentTable.PascalName + ".FieldNameConstants field, object value)");
- sb.AppendLine(" {");
- foreach (Column column in validColumns.OrderBy(x => x.Name))
- {
- sb.AppendLine(" if (field == " + _currentTable.PascalName + ".FieldNameConstants." + column.PascalName + ") this." + column.PascalName + " = (" + column.GetCodeType(false) + ")value;");
- }
- sb.AppendLine(" }");
- sb.AppendLine();
- foreach (Column column in validColumns.OrderBy(x => x.Name))
- {
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// This field determines the value of the '" + column.PascalName + "' field on the '" + _currentTable.PascalName + "' object when this search object is applied.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public " + column.GetCodeType(true, true) + " " + column.PascalName + " { get; set; }");
- sb.AppendLine();
- }
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #endregion ");
- sb.AppendLine();
- }
- }
-
- private void AppendPagingClass()
- {
- sb.AppendLine(" #region " + _currentTable.PascalName + "Paging");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// A field sort object for the " + _currentTable.PascalName + "Paging object.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" [Serializable]");
- sb.AppendLine(" public class " + _currentTable.PascalName + "PagingFieldItem : IPagingFieldItem");
- sb.AppendLine(" {");
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Determines the direction of the sort.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public bool Ascending { get; set; }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Determines the field on which to sort.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public " + DefaultNamespace + ".Business.Objects." + _currentTable.PascalName + ".FieldNameConstants Field { get; set; }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Create a sorting field object for the " + _currentTable.PascalName + "Paging object.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"field\">The field on which to sort.</param>");
- sb.AppendLine(" public " + _currentTable.PascalName + "PagingFieldItem(" + DefaultNamespace + ".Business.Objects." + _currentTable.PascalName + ".FieldNameConstants field)");
- sb.AppendLine(" {");
- sb.AppendLine(" this.Field = field;");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Create a sorting field object for the " + _currentTable.PascalName + "Paging object.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"field\">The field on which to sort.</param>");
- sb.AppendLine(" /// <param name=\"ascending\">Determines the direction of the sort.</param>");
- sb.AppendLine(" public " + _currentTable.PascalName + "PagingFieldItem(" + DefaultNamespace + ".Business.Objects." + _currentTable.PascalName + ".FieldNameConstants field, bool ascending)");
- sb.AppendLine(" : this(field)");
- sb.AppendLine(" {");
- sb.AppendLine(" this.Ascending = ascending;");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #region IPagingFieldItem Members");
- sb.AppendLine();
- sb.AppendLine(" Enum IPagingFieldItem.GetField()");
- sb.AppendLine(" {");
- sb.AppendLine(" return this.Field;");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// The paging object for the " + _currentTable.PascalName + " collection");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" [Serializable]");
- sb.AppendLine(" public class " + _currentTable.PascalName + "Paging : PagingBase<" + _currentTable.PascalName + "PagingFieldItem>");
- //sb.AppendLine(" public class " + _currentTable.PascalName + "Paging : IPagingObject");
- sb.AppendLine(" {");
- //sb.AppendLine(" #region Class Members");
- //sb.AppendLine();
- //sb.AppendLine(" private int _pageIndex = 1;");
- //sb.AppendLine(" private int _recordsperPage = 10;");
- //sb.AppendLine(" private List<" + _currentTable.PascalName + "PagingFieldItem> _orderByList = new List<" + _currentTable.PascalName + "PagingFieldItem>(); ");
- //sb.AppendLine(" private int _recordCount = 0;");
- //sb.AppendLine();
- //sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" #region Constructors");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Creates a paging object");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public " + _currentTable.PascalName + "Paging()");
- sb.AppendLine(" : this(1, 10, null)");
- sb.AppendLine(" {");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Creates a paging object");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"pageIndex\">The page number to load</param>");
- sb.AppendLine(" /// <param name=\"recordsperPage\">The number of records per page.</param>");
- sb.AppendLine(" public " + _currentTable.PascalName + "Paging(int pageIndex, int recordsperPage)");
- sb.AppendLine(" : this(pageIndex, recordsperPage, null)");
- sb.AppendLine(" {");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Creates a paging object");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"pageIndex\">The page number to load</param>");
- sb.AppendLine(" /// <param name=\"recordsperPage\">The number of records per page.</param>");
- sb.AppendLine(" /// <param name=\"field\">The field on which to sort.</param>");
- sb.AppendLine(" /// <param name=\"ascending\">Determines the sorted direction.</param>");
- sb.AppendLine(" public " + _currentTable.PascalName + "Paging(int pageIndex, int recordsperPage, " + DefaultNamespace + ".Business.Objects." + _currentTable.PascalName + ".FieldNameConstants field, bool ascending)");
- sb.AppendLine(" : this(pageIndex, recordsperPage, new " + _currentTable.PascalName + "PagingFieldItem(field, ascending))");
- sb.AppendLine(" {");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Creates a paging object");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"pageIndex\">The page number to load</param>");
- sb.AppendLine(" /// <param name=\"recordsperPage\">The number of items per page.</param>");
- sb.AppendLine(" /// <param name=\"orderByField\">The field on which to sort.</param>");
- sb.AppendLine(" public " + _currentTable.PascalName + "Paging(int pageIndex, int recordsperPage, " + _currentTable.PascalName + "PagingFieldItem orderByField)");
- sb.AppendLine(" : base(pageIndex, recordsperPage, orderByField)");
- sb.AppendLine(" {");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- //sb.AppendLine();
- //sb.AppendLine(" #region Property Implementations");
- //sb.AppendLine();
- //sb.AppendLine(" /// <summary>");
- //sb.AppendLine(" /// The page number of load.");
- //sb.AppendLine(" /// </summary>");
- //sb.AppendLine(" public int PageIndex");
- //sb.AppendLine(" {");
- //sb.AppendLine(" get { return _pageIndex; }");
- //sb.AppendLine(" set");
- //sb.AppendLine(" {");
- //sb.AppendLine(" if (value < 1) throw new Exception(\"The PageIndex must be 1 or greater.\");");
- //sb.AppendLine(" _pageIndex = value;");
- //sb.AppendLine(" }");
- //sb.AppendLine(" }");
- //sb.AppendLine();
- //sb.AppendLine(" /// <summary>");
- //sb.AppendLine(" /// The number of items per page.");
- //sb.AppendLine(" /// </summary>");
- //sb.AppendLine(" public int RecordsperPage");
- //sb.AppendLine(" {");
- //sb.AppendLine(" get { return _recordsperPage; }");
- //sb.AppendLine(" set");
- //sb.AppendLine(" {");
- //sb.AppendLine(" if (value < 1) throw new Exception(\"The RecordsperPage must be 1 or greater.\");");
- //sb.AppendLine(" _recordsperPage = value;");
- //sb.AppendLine(" }");
- //sb.AppendLine(" }");
- //sb.AppendLine();
- //sb.AppendLine(" /// <summary>");
- //sb.AppendLine(" /// A list of fields on which to sort.");
- //sb.AppendLine(" /// </summary>");
- //sb.AppendLine(" public List<" + _currentTable.PascalName + "PagingFieldItem> OrderByList");
- //sb.AppendLine(" {");
- //sb.AppendLine(" get { return _orderByList; } ");
- //sb.AppendLine(" }");
- //sb.AppendLine();
- //sb.AppendLine(" /// <summary>");
- //sb.AppendLine(" /// The total number of non-paged items returned for the search.");
- //sb.AppendLine(" /// </summary>");
- //sb.AppendLine(" public int RecordCount");
- //sb.AppendLine(" {");
- //sb.AppendLine(" get { return _recordCount; }");
- //sb.AppendLine(" set { _recordCount = value; }");
- //sb.AppendLine(" }");
- //sb.AppendLine();
- //sb.AppendLine(" #endregion");
- //sb.AppendLine();
- //sb.AppendLine(" #region IPagingObject Members");
- //sb.AppendLine();
- //sb.AppendLine(" IEnumerable<IPagingFieldItem> IPagingObject.GetOrderByList()");
- //sb.AppendLine(" {");
- //sb.AppendLine(" List<IPagingFieldItem> retval = new List<IPagingFieldItem>();");
- //sb.AppendLine(" foreach (IPagingFieldItem item in this.OrderByList)");
- //sb.AppendLine(" {");
- //sb.AppendLine(" retval.Add(item);");
- //sb.AppendLine(" }");
- //sb.AppendLine(" return retval.AsEnumerable();");
- //sb.AppendLine(" }");
- //sb.AppendLine();
- //sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
-
- private IEnumerable<Column> GetValidSearchColumns()
- {
- List<Column> allColumns = _currentTable.GetColumnsFullHierarchy().Where(x => x.Generated).ToList();
- List<Column> validColumns = new List<Column>();
- foreach (Column column in allColumns.OrderBy(x => x.Name))
- {
- if (!(column.DataType == System.Data.SqlDbType.Binary ||
- column.DataType == System.Data.SqlDbType.Image ||
- column.DataType == System.Data.SqlDbType.NText ||
- column.DataType == System.Data.SqlDbType.Text ||
- column.DataType == System.Data.SqlDbType.Timestamp ||
- column.DataType == System.Data.SqlDbType.Udt ||
- column.DataType == System.Data.SqlDbType.VarBinary ||
- column.DataType == System.Data.SqlDbType.Variant ||
- column.DataType == System.Data.SqlDbType.Money))
- {
- validColumns.Add(column);
- }
- }
- return validColumns;
- }
-
- private void AppendClassEnumerator()
- {
- sb.AppendLine(" #region IEnumerator");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// An strongly-typed enumerator for the '" + _currentTable.PascalName + "' object collection");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public class " + _currentTable.PascalName + "Enumerator : IEnumerator ");
- sb.AppendLine(" {");
- sb.AppendLine(" private IEnumerator internalEnumerator;");
- sb.AppendLine(" internal " + _currentTable.PascalName + "Enumerator(IEnumerator icg)");
- sb.AppendLine(" {");
- sb.AppendLine(" internalEnumerator = icg;");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #region IEnumerator Members");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Reset the enumerator to the first object in this collection");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public void Reset()");
- sb.AppendLine(" {");
- sb.AppendLine(" try");
- sb.AppendLine(" {");
- sb.AppendLine(" internalEnumerator.Reset();");
- sb.AppendLine(" }");
- Globals.AppendBusinessEntryCatch(sb);
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Gets the current element in the collection.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <returns>The current element in the collection.</returns>");
- sb.AppendLine(" public object Current");
- sb.AppendLine(" {");
- sb.AppendLine(" get");
- sb.AppendLine(" {");
- sb.AppendLine(" try");
- sb.AppendLine(" {");
- sb.AppendLine(" return new " + _currentTable.PascalName + "((Domain" + _currentTable.PascalName + ")internalEnumerator.Current);");
- sb.AppendLine(" }");
- Globals.AppendBusinessEntryCatch(sb, true);
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Advances the enumerator to the next element of the collection.");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public bool MoveNext()");
- sb.AppendLine(" {");
- sb.AppendLine(" try");
- sb.AppendLine(" {");
- sb.AppendLine(" bool movedNext = internalEnumerator.MoveNext();");
- sb.AppendLine(" if(movedNext)");
- sb.AppendLine(" {");
- sb.AppendLine(" Domain" + _currentTable.PascalName + " currentRow = (Domain" + _currentTable.PascalName + ")internalEnumerator.Current;");
- sb.AppendLine(" while(currentRow.RowState == System.Data.DataRowState.Deleted || currentRow.RowState == System.Data.DataRowState.Detached)");
- sb.AppendLine(" {");
- sb.AppendLine(" movedNext = internalEnumerator.MoveNext();");
- sb.AppendLine(" if(!movedNext)");
- sb.AppendLine(" break;");
- sb.AppendLine(" currentRow = (Domain" + _currentTable.PascalName + ")internalEnumerator.Current;");
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- sb.AppendLine(" return movedNext;");
- sb.AppendLine(" }");
- Globals.AppendBusinessEntryCatch(sb);
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
-
- #endregion
-
- #region append member variables
-
- public void AppendMemberVariables()
- {
- sb.AppendLine(" #region Member Variables");
- sb.AppendLine();
-
- if (_currentTable.ParentTable == null)
- {
- sb.AppendLine(" internal Domain" + _currentTable.PascalName + "Collection wrappedClass;");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// The parent subdomain object");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" protected SubDomain _subDomain = null;");
- }
- else
- {
- sb.AppendLine(" internal new Domain" + _currentTable.PascalName + "Collection wrappedClass;");
- }
-
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
- #endregion
-
- #region append constructors
-
- public void AppendConstructors()
- {
- sb.AppendLine(" #region Constructor / Initialize");
- sb.AppendLine();
- AppendConstructorDomainClass();
- AppendConstructorModifier();
- AppendConstructorDefault();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
-
- private void AppendConstructorDomainClass()
- {
- if (_currentTable.ParentTable == null)
- {
- sb.AppendLine(" internal " + _currentTable.PascalName + "Collection(Domain" + _currentTable.PascalName + "Collection classToWrap)");
- sb.AppendLine(" {");
- sb.AppendLine(" _subDomain = classToWrap.SubDomain;");
- sb.AppendLine(" wrappedClass = classToWrap;");
- sb.AppendLine(" }");
- }
- else
- {
- sb.AppendLine(" internal " + _currentTable.PascalName + "Collection(Domain" + _currentTable.PascalName + "Collection classToWrap):base(classToWrap)");
- sb.AppendLine(" {");
- sb.AppendLine(" wrappedClass = classToWrap;");
- sb.AppendLine(" base.wrappedClass = wrappedClass;");
- sb.AppendLine(" }");
- }
-
- sb.AppendLine();
- }
-
- private void AppendConstructorModifier()
- {
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Constructor that enables you to specify a modifier");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"modifier\">Used in audit operations to track changes</param>");
- sb.AppendLine(" public " + _currentTable.PascalName + "Collection(string modifier)");
- sb.AppendLine(" {");
- sb.AppendLine(" _subDomain = new SubDomain(modifier);");
- sb.AppendLine(" ResetWrappedClass((Domain" + _currentTable.PascalName + "Collection)_subDomain.GetDomainCollection(Collections." + _currentTable.PascalName + "Collection));");
- sb.AppendLine(" }");
- sb.AppendLine();
- }
-
- private void AppendConstructorDefault()
- {
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// The default constructor");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public " + _currentTable.PascalName + "Collection() ");
- sb.AppendLine(" {");
- sb.AppendLine(" _subDomain = new SubDomain(\"\");");
- sb.AppendLine(" ResetWrappedClass((Domain" + _currentTable.PascalName + "Collection)_subDomain.GetDomainCollection(Collections." + _currentTable.PascalName + "Collection));");
- sb.AppendLine(" }");
- sb.AppendLine();
- }
-
- #endregion
-
- #region append properties
-
- private void AppendProperties()
- {
- sb.AppendLine(" #region Property Implementations");
- sb.AppendLine();
- AppendPropertyWrappedClass();
- AppendPropertyModifier();
- AppendPropertySubDomain();
- AppendPropertyCount();
- AppendPropertyContainedType();
- AppendPropertyCollection();
- sb.AppendLine();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
-
- private void AppendPropertyWrappedClass()
- {
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Returns the internal object that this object wraps");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" [System.ComponentModel.Browsable(false)]");
-
- if (_currentTable.ParentTable == null)
- sb.AppendLine(" internal virtual object WrappedClass");
- else
- sb.AppendLine(" internal override object WrappedClass");
-
- sb.AppendLine(" {");
- sb.AppendLine(" get { return wrappedClass ; }");
- sb.AppendLine(" set { wrappedClass = (Domain" + _currentTable.PascalName + "Collection)value ; }");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" //WrappingClass Interface");
- sb.AppendLine(" object IWrappingClass.WrappedClass");
- sb.AppendLine(" {");
- sb.AppendLine(" get { return this.WrappedClass; }");
- sb.AppendLine(" set { this.WrappedClass = value; }");
- sb.AppendLine(" }");
- sb.AppendLine();
- }
-
- private void AppendPropertySubDomain()
- {
- if (_currentTable.ParentTable != null)
- return;
-
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// A reference to the SubDomain that holds this collection");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public SubDomain SubDomain");
- sb.AppendLine(" {");
- sb.AppendLine(" get");
- sb.AppendLine(" {");
- sb.AppendLine(" try");
- sb.AppendLine(" {");
- sb.AppendLine(" return wrappedClass.SubDomain;");
- sb.AppendLine(" }");
- Globals.AppendBusinessEntryCatch(sb, true);
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- sb.AppendLine();
- }
-
- private void AppendPropertyModifier()
- {
- if (_currentTable.ParentTable != null)
- return;
-
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Specifies a modifier string to be used in the audit functionality");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public string Modifier");
- sb.AppendLine(" {");
- sb.AppendLine(" get");
- sb.AppendLine(" {");
- sb.AppendLine(" try");
- sb.AppendLine(" {");
- sb.AppendLine(" return wrappedClass.Modifier;");
- sb.AppendLine(" }");
- Globals.AppendBusinessEntryCatch(sb, true);
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- sb.AppendLine();
- }
-
- private void AppendPropertyCount()
- {
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Returns the number of items in this collection");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" public override int Count");
- sb.AppendLine(" {");
- sb.AppendLine(" get");
- sb.AppendLine(" {");
- sb.AppendLine(" try");
- sb.AppendLine(" {");
- sb.AppendLine(" lock (wrappedClass.SubDomain)");
- sb.AppendLine(" {");
- sb.AppendLine(" DataTable dt = wrappedClass.GetChanges(DataRowState.Deleted);");
- sb.AppendLine(" if (dt == null) return wrappedClass.Count;");
- sb.AppendLine(" else return wrappedClass.Count - dt.Rows.Count;");
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- Globals.AppendBusinessEntryCatch(sb, true);
- sb.AppendLine(" }");
- sb.AppendLine(" }");
- sb.AppendLine();
- }
-
- private void AppendPropertyContainedType()
- {
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Determines the type of object contained by this collection.");
- sb.AppendLine(" /// </summary>");
- if (_currentTable.ParentTable == null)
- sb.AppendLine(" public virtual Type ContainedType");
- else
- sb.AppendLine(" public override Type ContainedType");
-
- sb.AppendLine(" {");
- sb.AppendLine(" get { return typeof(" + _currentTable.PascalName + "); }");
- sb.AppendLine(" }");
- sb.AppendLine();
- }
-
- private void AppendPropertyCollection()
- {
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Determines the type of collection for this object.");
- sb.AppendLine(" /// </summary>");
- if (_currentTable.ParentTable == null)
- sb.AppendLine(" public virtual Collections Collection");
- else
- sb.AppendLine(" public override Collections Collection");
-
- sb.AppendLine(" {");
- sb.AppendFormat(" get {{ return Collections.{0}Collection; }}", _currentTable.PascalName).AppendLine();
- sb.AppendLine(" }");
- }
-
- #endregion
-
- #region append methods
- public void AppendMethods()
- {
- sb.AppendLine(" #region Methods");
- sb.AppendLine();
- this.AppendMethodNewItems();
- this.AppendMethodAddNewItem();
- this.AppendMethodVisitor();
- this.AppendStaticSQLMethods();
- this.AppendMethodPersist();
- this.AppendMethodSelectAll();
- this.AppendMethodSelectSearch();
- this.AppendAggregateMethods();
- this.AppendUpdateDataScaler();
- this.AppendDeleteDataScaler();
- this.AppendMethodSelectPaged();
- this.AppendMethodOther();
- this.AppendMethodRetieveByPrimaryKey();
- this.AppendMethodRetieveBySearchableFields();
- this.AppendMethodGet();
- this.AppendMethodGetEnumerator();
- this.AppendRejectChanges();
- this.AppendResetWrappedClass();
- sb.AppendLine(" #endregion");
- sb.AppendLine();
- }
-
- private void AppendUpdateDataScaler()
- {
- //All types that are valid for these operations
- List<string> typeList = new List<string>();
- typeList.Add("int");
- typeList.Add("Single");
- typeList.Add("decimal");
- typeList.Add("double");
- typeList.Add("string");
- typeList.Add("DateTime");
- typeList.Add("bool");
- typeList.Add("Guid");
-
- List<Table> tableList = _currentTable.GetTableHierarchy();
- tableList.Remove(_currentTable);
- Dictionary<string, Column> columnList = new Dictionary<string, Column>();
-
- //Need the columns in order from base UP
- foreach (Table t in tableList.OrderBy(x => x.Name))
- {
- foreach (Column c in t.GetColumns().Where(x => x.Generated))
- {
- if (!columnList.ContainsKey(c.DatabaseName.ToLower()))
- columnList.Add(c.DatabaseName.ToLower(), c);
- }
- }
-
- //Add primary Keys
- foreach (Column c in _currentTable.PrimaryKeyColumns.OrderBy(x => x.Name))
- {
- if (columnList.ContainsKey(c.DatabaseName.ToLower()))
- columnList.Remove(c.DatabaseName.ToLower());
- }
-
- foreach (string typeName in typeList)
- {
- string nullTypeName = typeName + (typeName == "string" ? "" : "?");
-
- //The NON-nullable call
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Update the specified field that matches the Where expression with the new data value");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"select\">The field to update</param>");
- sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
- sb.AppendLine(" /// <param name=\"newValue\">The new value to set the specified field in all matching records</param>");
- sb.AppendLine(" /// <returns>The number of records affected</returns>");
- sb.AppendLine(" public static int UpdateData(Expression<Func<" + _currentTable.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentTable.PascalName + "Query, bool>> where, " + typeName + " newValue)");
- sb.AppendLine(" {");
- sb.AppendLine(" return BusinessObjectQuery<" + _currentTable.PascalName + ", " + _currentTable.PascalName + "Query, " + typeName + ">.UpdateData(select, where, newValue, \"" + _currentTable.DatabaseName + "\", GetDatabaseFieldName, " + _currentTable.AllowModifiedAudit.ToString().ToLower() + ");");
- sb.AppendLine(" }");
- sb.AppendLine();
-
- //The Nullable call
- if (nullTypeName != typeName)
- {
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Update the specified field that matches the Where expression with the new data value");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"select\">The field to update</param>");
- sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
- sb.AppendLine(" /// <param name=\"newValue\">The new value to set the specified field in all matching records</param>");
- sb.AppendLine(" /// <returns>The number of records affected</returns>");
- sb.AppendLine(" public static int UpdateData(Expression<Func<" + _currentTable.PascalName + "Query, " + nullTypeName + ">> select, Expression<Func<" + _currentTable.PascalName + "Query, bool>> where, " + nullTypeName + " newValue)");
- sb.AppendLine(" {");
- sb.AppendLine(" return BusinessObjectQuery<" + _currentTable.PascalName + ", " + _currentTable.PascalName + "Query, " + nullTypeName + ">.UpdateData(select, where, newValue, \"" + _currentTable.DatabaseName + "\", GetDatabaseFieldName, " + _currentTable.AllowModifiedAudit.ToString().ToLower() + ");");
- sb.AppendLine(" }");
- sb.AppendLine();
- }
- }
-
- }
-
- private void AppendAggregateMethods()
- {
- string scope = "";
-
- List<Table> tableList = _currentTable.GetTableHierarchy();
- tableList.Remove(_currentTable);
- Dictionary<string, Column> columnList = new Dictionary<string, Column>();
-
- //Need the colums in order from base UP
- foreach (Table t in tableList)
- {
- foreach (Column c in t.GetColumns().Where(x => x.Generated))
- {
- if (!columnList.ContainsKey(c.DatabaseName.ToLower()))
- columnList.Add(c.DatabaseName.ToLower(), c);
- }
- }
-
- //Add primary Keys
- foreach (Column c in _currentTable.PrimaryKeyColumns.OrderBy(x => x.Name))
- {
- if (columnList.ContainsKey(c.DatabaseName.ToLower()))
- columnList.Remove(c.DatabaseName.ToLower());
- }
-
- //All types that are valid for these operations
- List<string> typeList = new List<string>();
- typeList.Add("int");
- typeList.Add("Single");
- typeList.Add("double");
- typeList.Add("decimal");
- typeList.Add("string");
- typeList.Add("DateTime");
-
- //Max
- this.AppendAggregateMax(scope, tableList, columnList, typeList);
-
- //Min
- this.AppendAggregateMin(scope, tableList, columnList, typeList);
-
- typeList = new List<string>();
- typeList.Add("int");
- typeList.Add("Single");
- typeList.Add("double");
- typeList.Add("decimal");
-
- //Average
- this.AppendAggregateAverage(scope, tableList, columnList, typeList);
-
- //Sum
- this.AppendAggregateSum(scope, tableList, columnList, typeList);
-
- typeList = new List<string>();
- typeList.Add("int");
- typeList.Add("Single");
- typeList.Add("double");
- typeList.Add("decimal");
- typeList.Add("string");
- typeList.Add("DateTime");
- typeList.Add("Guid");
-
- //Count
- this.AppendAggregateCount(scope, tableList, columnList);
-
- //Distinct
- this.AppendAggregateDistinct(scope, tableList, columnList, typeList);
-
- }
-
- private void AppendAggregateSum(string scope, List<Table> tableList, Dictionary<string, Column> columnList, List<string> typeList)
- {
- foreach (string typeName in typeList)
- {
- AppendAggregateSumBody(scope, columnList, typeName);
- if (typeName != "string")
- AppendAggregateSumBody(scope, columnList, typeName + "?");
- }
- }
-
- private void AppendAggregateSumBody(string scope, Dictionary<string, Column> columnList, string typeName)
- {
- string returnType = "double";
- //if (typeName.StartsWith("decimal")) returnType = "decimal";
-
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Get the summary value of the field for all objects");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
- sb.AppendLine(" public static " + scope + returnType + "? GetSum(Expression<Func<" + _currentTable.PascalName + "Query, " + typeName + ">> select)");
- sb.AppendLine(" {");
- sb.AppendLine(" return GetSum(select, x => true);");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Get the summary value of the field for all objects");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
- sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
- sb.AppendLine(" public static " + scope + returnType + "? GetSum(Expression<Func<" + _currentTable.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentTable.PascalName + "Query, bool>> where)");
- sb.AppendLine(" {");
- sb.AppendLine(" return GetSum(select, where, new QueryOptimizer());");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Get the summary value of the field in the set of records that match the Where condition");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
- sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
- sb.AppendLine(" /// <param name=\"optimizer\">The optimization object to use for running queries</param>");
- sb.AppendLine(" public static " + scope + returnType + "? GetSum(Expression<Func<" + _currentTable.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentTable.PascalName + "Query, bool>> where, QueryOptimizer optimizer)");
- sb.AppendLine(" {");
- sb.AppendLine(" return BusinessObjectQuery<" + _currentTable.PascalName + ", " + _currentTable.PascalName + "Query, " + typeName + ">.GetSum(select, where, optimizer, \"" + _currentTable.DatabaseName + "\", GetDatabaseFieldName, LinqSQLParser.ObjectTypeConstants.Table);");
- sb.AppendLine(" }");
- sb.AppendLine();
- }
-
- private void AppendAggregateAverage(string scope, List<Table> tableList, Dictionary<string, Column> columnList, List<string> typeList)
- {
- foreach (string typeName in typeList)
- {
- AppendAggregateAverageBody(scope, columnList, typeName);
- if (typeName != "string")
- AppendAggregateAverageBody(scope, columnList, typeName + "?");
- }
- }
-
- private void AppendAggregateAverageBody(string scope, Dictionary<string, Column> columnList, string typeName)
- {
- string returnType = "double";
- if (typeName.StartsWith("decimal")) returnType = "decimal";
-
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Get the average value of the field for all objects");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
- sb.AppendLine(" public static " + scope + returnType + "? GetAverage(Expression<Func<" + _currentTable.PascalName + "Query, " + typeName + ">> select)");
- sb.AppendLine(" {");
- sb.AppendLine(" return GetAverage(select, x => true);");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Get the average value of the field in the set of records that match the Where condition");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
- sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
- sb.AppendLine(" public static " + scope + returnType + "? GetAverage(Expression<Func<" + _currentTable.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentTable.PascalName + "Query, bool>> where)");
- sb.AppendLine(" {");
- sb.AppendLine(" return GetAverage(select, where, new QueryOptimizer());");
- sb.AppendLine(" }");
- sb.AppendLine();
- sb.AppendLine(" /// <summary>");
- sb.AppendLine(" /// Get the average value of the field in the set of records that match the Where condition");
- sb.AppendLine(" /// </summary>");
- sb.AppendLine(" /// <param name=\"select\">The field to aggregate</param>");
- sb.AppendLine(" /// <param name=\"where\">The expression that determines the records selected</param>");
- sb.AppendLine(" /// <param name=\"optimizer\">The optimization object to use for running queries</param>");
- sb.AppendLine(" public static " + scope + returnType + "? GetAverage(Expression<Func<" + _currentTable.PascalName + "Query, " + typeName + ">> select, Expression<Func<" + _currentTable.PascalName + "Query, bool>> where, QueryOptimizer optimizer)");
- sb.AppendLine(" {");
- sb.AppendLine(" return BusinessObjectQuery<" + _currentTable.PascalName + ", " + _currentTable.PascalName + "Query, " + typeName + ">.GetAverage(select, where, optimizer, \"" + _currentTable.DatabaseName + "\", GetDatabaseFieldName, LinqSQLParser.ObjectTypeConstants.Table);");
- sb.AppendLine(" }");
- sb.AppendLine();
- }
-
- private void AppendAggregateDistinct(string scope, List<Table> tableList, Dictionary<string, Column> columnList, List<string> typeList)
- {
- foreach (string typeName in typeList)
- {
- AppendAggregateDistinctBody(scope, columnList, typeName);
- if (typeName != "string")
- AppendAggregateDistinctBody(scope, columnList, typeName + "?");
- }
- }
-
- private void AppendAggregateDistinctBody(string