package require java
proc getDatabaseHandle {sessionType} {
GuidoApp get_handle "GET DATABASE HANDLE"
$get_handle setParam sessionType $sessionType
set result [$get_handle invoke]
set dbHandle [$get_handle getParam "DatabaseHandle"]
$get_handle destroy
return $dbHandle
}
set clientManager [java::call com.surpac.client.ClientManager getSharedInstance]
set progressFeedback [java::new com.surpac.gui.ProgressDialog [$clientManager getActiveFrame] ]
$progressFeedback setAbortEnabled false
$progressFeedback { add String int} "Form loading - Please Wait" 99999
proc endProgressFeedback { } {
global progressFeedback
$progressFeedback {remove int} 99999
}
set dbType [lindex $argv 3]
set physicalDBType [lindex $argv 4]
set physicalDBType [string tolower $physicalDBType]
set databaseHandle [getDatabaseHandle $dbType]
set unrequiredField {}
set mandatoryFields {}
set num_unrequired_fields 0
set tableStructuresParam [GuidoExecServer "GetDatabaseTableStructures" {}]
set numTableTypes [GuidoGetParamBufferValue $tableStructuresParam num_table_types]
for {set idx 0} {$idx < $numTableTypes} {incr idx} {
set table_type "[GuidoGetParamBufferValue $tableStructuresParam table($idx).type]"
set table($table_type).num_mand_fields "[GuidoGetParamBufferValue $tableStructuresParam table($idx).num_mand_fields]"
upvar 0 table($table_type).num_mand_fields num_mand_fields
for {set jdx 0} {$jdx < $num_mand_fields} {incr jdx} {
set table($table_type).field($jdx).name "[GuidoGetParamBufferValue $tableStructuresParam table($idx).field($jdx).name]"
if {"[GuidoGetParamBufferValue $tableStructuresParam table($idx).field($jdx).required]" == "false"} {
set unrequired($num_unrequired_fields).name "[GuidoGetParamBufferValue $tableStructuresParam table($idx).field($jdx).name]"
lappend unrequiredField "[GuidoGetParamBufferValue $tableStructuresParam table($idx).field($jdx).name]"
incr num_unrequired_fields
} else {
lappend mandatoryFields "[GuidoGetParamBufferValue $tableStructuresParam table($idx).field($jdx).name]"
}
}
set table($table_type).num_indexes "[GuidoGetParamBufferValue $tableStructuresParam table($idx).num_indexes]"
upvar 0 table($table_type).num_indexes num_indexes
for {set jdx 0} {$jdx < $num_indexes} {incr jdx} {
set table($table_type).index($jdx).name "[GuidoGetParamBufferValue $tableStructuresParam table($idx).index($jdx).name]"
set table($table_type).index($jdx).unique "[GuidoGetParamBufferValue $tableStructuresParam table($idx).index($jdx).unique]"
set table($table_type).index($jdx).num_fields "[GuidoGetParamBufferValue $tableStructuresParam table($idx).index($jdx).num_fields]"
upvar 0 table($table_type).index($jdx).num_fields num_index_fields
for {set kdx 0} {$kdx < $num_index_fields} {incr kdx} {
set table($table_type).index($jdx).field($kdx).name "[GuidoGetParamBufferValue $tableStructuresParam table($idx).index($jdx).field($kdx).name]"
}
}
}
proc isMandatoryCalculatedField { node } {
global dbType
set parent [$node getParent]
set surpacTableName "[getNodeSurpacName $parent]"
if {"$surpacTableName" == "Optional Fields"} {
set pparent [$parent getParent]
set surpacTableName "[getNodeSurpacName $pparent]"
}
set dbTableName "[getTableMapping $node]"
set surpacFieldName "[getNodeSurpacName $node]"
set dbFieldName "[getFieldMapping $node]"
set fieldParams [GuidoExecServer "GetFieldInformation" [subst {DatabaseType = $dbType DbTableName = "$dbTableName" SurpacTableName = "$surpacTableName" DbFieldName = "$dbFieldName" SurpacFieldName = "$surpacFieldName" } ]]
if {[GuidoGetParamBufferValue $fieldParams status] != -1} {
return [GuidoGetParamBufferValue $fieldParams mandatoryCalculated]
} else {
return "false"
}
}
proc databaseTypeCheck { obj type value} {
if {"$type" == "$value"} {
$obj setInputAllowed true
return 1
} else {
$obj setInputAllowed false
return 0
}
}
proc refreshODBCTreeView { tables views procedures systables synonyms umask tmask tree} {
global dbType
set getTables "false"
set getViews "false"
set getProcedures "false"
set getSystables "false"
set getSynonyms "false"
if {[$tables isSelected]} {
set getTables "true"
}
if {[$views isSelected]} {
set getViews "true"
}
if {[$procedures isSelected]} {
set getProcedures "true"
}
if {[$systables isSelected]} {
set getSystables "true"
}
if {[$synonyms isSelected]} {
set getSynonyms "true"
}
set userMask "[$umask getCurrentValue]"
set tableMask "[$tmask getCurrentValue]"
$tree setRefreshEnabled false
set rootNode [$tree getRootNode]
set count [$rootNode getChildCount]
for {set idx 0} {$idx < $count} {incr idx} {
set node [$rootNode getChildAt $idx]
$node setInputAllowed false
}
set tableParam [GuidoExecServer "RefreshODBCDatabaseView" [subst {DatabaseType = $dbType Tables = $getTables Views = $getViews Procedures = $getProcedures Systables = $getSystables Synonyms = $getSynonyms UserMask = "$userMask" TableMask = "$tableMask"} ]]
set tableCount [GuidoGetParamBufferValue $tableParam TableCount]
for {set idx 0} {$idx < $tableCount} {incr idx} {
set tableName "[GuidoGetParamBufferValue $tableParam TableName($idx)]"
set node [getNodeHandle $rootNode $tableName "branch"]
$node setInputAllowed true
}
$tree setRefreshEnabled true
return 1
}
proc getDatabaseStrippedName { name } {
if {[string match \"*\" $name] ||
[string match \'*\' $name] ||
[string match `*` $name]} {
set length [string length $name]
incr length -2
return [string range $name 1 $length]
}
return $name
}
proc getTableMapping { node } {
set nodeLabel "[$node getLabelMLTKey]"
if {[$node isLeaf] ||
"$nodeLabel" == "Optional Fields" || "$nodeLabel" == "Index" || "$nodeLabel" == "Indexes"} {
set parent [$node getParent]
return [getTableMapping $parent]
} else {
set parent [$node getParent]
set parentLabel "[$parent getLabelMLTKey]"
if {"$parentLabel" == "Indexes"} {
return [getTableMapping $parent]
} else {
return "[$node getCurrentValue]"
}
}
}
proc setTableMapping { node tablename validateName } {
set tablename "[getDatabaseStrippedName $tablename]"
if {"$validateName" == "true"} {
set validParam [GuidoExecServer "ValidTableFieldName" [subst {dbname = "$tablename"}]]
if {"[GuidoGetParamBufferValue $validParam validName]" == "false"} {
GuidoMessage message DB_CANNOT_MAP_INVALID_TBL_NAME "$tablename"
return 0
}
}
set currentMapping "[getTableMapping $node]"
if {"$currentMapping" != "$tablename"} {
set changeMapping "true"
set count [$node getChildCount]
for {set idx 0} {$idx < $count} {incr idx} {
set child [$node getChildAt $idx]
if {[$child isLeaf]} {
if {"[$child getCurrentValue]" != ""} {
if {"[$child getCurrentValue]" != "[getNodeSurpacName $child]"} {
GuidoMessage message DB_CANNOT_CHANGE_TABLE_MAPPING "$tablename" "$currentMapping"
set changeMapping "false"
return 0
}
}
}
}
if {"$changeMapping" == "true"} {
$node setCurrentValue "$tablename"
$node setLabelNoMlt "[getNodeSurpacName $node] -> $tablename"
$node setMenuEnabled true
}
} elseif {"[getNodeSurpacName $node]" == "$tablename"} {
$node setCurrentValue "$tablename"
$node setLabelNoMlt "$tablename"
$node setMenuEnabled false
}
return 1
}
proc getNodeSurpacName { node } {
set label "[$node getLabelMLTKey]"
set idx [string first " -> " $label]
if {$idx != -1} {
incr idx -1
return "[string range $label 0 $idx]"
} else {
set idx [string first " *" $label]
if {$idx != -1} {
incr idx -1
return "[string range $label 0 $idx]"
} else {
return "$label"
}
}
}
proc getFieldMapping { node } {
if {[$node isLeaf]} {
set surpacName "[$node getLabelMLTKey]"
set parent [$node getParent]
set parentLabel "[$parent getLabelMLTKey]"
set pparent [$parent getParent]
if {"[$pparent getLabelMLTKey]" == "Indexes"} {
set parentLabel "Index"
set parent $pparent
}
if {"$parentLabel" == "Index"} {
set table [$parent getParent]
set count [$table getChildCount]
for {set idx 0} {$idx < $count} {incr idx} {
set child [$table getChildAt $idx]
if {[$child isLeaf]} {
set childSurpacName "[getNodeSurpacName $child]"
if {"$childSurpacName" == "$surpacName"} {
return "[$child getCurrentValue]"
}
} elseif {"[$child getLabelMLTKey]" == "Optional Fields"} {
set count2 [$child getChildCount]
for {set idx2 0} {$idx2 < $count2} {incr idx2} {
set child2 [$child getChildAt $idx2]
if {[$child2 isLeaf]} {
set childSurpacName "[getNodeSurpacName $child2]"
if {"$childSurpacName" == "$surpacName"} {
return "[$child2 getCurrentValue]"
}
}
}
}
}
return "no mapping"
} else {
return "[$node getCurrentValue]"
}
} else {
return "no mapping"
}
}
proc setFieldMapping { node tableName fieldName validateName } {
global mandatoryFields
set fieldName "[getDatabaseStrippedName $fieldName]"
if {"$validateName" == "true"} {
set validParam [GuidoExecServer "ValidTableFieldName" [subst {dbname = "$fieldName"}]]
if {"[GuidoGetParamBufferValue $validParam validName]" == "false"} {
GuidoMessage message DB_CANNOT_MAP_INVALID_FLD_NAME "$fieldName" "$tableName"
return 0
}
}
set parent [$node getParent]
set tableMapped [getTableMapping $parent]
set surpacTableName "[getNodeSurpacName $parent]"
if {"$surpacTableName" == "Optional Fields"} {
set pparent [$parent getParent]
set surpacTableName "[getNodeSurpacName $pparent]"
}
set surpacFieldName "[getNodeSurpacName $node]"
if {"$validateName" == "true"} {
set connectParams [GuidoExecServer "ValidTableFieldType" [subst { user_table_name = "$tableName" dbname = "$fieldName" SurpacTableName = "$surpacTableName" SurpacFieldName = "$surpacFieldName" MandatoryFields = "$mandatoryFields"}]]
if {[GuidoGetParamBufferValue $connectParams status] == 0} {
} elseif {[GuidoGetParamBufferValue $connectParams status] == -1} {
set user_fieldtype [GuidoGetParamBufferValue $connectParams userfielddatatype]
set surpac_fieldtype [GuidoGetParamBufferValue $connectParams surpacfielddatatype]
GuidoMessage error DB_FIELD_TYPE_MISSMATCH "$fieldName" "$tableName" "$user_fieldtype" "$surpac_fieldtype"
return 0
} elseif {[GuidoGetParamBufferValue $connectParams status] == -2} {
GuidoMessage error DB_SELECT_FIELD_FROM_TABLE "$tableName"
return 0
} else {
return 0
}
}
set return_code 1
if {"$tableMapped" != "$tableName" || "[$parent getLabelMLTKey]" == "$tableMapped *"} {
set return_code [setTableMapping $parent "$tableName" true]
}
if {$return_code == 1} {
set nodeSurpacName "[getNodeSurpacName $node]"
if {"$fieldName" == ""} {
$node setCurrentValue ""
$node setLabelNoMlt "$nodeSurpacName"
} elseif {"[getFieldMapping $node]" != "$fieldName"} {
$node setCurrentValue "$fieldName"
$node setLabelNoMlt "$nodeSurpacName -> $fieldName"
$node setMenuEnabled true
} elseif {"$nodeSurpacName" == "$fieldName"} {
$node setCurrentValue "$fieldName"
$node setLabelNoMlt "$fieldName"
$node setMenuEnabled false
}
return 1
} else {
GuidoMessage message DB_CANNOT_MAP_FIELD "$fieldName" "$tableMapped"
return 0
}
}
proc getSurpacFieldName { tableNode dbName } {
set count [$tableNode getChildCount]
for {set idx 0} {$idx < $count} {incr idx} {
set child [$tableNode getChildAt $idx]
if {[$child isLeaf]} {
if {"[getFieldMapping $child]" == "$dbName"} {
return "[getNodeSurpacName $child]"
}
} elseif {"[$child getLabelMLTKey]" == "Optional Fields"} {
return "[getSurpacFieldName $child $dbName]"
}
}
return ""
}
proc getNodeType { node } {
set tableMapped "[getTableMapping $node]"
set parent [$node getParent]
set folderName "[$parent getCurrentValue]"
if {[$node isLeaf]} {
if {"[$node getCurrentValue]" == "" ||
"[isMandatoryCalculatedField $node]" == "true"} {
return "calculated"
} elseif {"$folderName" == "$tableMapped" ||
"$folderName" == "Optional Fields"} {
return "field"
} else {
return "unknown"
}
} elseif {"[$node getLabelMLTKey]" == "Index" ||
"[$parent getLabelMLTKey]" == "Indexes"} {
return "index"
} else {
return "unknown"
}
}
proc getNodeHandle { node name nodeType } {
if {"[$node getCurrentValue]" == "$name"} {
if {"$nodeType" == "leaf" && [$node isLeaf]} {
return $node
} elseif {"$nodeType" == "branch" && ![$node isLeaf]} {
return $node
}
}
if {![$node isLeaf]} {
set childCount [$node getChildCount]
for {set idx 0} {$idx < $childCount} {incr idx} {
set child [$node getChildAt $idx]
set n [getNodeHandle $child $name $nodeType]
if {$n != 0} {
return $n
}
}
}
return 0
}
proc getFieldInfo { node } {
global dbType
set parent [$node getParent]
set surpacTableName "[getNodeSurpacName $parent]"
if {"$surpacTableName" == "Optional Fields"} {
set pparent [$parent getParent]
set surpacTableName "[getNodeSurpacName $pparent]"
}
set dbTableName "[getTableMapping $node]"
set surpacFieldName "[getNodeSurpacName $node]"
set dbFieldName "[getFieldMapping $node]"
set fieldParams [GuidoExecServer "GetFieldInformation" [subst {DatabaseType = $dbType DbTableName = "$dbTableName" SurpacTableName = "$surpacTableName" DbFieldName = "$dbFieldName" SurpacFieldName = "$surpacFieldName" } ]]
if {[GuidoGetParamBufferValue $fieldParams status] != -1} {
set fieldType "[GuidoGetParamBufferValue $fieldParams FieldType]"
global fieldTypeComboBox
$fieldTypeComboBox setCurrentValue "$fieldType"
global nullCheckBox
if { "[GuidoGetParamBufferValue $fieldParams Nulls]" == "true" } {
$nullCheckBox setSelected true
} else {
$nullCheckBox setSelected false
}
global lengthFld
$lengthFld setCurrentValue "[GuidoGetParamBufferValue $fieldParams Length]"
global caseComboBox
$caseComboBox setCurrentValue "[GuidoGetParamBufferValue $fieldParams Case]"
global validValuesFld
$validValuesFld setCurrentValue "[GuidoGetParamBufferValue $fieldParams ValidValues]"
global numDecimalsFld
$numDecimalsFld setCurrentValue "[GuidoGetParamBufferValue $fieldParams NumDecimals]"
global lowBoundFld
$lowBoundFld setCurrentValue "[GuidoGetParamBufferValue $fieldParams LowBound]"
global highBoundFld
$highBoundFld setCurrentValue "[GuidoGetParamBufferValue $fieldParams HighBound]"
} else {
GuidoMessage message DB_CANNOT_GET_FIELD_INFO "$surpacFieldName" "$surpacTableName"
}
return 1
}
proc assignIndexInfo { node } {
global indexFieldsTable
global uniqueCheckBox
global ascendingCheckBox
global fieldName
global indexFieldLabel
set count [$indexFieldsTable getRowCount]
for {set idx 0} {$idx < $count} {incr idx} {
$fieldName setCurrentValue $idx ""
$ascendingCheckBox setCurrentValue $idx N
}
set indexName "[$node getLabelMLTKey]"
$indexFieldLabel setCurrentValue "$indexName"
if {"[$node getCurrentValue]" == "unique"} {
$uniqueCheckBox setCurrentValue Y
} else {
$uniqueCheckBox setCurrentValue N
}
set count [$node getChildCount]
for {set idx 0} {$idx < $count} {incr idx} {
set child [$node getChildAt $idx]
$fieldName setCurrentValue $idx "[$child getLabelMLTKey]"
$ascendingCheckBox setCurrentValue $idx Y
}
return 1
}
proc setFieldInfo { node } {
global dbType
set parent [$node getParent]
set surpacTableName "[getNodeSurpacName $parent]"
if {"$surpacTableName" == "Optional Fields"} {
set pparent [$parent getParent]
set surpacTableName "[getNodeSurpacName $pparent]"
}
set dbTableName "[getTableMapping $node]"
set dbFieldName "[getFieldMapping $node]"
set surpacFieldName "[getNodeSurpacName $node]"
global fieldTypeComboBox
set fieldType "[$fieldTypeComboBox getCurrentValue]"
global nullCheckBox
if { [$nullCheckBox isSelected] == 1 } {
set nulls "true"
} else {
set nulls "false"
}
global lengthFld
set length "[$lengthFld getCurrentValue]"
global caseComboBox
set case "[$caseComboBox getCurrentValue]"
global validValuesFld
set validValues "[$validValuesFld getCurrentValue]"
global numDecimalsFld
set numDecimals "[$numDecimalsFld getCurrentValue]"
global lowBoundFld
set lowBound "[$lowBoundFld getCurrentValue]"
global highBoundFld
set highBound "[$highBoundFld getCurrentValue]"
GuidoExecServer "SetFieldInformation" [subst {DatabaseType = $dbType DbTableName = "$dbTableName" DbFieldName = "$dbFieldName" SurpacTableName = "$surpacTableName" SurpacFieldName = "$surpacFieldName" FieldType = "$fieldType" Nulls = "$nulls" Length = "$length" Case = "$case" ValidValues = "$validValues" NumDecimals = "$numDecimals" LowBound = "$lowBound" HighBound = "$highBound"} ]
return 1
}
proc saveCalcFieldInfo { surpacTable dbTable field } {
global functionComboBox
global expressionField
global dbType
global holeIdField
global depthField
set function "[$functionComboBox getCurrentValue]"
if {"$function" == "translate"} {
set constType "\"\""
global transTableField
set exprString "[$transTableField getCurrentValue]"
global transFieldComboBox
set exprString2 "[$transFieldComboBox getCurrentValue]"
global fieldToBeTrans
set exprString3 "[$fieldToBeTrans getCurrentValue]"
set expr "$exprString,$exprString2,$exprString3"
global fieldsTable
set exprCount [$fieldsTable getInstances]
global LHSValueBrowser
global operatorComboBox
global RHSValueBrowser
for {set idx 0} {$idx < $exprCount} {incr idx} {
set LHS "[$LHSValueBrowser getCurrentValue $idx]"
set op "[$operatorComboBox getCurrentValue $idx]"
set RHS "[$RHSValueBrowser getCurrentValue $idx]"
if {"$LHS" != "" && "$op" != "" && "$RHS" != ""} {
if {[string match \"*\" $RHS]} {
set idx [string last "\"" $RHS]
incr idx -1
set strippedRHS "[string range $RHS 1 $idx]"
set newExpr "char($op),$LHS,char($strippedRHS)"
} else {
set newExpr "char($op),$LHS,$RHS"
}
set temp "$expr"
set expr "$temp,$newExpr"
}
}
} elseif {"$function" == "expression"} {
set expr [subst {"[$expressionField getCurrentValue]"}]
set constType {""}
} elseif {"$function" == "x" || "$function" == "y" || "$function" == "z"} {
set expr "[$holeIdField getCurrentValue], [$depthField getCurrentValue]"
set constType {""}
} else {
global constComboBox
set constType "[$constComboBox getCurrentValue]"
global constValueField
set expr "[$constValueField getCurrentValue]"
if {"$expr" == ""} {
set expr "\"\""
}
}
global fldTypeComboBox
set fieldType "[$fldTypeComboBox getCurrentValue]"
global fieldLengthFld
set fieldLength "[$fieldLengthFld getCurrentValue]"
global fieldNumDecFld
set numDecimals "[$fieldNumDecFld getCurrentValue]"
GuidoExecServer "UpdateCalculatedField" [subst {DatabaseType = "$dbType" FieldName = "$field" SurpacTableName = "$surpacTable" DbTableName = "$dbTable" FieldType = "$fieldType" FieldLength = "$fieldLength" NumDecimals = "$numDecimals" FunctionName = "$function" ConstType = "$constType" ExprString = "$expr"} ]
return 1
}
proc needToSaveHolePath {} {
global fieldLengthFld
if {[$fieldLengthFld getCurrentValue] != 6} {
return true
}
global fieldNumDecFld
if {[$fieldNumDecFld getCurrentValue] != 0} {
return true
}
global constValueField
if {"[$constValueField getCurrentValue]" != "CURVED"} {
return true
}
return false
}
proc setNodeInformation { node } {
set selectionType "[getNodeType $node]"
if {"$selectionType" == "field"} {
setFieldInfo $node
} elseif {"$selectionType" == "calculated"} {
set fieldName "[$node getLabelMLTKey]"
set tableMapped "[getTableMapping $node]"
set parent [$node getParent]
set pparent [$parent getParent]
set surpacTableName "[getNodeSurpacName $pparent]"
set saveCalcFunction "true"
if {"$fieldName" == "hole_path *"} {
set saveCalcFunction [needToSaveHolePath]
if {"$saveCalcFunction" == "true"} {
set surpacTableName "[getNodeSurpacName $parent]"
set fieldName "[getNodeSurpacName $node]"
$node setLabelNoMlt "$fieldName"
$node setCurrentValue ""
}
global fieldLengthFld
$fieldLengthFld setCurrentValue 6
global fieldNumDecFld
$fieldNumDecFld setCurrentValue 0
global constComboBox
$constComboBox setCurrentValue "character"
global constValueField
$constValueField setCurrentValue CURVED
} elseif {"$fieldName" == "x_from *" ||
"$fieldName" == "y_from *" ||
"$fieldName" == "z_from *" ||
"$fieldName" == "x_to *" ||
"$fieldName" == "y_to *" ||
"$fieldName" == "z_to *" ||
"$fieldName" == "x *" ||
"$fieldName" == "y *" ||
"$fieldName" == "z *"} {
global fieldLengthFld
global fldTypeComboBox
global fieldNumDecFld
global holeIdField
global depthField
global functionComboBox
set depth_check "depth[string range $fieldName 1 [expr [string length $fieldName] - 3]]"
set function_check "[string range $fieldName 0 0]"
if {[$fieldLengthFld getCurrentValue] != 11 ||
[$fldTypeComboBox getCurrentValue] != "real" ||
[$fieldNumDecFld getCurrentValue] != 3 ||
[$holeIdField getCurrentValue] != "hole_id" ||
[$depthField getCurrentValue] != $depth_check ||
[$functionComboBox getCurrentValue] != $function_check} {
set fieldName "[getNodeSurpacName $node]"
$node setLabel "$fieldName"
set saveCalcFunction "true"
} else {
set saveCalcFunction "false"
}
set surpacTableName "[getNodeSurpacName $parent]"
} elseif {"$fieldName" == "hole_path" ||
"$fieldName" == "x_from" ||
"$fieldName" == "y_from" ||
"$fieldName" == "z_from" ||
"$fieldName" == "x_to" ||
"$fieldName" == "y_to" ||
"$fieldName" == "y_to" ||
"$fieldName" == "x" ||
"$fieldName" == "y" ||
"$fieldName" == "z"} {
set surpacTableName "[getNodeSurpacName $parent]"
}
if {"$saveCalcFunction" == "true"} {
saveCalcFieldInfo $surpacTableName $tableMapped $fieldName
}
}
}
proc getNodeInformation { node } {
global fieldInfoPanel
global indexInfoPanel
global calcFieldInfoPanel
if {"[getNodeType $node]" == "index"} {
$fieldInfoPanel setVisible false
$indexInfoPanel setVisible true
$calcFieldInfoPanel setVisible false
assignIndexInfo $node
} elseif {"[getNodeType $node]" == "calculated"} {
$fieldInfoPanel setVisible false
$indexInfoPanel setVisible false
$calcFieldInfoPanel setVisible true
global functionComboBox
global ddbStructure
global transFieldComboBox
global LHSValueBrowser
global RHSValueBrowser
set trans [getTableNodeByTableType DB_TRANSLATION_TABLE]
if {$trans != 0} {
updateTransBrowserLists $functionComboBox $ddbStructure $trans $transFieldComboBox $LHSValueBrowser $RHSValueBrowser
} else {
$functionComboBox removeItem "translate"
}
getCalcFunction $node
} elseif {"[getNodeType $node]" == "field"} {
$fieldInfoPanel setVisible true
$indexInfoPanel setVisible false
$calcFieldInfoPanel setVisible false
getFieldInfo $node
}
}
set lastNodeSelected ""
proc nodeSelectionCallback { tree } {
set currentNodeSelected [$tree getSelectedNode]
global lastNodeSelected
if {"$lastNodeSelected" != "" &&
"$currentNodeSelected" == ""} {
return 1
}
if {"$lastNodeSelected" != ""} {
if {[$lastNodeSelected isLeaf]} {
setNodeInformation $lastNodeSelected
}
}
if {"$currentNodeSelected" != ""} {
set parent [$currentNodeSelected getParent]
if {"$currentNodeSelected" != "" && $parent != ""} {
if {[$currentNodeSelected isLeaf] ||
"[$currentNodeSelected getLabelMLTKey]" == "Index" ||
"[$parent getLabelMLTKey]" == "Indexes"} {
getNodeInformation $currentNodeSelected
}
set lastNodeSelected "$currentNodeSelected"
}
}
return 1
}
proc saveSelectedNodeInfo { tree } {
set currentNodeSelected [$tree getSelectedNode]
if {"$currentNodeSelected" != ""} {
if {[$currentNodeSelected isLeaf]} {
setNodeInformation $currentNodeSelected
}
}
return 1
}
GuidoPopupMenu removeMappingMenu {
GuidoMenuItem removeMappingItem {
-label "Remove mapping"
}
}
GuidoPopupMenu optFieldsMenu {
GuidoMenuItem addFieldItem {
-label "Add"
}
}
GuidoPopupMenu removeNodeMenu {
GuidoMenuItem removeNodeItem {
-label "Remove"
}
GuidoMenuItem renameNodeItem {
-label "Rename"
}
}
proc createTableStructure { table_type surpac_table_name db_table_name } {
global optFieldsMenu
global removeNodeMenu
GuidoTreeBranch "table($surpac_table_name)" {
-label_no_mlt "$surpac_table_name *"
-default $db_table_name
global "table($table_type).num_mand_fields"
upvar 0 table($table_type).num_mand_fields num_mand_fields
for {set idx 0} {$idx < $num_mand_fields} {incr idx} {
global "table($table_type).field($idx).name"
upvar 0 table($table_type).field($idx).name field_name
GuidoTreeLeaf "field($surpac_table_name)$idx" {
-label_no_mlt "$field_name *"
-default "$field_name"
-menu_enabled false
}
}
GuidoTreeBranch "opt_fields($surpac_table_name)" {
-menu $optFieldsMenu
-label "Optional Fields"
-default "Optional Fields"
}
GuidoTreeBranch indexes($surpac_table_name) {
-label "Indexes"
-default "Indexes"
-menu_enabled false
global "table($table_type).num_indexes"
upvar 0 table($table_type).num_indexes num_indexes
for {set idx 0} {$idx < $num_indexes} {incr idx} {
global "table($table_type).index($idx).unique"
upvar 0 table($table_type).index($idx).unique unique
set default_value "$unique"
global "table($table_type).index($idx).name"
upvar 0 table($table_type).index($idx).name index_name
GuidoTreeBranch index($surpac_table_name)$idx {
-label_no_mlt "$index_name"
-default $default_value
-menu_enabled false
global "table($table_type).index($idx).num_fields"
upvar 0 table($table_type).index($idx).num_fields num_fields
for {set jdx 0} {$jdx < $num_fields} {incr jdx} {
global "table($table_type).index($idx).field($jdx).name"
upvar 0 table($table_type).index($idx).field($jdx).name field_name
GuidoTreeLeaf index($surpac_table_name)field$idx$jdx {
-label_no_mlt "$field_name"
-default "$field_name"
-menu_enabled false
}
}
}
}
}
}
upvar 0 "table($surpac_table_name)" branch_node
set disable_table_menu true
global num_opt_table_types
for {set idx 0} {$idx < $num_opt_table_types} {incr idx} {
global "opt_table_types($idx).type"
upvar 0 opt_table_types($idx).type opt_type
if {"$opt_type" == "$table_type"} {
$branch_node setMenu $removeNodeMenu
set disable_table_menu false
break
}
}
if {"$disable_table_menu" == "true"} {
$branch_node setMenuEnabled false
}
return $branch_node
}
proc addIndex { dropNode data } {
set fromTable "[getTableMapping $dropNode]"
set toTable "[getTableMapping $data]"
if {"$fromTable" == "$toTable"} {
set parent [$dropNode getParent]
set pparent [$parent getParent]
set count [$data getChildCount]
for {set idx 0} {$idx < $count} {incr idx} {
set child [$data getChildAt $idx]
set fieldName "[$child getLabelMLTKey]"
$child setLabelNoMlt "[getSurpacFieldName $pparent $fieldName]"
$child setCurrentValue "$fieldName"
$child setMenuEnabled false
}
global removeNodeMenu
$data setMenu $removeNodeMenu
$dropNode addChild $data
} else {
GuidoMessage message DB_CANNOT_ADD_INDEX "[$data getLabelMLTKey]" "$toTable"
}
return $data
}
proc addField { node tablename surpacFieldName dbFieldName validateName } {
global removeNodeMenu
set tableMapped "[getTableMapping $node]"
set parent [$node getParent]
set tablename "[getDatabaseStrippedName $tablename]"
set strippedName "[getDatabaseStrippedName $dbFieldName]"
if {"$validateName" == "true"} {
set validParam [GuidoExecServer "ValidTableFieldName" [subst {dbname = "$strippedName"}]]
if {"[GuidoGetParamBufferValue $validParam validName]" == "false"} {
GuidoMessage message DB_CANNOT_MAP_INVALID_FLD_NAME "$strippedName" "$tablename"
return 0
}
}
if {"$tableMapped" == "$tablename" ||
"[getNodeSurpacName $parent]" == "$tablename"} {
if {"$strippedName" == ""} {
set mapping "$surpacFieldName"
} elseif {"$surpacFieldName" != "$strippedName"} {
set mapping "$surpacFieldName -> $strippedName"
} else {
set mapping "$strippedName"
}
set leafName "$tablename-$surpacFieldName"
GuidoTreeLeaf "$leafName" {
-menu $removeNodeMenu
-label_no_mlt "$mapping"
-default "$dbFieldName"
}
upvar 0 "$leafName" field
$node addChild $field
return $field
} else {
GuidoMessage message DB_CANNOT_ADD_FIELD "$surpacFieldName" "$tableMapped"
return 0
}
}
proc getTableNodeByTableType { table_type } {
global num_mand_tables
for {set idx 0} {$idx < $num_mand_tables} {incr idx} {
global mand_table($idx).type ttype
upvar 0 mand_table($idx).type ttype
if {"$table_type" == "$ttype"} {
global mand_table($idx).node_handle
upvar 0 mand_table($idx).node_handle nhandle
return $nhandle
}
}
global num_opt_tables
for {set idx 0} {$idx < $num_opt_tables} {incr idx} {
global opt_table($idx).type opt_table_type
upvar 0 opt_table($idx).type opt_table_type
if {"$table_type" == "$opt_table_type"} {
global opt_table($idx).node_handle
upvar 0 opt_table($idx).node_handle nhandle
return $nhandle
}
}
return 0
}
proc getOptTableNodeByTableType { table_type } {
global num_opt_table_types
for {set idx 0} {$idx < $num_opt_table_types} {incr idx} {
global opt_table_types($idx).type
upvar 0 opt_table_types($idx).type opt_types
if {"$table_type" == "$opt_types"} {
global opt_table_types($idx).node_handle
upvar 0 opt_table_types($idx).node_handle nhandle
return $nhandle
}
}
return 0
}
proc getOptTableTypeByNodeName { node_name } {
global num_opt_table_types
for {set idx 0} {$idx < $num_opt_table_types} {incr idx} {
global opt_table_types($idx).name
upvar 0 opt_table_types($idx).name opt_type_name
if {"$node_name" == "$opt_type_name"} {
global opt_table_types($idx).type
upvar 0 opt_table_types($idx).type optable_type
return $optable_type
}
}
return DB_UNKNOWN_TABLE
}
proc getDatabaseMappings { tree } {
global dbType
$tree setRefreshEnabled false
set mappingParams [GuidoExecServer "GetDatabaseMappings" [subst {DatabaseType = "$dbType"}]]
set databaseName "[GuidoGetParamBufferValue $mappingParams DatabaseName]"
set numTables [GuidoGetParamBufferValue $mappingParams NumTables]
for {set idx 0} {$idx < $numTables} {incr idx} {
set is_opt_table false
set tableName "[GuidoGetParamBufferValue $mappingParams TableName($idx)]"
set tableType [GuidoGetParamBufferValue $mappingParams TableType($idx)]
set dbName "[GuidoGetParamBufferValue $mappingParams DbName($idx)]"
set numFields [GuidoGetParamBufferValue $mappingParams NumFields($idx)]
set node [getTableNodeByTableType $tableType]
if {$node != 0} {
setTableMapping $node $dbName false
} else {
set node [getOptTableNodeByTableType $tableType]
if {$node != 0} {
set is_opt_table true
set newnode [createTableStructure $tableType $tableName $dbName]
if {"$dbName" != "$tableName"} {
$newnode setLabelNoMlt "$tableName -> $dbName"
} else {
$newnode setLabelNoMlt $dbName
}
$node addChild $newnode
set node $newnode
}
}
if {$node != 0} {
set optNode [getNodeHandle $node "Optional Fields" "branch"]
for {set idx2 0} {$idx2 < $numFields} {incr idx2} {
set fieldName "[GuidoGetParamBufferValue $mappingParams Table($idx)_FieldName($idx2)]"
set databaseName "[GuidoGetParamBufferValue $mappingParams Table($idx)_DbName($idx2)]"
set fieldNode [getNodeHandle $node $fieldName "leaf"]
if {$fieldNode != 0} {
setFieldMapping $fieldNode $dbName $databaseName false
} else {
if {"$is_opt_table" == "false"} {
addField $optNode $tableName $fieldName $databaseName false
} else {
addField $optNode $dbName $fieldName $databaseName false
}
}
}
}
}
$tree setRefreshEnabled true
return 1
}
proc setPromptPasswordDefault { physicalDBType promptFld } {
global argv
if {"$physicalDBType" == "odbc"} {
set prompt [lindex $argv 4]
if {"$prompt" == "true"} {
$promptFld setSelected true
} else {
$promptFld setSelected false
}
} else {
$promptFld setSelected false
}
return 1
}
proc getCurrentTableFields { node fldComboBox } {
set count [$node getChildCount]
for {set idx 0} {$idx < $count} {incr idx} {
set child [$node getChildAt $idx]
if {[$child isLeaf]} {
$fldComboBox addItem "[getNodeSurpacName $child]"
} elseif {"[$child getCurrentValue]" == "Optional Fields"} {
set count2 [$child getChildCount]
for {set idx2 0} {$idx2 < $count2} {incr idx2} {
set child2 [$child getChildAt $idx2]
$fldComboBox addItem "[getNodeSurpacName $child2]"
}
}
}
return 1
}
proc updateTransBrowserLists { func tree trans transFldCombo LHSCombo RHSCombo } {
$transFldCombo removeAllItems
getCurrentTableFields $trans $transFldCombo
$LHSCombo removeAllItems
getCurrentTableFields $trans $LHSCombo
set selectedNode [$tree getSelectedNode]
set parent [$selectedNode getParent]
set table [$parent getParent]
$RHSCombo removeAllItems
getCurrentTableFields $table $RHSCombo
return 1
}
proc DragDropped {event tree} {
set dropNode [$tree getLastDropNode]
set data [$event getData]
if {[$dropNode isLeaf]} {
if {[$data isLeaf]} {
set dropNodeParent [$dropNode getParent]
set dropNodePParent [$dropNodeParent getParent]
if {"[$dropNodePParent getLabelMLTKey]" != "Indexes" &&
"[$dropNodeParent getLabelMLTKey]" != "Index"} {
set table [$data getParent]
set tablename [$table getLabelMLTKey]
set mapName [$data getLabelMLTKey]
set rcode [setFieldMapping $dropNode $tablename $mapName true]
if {$rcode == 1} {
set tNode [$dropNode getParent]
set optNode [getNodeHandle $tNode "Optional Fields" "branch"]
if {$optNode != 0} {
set fNode [getNodeHandle $optNode $mapName "leaf"]
if {$fNode != 0} {
$optNode removeChild $fNode
}
}
}
}
} else {
GuidoMessage message "Cannot map field name because data is not a table field"
}
} else {
set folderName "[$dropNode getLabelMLTKey]"
set parent [$dropNode getParent]
set parentName "[$parent getLabelMLTKey]"
if {![$data isLeaf]} {
set tableName "[$data getLabelMLTKey]"
set tNode 0
set tableType [getOptTableTypeByNodeName $folderName]
if {"$tableType" != "DB_UNKNOWN_TABLE"} {
set tableName "[getDatabaseStrippedName $tableName]"
set validParam [GuidoExecServer "ValidTableFieldName" [subst {dbname = "$tableName"}]]
if {"[GuidoGetParamBufferValue $validParam validName]" == "false"} {
GuidoMessage message DB_CANNOT_MAP_INVALID_TBL_NAME "$tableName"
} else {
set tNode [createTableStructure $tableType $tableName $tableName]
$tNode setLabelNoMlt $tableName
$dropNode addChild $tNode
}
} elseif {"$folderName" != "Optional Fields" &&
"$folderName" != "Index" &&
"$folderName" != "Optional Tables" &&
"$folderName" != "Indexes" &&
"$parentName" != "Indexes"} {
setTableMapping $dropNode $tableName true
set tNode $dropNode
}
if {$tNode != 0} {
set children [$data getChildCount]
set optNode [getNodeHandle $tNode "Optional Fields" "branch"]
if {$optNode != 0} {
for {set idx 0} {$idx < $children} {incr idx} {
set child [$data getChildAt $idx]
if {[$child isLeaf]} {
set fName "[$child getLabelMLTKey]"
set fNode [getNodeHandle $tNode $fName "leaf"]
if {$fNode != 0} {
setFieldMapping $fNode $tableName $fName true
} else {
addField $optNode $tableName $fName $fName true
}
}
}
}
}
} else {
set fieldname [$data getLabelMLTKey]
set table [$data getParent]
set tablename [$table getLabelMLTKey]
if {[string compare $folderName "Optional Fields"] == 0} {
addField $dropNode $tablename $fieldname $fieldname true
}
}
}
}
proc getCalcFunction { node } {
global holeIdField
global depthField
global functionComboBox
global fldTypeComboBox
global fieldLengthFld
global fieldNumDecFld
global constComboBox
global constValueField
global expressionField
global dbType
set name "[$node getLabelMLTKey]"
if {[string first "->" $name] != -1} {
return
}
$fldTypeComboBox setCurrentValue "character"
$fieldLengthFld setCurrentValue 11
$fieldNumDecFld setCurrentValue 3
$functionComboBox setCurrentValue "constant"
$constComboBox setCurrentValue "NULL"
$constValueField setCurrentValue ""
switch $name {
"" {  }
"y *" {
$functionComboBox setCurrentValue "y"
$holeIdField setCurrentValue "hole_id"
$depthField setCurrentValue "depth"
$fldTypeComboBox setCurrentValue "real"
}
"y_from *" {
$functionComboBox setCurrentValue "y"
$holeIdField setCurrentValue "hole_id"
$depthField setCurrentValue "depth_from"
$fldTypeComboBox setCurrentValue "real"
}
"y_to *" {
$functionComboBox setCurrentValue "y"
$holeIdField setCurrentValue "hole_id"
$depthField setCurrentValue "depth_to"
$fldTypeComboBox setCurrentValue "real"
}
"x *" {
$functionComboBox setCurrentValue "x"
$holeIdField setCurrentValue "hole_id"
$depthField setCurrentValue "depth"
$fldTypeComboBox setCurrentValue "real"
}
"x_from *" {
$functionComboBox setCurrentValue "x"
$holeIdField setCurrentValue "hole_id"
$depthField setCurrentValue "depth_from"
$fldTypeComboBox setCurrentValue "real"
}
"x_to *" {
$functionComboBox setCurrentValue "x"
$holeIdField setCurrentValue "hole_id"
$depthField setCurrentValue "depth_to"
$fldTypeComboBox setCurrentValue "real"
}
"z *" {
$functionComboBox setCurrentValue "z"
$holeIdField setCurrentValue "hole_id"
$depthField setCurrentValue "depth"
$fldTypeComboBox setCurrentValue "real"
}
"z_from *" {
$functionComboBox setCurrentValue "z"
$holeIdField setCurrentValue "hole_id"
$depthField setCurrentValue "depth_from"
$fldTypeComboBox setCurrentValue "real"
}
"z_to *" {
$functionComboBox setCurrentValue "z"
$holeIdField setCurrentValue "hole_id"
$depthField setCurrentValue "depth_to"
$fldTypeComboBox setCurrentValue "real"
}
"hole_path *" {
$fldTypeComboBox setCurrentValue "character"
$fieldLengthFld setCurrentValue 6
$fieldNumDecFld setCurrentValue 0
$functionComboBox setCurrentValue "constant"
global constComboBox
$constComboBox setCurrentValue "character"
global constValueField
$constValueField setCurrentValue "CURVED"
}
default {
set fieldName "[$node getLabelMLTKey]"
set dbTableName "[getTableMapping $node]"
set parent [$node getParent]
set pparent [$parent getParent]
if {"[getNodeSurpacName $parent]" != "Optional Fields"} {
set pparent $parent
}
set surpacTableName "[getNodeSurpacName $pparent]"
set calcParams [GuidoExecServer "GetCalcExpression" [subst {DatabaseType = $dbType SurpacTableName = $surpacTableName DbTableName = $dbTableName FieldName = $fieldName} ]]
if {[GuidoGetParamBufferValue $calcParams status] != -1} {
set function "[GuidoGetParamBufferValue $calcParams FunctionName]"
if {"$function" == "constant"} {
$functionComboBox setCurrentValue "constant"
$constComboBox setCurrentValue "[GuidoGetParamBufferValue $calcParams ConstType]"
set expr "[GuidoGetParamBufferValue $calcParams ExprString]"
if {"[GuidoGetParamBufferValue $calcParams ConstType]" == "character"} {
set expr "[string range $expr 1 [expr [string length $expr] - 2]]"
}
$constValueField setCurrentValue $expr
} elseif {"$function" == "translate"} {
$functionComboBox setCurrentValue "translate"
set numExpr "[GuidoGetParamBufferValue $calcParams NumExpr]"
global transTableField
$transTableField setCurrentValue "[GuidoGetParamBufferValue $calcParams expr(0)]"
global transFieldComboBox
$transFieldComboBox setCurrentValue "[GuidoGetParamBufferValue $calcParams expr(1)]"
global fieldToBeTrans
$fieldToBeTrans setCurrentValue "[GuidoGetParamBufferValue $calcParams expr(2)]"
set rowCount 0
set exprCount 0
for {set idx 3} {$idx < $numExpr} {incr idx} {
if {$exprCount == 0} {
global operatorComboBox
set value "[GuidoGetParamBufferValue $calcParams expr($idx)]"
set index [string last "\"" $value]
incr index -1
set strippedValue "[string range $value 1 $index]"
$operatorComboBox setCurrentValue $rowCount "$strippedValue"
incr exprCount
} elseif {$exprCount == 1} {
global LHSValueBrowser
$LHSValueBrowser setCurrentValue $rowCount "[GuidoGetParamBufferValue $calcParams expr($idx)]"
incr exprCount
} else {
global RHSValueBrowser
$RHSValueBrowser setCurrentValue $rowCount "[GuidoGetParamBufferValue $calcParams expr($idx)]"
incr rowCount
set exprCount 0
}
}
} elseif {"$function" == "x" || "$function" == "y" || "$function" == "z"} {
$functionComboBox setCurrentValue $function
$holeIdField setCurrentValue "[GuidoGetParamBufferValue $calcParams Field1]"
$depthField setCurrentValue "[GuidoGetParamBufferValue $calcParams Field2]"
} elseif {"$function" == "expression"} {
$functionComboBox setCurrentValue "expression"
set algebraic_expression "[GuidoGetParamBufferValue $calcParams expression]"
$expressionField setCurrentValue $algebraic_expression
}
$fldTypeComboBox setCurrentValue "[GuidoGetParamBufferValue $calcParams FieldType]"
$fieldLengthFld setCurrentValue "[GuidoGetParamBufferValue $calcParams FieldLength]"
$fieldNumDecFld setCurrentValue "[GuidoGetParamBufferValue $calcParams NumDecimals]"
}
}
}
}
proc isUnrequiredField { node_name } {
global num_unrequired_fields
for {set idx 0} {$idx < $num_unrequired_fields} {incr idx} {
global unrequired($idx).name
upvar 0 unrequired($idx).name unreq_fld
if {"$node_name" == "$unreq_fld"} {
return true
}
}
return false
}
proc removeNode { tree } {
global lastNodeSelected
global dbType
set selectedNode [$tree getSelectedNode]
set parent [$selectedNode getParent]
if {![$selectedNode isLeaf]} {
set count [$selectedNode getChildCount]
for {set idx 0} {$idx < $count} {incr idx} {
set child [$selectedNode getChildAt $idx]
if {![$child isLeaf] && "[$child getCurrentValue]" == "Optional Fields"} {
set count2 [$child getChildCount]
for {set idx2 0} {$idx2 < $count2} {incr idx2} {
set child2 [$child getChildAt $idx2]
if {"[$child2 getCurrentValue]" == ""} {
set fieldName "[$child2 getLabelMLTKey]"
set tableName "[$selectedNode getCurrentValue]"
GuidoExecServer "RemoveCalculatedField" [subst {DatabaseType = $dbType FieldName = $fieldName SurpacTableName = $tableName DbTableName = $tableName } ]
}
}
break
}
}
} else {
set pparent [$parent getParent]
set dbTableName "[$pparent getCurrentValue]"
set surpacTableName "[getNodeSurpacName $pparent]"
set dbFieldName "[$selectedNode getCurrentValue]"
if {$dbFieldName == ""} {
set surpacFieldName "[getNodeSurpacName $selectedNode]"
GuidoExecServer "RemoveCalculatedField" [subst {DatabaseType = $dbType FieldName = $surpacFieldName SurpacTableName = $surpacTableName DbTableName = $dbTableName } ]
}
}
$parent removeChild $selectedNode
set lastNodeSelected ""
return 1
}
proc removeMapping { tree } {
set selectedNode [$tree getSelectedNode]
set surpacName "[getNodeSurpacName $selectedNode]"
$selectedNode setLabelNoMlt "$surpacName *"
$selectedNode setCurrentValue $surpacName
if {![$selectedNode isLeaf]} {
set count [$selectedNode getChildCount]
for {set idx 0} {$idx < $count} {incr idx} {
set child [$selectedNode getChildAt $idx]
if {![$child isLeaf]} {
if {"[$child getCurrentValue]" == "Optional Fields"} {
set count2 [$child getChildCount]
set removeIdx 0
for {set idx2 0} {$idx2 < $count2} {incr idx2} {
set child2 [$child getChildAt $removeIdx]
if {"[$child2 getCurrentValue]" != ""} {
$child removeChild $child2
} else {
incr removeIdx
}
}
}
} else {
set surpacName "[getNodeSurpacName $child]"
$child setLabelNoMlt "$surpacName *"
$child setCurrentValue $surpacName
$child setMenuEnabled true
}
}
}
}
proc renameNodeAction { formHandle formStatus field } {
global ddbStructure
if {"$formStatus" == "rename"} {
set selectedNode [$ddbStructure getSelectedNode]
set newName "[$field getCurrentValue]"
set dbName "[$selectedNode getCurrentValue]"
if {"$newName" != "$dbName"} {
set mapping "$newName -> $dbName"
} else {
set mapping "$dbName"
}
$selectedNode setLabelNoMlt "$mapping"
$formHandle hide
$formHandle destroy
} elseif {"$formStatus" == "cancel"} {
$formHandle hide
$formHandle destroy
} else {
$formHandle setStatus $formStatus
}
}
proc renameNode { } {
GuidoForm renameNodeForm {
-help_id 778
-label "Rename a field or table"
-layout BoxLayout Y_AXIS
GuidoPanel outerRenameNodePanel {
-layout CentreLineLayout
-border etched true
GuidoField newNameFld {
-default ""
-display_length 15
-format none
-label "New name"
-max_length 36
-null false
}
}
GuidoPanel renameButtonPanel {
-layout FlowLayout Left
GuidoButton helpButton {
-caption " "
-icon "icons/16/help.png"
-action valueChanged {[renameNodeAction $renameNodeForm "help" "$newNameFld"] }
}
GuidoButton renameButton {
-caption "Rename"
-display_length 10
-icon "icons/16/edit.png"
-action valueChanged {[renameNodeAction $renameNodeForm "rename" "$newNameFld"]}
}
GuidoButton cancelButton {
-caption "Cancel"
-display_length 10
-icon "icons/cancel.png"
-action valueChanged {[renameNodeAction $renameNodeForm "cancel" "$newNameFld"]}
}
}
GuidoFiller f {
-height 0.5
}
}
$renameNodeForm show modal
return 1
}
proc addFieldAction { formHandle formStatus fieldName } {
global ddbStructure
set selectedNode [$ddbStructure getSelectedNode]
set parent [$selectedNode getParent]
if {"$formStatus" == "add"} {
GuidoPopupMenu removeFieldMenu {
GuidoMenuItem removeFieldItem {
-label "Remove"
-action mouseReleased {[removeNode $ddbStructure]}
}
}
set newName "[$fieldName getCurrentValue]"
set dbTableName "[$parent getCurrentValue]"
set leafName "$dbTableName-$newName"
GuidoTreeLeaf "$leafName" {
-menu $removeFieldMenu
-label_no_mlt "$newName"
-default "$newName"
}
upvar 0 "$leafName" field
$selectedNode addChild "$field"
$formHandle hide
$formHandle destroy
$ddbStructure setSelectedNode $field
$ddbStructure scrollPathToVisible $field
} elseif {"$formStatus" == "cancel"} {
$formHandle hide
$formHandle destroy
} else {
$formHandle setStatus $formStatus
}
}
proc addCalculatedField { } {
GuidoForm addFieldForm {
-help_id 778
-label "Add a new field"
-layout BoxLayout Y_AXIS
GuidoPanel outerAddFieldPanel {
-layout CentreLineLayout
-border etched true
GuidoField newFieldName {
-default ""
-display_length 15
-format none
-label "Field Name"
-max_length 36
-null false
}
}
GuidoPanel addFieldButtonPanel {
-layout FlowLayout Left
GuidoButton helpButton {
-caption " "
-icon "icons/16/help.png"
-action valueChanged {[ addFieldAction $addFieldForm "help" "$newFieldName" ]}
}
GuidoButton applyButton {
-caption "Add"
-icon "icons/16/activate.png"
-display_length 10
-action valueChanged {[ addFieldAction $addFieldForm "add" "$newFieldName" ]}
}
GuidoButton cancelButton {
-caption "Cancel"
-display_length 10
-icon "icons/cancel.png"
-action valueChanged {[ addFieldAction $addFieldForm "cancel" "$newFieldName" ]}
}
}
GuidoFiller f12 {
-height 0.5
}
}
$addFieldForm show modal
return 1
}
GuidoTree realDatabaseStructure {
-enable_action dragSourceGestureRecognized
-label "Database Structure"
-no_mlt
-database_handle $databaseHandle
}
GuidoTree ddbStructure {
-action dropTarget {[DragDropped GUIDO_EVENT $ddbStructure]}
-action valueChanged {[nodeSelectionCallback $ddbStructure]}
-branch_menu $removeMappingMenu
-editable false
-leaf_menu $removeMappingMenu
-label "Surpac Database"
}
GuidoForm mapDatabaseForm {
-action initial {[endProgressFeedback]}
-help_id 778
-label "Map the database"
GuidoPanel mapDatabasePanel {
-layout BoxLayout Y_AXIS
GuidoSplitPane spane {
-divider_location 39%
-expandable true
GuidoPanel leftTreeViewPanel {
-layout BoxLayout Y_AXIS
GuidoLabel realDatabaseLabel {
-label "Source database"
-font_style bold
}
GuidoScrollPane realDatabaseScroll {
-height 16
-width 25
}
}
GuidoPanel rightTreeViewPanel {
-layout BoxLayout Y_AXIS
GuidoLabel ddbLabel {
-label "Mapping detail"
-font_style bold
}
GuidoScrollPane ddbScroll {
-height 16
-width 39
}
}
}
GuidoPanel databaseInfoPanel {
-layout BoxLayout X_AXIS
GuidoPanel dbSpecificsPanel {
-border etched true
-font_style bold
-label "Database specifics"
-layout OverlayLayout
-width 25
-height 14
GuidoPanel odbcSpecPanel {
-action initial {[databaseTypeCheck $odbcSpecPanel $physicalDBType odbc]}
-layout CentreLineLayout
GuidoLabel tableViewLabel {
-font_style bold
-label "Table filter:"
}
GuidoButton refreshViewButton {
-caption "Refresh tree view"
}
GuidoCheckBox showTablesCheckBox {
-default true
-label "Tables"
-selected_value Y
-unselected_value N
}
GuidoCheckBox showViewsCheckBox {
-default true
-label "Views"
-selected_value Y
-unselected_value N
}
GuidoCheckBox showProceduresCheckBox {
-default false
-label "Procedures"
-selected_value Y
-unselected_value N
}
GuidoCheckBox showSystablesCheckBox {
-default false
-label "Systables"
-selected_value Y
-unselected_value N
}
GuidoCheckBox showSynonymsCheckBox {
-default true
-label "Synonyms"
-selected_value Y
-unselected_value N
}
GuidoCheckBox promptIdCheckBox {
-action initial {[setPromptPasswordDefault $physicalDBType $promptIdCheckBox]}
-label "Prompt id"
-selected_value Y
-unselected_value N
}
GuidoField oracleRoleField {
-display_length 17
-label "Oracle role"
}
GuidoField tableMaskField {
-display_length 12
-label "Table mask"
}
GuidoField userMaskField {
-display_length 12
-label "User mask"
}
}
GuidoPanel paradoxSpecPanel {
-action initial {[databaseTypeCheck $paradoxSpecPanel $physicalDBType paradox]}
-layout CentreLineLayout
GuidoCheckBox multiuserCheckBox {
-default false
-label "Multiuser"
-selected_value Y
-unselected_value N
}
}
GuidoPanel accessSpecPanel {
-action initial {[databaseTypeCheck $accessSpecPanel $physicalDBType access]}
-layout CentreLineLayout
GuidoField sqlExtraField {
-display_length 17
-label "SQL extra"
}
}
}
GuidoPanel fieldIndexInfoPanel {
-border etched true
-font_style bold
-label "Field and index information"
-layout OverlayLayout
-width 39
-height 14
GuidoPanel fieldInfoPanel {
-layout BoxLayout X_AXIS
GuidoPanel fieldTypeInfoPanel {
-layout CentreLineLayout
GuidoFiller filler14 {
-height 0.5
}
GuidoFiller filler32 {
-height 0.5
}
GuidoComboBox fieldTypeComboBox {
-display_length 10
-exclusive true
-label "Field type"
-null disallowed
-value_in "character" "real" "integer" "datetime" "duration" "boolean" "memo"
}
GuidoCheckBox nullCheckBox {
-default false
-label "Nulls allowed"
-selected_value Y
-unselected_value N
}
GuidoField lengthFld {
-display_length 5
-format integer
-label "Length"
-max_length 5
-translate none
}
GuidoComboBox caseComboBox {
-default "mixed"
-dependency {"[$fieldTypeComboBox getCurrentValue]" == "character" ||
"[$fieldTypeComboBox getCurrentValue]" == "memo"}
-display_length 8
-label "Case"
-exclusive true
-null disallowed
-value_in "lower" "mixed" "upper"
}
GuidoField validValuesFld {
-dependency {"[$fieldTypeComboBox getCurrentValue]" == "character"}
-display_length 15
-format none
-label "Valid values"
-translate none
}
GuidoField numDecimalsFld {
-dependency {"[$fieldTypeComboBox getCurrentValue]" == "real"}
-display_length 3
-format integer
-label "No decimals"
-translate none
-max_length 3
}
GuidoField lowBoundFld {
-dependency {"[$fieldTypeComboBox getCurrentValue]" == "real" ||
"[$fieldTypeComboBox getCurrentValue]" == "integer"}
-display_length 8
-format double
-label "Low bound"
-translate none
}
GuidoField highBoundFld {
-dependency {"[$fieldTypeComboBox getCurrentValue]" == "real" ||
"[$fieldTypeComboBox getCurrentValue]" == "integer"}
-display_length 8
-format double
-label "High bound"
-translate none
}
}
}
GuidoPanel indexInfoPanel {
-layout BoxLayout X_AXIS
-visible false
GuidoPanel innerIndexPanel {
-layout BoxLayout Y_AXIS
GuidoPanel idxPanel {
-layout CentreLineLayout
GuidoFiller filler20 {
-height 1
}
GuidoFiller filler21 {
-height 1
}
GuidoLabel indexLabel {
-label "Index"
-font_style bold
}
GuidoLabel indexFieldLabel {
}
GuidoLabel uniqueLabel {
-label "Unique"
}
GuidoCheckBox uniqueCheckBox {
-default false
-selected_value Y
-unselected_value N
-input false
}
}
GuidoPanel fieldsTablePanel {
-layout BoxLayout X_AXIS
GuidoFiller filler22 {
-width 3.7
}
GuidoScrollPane fieldsTableScroll {
-scroll_size 20 5
GuidoTable indexFieldsTable {
-instances 5
-input false
-interactive false
-row_headings_visible false
GuidoField fieldName {
-display_length 15
-format none
-input false
-label "Field Name"
}
GuidoCheckBox ascendingCheckBox {
-default false
-input false
-label "ASC"
-selected_value Y
-unselected_value N
}
}
}
}
}
}
GuidoPanel calcFieldInfoPanel {
-layout BoxLayout X_AXIS
-visible false
GuidoPanel outerCalcFieldPanel {
-layout BoxLayout Y_AXIS
GuidoFiller filler24 {
-height 0.5
}
GuidoPanel calcFieldPanel {
-layout BoxLayout X_AXIS
GuidoComboBox fldTypeComboBox {
-display_length 5
-exclusive true
-format none
-input true
-label "Field Type"
-next_focus fieldLengthFld
-null disallowed
-value_in "character" "real" "integer" "datetime" "duration" "boolean" "memo"
}
GuidoFiller filler25 {
-width 0.2
}
GuidoField fieldLengthFld {
-display_length 5
-format none
-input true
-label "Field Length"
-next_focus fieldNumDecFld
-null disallowed
}
GuidoFiller filler26 {
-width 0.2
}
GuidoField fieldNumDecFld {
-default 0
-dependency {"[$fldTypeComboBox getCurrentValue]" == "real"}
-display_length 5
-format none
-input true
-label "Num Decimals"
-null disallowed
}
}
GuidoFiller filler27 {
-height 0.2
}
GuidoPanel calcFunctionPanel {
-layout BoxLayout Y_AXIS
GuidoPanel innerCalcFunctionPanel {
-layout BoxLayout X_AXIS
GuidoComboBox functionComboBox {
-display_length 6
-exclusive true
-format none
-input true
-label "Calc Func"
-null disallowed
-value_in "constant" "expression" "translate" "x" "y" "z"
}
}
GuidoFiller filler28 {
-height 0.2
}
GuidoPanel functionOverLayPanel {
-layout OverlayLayout
GuidoPanel constValuePanel {
-dependency {"[$functionComboBox getCurrentValue]" == "constant"}
-layout BoxLayout X_AXIS
GuidoComboBox constComboBox {
-display_length 6
-exclusive true
-format none
-input true
-label "Constant Type"
-next_focus constValueField
-null disallowed
-value_in "NULL" "boolean" "integer" "real" "character" "datetime" "duration"
}
GuidoFiller filler29 {
-width 0.2
}
GuidoField constValueField {
-default ""
-dependency {"[$constComboBox getCurrentValue]" != "NULL"}
-display_length 8
-input true
-label "Constant Value"
}
}
GuidoPanel translatePanel {
-dependency {"[$functionComboBox getCurrentValue]" == "translate"}
-layout CentreLineLayout
GuidoField transTableField {
-default "translation"
-display_length 7
-label "Translation Table"
-next_focus transFieldComboBox
}
GuidoComboBox transFieldComboBox {
-default "code"
-display_length 8
-null false
-input false
-label "Translation Field"
-next_focus fieldToBeTrans
}
GuidoField fieldToBeTrans {
-display_length 7
-label "Field To Be Translated"
}
}
GuidoPanel xyzPanel {
-dependency {"[$functionComboBox getCurrentValue]" != "constant" &&
"[$functionComboBox getCurrentValue]" != "translate" &&
"[$functionComboBox getCurrentValue]" != "expression"}
-layout BoxLayout X_AXIS
GuidoField holeIdField {
-default ""
-display_length 8
-input true
-label "Hole Id Field"
}
GuidoFiller filler32 {
-width 0.2
}
GuidoField depthField {
-default ""
-display_length 8
-input true
-label "Depth Field"
}
}
GuidoPanel expressionPanel {
-layout BoxLayout X_AXIS
-dependency {"[$functionComboBox getCurrentValue]" == "expression"}
GuidoLabel expressionLabel {
-label "Expression"
}
GuidoFiller filler34 {
-width 0.2
}
GuidoField expressionField {
-display_length 30
-max_length DB_MAX_EXPRESSION_LENGTH
-null false
-tip DB_ALGEBRAIC_EXPRESSION_TIP
}
}
}
}
GuidoPanel calcTablePanel {
-layout BoxLayout Y_AXIS
GuidoFiller filler33 {
-height 0.3
}
GuidoScrollPane fieldsTableScroll {
-dependency {"[$functionComboBox getCurrentValue]" == "translate"}
-scroll_size 33 4
GuidoTable fieldsTable {
-instances 5
-interactive true
-row_headings_visible false
GuidoComboBox LHSValueBrowser {
-display_length 11
-exclusive true
-format none
-input true
-label "Field Name"
-max_length 1024
}
GuidoComboBox operatorComboBox {
-display_length 0.5
-exclusive true
-input true
-label "Op"
-null disallowed
-value_in "=" "<" ">" "<>"
}
GuidoComboBox RHSValueBrowser {
-display_length 11
-exclusive false
-format none
-input true
-label "RHS"
-null allowed
-max_length 1024
}
}
}
}
}
}
}
}
GuidoPanel buttonPanel {
-layout FlowLayout Left
GuidoButton helpButton3 {
-caption " "
-icon "icons/16/help.png"
-action valueChanged { [$mapDatabaseForm setStatus "help"] }
}
GuidoFiller filler12 {
-width 30
}
GuidoButton prevButton3 {
-caption "Prev"
-display_length 10
-icon "icons/LeftArrow.gif"
-action valueChanged { [$mapDatabaseForm setStatus "prev"] }
}
GuidoButton finishButton3 {
-caption "Finish"
-display_length 10
-icon "icons/16/activate.png"
-action valueChanged { [$mapDatabaseForm setStatus "finish"] }
}
GuidoButton cancelButton3 {
-caption "Cancel"
-display_length 10
-icon "icons/cancel.png"
-action valueChanged { [$mapDatabaseForm setStatus "cancel"] }
}
}
}
}
$refreshViewButton setActionCallback valueChanged {[refreshODBCTreeView $showTablesCheckBox $showViewsCheckBox $showProceduresCheckBox $showSystablesCheckBox $showSynonymsCheckBox $userMaskField $tableMaskField $realDatabaseStructure]}
$addFieldItem setActionCallback mouseReleased {[addCalculatedField]}
$removeNodeItem setActionCallback mouseReleased {[removeNode $ddbStructure]}
$removeMappingItem setActionCallback mouseReleased {[removeMapping $ddbStructure]}
$renameNodeItem setActionCallback mouseReleased {[renameNode]}
$realDatabaseStructure installTreeLoader DatabaseStructureBrowser
$realDatabaseStructure setEditable false
$realDatabaseScroll add [$realDatabaseStructure getObject]
set tcl_path [ GuidoGetParamBufferValue [ GuidoExecServer GetTCLPath { } ] tclPath ]
set mapping_filename [lindex $argv 0]
source "$tcl_path/$mapping_filename"
if {$num_mand_tables != 0 || $num_opt_tables != 0 || $num_opt_table_types != 0} {
set root_node [$ddbStructure getRootNode]
if {$num_mand_tables > 0} {
GuidoTreeBranch mandatory_tables {
-label "Mandatory Tables"
-default "Mandatory Tables"
-menu_enabled false
}
$root_node addChild $mandatory_tables
for {set idx 0} {$idx < $num_mand_tables} {incr idx} {
upvar 0 mand_table($idx).type ttype
upvar 0 mand_table($idx).name tname
set mtable [createTableStructure $ttype $tname $tname]
$mandatory_tables addChild $mtable
set mand_table($idx).node_handle $mtable
}
}
if {$num_opt_tables > 0 || $num_opt_table_types > 0} {
GuidoTreeBranch optional_tables {
-label "Optional Tables"
-default "Optional Tables"
-menu_enabled false
}
$root_node addChild $optional_tables
for {set idx 0} {$idx < $num_opt_tables} {incr idx} {
upvar 0 opt_table($idx).type opt_table_type
upvar 0 opt_table($idx).name opt_table_name
set otable [createTableStructure $opt_table_type $opt_table_name $opt_table_name]
$optional_tables addChild $otable
set opt_table($idx).node_handle $otable
}
for {set idx 0} {$idx < $num_opt_table_types} {incr idx} {
upvar 0 opt_table_types($idx).name opt_table_types_name
GuidoTreeBranch opt_table_types_$idx {
-label "$opt_table_types_name"
-default "DB_OPTIONAL_TABLE_TYPE"
-menu_enabled false
}
upvar 0 opt_table_types_$idx table
$optional_tables addChild $table
set opt_table_types($idx).node_handle $table
}
}
getDatabaseMappings $ddbStructure
$ddbScroll add [$ddbStructure getObject]
set num_child [$root_node getChildCount]
incr num_child -1
set last_node [$root_node getChildAt $num_child]
$ddbStructure scrollPathToVisible $last_node
set mapperApp [lindex $argv 2]
while {1} {
set returnCode [$mapDatabaseForm interact]
if {"$returnCode" == "cancel"} {
GuidoExecServer "MapDatabaseCleanup" [subst {DatabaseType = $dbType}]
set returnVal "CANCEL"
break
} elseif {"$returnCode" == "prev"} {
GuidoExecServer "MapDatabaseCleanup" [subst {DatabaseType = $dbType}]
set returnVal "PREVIOUS"
break
} elseif {"$returnCode" == "finish"} {
saveSelectedNodeInfo $ddbStructure
set checkParams [GuidoExecServer "checkNodeIsMapped" [subst { surpacDBStructure = "[$ddbStructure getDataBufferString]" unrequired = "$unrequiredField" }]]
set isMapped [GuidoGetParamBufferValue $checkParams isMapped]
if {"$isMapped" == "true"} {
$mapperApp setParam DDBTree "[$ddbStructure getDataBufferString]"
$mapperApp setParam DatabaseType $dbType
if {"$physicalDBType" == "odbc"} {
$mapperApp setParam Systables [$showSystablesCheckBox isSelected]
$mapperApp setParam Tables [$showTablesCheckBox isSelected]
$mapperApp setParam Procedures [$showProceduresCheckBox isSelected]
$mapperApp setParam Synonyms [$showSynonymsCheckBox isSelected]
$mapperApp setParam Views [$showViewsCheckBox isSelected]
$mapperApp setParam PromptID [$promptIdCheckBox isSelected]
$mapperApp setParam OracleSetRole "[$oracleRoleField getCurrentValue]"
$mapperApp setParam UserMask "[$userMaskField getCurrentValue]"
$mapperApp setParam TableMask "[$tableMaskField getCurrentValue]"
} elseif {"$physicalDBType" == "access"} {
$mapperApp setParam SQLExtra "[$sqlExtraField getCurrentValue]"
} elseif {"$physicalDBType" == "paradox"} {
$mapperApp setParam Multiuser [$multiuserCheckBox isSelected]
}
set returnCode [$mapperApp invoke]
if { $returnCode == "0" } {
set returnVal "FINISH"
break
}
}
}
}
$mapDatabaseForm destroy
} else {
endProgressFeedback
}
set returnStatus $returnVal
