WinPart Id with ERLB
Old forum URL: forums.lhotka.net/forums/t/6262.aspx
esteban404 posted on Tuesday, January 27, 2009
I have several editors for ERLB objects. The WinPart code needs an id to identify the object being edited. What is the practice to identify these? Do I add an ID property to the ERLB itself? Seems reasonable, just checking for best practice.
_Ekdlc replied on Tuesday, March 17, 2009
Did you find a way to handle this?
I'm having trouble if I try to load an empty ERLB liist to the Winpart-Inherited form. I'm thinking about removing the GetID and String methods.
Any suggestions?
esteban404 replied on Tuesday, March 17, 2009
I don't think I solved anything. I just got it to work. I do include a Guid, but it hasn't been used. I get the Window list to populate with the open editors OK, and they are only allowed one open window per BO type. I constructed the ERLB list like this:
[Serializable()]
public class QcpcList : Csla.EditableRootListBase
{
private Guid _Id;
public Guid Id
{get{ return _Id;}
set{ if (_Id == value) return;
_Id = value;}
}
#region Authorization Rules
#endregion
#region Factory Methods
protected override object AddNewCore()
{Qcpc item = Qcpc.NewQcpc();
Add(item);
return item;
}
public static QcpcList NewList()
{
return DataPortal.Create();
}
public static QcpcList GetList()
{
return DataPortal.Create();
}
public static QcpcList GetList(string workOrder)
{
return DataPortal.Fetch(new Criteria(workOrder));
}
private QcpcList()
{
this.AllowEdit = true;
this.AllowNew = true;
this.AllowRemove = true;
}
#endregion
#region Data Access
#region Criteria
[Serializable()]
public class Criteria
{
private string _WorkOrder;
public string WorkOrder
{ get { return _WorkOrder; } }
public Criteria(string workOrder)
{
_WorkOrder = workOrder;
}
}
#endregion
private void DataPortal_Create()
{
Qcpc q = Qcpc.NewQcpc();
Add(q);
}
private void DataPortal_Fetch()
{
DataPortal_Create();
}
private void DataPortal_Fetch(Criteria criteria)
{
this.RaiseListChangedEvents = false;
using (SqlConnection cn = new SqlConnection(Database.ProCertConnection))
{
cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.AddWithValue("@WorkOrder", criteria.WorkOrder);
cm.CommandText = "getQcpcDefectList";
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read())
{
Add(Qcpc.GetQcpc(dr));
}
}
}
}
this.RaiseListChangedEvents = true;
}
#endregion
}
Qcpc is a Csla.BusinessBase item. A new item is created with default values. In a couple of UIs, the list is summarily cleared just to make sure nothing is sitting there that's not part of the user's input before they begin. It's a hack.
HTH,
_ECopyright (c) Marimer LLC