private void AppendRegionConstructors() { sb.AppendLine(" #region Contructors /Initialization"); sb.AppendLine(); sb.AppendLine(" internal Domain"+ _currentStoredProcedure.PascalName + "Collection():base(\"" + _currentStoredProcedure.PascalName + "\")"); sb.AppendLine(" {"); sb.AppendLine(" try"); sb.AppendLine(" {"); sb.AppendLine(" base.TableName = \""+ _currentStoredProcedure.PascalName + "Collection\";"); sb.AppendLine(" this.InitClass();"); sb.AppendLine(" }"); Globals.AppendBusinessEntryCatch(sb); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" private void InitClass() "); sb.AppendLine(" {"); sb.AppendLine(" BeginInit();"); //Create columns foreach (Reference reference in _currentStoredProcedure.GeneratedColumns) { CustomStoredProcedureColumn column = (CustomStoredProcedureColumn)reference.Object; sb.AppendLine(" this.column"+ column.PascalName + " = new DataColumn(\"" + column.DatabaseName + "\", typeof(" + column.GetCodeType() + "), null, System.Data.MappingType.Element);"); sb.AppendLine(" base.Columns.Add(this.column"+ column.PascalName + ");"); sb.AppendLine(" this.column"+ column.PascalName + ".AllowDBNull = true;"); sb.AppendLine(" this.column"+ column.PascalName + ".Caption = \"" + column.PascalName + "\";"); sb.AppendLine(" this.column"+ column.PascalName + ".ReadOnly = true;"); } sb.AppendLine(" EndInit();"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); }
private void AppendRegionGetFriendlyName() { sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Gets the friendly name (if one is defined) of the field."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public static string GetFriendlyName(FieldNameConstants field)"); sb.AppendLine(" {"); sb.AppendLine(" switch (field)"); sb.AppendLine(" {"); foreach (Reference reference in _currentStoredProcedure.Columns) { CustomStoredProcedureColumn column = (CustomStoredProcedureColumn)reference.Object; if (column.Generated) { sb.AppendLine(" case FieldNameConstants."+ column.PascalName + ":"); sb.AppendLine(" return \""+ column.FriendlyName + "\";"); } } sb.AppendLine(" }"); sb.AppendLine(" return \"\";"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" string IBusinessObject.GetFriendlyName(Enum field)"); sb.AppendLine(" {"); sb.AppendLine(" return GetFriendlyName((FieldNameConstants)field);"); sb.AppendLine(" }"); sb.AppendLine(); }
private void AppendRegionGetMaxLength() { sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Gets the maximum size of the field value."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public static int GetMaxLength(FieldNameConstants field)"); sb.AppendLine(" {"); sb.AppendLine(" switch (field)"); sb.AppendLine(" {"); foreach (Reference reference in _currentStoredProcedure.Columns) { CustomStoredProcedureColumn column = (CustomStoredProcedureColumn)reference.Object; if (column.Generated) { sb.AppendLine(" case FieldNameConstants."+ column.PascalName + ":"); if (ModelHelper.IsTextType(column.DataType)) { sb.AppendLine(" return "+ column.Length + ";"); } else { sb.AppendLine(" return 0;"); } } } sb.AppendLine(" }"); sb.AppendLine(" return 0;"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" int IBusinessObject.GetMaxLength(Enum field)"); sb.AppendLine(" {"); sb.AppendLine(" return GetMaxLength((FieldNameConstants)field);"); sb.AppendLine(" }"); sb.AppendLine(); }
private void AppendRegionDataColumnsSetup() { sb.AppendLine(" #region Data Columns Setup"); foreach (Reference reference in _currentStoredProcedure.GeneratedColumns) { CustomStoredProcedureColumn column = (CustomStoredProcedureColumn)reference.Object; sb.AppendLine(" private DataColumn column"+ column.PascalName + ";"); sb.AppendLine(); sb.AppendLine(" [Widgetsphere.Core.Attributes.DataSetting(\"\", false, 0)]"); sb.AppendLine(" public DataColumn "+ column.PascalName + "Column"); sb.AppendLine(" {"); sb.AppendLine(" get { return this.column"+ column.PascalName + "; }"); sb.AppendLine(" }"); sb.AppendLine(); } sb.AppendLine(" #endregion"); sb.AppendLine(); }
private string GetPropertyNode(CustomStoredProcedureColumn column) { var propertyString = new StringBuilder(); //Attributes Name and Type propertyString.AppendFormat(" <Property Name=\"{0}\" Type=\"{1}\" ", column.PascalName, column.EFSqlCodeType()); //Attribute Nullable propertyString.Append("Nullable=\"" + (column.AllowNull ? "true" : "false") + "\" "); //Attribute MaxLength if (!string.IsNullOrEmpty(column.EFGetCodeMaxLengthString())) { propertyString.AppendFormat("MaxLength=\"{0}\" ", column.EFGetCodeMaxLengthString()); } //Attribute Precision Scale if (column.EFSupportsPrecision()) { propertyString.AppendFormat("Precision=\"{0}\" Scale=\"{1}\" ", column.Length.ToString(), column.Scale); } //Attribute Unicode if (column.EFUnicode().HasValue) { var unicodeString = column.EFUnicode().Value ? "true" : "false"; propertyString.AppendFormat("Unicode=\"{0}\" ", unicodeString); } //Attribute FixedLength if (column.EFIsFixedLength().HasValue) { var isFixedLengthString = column.EFIsFixedLength().Value ? "true" : "false"; propertyString.AppendFormat("FixedLength=\"{0}\" ", isFixedLengthString); } propertyString.Append("/>").AppendLine(); return(propertyString.ToString()); }
private void AppendRegionGetFieldLength() { sb.AppendLine(" #region GetFieldLength"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Determines the length of the specified field if it can be set."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public int GetFieldLength("+ _currentStoredProcedure.PascalName + ".FieldNameConstants field)"); sb.AppendLine(" {"); foreach (Reference colRef in _currentStoredProcedure.Columns) { CustomStoredProcedureColumn column = (CustomStoredProcedureColumn)colRef.Object; if (ModelHelper.IsTextType(column.DataType)) { sb.AppendLine(" if(field == FieldNameConstants."+ column.PascalName + ")"); sb.AppendLine(" return "+ column.Length + ";"); } } sb.AppendLine(" //Catch all for all other data types"); sb.AppendLine(" return -1;"); sb.AppendLine(" }"); sb.AppendLine(" #endregion"); sb.AppendLine(); }
private void AppendTemplate() { sb.AppendLine(" #region Member Variables"); sb.AppendLine(); sb.AppendLine(" internal Domain"+ _currentStoredProcedure.PascalName + "Collection ParentCol;"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); sb.AppendLine(" #region Constructor"); sb.AppendLine(); sb.AppendLine(" internal Domain"+ _currentStoredProcedure.PascalName + "(DataRowBuilder rb) : base(rb) "); sb.AppendLine(" {"); sb.AppendLine(" this.ParentCol = ((Domain"+ _currentStoredProcedure.PascalName + "Collection)(base.Table));"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); sb.AppendLine(" #region Properties"); sb.AppendLine(); foreach (Reference reference in _currentStoredProcedure.GeneratedColumns) { CustomStoredProcedureColumn dbColumn = (CustomStoredProcedureColumn)reference.Object; sb.AppendLine(); sb.AppendLine(" internal "+ dbColumn.GetCodeType() + " " + dbColumn.PascalName + ""); sb.AppendLine(" {"); sb.AppendLine(" get "); sb.AppendLine(" {"); sb.AppendLine(" try "); sb.AppendLine(" {"); sb.AppendLine(" return (("+ dbColumn.GetCodeType() + ")(base[this.ParentCol." + dbColumn.PascalName + "Column]));"); sb.AppendLine(" }"); sb.Append(" catch "); if (StringHelper.Match(dbColumn.GetCodeType(), "string", true)) { sb.AppendLine(" (InvalidCastException) "); sb.AppendLine(" {"); sb.AppendLine(" return string.Empty;"); } else { sb.AppendLine(" (InvalidCastException e) "); sb.AppendLine(" {"); sb.AppendLine(" throw new StrongTypingException(\"Cannot get value because it is DBNull.\", e);"); } sb.AppendLine(" }"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" }"); } sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); sb.AppendLine(" #region Null Methods"); sb.AppendLine(); foreach (Reference reference in _currentStoredProcedure.GeneratedColumns) { CustomStoredProcedureColumn dbColumn = (CustomStoredProcedureColumn)reference.Object; if (dbColumn.AllowNull) { sb.AppendLine(); sb.AppendLine(" internal bool Is"+ dbColumn.PascalName + "Null() "); sb.AppendLine(" {"); sb.AppendLine(" return base.IsNull(this.ParentCol."+ dbColumn.PascalName + "Column);"); sb.AppendLine(" }"); sb.AppendLine(" "); } } sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); AppendRegionRelationshipMethods(); sb.AppendLine(); sb.Append("#region Remove"); sb.AppendLine(); sb.Append(" internal void Remove()").AppendLine(); sb.Append(" {").AppendLine(); sb.Append(" this.ParentCol.Remove"+ _currentStoredProcedure.PascalName + "(this);").AppendLine(); sb.Append(" }").AppendLine(); sb.AppendLine(); sb.Append("#endregion"); sb.AppendLine(); }
private void AppendRegionGetValue() { sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Gets the value of one of this object's properties."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" #region GetValue"); sb.AppendLine(); sb.AppendLine(" public object GetValue(FieldNameConstants field)"); sb.AppendLine(" {"); sb.AppendLine(" return GetValue(field, null);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Gets the value of one of this object's properties."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public object GetValue(FieldNameConstants field, object defaultValue)"); sb.AppendLine(" {"); foreach (Reference reference in _currentStoredProcedure.GeneratedColumns) { CustomStoredProcedureColumn dbColumn = (CustomStoredProcedureColumn)reference.Object; sb.AppendLine(" if(field == FieldNameConstants."+ dbColumn.PascalName + ")"); sb.AppendLine(" {"); if (dbColumn.AllowNull) { sb.AppendLine(" return (this.Is"+ dbColumn.PascalName + "Null() ? defaultValue : this." + EnsureValidPropertyName(dbColumn.PascalName) + ");"); } else { sb.AppendLine(" return this."+ EnsureValidPropertyName(dbColumn.PascalName) + ";"); } sb.AppendLine(" }"); } sb.AppendLine(" throw new Exception(\"Field '\" + field.ToString() + \"' not found!\");"); sb.AppendLine(" }"); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Gets the value of one of this object's properties."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public int GetInteger(FieldNameConstants field)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetInteger(field, int.MinValue);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Gets the value of one of this object's properties."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public int GetInteger(FieldNameConstants field, int defaultValue)"); sb.AppendLine(" {"); sb.AppendLine(" object o = this.GetValue(field, defaultValue);"); sb.AppendLine(" if (o is string)"); sb.AppendLine(" {"); sb.AppendLine(" int a;"); sb.AppendLine(" if (int.TryParse((string)o, out a))"); sb.AppendLine(" return a;"); sb.AppendLine(" else"); sb.AppendLine(" throw new InvalidCastException();"); sb.AppendLine(" }"); sb.AppendLine(" else"); sb.AppendLine(" {"); sb.AppendLine(" return (int)o;"); sb.AppendLine(" }"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Gets the value of one of this object's properties."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public double GetDouble(FieldNameConstants field)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetDouble(field, double.MinValue);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Gets the value of one of this object's properties."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public double GetDouble(FieldNameConstants field, double defaultValue)"); sb.AppendLine(" {"); sb.AppendLine(" object o = this.GetValue(field, defaultValue);"); sb.AppendLine(" if (o is string)"); sb.AppendLine(" {"); sb.AppendLine(" double a;"); sb.AppendLine(" if (double.TryParse((string)o, out a))"); sb.AppendLine(" return a;"); sb.AppendLine(" else"); sb.AppendLine(" throw new InvalidCastException();"); sb.AppendLine(" }"); sb.AppendLine(" else"); sb.AppendLine(" {"); sb.AppendLine(" return (double)o;"); sb.AppendLine(" }"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Gets the value of one of this object's properties."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public DateTime GetDateTime(FieldNameConstants field)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetDateTime(field, DateTime.MinValue);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Gets the value of one of this object's properties."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public DateTime GetDateTime(FieldNameConstants field, DateTime defaultValue)"); sb.AppendLine(" {"); sb.AppendLine(" object o = this.GetValue(field, defaultValue);"); sb.AppendLine(" if (o is string)"); sb.AppendLine(" {"); sb.AppendLine(" DateTime a;"); sb.AppendLine(" if (DateTime.TryParse((string)o, out a))"); sb.AppendLine(" return a;"); sb.AppendLine(" else"); sb.AppendLine(" throw new InvalidCastException();"); sb.AppendLine(" }"); sb.AppendLine(" else"); sb.AppendLine(" {"); sb.AppendLine(" return (DateTime)o;"); sb.AppendLine(" }"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Gets the value of one of this object's properties."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public string GetString(FieldNameConstants field)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetString(field, \"\");"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Gets the value of one of this object's properties."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public string GetString(FieldNameConstants field, string defaultValue)"); sb.AppendLine(" {"); sb.AppendLine(" object o = this.GetValue(field, defaultValue);"); sb.AppendLine(" if (o is string)"); sb.AppendLine(" {"); sb.AppendLine(" return (string)o;"); sb.AppendLine(" }"); sb.AppendLine(" else"); sb.AppendLine(" {"); sb.AppendLine(" return o.ToString();"); sb.AppendLine(" }"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); sb.AppendLine(); }
public void AppendFullTemplate() { try { sb.AppendLine(" #region Class Members"); sb.AppendLine(); sb.AppendLine(" #region FieldNameConstants Enumeration"); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Enumeration to define each property that maps to a database field for the '"+ _currentStoredProcedure.PascalName + "' object."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public enum FieldNameConstants"); sb.AppendLine(" {"); foreach (Reference reference in _currentStoredProcedure.GeneratedColumns) { CustomStoredProcedureColumn column = (CustomStoredProcedureColumn)reference.Object; sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Field mapping for the '"+ column.PascalName + "' property"); sb.AppendLine(" /// </summary>"); sb.AppendLine(" [System.ComponentModel.Description(\"Field mapping for the '"+ column.PascalName + "' property\")]"); sb.AppendLine(" "+ column.PascalName + ","); } sb.AppendLine(" }"); sb.AppendLine(" #endregion"); sb.AppendLine(); sb.AppendLine(" internal Domain"+ _currentStoredProcedure.PascalName + " wrappedClass;"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); //Constructors sb.AppendLine(" #region Constructors"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Creates a '"+ _currentStoredProcedure.PascalName + "' object from a domain object"); sb.AppendLine(" /// </summary>"); sb.AppendLine(" internal "+ _currentStoredProcedure.PascalName + "(Domain" + _currentStoredProcedure.PascalName + " classToWrap)"); sb.AppendLine(" {"); sb.AppendLine(" wrappedClass = classToWrap;"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Creates a '"+ _currentStoredProcedure.PascalName + "' object from a DataRowView"); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public "+ _currentStoredProcedure.PascalName + "(DataRowView drvToWrap)"); sb.AppendLine(" {"); sb.AppendLine(" wrappedClass = (Domain"+ _currentStoredProcedure.PascalName + ")drvToWrap.Row;"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); //Events sb.AppendLine(" #region Events"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// This event is raised when any field is changed."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public event PropertyChangedEventHandler PropertyChanged;"); foreach (Reference reference in _currentStoredProcedure.GeneratedColumns) { CustomStoredProcedureColumn dbColumn = (CustomStoredProcedureColumn)reference.Object; sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// This event is raised when the '"+ dbColumn.PascalName + "' field is changed."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public event EventHandler "+ dbColumn.PascalName + "Changed;"); } sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// This event is raised when any field is changed."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)"); sb.AppendLine(" {"); sb.AppendLine(" if (this.PropertyChanged != null)"); sb.AppendLine(" this.PropertyChanged(this, e);"); sb.AppendLine(" }"); sb.AppendLine(); foreach (Reference reference in _currentStoredProcedure.GeneratedColumns) { CustomStoredProcedureColumn dbColumn = (CustomStoredProcedureColumn)reference.Object; sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Raises the "+ dbColumn.PascalName + "Changed event."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" protected virtual void On"+ dbColumn.PascalName + "Changed(System.EventArgs e)"); sb.AppendLine(" {"); sb.AppendLine(" if (this."+ dbColumn.PascalName + "Changed != null)"); sb.AppendLine(" this."+ dbColumn.PascalName + "Changed(this, e);"); sb.AppendLine(" }"); sb.AppendLine(); } sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); //Properties sb.AppendLine(" #region Properties"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Determines if this object is part of a collection or is detached"); sb.AppendLine(" /// </summary>"); sb.AppendLine(" [System.ComponentModel.Browsable(false)]"); sb.AppendLine(" public bool IsParented"); sb.AppendLine(" {"); sb.AppendLine(" get { return (((DataRow)this.WrappedClass).RowState != DataRowState.Detached); }"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Returns the internal object that this object wraps"); sb.AppendLine(" /// </summary>"); sb.AppendLine(" [System.ComponentModel.Browsable(false)]"); sb.AppendLine(" public object WrappedClass"); sb.AppendLine(" {"); sb.AppendLine(" get{return wrappedClass;}"); sb.AppendLine(" set{wrappedClass = (Domain"+ _currentStoredProcedure.PascalName + ")value;}"); sb.AppendLine(" }"); sb.AppendLine(); foreach (Reference reference in _currentStoredProcedure.GeneratedColumns) { CustomStoredProcedureColumn dbColumn = (CustomStoredProcedureColumn)reference.Object; sb.AppendLine(" /// <summary>"); if (dbColumn.Description != "") { sb.AppendLine(" /// "+ dbColumn.Description); } else { sb.AppendLine(" /// Property for StoredProcedure field: "+ dbColumn.PascalName); } sb.AppendLine(" /// </summary>"); sb.AppendLine(" [Widgetsphere.Core.Attributes.DataSetting(\""+ dbColumn.FriendlyName + "\", " + dbColumn.GridVisible.ToString().ToLower() + ", " + dbColumn.SortOrder.ToString() + ")]"); sb.AppendLine(" public "+ dbColumn.GetCodeType() + " " + EnsureValidPropertyName(dbColumn.PascalName)); sb.AppendLine(" {"); sb.AppendLine(" get"); sb.AppendLine(" {"); sb.AppendLine(" try"); sb.AppendLine(" {"); sb.AppendLine(" return wrappedClass."+ dbColumn.PascalName + ";"); sb.AppendLine(" }"); Globals.AppendBusinessEntryCatch(sb); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" }"); } sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); sb.AppendLine(" #region Null Methods"); foreach (Reference reference in _currentStoredProcedure.GeneratedColumns) { CustomStoredProcedureColumn dbColumn = (CustomStoredProcedureColumn)reference.Object; if (dbColumn.AllowNull) { sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Determines if the field '"+ dbColumn.PascalName + "' is null"); sb.AppendLine(" /// </summary>"); sb.AppendLine(" /// <returns>Boolean value indicating if the specified value is null</returns>"); sb.AppendLine(" public bool Is"+ dbColumn.PascalName + "Null() "); sb.AppendLine(" {"); sb.AppendLine(" try"); sb.AppendLine(" {"); sb.AppendLine(" return wrappedClass.Is"+ dbColumn.PascalName + "Null();"); sb.AppendLine(" }"); Globals.AppendBusinessEntryCatch(sb); sb.AppendLine(" }"); sb.AppendLine(); } } sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); sb.AppendLine(" #region Collection Operation Methods"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Removes this object from its parent collection. It will not be deleted from the database."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public void Remove()"); sb.AppendLine(" {"); sb.AppendLine(" try"); sb.AppendLine(" {"); sb.AppendLine(" wrappedClass.Remove();"); sb.AppendLine(" }"); Globals.AppendBusinessEntryCatch(sb); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); sb.AppendLine(" #region Overrides"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Serves as a hash function for this particular type."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public override int GetHashCode()"); sb.AppendLine(" {"); sb.AppendLine(" return base.GetHashCode();"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Returns a value indicating whether the current object is equal to a specified object."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public override bool Equals(object obj)"); sb.AppendLine(" {"); sb.AppendLine(" if (obj == null)"); sb.AppendLine(" {"); sb.AppendLine(" return false;"); sb.AppendLine(" }"); sb.AppendLine(" else if (obj.GetType() == this.GetType())"); sb.AppendLine(" {"); sb.AppendLine(" if (this.wrappedClass == (("+ _currentStoredProcedure.PascalName + ")obj).wrappedClass)"); sb.AppendLine(" return true;"); sb.AppendLine(" }"); sb.AppendLine(" return false;"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); //IBusinessObject.ParentCollection sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// This is a reference back to the generic collection that holds this object."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" #region IBusinessObject ParentCollection"); sb.AppendLine(); sb.AppendLine(" [System.ComponentModel.Browsable(false)]"); sb.AppendLine(" IBusinessCollection IBusinessObject.ParentCollection"); sb.AppendLine(" {"); sb.AppendLine(" get"); sb.AppendLine(" {"); sb.AppendLine(" return ParentCollection;"); sb.AppendLine(" }"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); //ParentCollection sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// This is a reference back to the collection that holds this object."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" #region ParentCollection"); sb.AppendLine(); sb.AppendLine(" [System.ComponentModel.Browsable(false)]"); sb.AppendLine(" public "+ _currentStoredProcedure.PascalName + "Collection ParentCollection"); sb.AppendLine(" {"); sb.AppendLine(" get"); sb.AppendLine(" {"); sb.AppendLine(" return new "+ _currentStoredProcedure.PascalName + "Collection(wrappedClass.ParentCol);"); sb.AppendLine(" }"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); this.AppendRegionGetFriendlyName(); this.AppendRegionGetMaxLength(); this.AppendRegionGetMask(); this.AppendRegionGetDefault(); this.AppendRegionGetValue(); this.AppendRegionGetFieldLength(); } catch (Exception ex) { throw; } }
private void AppendRegionGetDefault() { sb.AppendLine(" #region GetDefault"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Gets the default value of one of this object's properties."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public object GetDefault(FieldNameConstants field)"); sb.AppendLine(" {"); foreach (Reference reference in _currentStoredProcedure.GeneratedColumns) { CustomStoredProcedureColumn dbColumn = (CustomStoredProcedureColumn)reference.Object; sb.AppendLine(" if(field == FieldNameConstants."+ dbColumn.PascalName + ")"); switch (dbColumn.DataType) { case System.Data.SqlDbType.Char: case System.Data.SqlDbType.NChar: case System.Data.SqlDbType.NText: case System.Data.SqlDbType.NVarChar: case System.Data.SqlDbType.Text: case System.Data.SqlDbType.VarChar: case System.Data.SqlDbType.UniqueIdentifier: sb.AppendLine(" return \""+ dbColumn.Default + "\";"); break; case System.Data.SqlDbType.BigInt: case System.Data.SqlDbType.Int: case System.Data.SqlDbType.SmallInt: case System.Data.SqlDbType.TinyInt: if (dbColumn.AllowNull) { sb.AppendLine(" return null;"); } else { long lvalue; if (long.TryParse("0" + dbColumn.Default, out lvalue)) { sb.AppendLine(" return 0"+ dbColumn.Default + ";"); } else //THIS IS AN ERROR CONDITION { sb.AppendLine(" return 0;"); } } break; case System.Data.SqlDbType.DateTime: case System.Data.SqlDbType.SmallDateTime: if (dbColumn.AllowNull) { sb.AppendLine(" return null;"); } else { DateTime dtvalue; if (dbColumn.Default == "") { sb.AppendLine(" return DateTime.Now;"); } else if (DateTime.TryParse(dbColumn.Default, out dtvalue)) { sb.AppendLine(" return DateTime.Parse(\""+ dbColumn.Default + "\");"); } else //THIS IS AN ERROR CONDITION { sb.AppendLine(" return DateTime.Now;"); } } break; case System.Data.SqlDbType.Bit: bool bvalue; if (bool.TryParse(dbColumn.Default, out bvalue)) { sb.AppendLine(" return "+ (bvalue ? "true" : "false") + ";"); } else //THIS IS AN ERROR CONDITION { sb.AppendLine(" return false;"); } break; case System.Data.SqlDbType.Decimal: case System.Data.SqlDbType.Float: case System.Data.SqlDbType.Money: case System.Data.SqlDbType.Real: case System.Data.SqlDbType.SmallMoney: if (dbColumn.AllowNull) { sb.AppendLine(" return null;"); } else { decimal dvalue; if (decimal.TryParse("0" + dbColumn.Default, out dvalue)) { sb.AppendLine(" return 0"+ dbColumn.Default + ";"); } else //THIS IS AN ERROR CONDITION { sb.AppendLine(" return 0;"); } } break; } } sb.AppendLine(); sb.AppendLine(" return null;"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" object IBusinessObject.GetDefault(Enum field)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetDefault((FieldNameConstants)field);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); }
private void AppendRegionIBusinessObject() { sb.AppendLine(" #region IBusinessObject Members"); sb.AppendLine(); sb.AppendLine(" IPrimaryKey IBusinessObject.PrimaryKey"); sb.AppendLine(" {"); sb.AppendLine(" get { return null; }"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" object IBusinessObject.GetValue(Enum field)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetValue((FieldNameConstants)field);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" object IBusinessObject.GetValue(Enum field, object defaultValue)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetValue((FieldNameConstants)field, defaultValue);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" double IBusinessObject.GetDouble(Enum field)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetDouble((FieldNameConstants)field);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" double IBusinessObject.GetDouble(Enum field, double defaultValue)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetDouble((FieldNameConstants)field, defaultValue);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" DateTime IBusinessObject.GetDateTime(Enum field)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetDateTime((FieldNameConstants)field);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" DateTime IBusinessObject.GetDateTime(Enum field, DateTime defaultValue)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetDateTime((FieldNameConstants)field, defaultValue);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" int IBusinessObject.GetInteger(Enum field)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetInteger((FieldNameConstants)field);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" int IBusinessObject.GetInteger(Enum field, int defaultValue)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetInteger((FieldNameConstants)field, defaultValue);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" string IBusinessObject.GetString(Enum field)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetString((FieldNameConstants)field);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" string IBusinessObject.GetString(Enum field, string defaultValue)"); sb.AppendLine(" {"); sb.AppendLine(" return this.GetString((FieldNameConstants)field, defaultValue);"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" Enum IBusinessObject.Container"); sb.AppendLine(" {"); sb.AppendLine(" get { return this.Container; }"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Determines if all of the fields for the specified object exactly matches the current object."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" /// <param name=\"item\">The object to compare</param>"); sb.AppendLine(" /// <returns></returns>"); sb.AppendLine(" public override bool IsEquivalent(IBusinessObject item)"); sb.AppendLine(" {"); sb.AppendLine(" if (item == null) return false;"); sb.AppendLine(" if (!(item is "+ _currentStoredProcedure.PascalName + ")) return false;"); sb.AppendLine(" "+ _currentStoredProcedure.PascalName + " o = item as " + _currentStoredProcedure.PascalName + ";"); sb.AppendLine(" return ("); int index = 0; foreach (Reference reference in _currentStoredProcedure.GeneratedColumns) { CustomStoredProcedureColumn column = (CustomStoredProcedureColumn)reference.Object; sb.Append(" o."+ column.PascalName + " == this." + column.PascalName); if (index < _currentStoredProcedure.GeneratedColumns.Count - 1) { sb.Append(" &&"); } sb.AppendLine(); index++; } sb.AppendLine(" );"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); }