private void AppendTemplate() { sb.AppendLine(" #region Member Variables"); sb.AppendLine(); sb.AppendLine(" internal Domain"+ _currentView.PascalName + "Collection ParentCol;"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); sb.AppendLine(" #region Constructor"); sb.AppendLine(); sb.AppendLine(" internal Domain"+ _currentView.PascalName + "(DataRowBuilder rb) : base(rb) "); sb.AppendLine(" {"); sb.AppendLine(" this.ParentCol = ((Domain"+ _currentView.PascalName + "Collection)(base.Table));"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); sb.AppendLine(" #region Properties"); sb.AppendLine(); foreach (Reference reference in _currentView.GeneratedColumns) { CustomViewColumn dbColumn = (CustomViewColumn)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 _currentView.GeneratedColumns) { CustomViewColumn dbColumn = (CustomViewColumn)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.Append(" internal void Remove()").AppendLine(); sb.Append(" {").AppendLine(); sb.Append(" this.ParentCol.Remove"+ _currentView.PascalName + "(this);").AppendLine(); sb.Append(" }").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 '"+ _currentView.PascalName + "' view."); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public enum FieldNameConstants"); sb.AppendLine(" {"); foreach (Reference reference in _currentView.GeneratedColumns) { CustomViewColumn column = (CustomViewColumn)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"+ _currentView.PascalName + " wrappedClass;"); sb.AppendLine(); sb.AppendLine(" #endregion"); sb.AppendLine(); //Constructors sb.AppendLine(" #region Constructors"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Creates a '"+ _currentView.PascalName + "' object from a domain object"); sb.AppendLine(" /// </summary>"); sb.AppendLine(" internal "+ _currentView.PascalName + "(Domain" + _currentView.PascalName + " classToWrap)"); sb.AppendLine(" {"); sb.AppendLine(" wrappedClass = classToWrap;"); sb.AppendLine(" }"); sb.AppendLine(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Creates a '"+ _currentView.PascalName + "' object from a DataRowView"); sb.AppendLine(" /// </summary>"); sb.AppendLine(" public "+ _currentView.PascalName + "(DataRowView drvToWrap)"); sb.AppendLine(" {"); sb.AppendLine(" wrappedClass = (Domain"+ _currentView.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 _currentView.GeneratedColumns) { CustomViewColumn dbColumn = (CustomViewColumn)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 _currentView.GeneratedColumns) { CustomViewColumn dbColumn = (CustomViewColumn)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"+ _currentView.PascalName + ")value;}"); sb.AppendLine(" }"); sb.AppendLine(); foreach (Reference reference in _currentView.GeneratedColumns) { CustomViewColumn dbColumn = (CustomViewColumn)reference.Object; sb.AppendLine(" "); sb.AppendLine(); sb.AppendLine(); sb.AppendLine(); sb.AppendLine(" /// <summary>"); if (dbColumn.Description != "") { sb.AppendLine(" /// "+ dbColumn.Description); } else { sb.AppendLine(" /// Property for View 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 _currentView.GeneratedColumns) { CustomViewColumn dbColumn = (CustomViewColumn)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 == (("+ _currentView.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 "+ _currentView.PascalName + "Collection ParentCollection"); sb.AppendLine(" {"); sb.AppendLine(" get"); sb.AppendLine(" {"); sb.AppendLine(" return new "+ _currentView.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 AppendRegionConstructors() { sb.AppendLine(" #region Contructors /Initialization"); sb.AppendLine(); sb.AppendLine(" internal Domain"+ _currentView.PascalName + "Collection():base(\"" + _currentView.PascalName + "\")"); sb.AppendLine(" {"); sb.AppendLine(" try"); sb.AppendLine(" {"); sb.AppendLine(" base.TableName = \""+ _currentView.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 _currentView.GeneratedColumns) { CustomViewColumn column = (CustomViewColumn)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(); }