Module cCJGridSortHandler.pkg
1Use VdfBase.pkg
2
3Struct tGridSortColumnRules
4 Integer iColumn
5 Integer eDataType
6 Boolean bDescending
7End_Struct
8
9Struct tGridSortRules
10 Boolean bDescending
11 tGridSortColumnRules[] Rules
12End_Struct
13
14Struct tGridSortData
15 Integer iIndex
16 String[] sData
17End_Struct
18
19{ Visibility=Private }
20Class cGridSortHandler is a cObject
21
22 Procedure Construct_Object
23 Forward Send Construct_Object
24 Property tGridSortColumnRules[] pColumnRules
25 End_Procedure
26
27 Function CompareGridSortData tGridSortData Data1 tGridSortData Data2 Returns Integer
28 Number nNum1 nNum2
29 Date dDate1 dDate2
30 DateTime dtDateTime1 dtDateTime2
31 String sVal1 sVal2
32 tGridSortColumnRules[] ColumnRules
33 Integer i iSegments
34 Get pColumnRules to ColumnRules
35 Move (SizeOfArray(ColumnRules)) to iSegments
36 For i from 0 to (iSegments-1)
37 If (ColumnRules[i].eDataType=Ascii_Window or ColumnRules[i].eDataType=Mask_Window) Begin
38 Move Data1.sData[i] to sVal1
39 Move Data2.sData[i] to sVal2
40 If (sVal1>sVal2) Begin
41 Function_Return (If(ColumnRules[i].bDescending,LT,GT))
42 End
43 If (sVal1<sVal2) Begin
44 Function_Return (If(ColumnRules[i].bDescending,GT,LT))
45 End
46 End
47 Else If (ColumnRules[i].eDataType=Mask_Date_Window or ColumnRules[i].eDataType=Date_Window) Begin
48 Move Data1.sData[i] to dDate1
49 Move Data2.sData[i] to dDate2
50 If (dDate1>dDate2) Begin
51 Function_Return (If(ColumnRules[i].bDescending,LT,GT))
52 End
53 If (dDate1<dDate2) Begin
54 Function_Return (If(ColumnRules[i].bDescending,GT,LT))
55 End
56 End
57 Else If (ColumnRules[i].eDataType=Mask_Datetime_Window) Begin
58 Move Data1.sData[i] to dtDateTime1
59 Move Data2.sData[i] to dtDateTime2
60 If (dtDateTime1>dtDateTime2) Begin
61 Function_Return (If(ColumnRules[i].bDescending,LT,GT))
62 End
63 If (dtDateTime1<dtDateTime2) Begin
64 Function_Return (If(ColumnRules[i].bDescending,GT,LT))
65 End
66 End
67 Else Begin // Mask_Numeric_Window Mask_Currency_Window <Ascii_Window
68 Move Data1.sData[i] to nNum1
69 Move Data2.sData[i] to nNum2
70 If (nNum1>nNum2) Begin
71 Function_Return (If(ColumnRules[i].bDescending,LT,GT))
72 End
73 If (nNum1<nNum2) Begin
74 Function_Return (If(ColumnRules[i].bDescending,GT,LT))
75 End
76 End
77 Loop
78 Function_Return (EQ)
79 End_Function
80
81
82 Function SortDataSource tGridSortRules GridSortRules tDataSourceRow[] DataSource Integer ByRef iSelectedRow Returns tDataSourceRow[]
83 tDataSourceRow[] NewDataSource
84 tGridSortData[] SortData
85 Integer[] iIndexes
86 Integer iNewSelectedRow
87 Integer i iRows iRow j iCols iSortCol
88
89 Set pColumnRules to GridSortRules.Rules
90 Move (SizeOfArray(DataSource)) to iRows
91 Move (SizeOfArray(GridSortRules.Rules)) to iCols
92 For i from 0 to (iRows-1)
93 Move i to SortData[i].iIndex
94 For j from 0 to (iCols-1)
95 Move GridSortRules.Rules[j].iColumn to iSortCol
96 If (iSortCol=-1) Begin
97 Move (SerializeRowID(DataSource[i].riID)) to SortData[i].sData[j]
98 End
99 Else If (SizeOfArray(DataSource[i].sValue)>iSortCol) Begin
100 Move DataSource[i].sValue[iSortCol] to SortData[i].sData[j]
101 End
102 Else Begin
103 Move "" to SortData[i].sData[j]
104 End
105 Loop
106 Loop
107
108 Move (SortArray(SortData,Self,RefFunc(CompareGridSortData))) to SortData
109
110 If (not(GridSortRules.bDescending)) Begin
111 For i from 0 to (iRows-1)
112 Move SortData[i].iIndex to iIndexes[i]
113 Loop
114 End
115 Else Begin
116 Move 0 to i
117 Move (iRows-1) to iRow
118 For i from 0 to (iRows-1)
119 Move SortData[iRow].iIndex to iIndexes[i]
120 Decrement iRow
121 Loop
122 End
123
124 Move -1 to iNewSelectedRow
125 Move (SizeOfArray(iIndexes)) to iRows
126 For i from 0 to (iRows-1)
127 Move DataSource[iIndexes[i]] to NewDataSource[i]
128 If (iIndexes[i]=iSelectedRow) Begin
129 Move i to iNewSelectedRow
130 End
131 Loop
132 Move iNewSelectedRow to iSelectedRow
133 Function_Return NewDataSource
134
135 End_Procedure
136
137End_Class