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

 This is the whole Desktop Code Sheet


;/ Created with PureVision64 v6.01 x64
;/ Thu, 05 Oct 2023 18:19:52
;/ by Peter Hollyer             




XIncludeFile "Blog_Constants.pb"
XIncludeFile "Blog_Windows.pb"

XIncludeFile "Utils/ComboBoxExModule.pbi"
XIncludeFile "Utils/ListExModule.pbi"

XIncludeFile "Models/DB.pbi"
XIncludeFile "Models/SolarSystem.pbi"
XIncludeFile "Models/Galaxy.pbi"

Global WorkGalaxy.GALAXY::Galaxy
Global WorkSolarSystem.SOLARSYSTEM::SolarSystem

XIncludeFile "Views/frmSolarSystem.pbi"
XIncludeFile "Views/frmGalaxy.pbi"

Declare frmMainCustom()


;- Main Loop
If Window_frmMain()
  frmMainCustom()
  Define Index, ID
  
  ;This Loads the ListIcon with all Galaxies in the Database
  GALAXY::LoadListIcon(#Gadget_frmMain_liList)
  
  ;If there ARE Records select the First
  If ListEx::CountItems(#Gadget_frmMain_liList) > 0
    ListEx::SetState(#Gadget_frmMain_liList, 0)
  EndIf
  
  
  Define quitfrmMain=0
  Repeat
    EventID  =WaitWindowEvent()
    MenuID   =EventMenu()
    GadgetID =EventGadget()
    WindowID =EventWindow()

    Select EventID
      Case #PB_Event_CloseWindow
        Select WindowID
          Case #Window_frmMain
            quitfrmMain=1
        EndSelect

       Case #PB_Event_Gadget
        Select GadgetID
          Case #Gadget_frmMain_ctrToolbar
            Select EventType()
              Case #PB_EventType_Resize
              Default
            EndSelect
          Case #Gadget_frmMain_ctrLeft
            Select EventType()
              Case #PB_EventType_Resize
              Default
            EndSelect
          Case #Gadget_frmMain_liList
            Select EventType()
              Case #PB_EventType_LeftDoubleClick
                PostEvent(#PB_Event_Gadget, #Window_frmMain, #Gadget_frmMain_btModify, #PB_EventType_LeftClick)
              Default
            EndSelect
          Case #Gadget_frmMain_btCreate
            Select EventType()
              Case #PB_EventType_LeftClick
                GalaxyCreate()
              Default
            EndSelect
          Case #Gadget_frmMain_btModify
            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
          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
          Case #Gadget_frmMain_btPower
            Select EventType()
              Case #PB_EventType_LeftClick
                 quitfrmMain = #True
              Default
            EndSelect
        EndSelect

    EndSelect
  Until quitfrmMain
  CloseWindow(#Window_frmMain)
EndIf
End


Procedure frmMainCustom()
  Protected X, Y, w, H, Flags
  ;I put the List in a Container so we must open container Gadget List
  OpenGadgetList(#Gadget_frmMain_ctrLeft)
    ;Convert the LidtIcinGadget to ListEX Custom Gadget
    X = GadgetX(#Gadget_frmMain_liList)     : Y = GadgetY(#Gadget_frmMain_liList)
    W = GadgetWidth(#Gadget_frmMain_liList) : H = GadgetHeight(#Gadget_frmMain_liList)
    FreeGadget(#Gadget_frmMain_liList)
    ;Now to create oue ListEx
    Flags = ListEx::#AdjustColumns|ListEx::#ResizeColumn|ListEx::#GridLines;|ListEx::#AutoResize
    ListEx::Gadget(#Gadget_frmMain_liList, X, Y, W, H, "", 25, "", Flags, #Window_frmMain)
  CloseGadgetList()
  ;Other exchanges we could do are to swap out Buttons, ComboBox to ComboBoxEx
  ;This is where we can theme your application
EndProcedure


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)