3
Tags: .NET , Frameworks (XAF & XPO) , eXpress Persistent Objects ID: T210787 Created On: 2/18/2015 2:12:34 PM Modified On: 3/11/2015 12:59:36 PM Build: v2014 vol 2.3 / 4-Dec-2014 Related Questions How to view persistent objects in the XtraGrid and edit them in a separate window XPO-XAF-GRID Async XPServerCollectionSource, GridLookUpEdit, Server mode server mode grid not editable (XPServerCollectionSource and Oracle) What is the best way to change ObjectClassInfo for xpcollection at runtime Show More SUPPORT CENTER FAQ Training Events Localization Examples Tickets Submit a Support Ticket Submit a Support Ticket Type search string and press Enter 1 solution Editing an XPO object in a separate Form in Server Mode 0 Chris D 4 months ago [DevExpress Support Team: CLONED FROM T210099: How to synchronize XPServerCollectionSource with BindingContext?] Furthermore, i really appreciate your help / advise: This is my szenario: I have a grid with 100.000 records. (servermode). If I doubleclick on a row, i need to open a new form with this record in a datalayoutcontrol + some buttons / etc. A possibilty to add a new record should also be forseen. old szenario: No server mode, XPcollection, Custom-Editform (not everythings possible with editform), slow new Szenario: Server Mode, new form for adding/editing, either linked by CurrencManager or (what do you think) by fetching the selected record again with XPcollection on the new form (no server mode) and refreshing the grid after leaving the input form. Please feel free to comment, i really need your input Code: on Doublecklick show the form: ff.ShowDialog(ID) search the selected record inside the new form: XpCollection1.CriteriaString = "ID=" & id Save the record after changes are made : Session1.Save(XpCollection1) refresh the grid after leaving the form and hold the current row: Dim i As Integer = GridView1.FocusedRowHandle Dim top As Integer = GridView1.TopRowIndex Session1.DropIdentityMap() XpServerCollectionSource1.Reload() GridView1.FocusedRowHandle = i GridView1.TopRowIndex = top What do you think ?? Thanks a lot. [Updated] Perfect, this is exactly the solution i want to go for ! Last question, how do you handle the add of a new recordset. Grid.addnew is not the right one, because i have no rowid if i go to the edit form ?! Thanks for your help ! [VB.NET] Leave a Comment 1 Solution T210099VB.zip 0 Uriah (DevExpress Support) 4 months ago You can simply pass to the edit form persistent object that you want to edit. I have attached a simple example illustrating this approach. In the edit form I use the XPCollection with the LoadingEnabled property set to false. I do not need to load any objects, I just want to add a single object to edit its properties. I also do not bind the XPCollection to the Session at design time. I do it at run time using the ResolveSession event. This trick helps me bind the XPCollection to the Session instance related to the parent Form and avoid mixing different Sessions. In the edit form constructor, I create the NestedUnitOfWork and use it to reload the object passed from the parent form. The purpose of the NestedUnitOfWork in this example is to allow users to cancel changes without affecting objects in the parent form. If you want to learn more about nested unit of work, refer to this article: Nested Units of Work. When the user clicks the "Save" button in the edit form, I execute the CommitChanges method of the nested unit of work. This method update changed objects in the parent Session. In other words, a corresponding record in the GridView will be automatically updated. You do not need to call the XPServerCollectionSource.Reload method or use dirty hacks such as clearing the Session's identity map. If the XPServerCollectionSource is bound to the Session instance, changes made in the edit form will be automatically saved to the database. If the XPServerCollectionSource is bound to the UnitOfWork instance, you need to execute the CommitChanges method after the edit form is closed. To add a new record, create a new persistent object instance and pass it to the edit form as a parameter. This time, however, you will need to reload the XPServerCollectionSource, because the new object will not automatically appear in the grid. Executing the XPServerCollectionSource.Reload method will be sufficient. Also, if you want to immediately display the added record to a user, use the GridView.LocateByValue method to obtain the handle of a row that displays the new object and assign the result to the GridView.FocusedRowHandle property. Attached is a sample project demonstrating how to implement this. Show all comments So, we got stucked ?! The thing is, my procedure is working fine, but i would like to follow the (your) rules and have this accorate running. Chris D 3 months ago Products Free Trials & Demos Buy Support My Account About Us Log In Open in popup window T210787 - Editing an XPO object in a separate Form in Server Mode | DevExpress Support Center 25-May-15 https://www.devexpress.com/Support/Center/Question/Details/T210787 1 / 3

