Connecting the Forms to the Data-Layer (part 7)
Here is the entire Galaxy Code Sheet:
Define quitfrmGalaxy
Declare GalaxyCustom()
Declare GalaxySetScreen()
Declare GalaxyCreate()
Declare GalaxyModify(GalaxyID.i)
Declare GalaxyDelete(GalaxyID.i)
Declare GalaxySetData()
Declare GalaxySave()
Declare GalaxyClose()
Procedure GalaxySetScreen()
Protected String$, x, y, w, h, ID
Shared WorkGalaxy
Protected EventID, MenuID, GadgetID, WindowID, Index
Shared quitfrmGalaxy
quitfrmGalaxy = #False
If Window_frmGalaxy()
DisableWindow(#Window_frmMain, #True)
SetActiveWindow(#Window_frmGalaxy)
GalaxyCustom()
SetGadgetText(#Gadget_frmGalaxy_txtName, WorkGalaxy\Name)
SetActiveGadget(#Gadget_frmGalaxy_txtName)
;Set Screen Data
GALAXY::LoadListIcon(#Gadget_frmGalaxy_liSolarsystems)
If ListEx::CountItems(#Gadget_frmGalaxy_liSolarsystems) > 0
ListEx::SetState(#Gadget_frmGalaxy_liSolarsystems, 0)
EndIf
Repeat
EventID =WaitWindowEvent()
MenuID =EventMenu()
GadgetID =EventGadget()
WindowID =EventWindow()
Select EventID
Case #PB_Event_CloseWindow
Select WindowID
Case #Window_frmGalaxy
GalaxyClose()
EndSelect
Case #PB_Event_Menu
Select WindowID
EndSelect
Case #PB_Event_Gadget
Select GadgetID
;*************************************
;**** Start frmGalaxy
;*************************************
Case #Gadget_frmGalaxy_lbName
Case #Gadget_frmGalaxy_txtName
Select EventType()
Case #PB_EventType_Focus
Default
EndSelect
Case #Gadget_frmGalaxy_lbSolarsystems
Case #Gadget_frmGalaxy_liSolarsystems
Select EventType()
Case #PB_EventType_LeftDoubleClick
PostEvent(#PB_Event_Gadget, #Window_frmGalaxy, #Gadget_frmGalaxy_btModify, #PB_EventType_LeftClick)
EndSelect
Case #Gadget_frmGalaxy_btCreate
Select EventType()
Case #PB_EventType_LeftClick
SolarSystemCreate()
EndSelect
Case #Gadget_frmGalaxy_btModify
Select EventType()
Case #PB_EventType_LeftClick
Index=ListEx::GetState(#Gadget_frmGalaxy_liSolarsystems)
If Index>-1
SolarSystemModify()
Else
MessageRequester("Blog", "Please Select a Record To MODIFY!")
EndIf
EndSelect
Case #Gadget_frmGalaxy_btDelete
Select EventType()
Case #PB_EventType_LeftClick
Index=ListEx::GetState(#Gadget_frmGalaxy_liSolarsystems)
If Index>-1
SolarSystemDelete()
Else
MessageRequester("Blog", "Please Select a Record To DELETE!")
EndIf
EndSelect
Case #Gadget_frmGalaxy_btSave
Select EventType()
Case #PB_EventType_LeftClick
GalaxySave()
EndSelect
Case #Gadget_frmGalaxy_btCancel
Select EventType()
Case #PB_EventType_LeftClick
GalaxyClose()
EndSelect
EndSelect
EndSelect
Until quitfrmGalaxy = #True
CloseWindow(#Window_frmGalaxy)
EndIf
EndProcedure
Procedure GalaxyCreate()
Shared WorkGalaxy
GALAXY::Init(@WorkGalaxy)
GalaxySetScreen()
EndProcedure
Procedure GalaxyModify(GalaxyID.i)
Shared WorkGalaxy
GALAXY::Find(GalaxyID , @WorkGalaxy)
GalaxySetScreen()
EndProcedure
Procedure GalaxyDelete(GalaxyID.i)
Protected Index, Result, itemCount
Index = ListEx::GetState(#Gadget_frmMain_liList)
DisableWindow(#Window_frmMain, #True)
Shared WorkGalaxy
GALAXY::Find(GalaxyID , @WorkGalaxy)
MessageRequester("Delete Confirmation", "Are you SURE you want To DELETE this Record ?", #PB_MessageRequester_YesNo )
If Result = #PB_MessageRequester_Yes
If GALAXY::Delete(@WorkGalaxy) = #True
ListEx::RemoveItem(#Gadget_frmMain_liList, Index)
itemCount.i = ListEx::CountItems(#Gadget_frmMain_liList)-1
If itemCount>0
ListEx::SetState(#Gadget_frmMain_liList, 0)
EndIf
EndIf
EndIf
DisableWindow(#Window_frmMain, #False)
EndProcedure
Procedure GalaxySetData()
Protected Index
Shared WorkGalaxy
WorkGalaxy\Name = GetGadgetText(#Gadget_frmGalaxy_txtName)
EndProcedure
Procedure GalaxySave()
Shared WorkGalaxy
Protected State = WorkGalaxy\State
GalaxySetData()
;Save to Database
If Galaxy::Save(@WorkGalaxy) = #True
If State = DB::#New ;insert record
ListEx::AddItem(#Gadget_frmMain_liList,-1, WorkGalaxy\Name, "", 0)
ListEx::SetItemData(#Gadget_frmMain_liList, ListEx::CountItems(#Gadget_frmMain_liList)-1, WorkGalaxy\ID)
ListEx::SetState(#Gadget_frmMain_liList , ListEx::CountItems(#Gadget_frmMain_liList)-1)
Else ;update selected record
ListEx::SetItemText(#Gadget_frmMain_liList, ListEx::GetState(#Gadget_frmMain_liList), WorkGalaxy\Name,0)
EndIf
GalaxyClose()
EndIf
EndProcedure
Procedure GalaxyClose()
Shared quitfrmGalaxy
If IsWindow(#Window_frmMain)
SetActiveWindow(#Window_frmMain)
DisableWindow(#Window_frmMain, #False)
EndIf
quitfrmGalaxy = #True
EndProcedure
Procedure GalaxyCustom()
Define X, Y, W, H, Flags
;Convert the LidtIcinGadget to ListEX Custom Gadget
X = GadgetX(#Gadget_frmGalaxy_liSolarsystems) : Y = GadgetY(#Gadget_frmGalaxy_liSolarsystems)
W = GadgetWidth(#Gadget_frmGalaxy_liSolarsystems) : H = GadgetHeight(#Gadget_frmGalaxy_liSolarsystems)
FreeGadget(#Gadget_frmGalaxy_liSolarsystems)
;Now to create oue ListEx
Flags = ListEx::#AdjustColumns|ListEx::#ResizeColumn|ListEx::#GridLines;|ListEx::#AutoResize
ListEx::Gadget(#Gadget_frmGalaxy_liSolarsystems, X, Y, W, H, "", 25, "", Flags, #Window_frmMain)
EndProcedure
Comments
Post a Comment