Add GRO Event.fh_lua--[[
@Title: Add GRO Event
@Author: Rodney Begg (from the original by Jane Taubman)
@LastUpdated: May 2012
@Version: 1.0.3
@Description: Add A GRO Event to an Individual and optionally create the event and or set the fields.
]]
-- Version Info:
-- 1.0 Original Version directly converted from Jane's code.
-- 1.0.1 Modified code to append Registration Data to Note Field if Note Field already populated
-- No validation on Note Field data contents is performed.
-- Modified code to replace more imprecise dates (calculated and approximate) with the Quarter Date
-- Absolute dates are untouched.
-- 1.0.2 Modified code to deal with the case where a year date only is in the Date field (1847)
-- - it is now replaced with the Quarter Date.
-- 1.0.3 Replaced getFams(ptr) function after over enthusiastic pruning in previous release :(
function getFamS(ptr)
local famsList = {}
local ptrFam = fhNewItemPtr()
local ptrFamR = fhNewItemPtr()
ptrFam:MoveTo(ptr,'~.FAMS')
while ptrFam:IsNotNull() do
ptrFamR = fhGetValueAsLink(ptrFam)
table.insert(famsList,ptrFamR:Clone())
ptrFam:MoveNext('SAME_TAG')
end
return famsList
end
---------------------------------------------------------------Main Code
require("iuplua")
-- Set up Defaults
period = {'Q1 Jan-Feb-Mar','Q2 Apr-May-Jun','Q3 Jul-Aug-Sep','Q4 Oct-Nov-Dec','January','February','March','April','May','June','July','August',
'September','October','November','December'}
strPeriod = table.concat(period,'|')..'|'
shortperiod = {'Q1','Q2','Q3','Q4','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'}
PromptDialogStr =
[[
%t
GRO Index Type: %l|Birth|Marriage|Death|
Year: %i
Quarter: %l|{strPeriod}
Registration District: %s
Reference: %s
]]
PromptDialogStr = PromptDialogStr:gsub('{strPeriod}',strPeriod)
-- Get Current Record if Available
ptrList = fhGetCurrentRecordSel('INDI')
if #ptrList == 1 then
strName = 'Current Record:'..fhGetItemText(ptrList[1],'~.NAME')..' ('..fhCallBuiltInFunction('LifeDates',ptrList[1])..')'
else
strName = '?'
end
ptype = 0
pqtr = 0
pdistrict = ''
pref = ' '
pyear = 0
events = {'BIRT','MARR','DEAT'}
GROType = {'Birth','Marriage','Death'}
dtDate = fhNewDate()
-- Get GRO Information
ret, ptype,pyear, pqtr,pdistrict,pref =
iup.GetParam("Add GRO Entry", param_action,
strName..PromptDialogStr,
ptype,pyear, pqtr,pdistrict,pref)
-- Check for Cancel
if not(ret) then
return
end
-- Set Variables
event = ptype + 1
qtr = period[pqtr + 1]
-- Allocate to Current Record
if (ptype == 1) then
ptrList = fhGetCurrentRecordSel('FAM')
if #ptrList == 0 then
ptrList = fhGetCurrentRecordSel('INDI')
if #ptrList == 1 then
ptrList = getFamS(ptrList[1])
end
end
if #ptrList ~= 1 then
ptrList = fhPromptUserForRecordSel('FAM',1)
end
else
ptrList = fhGetCurrentRecordSel('INDI')
if #ptrList ~= 1 then
ptrList = fhPromptUserForRecordSel('INDI',1)
end
end
if #ptrList == 0 then
error("No Record Selected - Process Aborted")
end
ptrEvent = fhNewItemPtr()
ptrField = fhNewItemPtr()
ptrEvent:MoveTo(ptrList[1],'~.'..events[event])
if ptrEvent:IsNull() then
-- Create Event
ptrEvent = fhCreateItem(events[event],ptrList[1])
end
ptrField:MoveTo(ptrEvent,'~.DATE')
if ptrField:IsNull() then
ptrField = fhCreateItem('DATE',ptrEvent)
end
dtDate = fhGetValueAsDate(ptrField)
strDate = fhGetDisplayText(ptrField)
if (dtDate:IsNull())or (string.match(strDate,"%)", -1) ~= nil) or (string.len(strDate) == 10) then
dtDate:SetValueAsText(shortperiod[pqtr + 1]..' '..pyear)
fhSetValueAsDate(ptrField,dtDate)
end
ptrField:MoveTo(ptrEvent,'~.NOTE2')
if ptrField:IsNull() then
ptrField = fhCreateItem('NOTE2',ptrEvent)
end
noteValue = fhGetValueAsText(ptrField)
if noteValue == '' then
fhSetValueAsText(ptrField,'Registered in '..pdistrict..' District, '..pref)
else
fhSetValueAsText(ptrField,noteValue..'\nRegistered in '..pdistrict..' District, '..pref)
end
-- Check Data
ptrField:MoveTo(ptrEvent,'~.DATE')
strResult = fhCallBuiltInFunction('GetDataWarning',ptrField,1)
if strResult ~= '' then
strButton = fhMessageBox(strResult..'\nDo you wish to undo the entry','MB_YESNO','MB_ICONEXCLAMATION')
if strButton == "Yes" then
error('Data Validation Failed')
end
end
--[[
@Title: Add GRO Event
@Author: Rodney Begg (from the original by Jane Taubman)
@LastUpdated: May 2012
@Version: 1.0.3
@Description: Add A GRO Event to an Individual and optionally create the event and or set the fields.
]]
-- Version Info:
-- 1.0 Original Version directly converted from Jane's code.
-- 1.0.1 Modified code to append Registration Data to Note Field if Note Field already populated
-- No validation on Note Field data contents is performed.
-- Modified code to replace more imprecise dates (calculated and approximate) with the Quarter Date
-- Absolute dates are untouched.
-- 1.0.2 Modified code to deal with the case where a year date only is in the Date field (1847)
-- - it is now replaced with the Quarter Date.
-- 1.0.3 Replaced getFams(ptr) function after over enthusiastic pruning in previous release :(
function getFamS(ptr)
local famsList = {}
local ptrFam = fhNewItemPtr()
local ptrFamR = fhNewItemPtr()
ptrFam:MoveTo(ptr,'~.FAMS')
while ptrFam:IsNotNull() do
ptrFamR = fhGetValueAsLink(ptrFam)
table.insert(famsList,ptrFamR:Clone())
ptrFam:MoveNext('SAME_TAG')
end
return famsList
end
---------------------------------------------------------------Main Code
require("iuplua")
-- Set up Defaults
period = {'Q1 Jan-Feb-Mar','Q2 Apr-May-Jun','Q3 Jul-Aug-Sep','Q4 Oct-Nov-Dec','January','February','March','April','May','June','July','August',
'September','October','November','December'}
strPeriod = table.concat(period,'|')..'|'
shortperiod = {'Q1','Q2','Q3','Q4','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'}
PromptDialogStr =
[[
%t
GRO Index Type: %l|Birth|Marriage|Death|
Year: %i
Quarter: %l|{strPeriod}
Registration District: %s
Reference: %s
]]
PromptDialogStr = PromptDialogStr:gsub('{strPeriod}',strPeriod)
-- Get Current Record if Available
ptrList = fhGetCurrentRecordSel('INDI')
if #ptrList == 1 then
strName = 'Current Record:'..fhGetItemText(ptrList[1],'~.NAME')..' ('..fhCallBuiltInFunction('LifeDates',ptrList[1])..')'
else
strName = '?'
end
ptype = 0
pqtr = 0
pdistrict = ''
pref = ' '
pyear = 0
events = {'BIRT','MARR','DEAT'}
GROType = {'Birth','Marriage','Death'}
dtDate = fhNewDate()
-- Get GRO Information
ret, ptype,pyear, pqtr,pdistrict,pref =
iup.GetParam("Add GRO Entry", param_action,
strName..PromptDialogStr,
ptype,pyear, pqtr,pdistrict,pref)
-- Check for Cancel
if not(ret) then
return
end
-- Set Variables
event = ptype + 1
qtr = period[pqtr + 1]
-- Allocate to Current Record
if (ptype == 1) then
ptrList = fhGetCurrentRecordSel('FAM')
if #ptrList == 0 then
ptrList = fhGetCurrentRecordSel('INDI')
if #ptrList == 1 then
ptrList = getFamS(ptrList[1])
end
end
if #ptrList ~= 1 then
ptrList = fhPromptUserForRecordSel('FAM',1)
end
else
ptrList = fhGetCurrentRecordSel('INDI')
if #ptrList ~= 1 then
ptrList = fhPromptUserForRecordSel('INDI',1)
end
end
if #ptrList == 0 then
error("No Record Selected - Process Aborted")
end
ptrEvent = fhNewItemPtr()
ptrField = fhNewItemPtr()
ptrEvent:MoveTo(ptrList[1],'~.'..events[event])
if ptrEvent:IsNull() then
-- Create Event
ptrEvent = fhCreateItem(events[event],ptrList[1])
end
ptrField:MoveTo(ptrEvent,'~.DATE')
if ptrField:IsNull() then
ptrField = fhCreateItem('DATE',ptrEvent)
end
dtDate = fhGetValueAsDate(ptrField)
strDate = fhGetDisplayText(ptrField)
if (dtDate:IsNull())or (string.match(strDate,"%)", -1) ~= nil) or (string.len(strDate) == 10) then
dtDate:SetValueAsText(shortperiod[pqtr + 1]..' '..pyear)
fhSetValueAsDate(ptrField,dtDate)
end
ptrField:MoveTo(ptrEvent,'~.NOTE2')
if ptrField:IsNull() then
ptrField = fhCreateItem('NOTE2',ptrEvent)
end
noteValue = fhGetValueAsText(ptrField)
if noteValue == '' then
fhSetValueAsText(ptrField,'Registered in '..pdistrict..' District, '..pref)
else
fhSetValueAsText(ptrField,noteValue..'\nRegistered in '..pdistrict..' District, '..pref)
end
-- Check Data
ptrField:MoveTo(ptrEvent,'~.DATE')
strResult = fhCallBuiltInFunction('GetDataWarning',ptrField,1)
if strResult ~= '' then
strButton = fhMessageBox(strResult..'\nDo you wish to undo the entry','MB_YESNO','MB_ICONEXCLAMATION')
if strButton == "Yes" then
error('Data Validation Failed')
end
end
Source:Add-GRO-Event3.fh_lua