T210787 - Editing an XPO Object in a Separate Form in Server

  • Upload
    tas-pro

  • View
    116

  • Download
    1

Embed Size (px)

DESCRIPTION

s

Citation preview

  • Tags: .NET, Frameworks (XAF & XPO), eXpress Persistent ObjectsID :T210787

    Created O n :2/18/2015 2:12:34 PM

    Mod if ied O n :3/11/2015 12:59:36 PM

    B u ild :v2014 vo l 2.3 / 4-Dec-2014

    Related Questions

    How to view persisten t ob jects inth e XtraG rid an d ed it th em in aseparate w in dow

    XPO -XAF-G RID Asyn c

    XPServerCo llection Sou rce,G ridLookU pEd it, Server mode

    server mode g rid n o t ed itab le(XPServerCo llection Sou rce an dO racle)

    W h at is th e best w ay to ch an geO b jectClassIn fo fo r xpco llection atru n time

    Sh ow More

    SUPPORT CENTER FAQTraining EventsLocalizationExamplesTickets

    Submit a Support TicketSubmit a Support TicketType search string and press Enter

    1solution

    Editing an XPO object in a separate Form in Server Mode

    0 Chris D 4 months ago

    [DevExpress Support Team: CLONED FROM T210099: How to synchronize XPServerCollectionSource with BindingContext?]

    Furthermore, i really appreciate your help / advise:

    This is my szenario:

    I have a grid with 100.000 records. (servermode).If I doubleclick on a row, i need to open a new form with this record in a datalayoutcontrol + some buttons / etc.A possibilty to add a new record should also be forseen.

    old szenario: No server mode, XPcollection, Custom-Editform (not everythings possible with editform), slow

    new Szenario: Server Mode, new form for adding/editing, either linked by CurrencManager or (what do you think) by fetching the selected record againwith XPcollection on the new form (no server mode) and refreshing the grid after leaving the input form. Please feel free to comment, i really need yourinput

    Code:on Doublecklick show the form: ff.ShowDialog(ID)

    search the selected record inside the new form: XpCollection1.CriteriaString = "ID=" & id

    Save the record after changes are made : Session1.Save(XpCollection1)

    refresh the grid after leaving the form and hold the current row:

    Dim i As Integer = GridView1.FocusedRowHandleDim top As Integer = GridView1.TopRowIndexSession1.DropIdentityMap()XpServerCollectionSource1.Reload()GridView1.FocusedRowHandle = iGridView1.TopRowIndex = top

    What do you think ??

    Thanks a lot.[Updated]

    Perfect, this is exactly the solution i want to go for !

    Last question, how do you handle the add of a new recordset. Grid.addnew is not the right one, because i have no rowid if i go to the edit form ?!

    Thanks for your help !

    [VB.NET]

    Leave a Comment

    1 Solution

    T210099VB.zip

    0 Uriah (DevExpress Support) 4 months agoYou can simply pass to the edit form persistent object that you want to edit. I have attached a simple example illustrating this approach.

    In the edit form I use the XPCollection with the LoadingEnabled property set to false. I do not need to load any objects, I just want to add a single object toedit its properties. I also do not bind the XPCollection to the Session at design time. I do it at run time using the ResolveSession event. This trick helps mebind the XPCollection to the Session instance related to the parent Form and avoid mixing different Sessions.

    In the edit form constructor, I create the NestedUnitOfWork and use it to reload the object passed from the parent form. The purpose of theNestedUnitOfWork in this example is to allow users to cancel changes without affecting objects in the parent form. If you want to learn more about nestedunit of work, refer to this article: Nested Units of Work.

    When the user clicks the "Save" button in the edit form, I execute the CommitChanges method of the nested unit of work. This method update changedobjects in the parent Session. In other words, a corresponding record in the GridView will be automatically updated. You do not need to call theXPServerCollectionSource.Reload method or use dirty hacks such as clearing the Session's identity map.

    If the XPServerCollectionSource is bound to the Session instance, changes made in the edit form will be automatically saved to the database. If theXPServerCollectionSource is bound to the UnitOfWork instance, you need to execute the CommitChanges method after the edit form is closed.

    To add a new record, create a new persistent object instance and pass it to the edit form as a parameter. This time, however, you will need to reload theXPServerCollectionSource, because the new object will not automatically appear in the grid. Executing the XPServerCollectionSource.Reload method will besufficient. Also, if you want to immediately display the added record to a user, use the GridView.LocateByValue method to obtain the handle of a row thatdisplays the new object and assign the result to the GridView.FocusedRowHandle property.

    Attached is a sample project demonstrating how to implement this.

    Show all comments

    So , w e go t stu cked ?! Th e th in g is , my p rocedu re is w o rk in g f in e, bu t i w ou ld like to fo llow th e (you r) ru les an d h ave th is acco rate ru n n in g .Chris D 3 months ago

    Products Free Trials & Demos Buy Support My Account About Us

    Log In

    Open in popup window

    T210787 - Editing an XPO object in a separate Form in Server Mode | DevExpress Support Center 25-May-15

    https://www.devexpress.com/Support/Center/Question/Details/T210787 1 / 3

  • DEVEXPRESSAbout UsNewsOur AwardsUpcoming EventsUser CommentsCase StudiesReviews and PublicationsLicensingPurchasingMVP ProgramContact UsLogos

    .NET CONTROLSWinFormsASP.NETMVCWPFSilverlightWindows 8 XAML

    CROSS PLATFORMReportingDocument Automation

    MOBILEDevExtreme Mobile

    ENTERPRISE TOOLSReport ServerAnalytics Dashboard

    FRAMEWORKSeXpressApp Framework

    CODE-DEBUG-REFACTORCodeRush for Visual Studio

    HTML5 JS WIDGETSDevExtreme Web

    iOS 7DataExplorer

    FUNCTIONAL WEB TESTINGTestCafe

    DELPHI C++BUILDERVCL

    SUPPORTSearch the Knowledge BaseMy QuestionsCode ExamplesGetting StartedDemosDocumentationBlogsTrainingWebinars

    Current Version/BuildVersion History

    FOLLOW US

    O n e remake, th e rou tin e (FLS_PO STEN w ill a lso w ork w ith con tacts, bu t n o t ch an g in g , ju st read in g )

    If i u se

    An y ideas ?

    W h at is th e Session f ield in th e code sn ippet above? If it is a U n itO fW ork in stan ce, ca ll Session .CommitCh an ges() in stead o f v.Save() w h encreatin g a VTSAU FTRAG _View in stan ce. In th is situ ation , you w ill be ab le to get a saved ob ject by its key.

    How ever, I w ou ld su ggest you rew rite you r code an d get rid o f u n n ecessary rou n d trip s to th e server. Th e code below does th e same as you rcode, bu t does n o t n eed to save th e VTSAU FTRAG _View in stan ce befo re assign in g it to th e con t.NU MB ER10 p roperty.

    Dim con_id As Integer = co.IDIf cONt.TEXT5 = "JA" And cONt.NUMBER2 > 0 ThenPOSTEN(con_id) (external procedure which needs the saved record)Else If cONt.TEXT5 = "JA" And (cONt.NUMBER2 = 0 Or cONt.NUMBER2 = Nothing) Then cONt.NUMBER2 = (FLS_POSTEN(con_id)) cont.NUMBER10 = Session.GetObjectByKey(Of VTSAUFTRAG_View(Convert.ToDouble(cont.NUMBER2)) If IsNothing(cont.NUMBER10) Then cont.NUMBER10 = New VTSAUFTRAG_View(Session) cont.NUMBER10.NR = cont.NUMBER2 cont.NUMBER10.AENDERUNGSDATUM = Date.Now End If

    Uriah (DevExpress Support) 3 months ago

    [VB.NET]

    in stead o f v.saveYes, i tried th is , too . I receive an erro r th at data are extern al ch an ged , lo ck in gexcep tion . . . . . . . .

    Chris D 3 months ago

    Th is I receive:

    Ein Ausnahmefehler des Typs "DevExpress.Xpo.DB.Exceptions.LockingException" ist in DevExpress.Data.v14.2.dll aufgetreten.Zustzliche Informationen: Das Objekt kann nicht bestehend bleiben. Es wurde von einem anderen Programm modifiziert oder gelscht (bereinigt).

    If i do th is : Me.Session .Lock in gO ption = Lock in gO ption .Non e, I receive n o erro r, bu t th is seems to be n o t th e righ t w ay.

    Cou ld it be possib le, th at th e p rob lem is th e IDENTITY server side f ield . W h at i recogn ized is th at w h en i w o rk w ith session on ly, a fter save, myID (au to in cremen t) is f illed in (con .ID= 4711). If I w o rk w ith U O W , after commit, th e ID is still empty (clien t side), on server side (sq l) th e id isf illed .

    I redu ced code to mimimu m an d still receive th is lo ck in g erro r:

    Me.BindingContext(Me.XpCollection1).EndCurrentEdit()Me.Session.CommitChanges()

    Me.Session.BeginNestedUnitOfWork()Dim cont As CONTACTS = Session.GetObjectByKey(Of CONTACTS)(co.ID)cont.NOTES0 = "test"Me.Session.CommitChanges()

    Cou ld it be th at U O W h as p rob lems th ere (iden tity f ield s):

    [ID] [int] IDENTITY(1,1) NOT NULL,

    ? Ch ris

    Chris D 3 months ago

    [VB.NET]

    [SQL]

    W e h ave d iscu ssed th is p rob lem above an d I su ggested you do n o t u se th e NestedU n itO fW ork , becau se in you r scen ario you can n o t avo idmu ltip le commits. Can you con firm th at Me.Session is th e same in stan ce as th e Session th at is u sed in th e paren t Fo rm?

    Have you tried th e code I su ggested above? If it does n o t w ork , w ou ld you p lease clarify w h at does n o t w ork?

    Uriah (DevExpress Support) 3 months ago

    Show all comments Leave a Comment

    If you need additional product information, write to us at [email protected] or call us at +1 (818) 844-3383

    Open in popup window

    Open in popup window

    Open in popup window

    T210787 - Editing an XPO object in a separate Form in Server Mode | DevExpress Support Center 25-May-15

    https://www.devexpress.com/Support/Center/Question/Details/T210787 2 / 3

  • Your Privacy - Legal Statements Copyright 1998-2014 Developer Express Inc.All trademarks or registered trademarks are property of their respective owners

    DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, BusinessApplication Frameworks, and Reporting Systems for Visual Studio, along with high-performanceHTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whetherusing WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help youbuild and deliver your best in the shortest time possible.

    T210787 - Editing an XPO object in a separate Form in Server Mode | DevExpress Support Center 25-May-15

    https://www.devexpress.com/Support/Center/Question/Details/T210787 3 / 3

    Editing an XPO object in a separate Form in Server ModeRelated Questions1Solution