proc PrevValue {fieldName} {
set rval [$fieldName getCurrentValueRelative -1]
if {[string length $rval] > 0} {
$fieldName setCurrentValue $rval
}
}
proc null_dependency {tableName fieldName} {
if {$fieldName == "hole_id"} {
return 0
} elseif {$tableName == "survey"} {
if {$fieldName == "depth"} {
return 0
}
} elseif {$tableName == "translation"} {
if {$fieldName == "table_name" || $fieldName == "field_name" || $fieldName == "code"} {
return 0;
}
} elseif {$tableName == "survey_stations"} {
if {$fieldName == "station_id" || $fieldName == "date_stamp"} {
return 0
}
} elseif {$fieldName == "prism_id" || $fieldName == "prism_date"} {
return 0
} elseif {$fieldName == "depth_from" || $fieldName == "depth_to" || $fieldName == "sampid" || $fieldName == "samp_date"} {
return 0
}
return 1
}
proc updateLengthFieldDefault {typeField lengthField} {
set type [$typeField getCurrentValue]
if {$type == "datetime" || $type == "duration"} {
$lengthField setCurrentValue 23
} else {
$lengthField setCurrentValue 10
}
}
proc createPanels { formHandle tableName index } {
global mainPanel
GuidoPanel "$tableName\Panel" {
-layout BoxLayout Y_AXIS
-no_mlt
-label $tableName
GuidoFiller "fillerHeight1$index" {
-height 1
}
GuidoLabel "MandatoryLabel$index" {
-label "Mandatory Fields"
}
GuidoScrollPane "Scroll1For$tableName" {
-height 9
-width 54
GuidoTable "mand_fields$index" {
-interactive false
GuidoLabel "mand_field_for_table$index" {
-label Field
-display_length 10
}
upvar 0 "mand_field_for_table$index" manField
GuidoLabel "mand_type_for_table$index" {
-label Type
-display_length 8
}
upvar 0 "mand_type_for_table$index" manType
GuidoCheckBox "mand_nulls_for_table$index" {
-dependency {[null_dependency "$tableName" "[$manField getCurrentValue]"]}
-default false
-label Nulls
-selected_value Y
-unselected_value N
-tip DB_FIELD_NULLS_TIP
}
GuidoComboBox "mand_index_for_table$index" {
-dependency {"[$manField getCurrentValue]" == "samp_id"}
-display_length 4
-format none
-label Index
-max_length 10
-value_in unique duplicates none
-tip DB_FIELD_MAND_INDEX_TIP
}
GuidoField "mand_length_for_table$index" {
-display_length 2
-format integer
-high_bound 512
-label Length
-low_bound 1
-translate none
-tip DB_FIELD_LENGTH_TIP
}
GuidoField "mand_decimals_for_table$index" {
-dependency {"[$manType getCurrentValue]" == "real"}
-display_length 2
-format integer
-high_bound 8
-label "No. Dec"
-low_bound 0
-translate none
-tip DB_FIELD_DECIMALS_TIP
}
GuidoField "mand_lo_bound_for_table$index" {
-dependency {"[$manType getCurrentValue]" != "character"}
-display_length 6
-format double
-label "DB_CREATE_TABLES_TEXT10"
-translate none
-tip DB_FIELD_LOW_BOUND_TIP
}
GuidoField "mand_hi_bound_for_table$index" {
-dependency {"[$manType getCurrentValue]" != "character"}
-display_length 6
-format double
-label "DB_CREATE_TABLES_TEXT11"
-translate none
-tip DB_FIELD_LOW_BOUND_TIP
}
}
}
GuidoFiller "Scroll2Filler$index" {
-height 1
}
GuidoLabel "OptionalLabel$index" {
-label "Optional Fields"
}
GuidoScrollPane "Scroll2For$tableName" {
-height 9
-width 105
GuidoTable "opt_fields$index" {
-interactive true
GuidoField "opt_field_for_table$index" {
-label Field
-display_length 10
-format none
-input true
-max_length 18
-translate lower
-tip DB_FIELD_TIP
}
upvar 0 "opt_type_for_table$index" optType
GuidoComboBox "opt_type_for_table$index" {
-label Type
-default character
-display_length 5
-format none
-max_length 9
-value_in character boolean datetime duration integer real memo
-action initial {[PrevValue $optType]}
-tip DB_FIELD_DATATYPE_TIP
}
upvar 0 "opt_nulls_for_table$index" optNulls
GuidoCheckBox "opt_nulls_for_table$index" {
-default false
-label Nulls
-selected_value Y
-unselected_value N
-action initial {[PrevValue $optNulls]}
-tip DB_FIELD_NULLS_TIP
}
upvar 0 "opt_length_for_table$index" optLength
GuidoField "opt_length_for_table$index" {
-dependency {"[$optType getCurrentValue]" != "memo" && "[$optType getCurrentValue]" != "boolean"}
-display_length 2
-format integer
-high_bound 512
-label Length
-low_bound 1
-max_length -1
-translate none
-action initial {[PrevValue $optLength]}
-tip DB_FIELD_MAND_INDEX_TIP
}
$optType setActionCallback valueChanged { [updateLengthFieldDefault $optType $optLength] }
upvar 0 "opt_decimals_for_table$index" optDecimals
GuidoField "opt_decimals_for_table$index" {
-dependency {"[$optType getCurrentValue]" == "real"}
-display_length 2
-format integer
-high_bound 8
-label "No. Dec"
-low_bound 0
-max_length -1
-translate none
-action initial {[PrevValue $optDecimals]}
-tip DB_FIELD_DECIMALS_TIP
}
GuidoComboBox "opt_case_for_table$index" {
-default mixed
-dependency {"[$optType getCurrentValue]" == "character" ||
"[$optType getCurrentValue]" == "memo" }
-display_length 4
-format none
-label Case
-max_length 5
-value_in lower upper mixed
-tip DB_FIELD_CASE_TIP
}
upvar 0 "opt_lo_bound_for_table$index" optLoBound
GuidoField "opt_lo_bound_for_table$index" {
-dependency {"[$optType getCurrentValue]" == "integer" || "[$optType getCurrentValue]" == "real"  }
-display_length 6
-format double
-label "DB_CREATE_TABLES_TEXT10"
-translate none
-action initial {[PrevValue $optLoBound]}
-tip DB_FIELD_LOW_BOUND_TIP
}
upvar 0 "opt_hi_bound_for_table$index" optHiBound
GuidoField "opt_hi_bound_for_table$index" {
-dependency {"[$optType getCurrentValue]" == "integer" || "[$optType getCurrentValue]" == "real"  }
-display_length 6
-format double
-label "DB_CREATE_TABLES_TEXT11"
-translate none
-action initial {[PrevValue $optHiBound]}
-tip DB_FIELD_LOW_BOUND_TIP
}
GuidoComboBox "phys_or_virt_for_table$index" {
-default physical
-display_length 6
-format none
-label "Phys, Virt or Exp"
-max_length 10
-value_in physical virtual expression
-tip DB_FIELD_SPECIAL_TYPE_TIP
}
upvar 0 "phys_or_virt_for_table$index" optPhys
GuidoField "reference_field_for_table$index" {
-dependency {"[$optPhys getCurrentValue]" != "physical"}
-display_length 20
-format none
-label "Reference field or Expression"
-max_length DB_MAX_EXPRESSION_LENGTH
-null false
-translate lower
-tip DB_DBCREATE_REF_FIELD_TIP
}
GuidoField "valid_entries_for_table$index" {
-dependency {"[$optType getCurrentValue]" == "character" ||
"[$optType getCurrentValue]" == "memo" }
-display_length 11
-format none
-label "DB_CREATE_TABLES_TEXT12"
-max_length 256
-translate none
-tip DB_VALID_ENTRIES_TIP
}
}
}
}
upvar 0 $tableName\Panel panel
set panelObject  [$panel getObject]
$mainPanel add $panelObject
set numberMandFields [$formHandle numberInputFields "mand_fields$index"]
upvar 0 mand_fields$index table
$table setInitialRows $numberMandFields 1 $numberMandFields
for {set i 0 } {$i < $numberMandFields} {incr i} {
upvar 0 mand_field_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "mand_fields$index\($i\).mand_field_for_table$index"]
upvar 0 mand_type_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "mand_fields$index\($i\).mand_type_for_table$index"]
upvar 0 mand_nulls_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "mand_fields$index\($i\).mand_nulls_for_table$index"]
upvar 0 mand_index_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "mand_fields$index\($i\).mand_index_for_table$index"]
upvar 0 mand_length_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "mand_fields$index\($i\).mand_length_for_table$index"]
upvar 0 mand_decimals_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "mand_fields$index\($i\).mand_decimals_for_table$index"]
upvar 0 mand_lo_bound_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "mand_fields$index\($i\).mand_lo_bound_for_table$index"]
upvar 0 mand_hi_bound_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "mand_fields$index\($i\).mand_hi_bound_for_table$index"]
}
set numberOptFields [$formHandle numberInputFields "opt_fields$index"]
upvar 0 opt_fields$index table
$table setInitialRows $numberOptFields 1 [expr 60 - $numberMandFields]
for {set i 0 } {$i < $numberOptFields} {incr i} {
upvar 0 opt_field_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "opt_fields$index\($i\).opt_field_for_table$index"]
upvar 0 opt_type_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "opt_fields$index\($i\).opt_type_for_table$index"]
upvar 0 opt_nulls_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "opt_fields$index\($i\).opt_nulls_for_table$index"]
upvar 0 opt_case_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "opt_fields$index\($i\).opt_case_for_table$index"]
upvar 0 opt_length_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "opt_fields$index\($i\).opt_length_for_table$index"]
upvar 0 opt_decimals_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "opt_fields$index\($i\).opt_decimals_for_table$index"]
upvar 0 opt_lo_bound_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "opt_fields$index\($i\).opt_lo_bound_for_table$index"]
upvar 0 opt_hi_bound_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "opt_fields$index\($i\).opt_hi_bound_for_table$index"]
upvar 0 valid_entries_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "opt_fields$index\($i\).valid_entries_for_table$index"]
upvar 0 phys_or_virt_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "opt_fields$index\($i\).phys_or_virt_for_table$index"]
upvar 0 reference_field_for_table$index field
$field setCurrentValue $i [$formHandle readInputField "opt_fields$index\($i\).reference_field_for_table$index"]
}
upvar 0 mand_fields$index table1
set manTable [$table1 getObject]
$manTable invalidate
$manTable repaint
upvar 0 opt_fields$index table2
set optTable [$table2 getObject]
$optTable invalidate
$optTable repaint
if {$index == 1} {
$table2 setEditingCell -1 -1
}
}
proc setupTables { formHandle } {
global mainPanel
set numberTables [expr [$formHandle numberInputFields] / 4 ]
for { set index 1 } {$index <= $numberTables } {incr index} {
set tableName [$formHandle readInputField "mand_table$index"]
createPanels $formHandle $tableName $index
}
$formHandle legacyProcessValues true
$formHandle updateFieldList
}
proc finished {formHandle} {
if { [string compare [$formHandle getStatus] "legacy preprocess apply"] ==  0 } {
$formHandle finishedWritingFields
}
}
GuidoForm frmCreateDatabase {
-layout BoxLayout Y_AXIS
-action initial {[setupTables $frmCreateDatabase ] }
-action stateChanged {[finished $frmCreateDatabase ]}
-label "Create Database"
-default_buttons
-width 80
-height 25
-next_focus opt_fields1
-help_id 204
-tip DEFINE_ALL_FIELDS_FOR_ALL_TABLES
GuidoTabbedPane mainPanel {
}
$frmCreateDatabase legacyProcessValues false
}
