One to one relationship


Author
Message
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Well, the error is telling you that you either do no have any records in the CompanyContactsBO or the CurrentRowIndex has been positioned outside of the valid records.  More than likely there are no records.  You can see that when the ContactTypeID property is being set through the SetDefaultvalues that the record pointer is wrong at this point.  If you put a break point in the SetDefaultvalues of CompanyCOntactsBO, is the CurrentRowIndex set property and is the Count of the BO greater than 1?
Chan
Chan
Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)
Group: Forum Members
Posts: 533, Visits: 2K
Hi,

I created an composite model class that host my parent and childs BO. I event bind them as suggested. But hit error as below. Crying



If I set my child BO as form's PrimarkBusinessObject, it works fine.



using System;

using System.Collections.Generic;

using System.Text;



using JK.Inventory.BusinessObject.Main;



using MicroFour.StrataFrame.Business;

using MicroFour.StrataFrame.Data;



namespace JK.Inventory.BusinessObject.Composite

{

public class CompaniesBOModel

{

#region "Private Fields"



private CompaniesBO _CompaniesBO;

private CompanyAddressBO _CompanyAddressBO;

private CompanyContactsBO _CompanyContactsBO;



#endregion "Private Fields"



#region "Constructor"



public CompaniesBOModel() :base()

{

}



public CompaniesBOModel(CompaniesBO toCompanyBO, CompanyAddressBO toCompanyAddressBO,

CompanyContactsBO toCompanyContactBO)

{

this._CompaniesBO = toCompanyBO;

this._CompanyAddressBO = toCompanyAddressBO;

this._CompanyContactsBO = toCompanyContactBO;



this._CompanyAddressBO.ParentBusinessObject = this._CompaniesBO;

this._CompanyContactsBO.ParentBusinessObject = this._CompaniesBO;

this._CompaniesBO.ChildAutoFilterOption = AutoChildFilterOptions.MatchCurrentRow;



this.BindBOEventHandler();

}



#endregion "Constructor"



#region "Methods"



private void BindBOEventHandler()

{

this._CompaniesBO.AfterAddNew += new CompaniesBO.AfterAddNewEventHandler(this.AfterCompaniesBOAddNewEventHandler);

this._CompaniesBO.AfterDelete += new CompaniesBO.AfterDeleteEventHandler(this.AfterCompaniesBODeleteEventHandler);

this._CompaniesBO.AfterSave += new CompaniesBO.AfterSaveEventHandler(this.AfterCompaniesBOSaveEventHandler);

this._CompaniesBO.AfterUndo += new CompaniesBO.AfterUndoEventHandler(this.AfterCompaniesBOUndoEventHandler);

this._CompaniesBO.EditingStateChanged += new CompaniesBO.EditingStateChangedEventHandler(this.CompaniesBOEditingStateChangedEventHandler);

}



#endregion "Methods"



#region "Event Handler"



private void AfterCompaniesBOAddNewEventHandler(EventArgs e)

{

//this._CompanyAddressBO.Add();

this._CompanyContactsBO.Add();

}



private void AfterCompaniesBOSaveEventHandler(AfterSaveUndoEventArgs e)

{

this._CompanyAddressBO.Save();

this._CompanyContactsBO.Save();

}



private void AfterCompaniesBOUndoEventHandler(AfterSaveUndoEventArgs e)

{

this._CompanyAddressBO.Undo(BusinessUndoType.AllRows);

this._CompanyContactsBO.Undo(BusinessUndoType.AllRows);

}



private void AfterCompaniesBODeleteEventHandler(AfterDeleteEventArgs e)

{

}



private void CompaniesBOEditingStateChangedEventHandler(EditingStateChangedEventArgs e)

{

if (e.EditingState == BusinessEditingState.Editing)

{

this._CompanyAddressBO.Edit();

this._CompanyContactsBO.Edit();

}

}

#endregion "Event Handler"



#region "Properties"

public CompaniesBO CompaniesBO

{

get

{

return this._CompaniesBO;

}

}



public CompanyAddressBO CompanyAddressBO

{

get

{

return this._CompanyAddressBO;

}

}



public CompanyContactsBO CompanyContactsBO

{

get

{

return this._CompanyContactsBO;

}

}



#endregion "Properties"

}

}







