############################################################################
# Copyright (C) 1982-2004 ESL Syndetic Limited #
# All Rights Reserved. #
# #
# NOTICE #
# PROPRIETARY AND CONFIDENTIAL #
# #
# This computer program is and contains trade secret and confidential and #
# proprietary information of ESL Syndetic Limited. All use, disclosure, #
# and/or reproduction not specifically authorized in writing by #
# ESL Syndetic Limited is prohibited. This program may also be protected #
# under the copyright and trade secrets laws of countries other than the #
# U.S.A. #
# #
# #
############################################################################
screen size dialog units
precision 6 # limits GetFlt's precision
include esllib.inc
include fileio.inc
include osutil.inc
include FAQs_CodeSamples_Q07_tablesort.inc
#
#************ Structure Definitions ************
#
structure CVS_FilesFilter_STR is
string Filter1 using string size 36 # Comma Separated Value Files (*.csv)
string Filter2 using string size 6 # *.csv
string Filter3 using string size 16 # includes one null
string Filter4 using string size 5 # includes two nulls
end structure
#
#************ Structure Instance ************
#
structure CVS_FilesFilter_STR FilesFilter
#
#************ Menu definition ************
#
action bar Menu_AB is
pulldown File_PD text "~File"
choice Open_MC text "~Open"
choice Clear_MC text "~Clear"
choice Save_MC text "~Save"
separator
choice Exit_MC text "E~xit"
end pulldown
end action bar
#
#************ Objects ************
#
enabled invisible temporary
primary dialog region Main_DR
size 340 200 at 40 40 in desktop
size border
title bar "ESL Table Sorting Demo"
action bar Menu_AB
system menu
minimize button
maximize button
#
#************ Table Object ************
#
enabled visible readonly table Table_TBL
size 340 200
at 0 0
in Main_DR
black foreground
column headings text
row headings numbers
column delimiter is csv
multiple row selection
horizontal scroll bar
vertical scroll bar
insert string column FName width is 70 # default to text size 32
left align heading is "Filename"
insert integer column FSize width is 50
format is "(#,##0)" center heading is "Size"
insert string column FDate width is 45 text size 12
center align right heading is "Mod.Date"
insert string column width is 45 text size 8 # No name for this one
center align left heading is "& Time"
insert float column FCost width is 60
format is "(£#,##0.00)" right heading is "Cost"
insert boolean column FBig width is 35 # No name for this one
format is "No|Yes" center align center heading is "Big?"
#
#*************** Sort Dialog using during Open *************************
#
invisible modal dialog box Sort_DB
size 134 135 at 99 50
in desktop
dialog border
title bar "Sort by Column"
system menu
list box Columns_LB
size 66 65 at 7 68
in Sort_DB
black foreground
font "system"
sort ascending
group box Order_GB
size 62 34 at 8 30
in Sort_DB
black foreground
font "system"
text "Sort Order"
checked radio button Ascending_RB
size 55 11 at 12 44
in Sort_DB
black foreground
font "system"
text "~Ascending"
group is Order
radio button Decending_RB
size 56 11 at 12 32
in Sort_DB
black foreground
font "system"
text "~Decending"
group is Order
group box Duplicates_GB
size 54 61 at 76 29
in Sort_DB
black foreground
font "system"
text "Duplicates"
checked radio button Before_RB
size 44 11 at 82 68
in Sort_DB
black foreground
font "system"
text "~Before"
group is DUPLICATE
parameter is "BEFORE"
radio button After_RB
size 44 11 at 82 56
in Sort_DB
black foreground
font "system"
text "A~fter"
group is DUPLICATE
parameter is "AFTER"
radio button Replace_RB
size 44 11 at 82 44
in Sort_DB
black foreground
font "system"
text "~Replace"
group is DUPLICATE
parameter is "REPLACE"
radio button Discard_RB
size 44 11 at 82 32
in Sort_DB
black foreground
font "system"
text "Di~scard"
group is DUPLICATE
parameter is "DISCARD"
default push button Sort_PB
size 38 15 at 14 7
in Sort_DB
font "system"
text "Sort"
cancel push button Unsort_PB
size 38 15 at 79 7
in Sort_DB
font "system"
text "Unsorted"
#
#************ Subroutine Definitions ********************
#
#
#****** Create a list of column headings that can be sorted ******
#
subroutine SortableColumns(string: TableName_SV,
string: ColumnList_SV) is
integer Column_LIV
string Heading_LSV
for each column Column_LIV of TableName_SV loop
switch (type of column Column_LIV of TableName_SV) is
case char "string" is
copy heading of column Column_LIV of TableName_SV to Heading_LSV
case char "float" is
copy heading of column Column_LIV of TableName_SV to Heading_LSV
case char "integer" is
copy heading of column Column_LIV of TableName_SV to Heading_LSV
default is
copy "" to Heading_LSV
end switch
if (Heading_LSV != "") then
if (ColumnList_SV = "") then
copy Heading_LSV " =" Column_LIV to ColumnList_SV
else
append "\n" Heading_LSV " =" Column_LIV to ColumnList_SV
end if
end if
end loop
#
#****** Display the Sort Options Dialog with a list of sortable columns ******
#
subroutine SetUpSortColumns(string: TableName_SV) is
string ColumnList_LSV
make Sort_DB permanent
call SortableColumns (TableName_SV,
ColumnList_LSV)
clear Columns_LB in Sort_DB
add to Columns_LB in Sort_DB
insert ColumnList_LSV
disable Sort_PB in Sort_DB
make Sort_DB visible
#
# Displays the Windows Open File Dialog - See OSUtil.inc
# storing the filename within the parameter before calling
# the sort options dialog.
#
subroutine Open() is
string TableName_LSV
integer ErrorLevel_LIV
copy parameter of Table_TBL in Main_DR to OS_FileName.Str
copy "Open Table File" to OS_StrTitle.Str
copy "Comma Separated Value Files (*.csv)" to FilesFilter.Filter1
copy "*.csv" to FilesFilter.Filter2
copy "All Files (*.*)" to FilesFilter.Filter3
copy "*.*" to FilesFilter.Filter4
# set up the information in the structure
copy size of OS_OPEN_STR to OS_OPEN_Data.LStructSize
copy handle of Main_DR to OS_OPEN_Data.HwndOwner
copy 1 to OS_OPEN_Data.NFilterIndex
copy handle of FilesFilter to OS_OPEN_Data.LpstrFilter
copy size of OS_256_STR to OS_OPEN_Data.NMaxFile
copy handle of OS_FileName to OS_OPEN_Data.LpstrFile
copy size of OS_256_STR to OS_OPEN_Data.NMaxFileTitle
copy handle of OS_StrFileTitle to OS_OPEN_Data.LpstrFileTitle
copy handle of OS_StrInitialDir to OS_OPEN_Data.LpstrInitialDir
copy handle of OS_StrTitle to OS_OPEN_Data.LpstrTitle
copy (1*16*16*16) to OS_OPEN_Data.Flags # file must exist
copy OS_GetOpenFileName(OS_OPEN_Data) to ErrorLevel_LIV
if (ErrorLevel_LIV != 0) then
copy Table_TBL in Main_DR to TableName_LSV
make Table_TBL in Main_DR parameter OS_FileName.Str
call SetUpSortColumns (TableName_LSV)
end if
#
#****** Reads the Specified file into the table without sorting ******
#
subroutine PopulateUnsorted() is
string FileName_LSV
copy parameter of Table_TBL in Main_DR to FileName_LSV
add to Table_TBL in Main_DR
insert file FileName_LSV
#
#****** Reads the Specified file into the table using the Add2Table routine ******
#
subroutine PopulateSorted(integer: Column_IV,
string: Match_SV) is
string FileName_LSV
Mode_LSV is "r"
Row_LSV
TableName_LSV
integer FileId_LIV
copy parameter of Table_TBL in Main_DR to FileName_LSV
copy Table_TBL in Main_DR to TableName_LSV
call OpenFile(FileId_LIV,
FileName_LSV,
Mode_LSV)
while (errorlevel = 0) loop
call ReadNext(FileId_LIV,
Row_LSV)
call ADD2Table(TableName_LSV,
Row_LSV,
Column_IV,
Match_SV)
end loop
call CloseFile(FileId_LIV)
change Table_TBL in Main_DR window position to 1 1
#
#************** Extract the options from the Sort Dialog **************
subroutine Sort() is
integer Column_LIV
string Match_LSV
for each selected line of Columns_LB in Sort_DB loop
extract from textual line (selected line) from Columns_LB in Sort_DB
skip by "="
take number Column_LIV
end loop
if (Decending_RB in Sort_DB is checked) then
copy (0 - Column_LIV) to Column_LIV
end if
copy parameter of checked in group DUPLICATE from Sort_DB to Match_LSV
make Sort_DB invisible
make Sort_DB temporary
call PopulateSorted(Column_LIV,
Match_LSV)
#
#********** Response Definitions ***********
#
response to start
make Main_DR permanent
make Main_DR visible
response to item Exit_MC
exit
response to item Open_MC
call Open()
response to item Clear_MC
clear Table_TBL in Main_DR
response to item Save_MC
write destructive Table_TBL in Main_DR to file (parameter of Table_TBL in Main_DR)
response to Sort_PB in Sort_DB
call Sort()
response to Unsort_PB in Sort_DB
call PopulateUnsorted()
make Sort_DB invisible
make Sort_DB temporary
response to Columns_LB in Sort_DB
on button1 double click
call Sort()
on button1 down
enable Sort_PB in Sort_DB