locked
Experts opinion using custom Previous/Next Button RRS feed

  • Question

  • Hi,

    I have already tried using custom add/previous button in a detail screen and it works  fine.  I also tried it in a list and detail screen and also worked as expected. 

    New scenario is:  I redesigned my ClientDetailScreen by following this video How Do I: Create a Screen that can Both Edit and Add Records in a LightSwitch Application?.   (screen shot below)

    This is a screen that can both add and edit using "New Data" screen template.  I have observed that when I using a "Detail Screen" and "List and Detail" there's a query parameter that was automatically created (in this case "BusinessTableId"). Does, when using this code it works fine.

     
    Private Sub NextRecord_Execute()
                ' Write your code here.
                Dim NextRecord = Me.DataWorkspace.ApplicationData.BusinessTables.Where(Function(x) x.Id > Me.BusinessTable.Id).OrderBy(Function(x) x.Id).FirstOrDefault()
                If NextRecord IsNot Nothing Then
                    Me.BusinessTableId = NextRecord.Id
                End If
    
            End Sub

    I understand well that using "New Data" screen template does not provide that table query paramemter for its just adding new record and simply doesn't connect to any screen control.  But, in my case where I employed this screen template as "ADD/EDIT" and "DETAIL" as one,  how can I achieve scrolling in my records using customized Next/Previous button?

          

    Nante


    Friday, April 5, 2013 2:59 AM

Answers

  • Hi,

    After a painful 12-hours of waiting and analyzing the problem, I took a nap and suddenly I'm in the state of "Ahaaa!".  That "Local property parameter" I assigned to track the record Id from the database should be hooked to the screen "TableProperty". I finally got it working.


    The problem I'm facing now is how to skip those records that were deleted before?  I understand that records are not actually deleted, they are just marked as deleted in the database.  In VisualFoxpro we use "Pack" command to get rid of those deleted items from the database. 
    • Edited by RKage Sunday, April 7, 2013 1:54 AM
    • Proposed as answer by Yann DuranModerator Monday, April 8, 2013 2:27 AM
    • Marked as answer by Angie Xu Wednesday, April 24, 2013 8:18 AM
    Sunday, April 7, 2013 1:15 AM
  • Glad you got the first bit sorted. I thought you had already hooked up the two, which is why I wasn't sure where you were having a problem.

    As for the other question, I guess you aren't saving the data in between edits. When you delete a record and save the data, it does get deleted from the database. Before saving they are marked as deleted.

    If this is the case, then all you need to do is modify the code you have that moves to the next record. You are just grabbing the record in the database, ordered by ID. What you would need to do is check the status as well. Your code would then look something like this...

    Dim NextRecord = Me.DataWorkspace.ApplicationData.BusinessHeaderTable
      .Where(Function(x) x.Id > Me.BusinessHeaderTable.Id And x.Details.EntityState != EntityState.Deleted)
      .OrderBy(Function(x) x.Id)
      .FirstOrDefault()

    Note that I wrote my code in C# and manually translated it into VB, so you may need to check I got the syntax right.

    Hope this helps.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    • Proposed as answer by Yann DuranModerator Monday, April 8, 2013 2:27 AM
    • Marked as answer by Angie Xu Wednesday, April 24, 2013 8:18 AM
    Sunday, April 7, 2013 2:01 PM

All replies

  • If you have an add/edit screen, then it should have an ID property, as that is needed when editing. Depending on how you set up the screen, you should be able to use this the same way as you showed.

    You would have to remember that if you are adding a new record, then the ID will be zero before you save, so the record won't be in the list, but that shouldn't cause any problems.

    Does that help? If not, please give more details as to how you set up your add/edit screen, as without that, it's hard to advise.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    Friday, April 5, 2013 2:22 PM
  • Hi Mr. Yossu,

    If you watch the video by Beth " http://msdn.microsoft.com/en-us/vstudio/ff945359 ", its similar approach I did in my detail screen.  I used a "New Data" screen template as a "Detail Screen".  When clicking a record from "search Screen"  it opens the "New Data" screen with the record details in it.  From there, I need to scroll the records using next/previous button. 

    To show the situation, I created a test detail screen and new data screen which are shown below.

    DETAIL SCREEN:

     Notice that "BusinessHeaderTableId" screen parameter is automatically produced which I need in scroll button using this code:

    Private Sub NextRecord_Execute()
               
    ' Write your code here.
               
    Dim NextRecord = Me.DataWorkspace.ApplicationData.BusinessHeaderTable.Where(Function(x) x.Id > Me.BusinessHeaderTable.Id).OrderBy(Function(x) x.Id).FirstOrDefault()
               
    If NextRecord IsNot Nothing Then
                   
    Me.BusinessHeaderTableId = NextRecord.Id
               
    End If

           
    End Sub

    Now in New "Data Screen" used as detail screen:

    No TableId parameter is produced thereby using the  code is not possible.  Maybe because "New Data" screen does not directly fetching a record from the database.

    I don't know if this explains well my situation but, if you are to use Beth's Add/Edit/Detail screen with an additional function button of scrolling the records,  what would be the best approach?

    Nante


    • Edited by RKage Saturday, April 6, 2013 7:29 AM
    Saturday, April 6, 2013 7:28 AM
  • Hi,

    After a painful 12-hours of waiting and analyzing the problem, I took a nap and suddenly I'm in the state of "Ahaaa!".  That "Local property parameter" I assigned to track the record Id from the database should be hooked to the screen "TableProperty". I finally got it working.


    The problem I'm facing now is how to skip those records that were deleted before?  I understand that records are not actually deleted, they are just marked as deleted in the database.  In VisualFoxpro we use "Pack" command to get rid of those deleted items from the database. 
    • Edited by RKage Sunday, April 7, 2013 1:54 AM
    • Proposed as answer by Yann DuranModerator Monday, April 8, 2013 2:27 AM
    • Marked as answer by Angie Xu Wednesday, April 24, 2013 8:18 AM
    Sunday, April 7, 2013 1:15 AM
  • Glad you got the first bit sorted. I thought you had already hooked up the two, which is why I wasn't sure where you were having a problem.

    As for the other question, I guess you aren't saving the data in between edits. When you delete a record and save the data, it does get deleted from the database. Before saving they are marked as deleted.

    If this is the case, then all you need to do is modify the code you have that moves to the next record. You are just grabbing the record in the database, ordered by ID. What you would need to do is check the status as well. Your code would then look something like this...

    Dim NextRecord = Me.DataWorkspace.ApplicationData.BusinessHeaderTable
      .Where(Function(x) x.Id > Me.BusinessHeaderTable.Id And x.Details.EntityState != EntityState.Deleted)
      .OrderBy(Function(x) x.Id)
      .FirstOrDefault()

    Note that I wrote my code in C# and manually translated it into VB, so you may need to check I got the syntax right.

    Hope this helps.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    • Proposed as answer by Yann DuranModerator Monday, April 8, 2013 2:27 AM
    • Marked as answer by Angie Xu Wednesday, April 24, 2013 8:18 AM
    Sunday, April 7, 2013 2:01 PM