open-insight/LSL2/STPROC/WIN_CHECK_REQ_FIELDS.txt
Infineon\StieberD 7762b129af pre cutover push
2024-09-04 20:33:41 -07:00

132 lines
4.9 KiB
Plaintext

Function Win_Check_Req_Fields(WinID, TabControl)
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
//
// This program is proprietary and is not to be used by or disclosed to others, nor is it to
// be copied without written permission from SRP Computer Solutions, Inc.
//
// Name : Win_Check_Req_Fields
//
// Description: Checks the Required fields of a window to make sure they have data entered.
//
// Notes: Currently, this only works with controls with TEXT properties and
// non-Edittables. Follow the examples below to hook this on to other windows.
// Also include the following line in the Window Case statement in the
// Promoted_Write_Event (Pre section):
//
// EventFlow = Win_Check_Req_Fields(@Window)
//
// It will automatically try and pull the STA_ controls text information. If no
// static control exists, then it will use the control name after re-formating it.
//
// Parameters:
// WinID [in] -- The window being validated. If blank, @WINDOW will be used.
// TabControl [in] -- The name of the Tab control that is associated with each window
// page. Not applicable with single-page forms.
// EventFlow [out] -- Event flow status variable. See EVENT_SETUP insert for more
// information on how this works.
//
// History (Date, Initials, Notes)
// 09/21/01 pcs Original programmer
// 12/06/05 dmb Updated code to support the OLE Tab control. Minor code clean up.
// 12/14/05 dmb Check IOOPTIONS<10> first before executing code.
//
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
If Assigned(WinID) else WinID = @Window
If Assigned(TabControl) else TabControl = ".OLE_TAB" ; // If no tab control is passed, this one will be assumed.
$insert SRP_APP_INSERTS
$insert SRP_EVENT_SETUP
$insert MSG_EQUATES
$insert OIWin_Comm_Init
Declare Subroutine First_Caps
Process = 1
Done = No$
// Only execute if required fields are checked during the WRITE event.
IOOptions = Get_Property(@Window, "IOOPTIONS")
If IOOptions<10> NE Yes$ then Done = Yes$
Loop
If Process GT 2 then Done = Yes$
Until Done
On Process GoSub Init_Vars, Process_Window
Process += 1
Repeat
If Assigned(EventFlow) else EventFlow = EVENT_CONTINUE$
Return EventFlow
Init_Vars:
TrueNames = ""
ReqFields = ""
CntrlSemantics = ControlSemantics@
ControlList = ControlList@
NumItems = Count(CntrlSemantics, @FM) + (CntrlSemantics NE "")
For ItemLoop = 1 to NumItems
If CntrlSemantics<ItemLoop, 17, 1> then
CurControl = ControlList<ItemLoop, 1>
ReqFields<-1> = CurControl
StartPos = Index(CurControl, ".", 1)
STAName = CurControl
STAName[(StartPos + 1), 3] = "STA"
CurTrueText = Get_Property(STAName, "TEXT")
If CurTrueText EQ "" then
CurTrueText = CurControl[(StartPos + 5), 999]
Swap "_" with " " in CurTrueText
First_Caps("", CurTrueText, "", NewText)
CurTrueText = NewText
end
TrueNames<-1> = CurTrueText
end
Next ItemLoop
If ReqFields EQ "" then
Done = Yes$
end
return
Process_Window:
MissingField = ""
CurFocus = ""
NumReqFields = Count(ReqFields, @FM) + (ReqFields NE "")
Count = 1
For ReqLoop = 1 to NumReqFields
CurReq = ReqFields<ReqLoop>
CurProp = Get_Property(CurReq, "DEFPROP")
If CurProp GT "" then
// Contains information. Continue.
end else
// Missing information. Flag for reminder.
If CurFocus = "" then
// Set Focus back into the first field.
CurFocus = CurReq
end
CurTrue = TrueNames<ReqLoop>
MissingField<-1> = Count:".)":Tab$:CurTrue
Count += 1
EventFlow = EVENT_STOP$
end
Next ReqLoop
If MissingField then
// Required fields are blank. Display error message.
Swap @FM with "|" in MissingField
MsgBody = "|Unable to save the record due to missing required information:||":MissingField:"|"
Set_Property("SYSTEM", "FOCUS", CurFocus)
If Get_Property(WinID:TabControl, "HANDLE") then
// A tab control that manages pages for this window exists. Reset so the appropriate tab has focus.
Page = Get_Property(WinID, "VPOSITION")<1>
Set_Property(WinID:TabControl, "OLE.SelectedTab", Page)
end
MsgTitle = "Missing Required Fields"
MsgStruct = ""
MsgStruct<MICON$> = "H"
Msg(WinID, MsgStruct, "OK", "", MsgTitle:@FM:MsgBody)
end
return