Search code examples
c#devexpressxaf

How to create multiple businessobject within one businessobject in XAF?


So here is what I am trying to achieve :

I am trying to create what is called Quick Production Fiche that includes multiple items created with same fiche . Example:

LOGICALREF  |  NAME   | MAINPRODREF (Id of the items connected to same fiche)

   1        | Fiche1  |      1
   2        | Fiche1  |      2
   3        | Fiche1  |      3
   4        | Fiche1  |      4

But as I am working on a company database I have set of rules:

  • I can only attach ID (key) of the multiple item (will be inserted to MAINPRODREF) to fiches. I have created the business object related to this.

Here is my business object for fiche and the item from altMamüller that I want to attach:

 int fLOGICALREF;
 [Key(true)]

 public int LOGICALREF
 {
     get { return fLOGICALREF; }
     set { SetPropertyValue<int>(nameof(LOGICALREF), ref fLOGICALREF, value); }
 }

 string fNAME;
 [Indexed(Name = @"I124_BOMASTER_I3aa")]
 [Size(51)]
 [XafDisplayName("İsim")]
 public string NAME
 {
     get { return fNAME; }
     set { SetPropertyValue<string>(nameof(NAME), ref fNAME, value); }
 }


int fMAINPRODREF;
[Indexed(Name = @"I124_BOMASTER_I4aa")]
[XafDisplayName("Ürün Anahtarı")]
[VisibleInDetailView(false)]
public int MAINPRODREF
{
    get
    {
        return fMAINPRODREF;
    }
    set { SetPropertyValue<int>(nameof(MAINPRODREF), ref fMAINPRODREF, value); }
}

 altMamüller fItemsConnected;
 [VisibleInListView(false)]
 [NonPersistent]
 [XafDisplayName("Ürün")]
 public altMamüller ItemsConnected
 {
     get { return fItemsConnected; }
     set { SetPropertyValue<altMamüller>(nameof(ItemsConnected), ref fItemsConnected, value); }
 }

------------------------------------
item

       int fID;
       public int ID
       {
           get { return fID; }
           set { SetPropertyValue<int>(nameof(ID), ref fID, value); }
       }

Update:

Solutions that I have tried but couldn't achieve:

  • PopUpWindowShowAction (designer doesn't work, I get "timed out while connecting to named pipe visual studio" error. Spent a whole day on it trying to solve)

  • For loop and custom SQL connection string but I couldn't find a way.

  • ObjectSpace (I am new to the language so I couldn't understand the system)


Solution

  • I found the answer. It seems like popupwindowshowaction was the total solution to the problem.

    I made the explanation of how it works inside the codes.

     
      public ViewControllerFiche()
      {
          InitializeComponent();
          //Add the necessary codes to target the BusinessObject and create a new popup window inside businessobject detailview
          TargetObjectType = typeof(Fiche);
          TargetViewType = ViewType.DetailView;
          PopupWindowShowAction showNotesAction = new PopupWindowShowAction(this, "AddItemsAction", PredefinedCategory.Edit)
          {
              Caption = "Add Items to Fiche"
          };
    
          showNotesAction.CustomizePopupWindowParams += ShowNotesAction_CustomizePopupWindowParams;
          showNotesAction.Execute += ShowNotesAction_Execute;
      }
    
      private void ShowNotesAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e)
      {
          //Create a List View for Note objects in the pop-up window.
          e.View = Application.CreateListView(typeof(items), true);
      }
    
      private void ShowNotesAction_Execute(object sender, PopupWindowShowActionExecuteEventArgs e)
      {
          //Take the fiche in current object to get its values
          Fiche task = (Fiche)View.CurrentObject;
          //open foreach loop to read every items' values
          foreach (items note in e.PopupWindowViewSelectedObjects)
          {
          
              //Create New Fiche
              Fiche hizliFis = ObjectSpace.CreateObject<Fiche>();
    
              //Reference all values of Items' to fiche
              hizliFis.ITEMREF = note.ID;
              .... // Other Object Relations
    
              //Create object and refresh the page.
              View.ObjectSpace.CommitChanges();
              View.Refresh();
          }}