System.IndexOutOfRangeException was unhandled by user code

Message="Index 0 is either negative or above rows count."

Source="System.Data"

StackTrace:

at System.Data.DataView.GetElement(Int32 index)

at System.Data.DataView.get_Item(Int32 recordIndex)

at MicroFour.StrataFrame.Business.BusinessLayer.get_CurrentRow()

at JK.Inventory.BusinessObject.Main.CompanyContactsBO.set_ContactTypeID(ContactType value) in F:\Projects\Inventory\InventoryBusinessObject\Main\CompanyContactsBO.Designer.cs:line 306

at JK.Inventory.BusinessObject.Main.CompanyContactsBO.CompanyContacts_SetDefaultValues() in F:\Projects\Inventory\InventoryBusinessObject\Main\CompanyContactsBO.cs:line 76

at MicroFour.StrataFrame.Business.BusinessLayer.raise_SetDefaultValues()

at MicroFour.StrataFrame.Business.BusinessLayer.OnSetDefaultValues()

at MicroFour.StrataFrame.Business.BusinessLayer.NewRow()

at MicroFour.StrataFrame.Business.BusinessLayer.Add(Boolean CheckSecurity)

at MicroFour.StrataFrame.Business.BusinessLayer.Add()

at JK.Inventory.BusinessObject.Composite.CompaniesBOModel.AfterCompaniesBOAddNewEventHandler(EventArgs e) in F:\Projects\Inventory\InventoryBusinessObject\Composite\CompanyBOModel.cs:line 62

at MicroFour.StrataFrame.Business.BusinessLayer.raise_AfterAddNew(EventArgs e)

at MicroFour.StrataFrame.Business.BusinessLayer.OnAfterAddNew(EventArgs e)

at MicroFour.StrataFrame.Business.BusinessLayer.NewRow()

at MicroFour.StrataFrame.Business.BusinessLayer.Add(Boolean CheckSecurity)

at MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.Add(Boolean CheckSecurity)

at MicroFour.StrataFrame.UI.Windows.Forms.MaintenanceFormToolStrip.cmdNew_Click(Object sender, EventArgs e)

at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)

at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)

at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)

at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)

at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)

at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)

at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ScrollableControl.WndProc(Message& m)

at System.Windows.Forms.ToolStrip.WndProc(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Within the child business object, you can attach a handler to the ParentBusinessObject's AfterAddNew event and add a new record to the child business object when it fires.  You can also add a handler to the ParentBusinessObject's EditingStateChanged event and when the editing state is Editing, call Edit() on the child business object.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I'm not entirely sure, but I think the first step is to do a relationship between the parent/child. Open the designer for the child BO and you can set its parent (ParentBO I think). You'll set the FK fields here.



Then on a form, you drop both BOs (parent first). Then open the properties window of the of the child BO and set its parent BO (I know this is a bit confusing, but setting at the class level sets the relationship, while this ties two instances together). In any case, the properties window will only let you set the correct one in each case.



I know this does things like automatically setting the value of the FK field in the child to the parent's PK and to auto navigate (if the parent instance is configured to do this one the form) the child BO when the parent BO is navigated. My guess is that it won't automatically handle adding or editing. However, there are a bunch of event the BO provides. Simply add handlers to the appropriate ones. The EditingStateChanged event is likely the best bet. In this one you can check the editing state and then enter the add or edit state in the child BO. You can then handle either the AfterSave or BeforeSave event to save the child, I'm not sure which one would work better.



BTW, I'm just a user like yourself, but I figured I might get you started in the right direction. When the SF devs answer, we'll all learn some more about SF! BigGrin



Good luck.
Chan
Chan
Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)
Group: Forum Members
Posts: 533, Visits: 2K
Hi,

I have two tables with 1:1 relationship, one BO for each table. I want to "sync" parent BO event to child BO. For example, calling ParentBO.Add() will automatically call ChildBO.Add, ParentBO.Edit() also call ChildBO.Edit and etc.



How to do this?



Thank you
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search