By Ross L. Rooker, Sr. - 8/10/2011
Lets say I want to add a property called RequiredAuditFields that does exactly what the RequiredFields. IE... a collection of collumns. What is the code to do this?
|
By Ivan George Borges - 8/10/2011
Hi Ross.
Here is a thread that could get you started:
http://forum.strataframe.net/FindPost27609.aspx
|
By Keith Chisarik - 8/10/2011
FYI, I ended up implementing the collection property without the editor, it proved a bit more work with the VS integration than I was willing to invest at the time, if you go down that road all the way, it would be great if you share your results
|
By Ross L. Rooker, Sr. - 8/10/2011
Before I abandon this I was hoping that you may be able to shed some light on this? The type or namespace name 'UITypeEditor' could not be found (are you missing a using directive or an assembly reference?) I placed this in my BO Base, along with other code that seems to be working but when it comes to this line I get this error above. Here are my USING statements in the BaseBO:
using
MicroFour.StrataFrame.Business;
using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Data.SqlClient;
using
System.Runtime.Serialization;
using
System.Text;
using
MicroFour.StrataFrame.Security;
using
System.Diagnostics;
using
Microsoft.VisualBasic;
using
System.ComponentModel.Design;
using
System.Collections.Specialized;
using
System.Reflection;
using
System.Runtime.InteropServices.ComTypes;
using
MicroFour.StrataFrame.UI.Windows.Forms;
using
MicroFour.StrataFrame.Extensibility;
using
System.Drawing.Design;
[Category(BUSINESSRULES_CATEGORY_NAME), Description("The AuditFieldsCollection that defines the fields within the business object that are required. If a required field is not populated, then a broken rule will be automatically added to the business object."), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Editor(Constants.TE_RequiredFieldsEditor, typeof(UITypeEditor)]
public virtual RequiredFieldsCollection AuditFields
{
Get
{
return _AuditFields;
}
set { _AuditFields = value; }
}
|
By Ross L. Rooker, Sr. - 8/10/2011
I am not trying to create a new UITypeEditor but just trying to use the same one used by StrataFrame.
|
By Ross L. Rooker, Sr. - 8/10/2011
Forget my last post for now. I just got past this.
|
By Ross L. Rooker, Sr. - 8/10/2011
The property "AuditFields" does now appear on the BOs that inherit from the Base BO but the caption "Collection" does not show and when I click on the eclips I get the follow error:
"An error occurred while attempting to load this type editor: Object reference not set to an instance of an object."
Again, my hope here, is that you may be able to provide any information that may assist. I have successfully integrating the Auditing into our BaseBO as well as a ActivityLog viewer. My last goal is the creating of a property to allow the user to select none or select what fields they want to include. In addition I have some other plans for this but need to know what I may need to consider.
public class AuditField : IRequiredField
{
#region
" Declare Privates "
private string _FieldName;
#endregion
private SqlDbType _FieldType;
#region
" Declare Public Properties "
/// <summary>
/// The field name that is required
/// </summary>
/// <value></value>
/// <remarks></remarks>
public string FieldName
{
get { return _FieldName; }
set { _FieldName = value; }
}
/// <summary>
/// The data type of the required field
/// </summary>
/// <value></value>
/// <remarks></remarks>
public SqlDbType FieldType
{
get { return _FieldType; }
set { _FieldType = value; }
}
#endregion
}
[
Category(BUSINESSRULES_CATEGORY_NAME), Description("The AuditFieldsCollection that defines the fields within the business object that are required. If a required field is not populated, then a broken rule will be automatically added to the business object."), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Editor(Constants.TE_RequiredFieldsEditor, typeof(UITypeEditor))]
public virtual RequiredFieldsCollection AuditFields
{
get
{
return _AuditFields;
}
set { _AuditFields = value; }
}
private
void ResetAuditFields()
{
_AuditFields =
new RequiredFieldsCollection();
}
private
bool ShouldSerializeRequiredFields()
{
return this._AuditFields.Count > 0;
}
[
Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
protected
virtual new string AllFieldNames
{
get
{
throw new NotImplementedException("A class derived from " + typeof(BusinessLayer).FullName + " must override the property 'AllFieldNames'");
}
}
public
class AuditFieldsCollection : System.Collections.CollectionBase, IRequiredFieldsCollection
{
public AuditFieldsCollection()
{
}
public void Add(IRequiredField Item)
{
InnerList.Add(Item);
}
public void Remove(AuditField Item)
{
InnerList.Remove(Item);
}
public bool Contains(AuditField Item)
{
return InnerList.Contains(Item);
}
public AuditField this[int Index]
{
get { return (AuditField)InnerList[Index]; }
set { InnerList[Index] = value; }
}
public void AddRange(AuditField[] Items)
{
InnerList.AddRange(Items);
}
public AuditField[] GetValues()
{
//-- Establish Locals
AuditField[] loReturn = null;
// ERROR: Not supported in C#: ReDimStatement
InnerList.CopyTo(0, loReturn, 0, InnerList.Count);
return loReturn;
}
protected override void OnInsert(int index, object value)
{
base.OnInsert(index, value);
}
public IRequiredField[] ToArray()
{
//-- Establish Locals
System.Collections.Generic.
List<RequiredField> loArray = new System.Collections.Generic.List<RequiredField>();
//RequiredField loItem = default(RequiredField);
foreach (RequiredField loItem in List)
{
loArray.Add(loItem);
}
return loArray.ToArray();
}
public new void Clear()
{
InnerList.Clear();
}
}
|
|