Connecting Forms to Data-Layer (part 4)

 Now we will finish out our frmMain or our Application Desk Top 

Scrolling down our Control loop we get to the section with out List of Galaxies, and our Create, Modify, Delete Buttons.

Our first change will be to the List, specifically we want the default behavior of Double-Clicking an Item in our list to be "Modify". To accomplish this, we insert a PostEvent command which will Left-Click the the Modify Button for us.


          Case #Gadget_frmMain_liList
            Select EventType()
              Case #PB_EventType_LeftDoubleClick
                PostEvent(#PB_Event_Gadget, #Window_frmMain, #Gadget_frmMain_btModify, #PB_EventType_LeftClick)
              Default
            EndSelect

Next we Come to the Create Button, Here we want to call our GalaxyCreate Method.


          Case #Gadget_frmMain_btCreate
            Select EventType()
              Case #PB_EventType_LeftClick
                GalaxyCreate()
              Default
            EndSelect

Here is our FIRST Reference to the View Code, or Code Behind the Form, I'll Jump to that code in a moment. First let us finish the Code here in the Control-Loop.  We have the Modify and Delete Buttons:


            Select EventType()
              Case #PB_EventType_LeftClick
                Index = ListEx::GetState(#Gadget_frmMain_liList)
                If Index > -1
                  ID = ListEx::GetItemData(#Gadget_frmMain_liList, Index)
                  GalaxyDelete(ID)
                Else
                  MessageRequester("Blog", "Please select a Galaxy to MODIFY!")
                EndIf
              Default
            EndSelect

In the Modify, we first need to make sure that the User has selected a Record, If Not then tell them of their mistake, If they Have selected a Record then we retrieve the Record ID from the ItemData Property of the selected record and once again call our View Code GalaxyModify Procedure passing it the ID.


          Case #Gadget_frmMain_btDelete
            Select EventType()
              Case #PB_EventType_LeftClick
                Index = ListEx::GetState(#Gadget_frmMain_liList)
                If Index > -1
                  ID = ListEx::GetItemData(#Gadget_frmMain_liList, Index)
                  GalaxyDelete(ID)
                Else
                  MessageRequester("Blog", "Please select a Galaxy to DELETE!")
                EndIf
              Default
            EndSelect

In the Delete, we ance again need to make sure that the User has selected a Record, If Not then tell them of their mistake, If they Have selected a Record then we retrieve the Record ID from the ItemData Property of the selected record and once again call our View Code GalaxyDelete Procedure passing it the ID.

And finally, we have the Power Button.


          Case #Gadget_frmMain_btPower
            Select EventType()
              Case #PB_EventType_LeftClick
                 quitfrmMain = #True
              Default
            EndSelect

So here is to Complete Code of the Desktop Form. We will picup the next Post on the Galaxy View Code.

++++++++++++++++++++++






Comments

Popular posts from this blog

Connecting the Forms to the Data-Layer (part 1)

Module DB, the foundation of any Data Layer.

Defining Database Tables (part 1)