home *** CD-ROM | disk | FTP | other *** search
- *******************************************************************************
- * PROGRAM: Getfield.wfm
- *
- * WRITTEN BY: Borland Samples Group
- *
- * DATE: 3/95
- *
- * UPDATED: 7/95
- *
- * REVISION: $Revision: 1.18 $
- *
- * VERSION: Visual dBASE
- *
- * DESCRIPTION: This is a tool for selecting fields from a list of tables.
- *
- * PARAMETERS: None
- *
- * CALLS: Buttons.cc (Custom Controls file)
- *
- * USAGE: DO Getfield.wfm
- *
- ********************************************************************************
- #include <Messdlg.h>
-
- *** Field restrictions
- #define MEMO_BINARY_OLE "M, B, O"
- #define PDOX_FIELD_DELIM ":"
-
- * GetField.wfm
- * (Take 2)
-
- create session
- set talk off
- set exact off
- set fullpath off
-
-
- ** END HEADER -- do not remove this line*
- * Generated on 04/10/95
- *
- parameter bModal
- local f
- f = new GETFIELDFORM()
- if (bModal)
- f.mdi = .F. && ensure not MDI
- f.ReadModal()
- else
- f.Open()
- endif
- CLASS GETFIELDFORM OF FORM
- set procedure to &_dbwinhome.custom\Buttons.cc additive
- this.OnClose = CLASS::FORM_ONCLOSE
- this.Text = "Select Fields"
- this.Left = 5
- this.ColorNormal = "N/BTNFACE"
- this.Top = 1
- this.TopMost = .F.
- this.PageNo = 1
- this.Height = 13.8232
- this.Width = 73.666
- this.OnOpen = CLASS::FORM_ONOPEN
-
- DEFINE RECTANGLE ALLRECT OF THIS;
- PROPERTY;
- Text "",;
- Left 0.5,;
- ColorNormal "BTNTEXT/BTNFACE",;
- Top 1.1758,;
- PageNo 1,;
- Border .T.,;
- Height 10.8242,;
- Width 73.166
-
- DEFINE RECTANGLE TABLESRECT OF THIS;
- PROPERTY;
- Text "",;
- Left 1.1973,;
- ColorNormal "BTNTEXT/gb",;
- Top 3.5293,;
- PageNo 1,;
- Border .T.,;
- Height 8.2939,;
- Width 21.3027
-
- DEFINE TEXT TABLESTEXT OF THIS;
- PROPERTY;
- Text "Available Tables:",;
- Left 1.5,;
- ColorNormal "w/gb",;
- Top 3.8223,;
- PageNo 1,;
- Border .F.,;
- Height 0.707,;
- FontSize 9,;
- Width 17.166
-
- DEFINE LISTBOX TABLELIST OF THIS;
- PROPERTY;
- Sorted .T.,;
- DataSource "TABLES",;
- FontBold .F.,;
- Left 1.75,;
- ColorNormal "n/w+",;
- ID 100,;
- Top 4.5879,;
- PageNo 1,;
- OnSelChange CLASS::TABLELIST_ONSELCHANGE,;
- Height 6.8232,;
- Width 20.083,;
- ColorHighLight "w+/w"
-
- DEFINE RECTANGLE FIELDRECT OF THIS;
- PROPERTY;
- FontBold .F.,;
- Text "",;
- Left 25.3311,;
- ColorNormal "gb/gb",;
- Top 3.5293,;
- FontItalic .T.,;
- PageNo 1,;
- FontName "Times New Roman",;
- Border .T.,;
- Height 8.2939,;
- FontSize 10,;
- Width 47.335
-
- DEFINE TEXT AVAILABLETEXT OF THIS;
- PROPERTY;
- Text "Available Fields:",;
- Left 26.5,;
- ColorNormal "w/gb",;
- Top 3.8223,;
- PageNo 1,;
- Border .F.,;
- Height 0.707,;
- FontSize 9,;
- Width 19.166
-
- DEFINE LISTBOX AVAILABLELIST OF THIS;
- PROPERTY;
- Sorted .T.,;
- OnLeftDblClick CLASS::SELECTONEFIELDPUSH_ONCLICK,;
- FontBold .F.,;
- Left 26.3311,;
- ColorNormal "b/w+",;
- ID 101,;
- Top 4.5879,;
- PageNo 1,;
- Height 6.8232,;
- Width 20.002,;
- ColorHighLight "w+/w"
-
- DEFINE PUSHBUTTON SELECTONEFIELDPUSH OF THIS;
- PROPERTY;
- Text ">",;
- Left 47,;
- ColorNormal "BtnText/BtnFace",;
- Top 4.5879,;
- PageNo 1,;
- OnClick CLASS::SELECTONEFIELDPUSH_ONCLICK,;
- Default .T.,;
- Group .T.,;
- Height 1.2939,;
- Width 4
-
- DEFINE PUSHBUTTON SELECTALLFIELDPUSH OF THIS;
- PROPERTY;
- Text ">>",;
- Left 47,;
- ColorNormal "BtnText/BtnFace",;
- Top 6,;
- PageNo 1,;
- OnClick CLASS::SELECTALLFIELDPUSH_ONCLICK,;
- Group .T.,;
- Height 1.2939,;
- Width 4
-
- DEFINE PUSHBUTTON UNSELECTONEFIELDPUSH OF THIS;
- PROPERTY;
- Text "<",;
- Left 47,;
- ColorNormal "BtnText/BtnFace",;
- Top 8.7051,;
- PageNo 1,;
- OnClick CLASS::UNSELECTONEFIELDPUSH_ONCLICK,;
- Group .T.,;
- Height 1.2949,;
- Width 4
-
- DEFINE PUSHBUTTON UNSELECTALLFIELDPUSH OF THIS;
- PROPERTY;
- Text "<<",;
- Left 47,;
- ColorNormal "BtnText/BtnFace",;
- Top 10.1758,;
- PageNo 1,;
- OnClick CLASS::UNSELECTALLFIELDPUSH_ONCLICK,;
- Group .T.,;
- Height 1.2939,;
- Width 4
-
- DEFINE TEXT SELECTEDTEXT OF THIS;
- PROPERTY;
- Text "Selected Fields:",;
- Left 52,;
- ColorNormal "w+/gb",;
- Top 3.8223,;
- PageNo 1,;
- Border .F.,;
- Height 0.7656,;
- FontSize 9,;
- Width 19.166
-
- DEFINE LISTBOX SELECTEDLIST OF THIS;
- PROPERTY;
- Sorted .T.,;
- OnLeftDblClick CLASS::UNSELECTONEFIELDPUSH_ONCLICK,;
- FontBold .F.,;
- Left 52,;
- ColorNormal "r/w+",;
- ID 101,;
- Top 4.5879,;
- PageNo 1,;
- Height 6.8232,;
- Width 20,;
- ColorHighLight "w+/w"
-
- DEFINE TEXT ARROWTEXT OF THIS;
- PROPERTY;
- Text "=>",;
- Left 22.8311,;
- ColorNormal "BtnText/BtnFace",;
- Top 7.1758,;
- Alignment 4,;
- PageNo 1,;
- FontName "Arial",;
- Border .F.,;
- Height 1.1182,;
- FontSize 11,;
- Width 2.002
-
- DEFINE PUSHBUTTON ALIASBUTTON OF THIS;
- PROPERTY;
- FontBold .F.,;
- Text "Aliases ...",;
- Left 15.1973,;
- ColorNormal "BtnText/BtnFace",;
- Top 12.2979,;
- PageNo 1,;
- Enabled .F.,;
- Group .T.,;
- Height 1.5254,;
- Width 14.1357
-
- DEFINE OKBUTTON OKBUTTON1 OF THIS;
- PROPERTY;
- FontBold .F.,;
- Left 30,;
- Top 12.2979,;
- OnClick {;form.Close()},;
- Group .T.,;
- Height 1.5254,;
- Width 14.166
-
- DEFINE CANCELBUTTON CANCELBUTTON1 OF THIS;
- PROPERTY;
- FontBold .F.,;
- Left 45,;
- Top 12.2979,;
- Group .T.,;
- Height 1.5254,;
- Width 14.166
-
- DEFINE HELPBUTTON HELPBUTTON1 OF THIS;
- PROPERTY;
- FontBold .F.,;
- Enabled .F.,;
- Left 59.5,;
- Top 12.2979,;
- Group .T.,;
- Height 1.5254,;
- Width 14.166
-
- DEFINE TEXT DIRECTORYTEXT OF THIS;
- PROPERTY;
- FontBold .F.,;
- Text "",;
- Left 0.5,;
- ColorNormal "W+/BTNFACE",;
- Top 0.1973,;
- PageNo 1,;
- Border .F.,;
- Height 0.8975,;
- Width 73
-
- DEFINE RECTANGLE RADIORECT OF THIS;
- PROPERTY;
- Text "",;
- Left 1,;
- ColorNormal "BTNTEXT/BTNFACE",;
- Top 1.2998,;
- PageNo 1,;
- Border .T.,;
- Height 2.1699,;
- Width 72.166
-
- DEFINE RADIOBUTTON DATABASERADIO OF THIS;
- PROPERTY;
- FontBold .F.,;
- Text "Tables from D&atabase",;
- Left 16.5,;
- ColorNormal "B/BTNFACE",;
- Top 2.4199,;
- PageNo 1,;
- OnChange CLASS::DATABASERADIO_ONCHANGE,;
- Group .T.,;
- Height 0.85,;
- Width 20.666,;
- Value .F.
-
- DEFINE RADIOBUTTON DIRRADIO OF THIS;
- PROPERTY;
- FontBold .F.,;
- Text "Tables from D&irectory",;
- Left 16.5,;
- ColorNormal "B/BTNFACE",;
- Top 1.5,;
- PageNo 1,;
- OnChange CLASS::DIRRADIO_ONCHANGE,;
- Group .F.,;
- Height 0.85,;
- Width 19.333,;
- Value .T.
-
- DEFINE PUSHBUTTON DIRECTORYBUTTON OF THIS;
- PROPERTY;
- FontBold .F.,;
- Text "&Directory",;
- Left 1.5,;
- ColorNormal "BtnText/BtnFace",;
- Top 1.6992,;
- PageNo 1,;
- OnClick CLASS::DIRECTORYBUTTON_ONCLICK,;
- UpBitmap "RESOURCE #137",;
- Group .T.,;
- Height 1.5352,;
- Width 14.166
-
- DEFINE PUSHBUTTON DATABASEBUTTON OF THIS;
- PROPERTY;
- FontBold .F.,;
- Visible .F.,;
- Text "&Login...",;
- Left 1.5,;
- ColorNormal "BtnText/BtnFace",;
- Top 1.6992,;
- PageNo 1,;
- OnClick CLASS::DATABASEBUTTON_ONCLICK,;
- UpBitmap "RESOURCE #137",;
- Group .T.,;
- Height 1.5352,;
- Width 14.166
-
- DEFINE ENTRYFIELD DATABASEENTRY OF THIS;
- PROPERTY;
- Function "!",;
- Left 40.5,;
- ColorNormal "WINDOWTEXT/W",;
- Top 2.31,;
- PageNo 1,;
- Function "!S25",;
- Enabled .F.,;
- Border .T.,;
- Height 1.0029,;
- Width 32,;
- Value "",;
- ColorHighLight "WINDOWTEXT/WINDOW"
-
- procedure FORM_OnOpen
- ****************************************************************************
-
- set procedure to &_dbwinhome.utils\Sql.wfm additive && Procedure file
-
-
- form.saveExact = set("exact")
- set exact off
-
-
- * Arrays for storing fields from selected tables -- all available and
- * those specifically selected.
- form.availableAr = new array(0)
- form.selectedAr = new array(0)
-
- form.tableNamesAr = new array(0)
-
- form.availableList.dataSource = "array form.availableAr"
- form.selectedList.dataSource = "array form.selectedAr"
-
- form.tableList.curSel = 1 && Immediately show fields of first table
-
- form.allFields = .F. && Indicates if all fields were selected
- form.tablesFromDatabase = .F. && Indicates if tables are from database
-
- form.saveArea = workarea() && Save workarea
- form.tempArea = select() && Temporary workarea
- form.saveDir = setto("directory") && Save directory, in case it changes
-
- if empty(setto("database"))
- form.dirRadio.SetFocus()
- form.directoryText.text = lower(form.saveDir)
- form.serverName = ""
- else
- form.databaseRadio.SetFocus()
- form.databaseButton.OnClick()
- form.serverName = setto("database")
- endif
- form.tableList.OnSelChange()
-
-
- ****************************************************************************
-
- procedure FORM_OnClose
- ****************************************************************************
- private i, saveArea, tempArea, afterPeriod, curDir, saveDir, saveExact,;
- serverName, selectedArSize, tableNamesArSize
-
- selectedArSize = form.selectedAr.size
- tableNamesArSize = form.tableNamesAr.size
-
- form.selectedAr.Sort()
- if form.tablesFromDatabase && Tables from database
- serverName = rtrim(form.directoryText.text)
- form.serverName = serverName
- for i = 1 to selectedArSize
- && Surround field name with double quotes (some servers don't like ')
- form.selectedAr[i] = SurroundLastWordByQuotes(form.selectedAr[i])
- next i
- for i = 1 to tableNamesArSize
- form.tableNamesAr[i] = SurroundByQuotes(form.tableNamesAr[i])
- next i
- else && Tables from directory
- * Uppercase selected table and field arrays
- for i = 1 to selectedArSize
- && Surround field name with double quotes
- form.selectedAr[i] = upper(;
- SurroundLastWordByQuotes(form.selectedAr[i]))
- next i
- *** Local SQL doesn't allow drives in table names w/o quotes
- curDir = setto("directory") + "\"
- for i = 1 to form.tableNamesAr.size
- form.tableNamesAr[i] = upper(;
- SurroundByQuotes(curDir + form.tableNamesAr[i]))
- next i
- endif
-
- form.tableNamesAr.Sort()
-
- close procedure &_dbwinhome.custom\Buttons.cc, &_dbwinhome.utils\Sql.wfm
-
- tempArea = str(form.tempArea)
- saveArea = str(form.saveArea)
- saveDir = form.saveDir
- saveExact = form.saveExact
- use in &tempArea
- select &saveArea
- cd &saveDir
- set exact &saveExact
-
-
- ****************************************************************************
-
- procedure SelectOneFieldPush_OnClick
- ****************************************************************************
- private tableName, markedField, lastSelectedField, saveExact, saveCurSel
-
- saveCurSel = form.availableList.curSel
- * if available fields exist, and one is marked
- if (form.availableAr.size > 0) .and. (form.availableList.curSel > 0)
- * Once a single field button is pressed, allFields is .F.
- form.allFields = .F.
-
- * Add currently marked item in "available" list to "selected" list
- markedField = form.availableList.selected()
- form.selectedAr.Add(markedField)
- if form.availableAr.size > 1
- form.availableAr.Delete(form.availableList.curSel) && No longer available
- form.availableAr.Resize(form.availableAr.size - 1) && Resize available ar
- else
- form.availableAr = new array(0)
- form.availableList.dataSource = "array form.availableAr"
- form.selectedList.curSel = 1 && Highlight first selected field
- endif
-
- * Add Table name to list of selected tables
- lastSelectedField = form.selectedAr[form.selectedAr.size]
- tableName = form.tableList.Selected() &&substr(lastSelectedField, 1, rat(".", lastSelectedField) -1)
- saveExact = set("exact")
- set exact on
- if form.tableNamesAr.Scan(tableName) = 0 && Add table to array of tables
- form.tableNamesAr.Add(tableName)
- endif
- set exact &saveExact
-
- form.UpdateListboxes()
- * Don't want curSel to ever = 0
- form.availableList.curSel = max(1, min(saveCurSel, form.availableAr.size))
- form.selectedList.curSel = form.selectedAr.Scan(markedField)
- if type("form.oneTable") <> "U"
- CLASS::CheckSelected(form.tableList, form.selectedList)
- endif
- endif
-
-
- ****************************************************************************
-
- procedure SelectAllFieldPush_OnClick
- ****************************************************************************
- local availableSize, prevSelectedSize, selectedTable, tableName
-
- if (form.availableAr.size > 0) && If some fields are available
- * Indicate that all fields have been selected
- form.allFields = .T.
-
- availableSize = form.availableAr.size
- prevSelectedSize = form.selectedAr.size
-
- * Copy all elements from "available" to "selected" array
- form.selectedAr.Resize(prevSelectedSize + availableSize)
- acopy(form.availableAr, form.selectedAr, 1, availableSize, prevSelectedSize + 1)
-
- * Delete all elements from "available" array
- form.availableAr = new array(0)
-
- * Add Table names to list of selected tables
- selectedTable = form.tableList.Selected()
- tableName = selectedTable
-
- if form.tableNamesAr.Scan(tableName) = 0
- form.tableNamesAr.Add(tableName)
- endif
-
- form.UpdateListboxes()
- form.selectedList.curSel = 1 && Highlight first selected field
- if type("form.oneTable") <> "U"
- CLASS::CheckSelected(form.tableList, form.selectedList)
- endif
- endif
-
- ****************************************************************************
-
- procedure UnSelectOneFieldPush_OnClick
- ****************************************************************************
- private tableName, selectedField, selectedTable, fieldAlias, saveCurSel
-
- saveCurSel = form.selectedList.curSel
- if (form.selectedAr.size > 0) .and. (form.selectedList.curSel > 0)
- * Once a single field button is pressed, allFields is .F.
- form.allFields = .F.
-
- selectedField = form.selectedList.Selected()
- selectedTable = form.tableList.Selected()
- tableName = selectedTable
- fieldAlias = substr(selectedField, 1, at(".", selectedField) -1)
-
- if tableName = fieldAlias &&= tableName && unmark field from cur. table
- form.availableAr.Add(selectedField)
- endif
- if form.selectedAr.size > 1
- form.selectedAr.Delete(form.selectedList.curSel)
- form.selectedAr.Resize(form.selectedAr.size - 1)
- else
- form.selectedAr = new array(0)
- form.selectedList.datasource = "array form.selectedAr"
- form.availableList.curSel = 1 && Highlight first available field
- endif
-
- * If no more fields selected from this table, delete table from array of tables
- if form.selectedAr.Scan(fieldAlias) = 0 .or. form.selectedList.Count() = 0
- * Delete table name from array of tables
- form.tableNamesAr.Delete(form.tableNamesAr.Scan(fieldAlias))
- if form.tableNamesAr.size > 1
- form.tableNamesAr.Resize(form.tableNamesAr.size - 1)
- else
- form.tableNamesAr = new array(0)
- endif
- endif
-
- form.UpdateListboxes()
- form.selectedList.curSel = max(1, min(saveCurSel, form.selectedAr.size))
- form.availableList.curSel = form.availableAr.Scan(selectedField)
- if type("form.oneTable") <> "U"
- CLASS::CheckSelected(form.tableList, form.selectedList)
- endif
- endif
-
- ****************************************************************************
-
- Procedure UnSelectAllFieldPush_OnClick
- ****************************************************************************
-
- form.allFields = .F. && all fields have not been selected
-
- form.selectedAr = new array(0) && Clear seleted field array
-
- form.tableNamesAr = new array(0) && Clear table names array
- form.tableList.OnSelChange() && Show fields of current table
-
- form.UpdateListboxes()
- form.availableList.curSel = 1 && Highlight first available field
- if type("form.oneTable") <> "U"
- CLASS::CheckSelected(form.tableList, form.selectedList)
- endif
-
-
- ****************************************************************************
-
- Procedure TABLELIST_OnSelChange
- ****************************************************************************
- private i, selAlias, fieldName, fullFieldName, tempArea
-
- tempArea = str(form.tempArea)
- use (this.selected()) in &tempArea && Open table so its structure visible from availableList
- select &tempArea
- if form.tablesFromDatabase && Table from database
- selAlias = this.selected()
- else && Table from directory
- selAlias = lower(StripDrive(StripExtension(dbf())))
- endif
-
- form.availableAr = new array(0)
- for i = 1 to fcount()
- fieldName = field(i)
- * Check if Paradox table, and remove delimiters
- if left(fieldName, 1) = PDOX_FIELD_DELIM
- fieldName = substr(fieldName, 2, len(fieldName) - 2)
- endif
- * Create correct <alias>.<field> string
- if form.tablesFromDatabase
- fullFieldName = selAlias + "." + fieldName && field name in original case
- else
- fullFieldName = selAlias + "." + lower(fieldName) && lower cased field name
- endif
- * Add field to available array, if it is not a BLOB
- if form.selectedAr.Scan(fullFieldName) = 0 .and.;
- (.not. type(fieldName) $ MEMO_BINARY_OLE) && Make sure field type is
- && not MEMO, OLE, or BINARY
- form.availableAr.Add(fullFieldName)
- endif
- next i
-
- form.UpdateListboxes()
- form.availableList.curSel = 1
-
-
- ****************************************************************************
- Procedure CheckSelected(tableList, selectedList)
-
- * This procedure is called only if the form property oneTable is set
- * in the calling form. It disables the tables list if a field
- * has been selected -- to make sure only fields from one table are
- * selected in this form.
- ****************************************************************************
- private selCount
-
- selCount = selectedList.Count()
-
- if selCount > 0 .and. tableList.enabled = .T.
- tableList.enabled = .F.
- else if selCount = 0
- tableList.enabled = .T.
- endif
-
-
-
- ****************************************************************************
-
- Procedure UpdateListboxes
- ****************************************************************************
-
- *** Sorted property on listboxes doesn't sort array datasources
- form.availableAr.Sort()
- form.selectedAr.Sort()
-
- form.availableList.dataSource = "array form.availableAr"
- form.selectedList.dataSource = "array form.selectedAr"
-
-
- form.selectOneFieldPush.enabled = .T.
- form.selectAllFieldPush.enabled = .T.
- form.unSelectOneFieldPush.enabled = .T.
- form.unSelectAllFieldPush.enabled = .T.
-
- * Only buttons capable of some action are made available
- if form.selectedAr.size = 0
- form.unSelectOneFieldPush.enabled = .F.
- form.unSelectAllFieldPush.enabled = .F.
- else if form.availableAr.size = 0
- form.selectOneFieldPush.enabled = .F.
- form.selectAllFieldPush.enabled = .F.
- endif
-
-
- show object form.availableList
- show object form.selectedList
- show object form.selectOneFieldPush
- show object form.selectAllFieldPush
- show object form.unSelectOneFieldPush
- show object form.unSelectAllFieldPush
-
-
- ****************************************************************************
-
- Procedure DIRECTORYBUTTON_OnClick
- ****************************************************************************
- private tablesDir
-
- tablesDir = getdirectory()
- if .not. empty(tablesDir)
- cd &tablesDir
- endif
- form.tableList.dataSource = "TABLES"
- form.directoryText.text = lower(tablesDir)
-
- form.tableList.curSel = 1
- form.tableList.OnSelChange()
-
-
- *******************************************************************************
- Procedure DATABASEBUTTON_OnClick
- *******************************************************************************
- private databaseName
-
- databaseName = form.databaseEntry.value
- on error HandleDatabaseError()
- open database &databaseName
- set database to &databaseName
- databaseName = setto("database")
- if .not. empty(databaseName)
- form.directoryText.text = databaseName
- show object form.tableList
- show object form.availableList
- show object form.selectedList
- form.tableList.OnSelChange()
- show object form.tableList
- show object form.availableList
- show object form.selectedList
- form.tableList.SetFocus()
- else
- form.databaseEntry.value = ""
- form.dirRadio.SetFocus()
- endif
- on error
-
-
- ****************************************************************************
-
- Procedure DIRRADIO_OnChange
- ****************************************************************************
-
- form.directoryButton.visible = this.Value
- if this.Value
- form.databaseEntry.value = ""
- show object form.databaseEntry
- endif
- form.databaseEntry.enabled = .not. this.Value
- form.tablesFromDatabase = .not. this.Value
-
-
- ****************************************************************************
-
- Procedure DATABASERADIO_OnChange
- ****************************************************************************
-
- form.databaseButton.visible = this.Value
- form.databaseEntry.enabled = this.Value
- if this.value
- form.databaseEntry.SetFocus()
- endif
- form.tablesFromDatabase = this.Value
-
-
-
- ENDCLASS
-
-