Connecting the Forms to the Data-Layer (part 9)
Here is the whole View Code Sheet
Define quitfrmSolarSystem
Declare SolarSystemCustom()
Declare SolarSystemSetScreen()
Declare SolarSystemCreate()
Declare SolarSystemModify()
Declare SolarSystemDelete()
Declare SolarSystemSetData()
Declare SolarSystemSave()
Declare SolarSystemClose()
Procedure SolarSystemSetScreen()
Protected String$, x, y, w, h, i, ID
Shared WorkSolarSystem
Protected EventID, MenuID, GadgetID, WindowID, Index
Shared quitfrmSolarSystem
quitfrmSolarSystem = #False
If Window_frmSolarSystem()
SolarSystemCustom()
SetActiveWindow(#Window_frmSolarSystem)
;Set Screen Data
SetGadgetText(#Gadget_frmSolarSystem_txtName, WorkSolarSystem\Name)
SetGadgetText(#Gadget_frmSolarSystem_txtGrow, Str(WorkSolarSystem\GRow))
SetGadgetText(#Gadget_frmSolarSystem_txtGCol, Str(WorkSolarSystem\GCol))
SetActiveGadget(#Gadget_frmSolarSystem_txtName)
Repeat
EventID =WaitWindowEvent()
MenuID =EventMenu()
GadgetID =EventGadget()
WindowID =EventWindow()
Select EventID
Case #PB_Event_CloseWindow
Select WindowID
Case #Window_frmSolarSystem
SolarSystemClose()
EndSelect
Case #PB_Event_Menu
Select WindowID
EndSelect
Case #PB_Event_Gadget
Select GadgetID
;*************************************
;**** Start frmSolarSystem
;*************************************
Case #Gadget_frmSolarSystem_lbName
Case #Gadget_frmSolarSystem_txtName
Select EventType()
Case #PB_EventType_Focus
Default
EndSelect
Case #Gadget_frmSolarSystem_lbGRow
Case #Gadget_frmSolarSystem_txtGrow
Select EventType()
Case #PB_EventType_Focus
Default
EndSelect
Case #Gadget_frmSolarSystem_lbGCol
Case #Gadget_frmSolarSystem_txtGCol
Select EventType()
Case #PB_EventType_Focus
Default
EndSelect
Case #Gadget_frmSolarSystem_btSave
Select EventType()
Case #PB_EventType_LeftClick
SolarSystemSave()
EndSelect
Case #Gadget_frmSolarSystem_btCancel
Select EventType()
Case #PB_EventType_LeftClick
SolarSystemClose()
EndSelect
EndSelect
EndSelect
Until quitfrmSolarSystem = #True
CloseWindow(#Window_frmSolarSystem)
EndIf
EndProcedure
Procedure SolarSystemCreate()
Shared WorkSolarSystem
DisableWindow(#Window_frmGalaxy, #True)
SOLARSYSTEM::Init(@WorkSolarSystem)
SolarSystemSetScreen()
EndProcedure
Procedure SolarSystemModify()
Protected Index
Index = GetGadgetState(#Gadget_frmGalaxy_liSolarsystems)
Shared WorkGalaxy
Shared WorkSolarSystem
DisableWindow(#Window_frmGalaxy, #True)
If Index > -1
SelectElement(WorkGalaxy\SolarSystemCollection(), Index)
WorkSolarSystem = WorkGalaxy\SolarSystemCollection()
If WorkSolarSystem\State = DB::#New Or WorkSolarSystem\State = DB::#NewDirty
WorkSolarSystem\State = DB::#NewDirty
Else
WorkSolarSystem\State = DB::#Dirty
EndIf
SolarSystemSetScreen()
EndIf
EndProcedure
Procedure SolarSystemDelete()
Protected Index, Result
Shared WorkGalaxy
Shared WorkSolarSystem
DisableWindow(#Window_frmGalaxy, #True)
Index = ListEx::GetState(#Gadget_frmGalaxy_liSolarsystems)
If Index > -1
Result = MessageRequester("Delete Confirmation", "Are you SURE you want To DELETE this Record ?", #PB_MessageRequester_YesNo)
If Result = #PB_MessageRequester_Yes
SelectElement(WorkGalaxy\SolarSystemCollection(), Index)
WorkSolarSystem = WorkGalaxy\SolarSystemCollection()
DeleteElement(WorkGalaxy\SolarSystemCollection())
If WorkSolarSystem\State <> DB::#New And WorkSolarSystem\State <> DB::#NewDirty
AddElement(WorkGalaxy\DeleteSolarSystemCollection())
WorkGalaxy\DeleteSolarSystemCollection() = WorkSolarSystem
EndIf
Index = ListEx::GetState(#Gadget_frmGalaxy_liSolarsystems)
EndIf
DisableWindow(#Window_frmGalaxy, #False)
EndIf
EndProcedure
Procedure SolarSystemSetData()
Protected Index
Shared WorkSolarSystem
WorkSolarSystem\Name = GetGadgetText(#Gadget_frmSolarSystem_txtName)
WorkSolarSystem\GRow = Val(GetGadgetText(#Gadget_frmSolarSystem_txtGrow))
WorkSolarSystem\GCol = Val(GetGadgetText(#Gadget_frmSolarSystem_txtGCol))
EndProcedure
Procedure SolarSystemSave()
Protected Index, State
Shared WorkGalaxy
Shared WorkSolarSystem
Index = GetGadgetState(#Gadget_frmGalaxy_liSolarsystems)
State = WorkSolarSystem\State
SolarSystemSetData()
If SOLARSYSTEM::Validate(WorkSolarSystem)
If State = DB::#New Or State = DB::#NewDirty
;ADD to Collection
LastElement(WorkGalaxy\SolarSystemCollection())
AddElement(WorkGalaxy\SolarSystemCollection())
WorkGalaxy\SolarSystemCollection()=WorkSolarSystem
ListEx::AddItem(#Gadget_frmGalaxy_liSolarsystems,-1, GALAXY::ListIconItemSolarSystem(@WorkSolarSystem), "", 0)
ListEx::SetState(#Gadget_frmGalaxy_liSolarsystems , ListEx::CountItems(#Gadget_frmGalaxy_liSolarsystems)-1)
Else
ListEx::SetItemText(#Gadget_frmGalaxy_liSolarsystems, Index, GALAXY::ListIconItemSolarSystem(@WorkSolarSystem), 0)
SelectElement(WorkGalaxy\SolarSystemCollection(), Index)
WorkGalaxy\SolarSystemCollection()=WorkSolarSystem
EndIf
SolarSystemClose()
EndIf
EndProcedure
Procedure SolarSystemClose()
Shared quitfrmSolarSystem
If IsWindow(#Window_frmGalaxy)
SetActiveWindow(#Window_frmGalaxy)
DisableWindow(#Window_frmGalaxy, #False)
EndIf
quitfrmSolarSystem = #True
EndProcedure
Procedure SolarSystemCustom()
EndProcedure
Comments
Post a Comment