The entire report consists of three parts
XXXX.ASP // Used to receive functions and from the database, basically each report has a file, which calls cyheader.asp and cyfooter.asp.
Cyheader.asp
Funcsort.inc
?
If you want to sort the original report, it is found that there are a variety of methods, but ideally double-click Crystal Report, which is not easy to implement in the Crystal Report 8.5 Web version.
In order to reduce the workload of the designer when the ordering function is achieved, it has the least workload.
Current sorting does not support Group, only support normal RECORD
?
?
How to use, in the report to implement:
(1) ??? Introducing in the head
(2) Insert the following block:
AddSortfield "Name", "{viw_recruit_simply.appname}", 0? 'Note that Sortorder written in this point is the initial sort type of the field.
AddSortfield "Archive", "{viw_recruit_simply.recordcode}", 0 ??????? '
?
'Sorting
ProcessSort
?
?
The implementation process is described as follows:
In order to facilitate trouble, set OptiOn Explicite in the master document, mandatory variable declaration
Do the following work:
1. CyHeader.asp adds the following sections at the Server end script:
Public Sortfieldcount
Sortfieldcount = 0
Public Sortfields (10, 3) 'Defines the sort domain name, up to ten
?
?
Public Sortfield, SortDesc, Sortorder
Public CsortDesc
?
Public Defaultsortfield, Defaultsortorder, DefaultsortDesc
Defaultsortfield = "" "
?
Defaultsortorder = "" "
?
Public RFINDSORTFIELD
RFINDSORTFIELD = -1
?
2. In addition to Cyfooter.asp's table (top), add the following
?????? Document.title = "<% = pagetitle%>";
?
<%
IF (sortfieldcount> 0) THEN
%>
?????? currencesortsortfield = "<% = sortfield%>";
?????? currentsortorder = "<% = sortorder%>";
?????? cutsc? = "<% = sortdesc%>";
?
?
/ / Set different sort fields and re-submit the page
Function Submitsort (Sortfield, Sortorder, Sortdesc) {
?????? window.onload = null;
?????? Var para = "sortfield =" encodeuricomponent "& Sortorder =" Sortorder "& SortDesc =" escape (sortdesc); ?????? varl = location.href;
?????? if (url.substring (url.indexof ('?') 1)! = para) {
????????????? Document.Sortform.Action = "<% = aspfilename%>?" para;
????????????? //alert (Document.SortForm.Action);
????????????? Document.Sortform.Submit ();
??????}
}
?
<%
END IF
%>
script>
3. The block of the output sort button is added to Cyfooter.asp.
If SortFieldCount is greater than 0, the hidden domain and sort button are output, and if not set, the hidden domain and the sort button are not output.
The increased program segment is as follows:
??????
4. Added functions in the new Function.inc library
?
/ *
1. Support for Null Keywords to support non-sorting
2. For "" "Non-related support, analyze the own Sort ORDER in Crystal Report
3. Support multi-field sort
* /
?
?
/ * Report Sort Series Function
* /
?
/ / Get the name and direction of the IID sort field
Function GetSortfield (RPT,
ind
) {
?????? rsf = ""
?????? rsflen = rpt. genecordsortfields.count;
?????? // rw ("The number of sorted fields of the report is:" RSFLEN);
?????? IF ((RSFLEN> 0) &&
ind
> = 1) &&
ind
<= RSFLEN)) {
????????????? rsf = rpt.recordsortfields.Item
ind
) .Field.name ", rpt.recordsortfields.Item
ind
.Sortdirection;
??????}
?????? RETURN RSF;
}
?
/ / Get the name of the INDS sequence field
Function GetSortfieldName (RPT,
ind
) {
?????? rsf = ""
?????? rsflen = rpt. genecordsortfields.count;
?????? IF ((RSFLEN> 0) &&
ind
> = 1) &&
ind
<= RSFLEN)) {
????????????? rsf = rpt.recordsortfields.Item
ind
) .Field.name;
??????}
?????? RETURN RSF;
}
?
/ / Get the sorting direction of the IID Sort field Function GetSortfieldDir (RPT,
ind
) {
?????? rsf = -1;
?????? rsflen = rpt. genecordsortfields.count;
?????? IF ((RSFLEN> 0) &&
ind
> = 1) &&
ind
<= RSFLEN)) {
????????????? rsf = rpt.recordsortfields.Item
ind
.Sortdirection;
??????}
?????? RETURN RSF;
}
?
// only support according to a column
// rpt - report to be sorted
// Fn - FieldName Sort column name
Function setsortfield (RPT, Fn, Order) {
?????? Clearsortfield (RPT);
?????? Addsortfield (RPT, Fn, Order);
}
?
Function Clearsortfield (RPT) {
?????? rsflen = rpt. genecordsortfields.count;
?????? for (i = rsflen; i> = 1; i -) {
????????????? rpt.recordsortfields.delete (i); // delete already sort
??????}
}
?
/ / Sort by a new sort method, the original main sequence is changed to secondary sequence, the original sequence column becomes three row sequences, and
// rpt - report to be sorted
// Fn - FieldName Sort column name
//Crsortdirection.crascendingorder
Function AddSortfield (RPT, Fn, Order) {
?????? var f = getfield (rpt, fn);
?????? if (f! = null) {
????????????? rpt.recordsortfields.add (f, order); // Add a column in the rank table
??????}
}
?
/ / Find the FN corresponding to the FIELD from the report
// If you don't exist, go
Function Getfield (RPT, FN) {
?????? // traversed to the data sheet in the report
?????? var i;
?????? var rf = null;
?????? var tlen = rpt.database.tables.count;
?????? for (i = 1; i <= tlen; i ) {
????????????? // traverse all fields, find the same field as FN
?????????????? flen = rpt.database.tables.item (i) .fields.count;
????????????? for (j = 1; j <= flen; J ) {
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????? IF (rpt.database.tables.item (i) .fields.Item (j) .name == fn) {
????????????????????????????? r RW ("both equal");
???????????????????????????? rf = rpt.database.tables.Item (i) .fields.Item (j); // Return This field ??????????????????? RETURN RF;
????????????????????}
?????????????}
??????}
?????? Return RF; // Return Undefined
}
?
// If sortdir <> "1", return 0
Function sortdir2int (sortdir) {
?????? var sa = 0;
?????? ing (sortdir == 1) {
????????????? so = 1;
??????}
?????? Return SO;
}
?
Function Sortdir2Desc (Sortdir) {
?????? var sod = "Sorting forward is ▲";
?????? ing (sortdir == 1) {
????????????? sod = "reverse sorting ▼";
??????}
????? Return SOD;
}
?
Function Contrary (Sortdir) {
?????? var sa = 1;
?????? ing (sortdir == 1) {
????????????? so = 0;
??????}
?????? Return SO;
}
?
Function ddfindsortfield (sf) {
?????? var ind, i;
?????? // DIM IND 'sf in the position in sortfields, if the sf is not in sortfields, return -1
?????? ing = -1;
?????? for (i = 1; i <= sortfieldcount; i ) {
????????????? // rw ("Sortfields (" & CSTR (I) ", 2) = [" & Sortfields [i] [2] "]");
????????????? // rw ("sf = [" & sf & "]");
????????????? IF (sortfields (i, 2) = sf) {
???????????????????? IND = I;
???????????????????? Return IND;
?????????????}
??????}
?????? // rfindsortfield = inde
?????? Return India
}
script>
?
Sub ProcessSort
?
?????? 'IF (SortfieldCount <1) THEN
?????? '?? End Sub
?????? 'end if
??????
'Begin Sort
'==================================================== ========================================= ????? 'reads whether or not to set up from the parameter of the URL
?????? 'If this parameter exists, sort by a given parameter
?????? sortfield = request.QueryString ("sortfield")
?????? Sortorder = CINT (Request.QueryString ("Sortorder"))
?????? Sortdesc = Request.QueryString ("sortdesc")
?????? 'sorted description
?????? 'rw "Request.QueryString (' sortfield ')" & sortfield
?????? if (sortfield = ") THEN 'If there is no value, read the default value
?????????????? sortfield = defaultsortfield
????????????? sortorder = defaultsortorder
????????????? sortdesc = defaultsortdesc
?????? end if
?????? DIM SFD
??????
?????? if (sortfield = ") THEN 'If there is no value, but also no default, the null value is processed.
????????????? '2. For "" "support for" "independent keyword, at this time, it analyzes the own Sort ORDER in Crystal Report.
????????????? SFD = GetSortfieldName (Session ("ORPT"), 1)
?
????????????? IF (SFD = ")")
????????????????????? sortdesc = "not sort"
????????????? ELSE
???????????????????? Findsortfield SFD
?
????????????????????? f (rfindsortfield = -1) THEN
???????????????????????????? csortdesc = "Sort by Crystal Report"
???????????????????? ELSE
??????????????????????????? sortfield = SFD
??????????????????????????? Sortorder = GetSortfieldDir (session ("ORPT"), 1)
???????????????????????????? sortdesc = sortfields (rfindsortfield, 1) ??????????????? ????????????? csortdesc = "Press" & SortDesc & SortDir2Desc (Sortorder)
??????????????????????????? Addsortfield SortDesc, SFD, Contrary (Sortorder)
???????????????????? End IF
????????????? End IF
?????? ELSE
????????????? 'set the current sorted display content
????????????? csortdesc = "Press" & SortDesc & SortDir2Desc (Sortorder)
?
????????????? IF (sortfield = "{null})") THEN
???????????????????? Clearsortfield Session ("ORPT")
???????????????????? IF (sortdesc = "") THEN
??????????????????????????? SortDesc = "not sort"
???????????????????? End IF
????????????? ELSE
????????????????????? If the number of the sort button is set, the type of the sort button will be adjusted according to the current sort field.
????????????????????????????, return 0, otherwise returns 1
???????????????????? Addsortfield SortDesc, Sortfield, Contrary (Sortorder)
?
???????????????????? IF (Sortfield <> ") THEN
??????????????????????? setsortfield? session ("ORPT"), Sortfield, Sortdir2int (Sortorder)
???????????????????? End IF
????????????? End IF
?
?????? end if
'==================================================== ================================
'end sort
?
End Sub
?
'Add ranking sequence
'SortDesc, sorted button name and description If SortDesc is "ID card", the button displays "ID card forward sort" or "identity card reverse sort"
'sortfield, the list of fields, see the field name in the Crystal Report, the shape is like {Table.field}' sortorder race sequence 0, is sorting forward? 1, reverse sort
SUB ADSORTFIELD (SD, SF, SO)
?????? DIM SFC
?????? sfc = sortfieldcount
?????? findsortfield? sf
?????? if (rfindsortfield = -1) Then 'If the sf is not in sortfields, the sort button is added
????????????? sortfieldcount = sortfieldcount 1
????????????? IF (SortfieldCount> 9) THEN
????????????? ?? exit sub
????????????? End IF
????????????? sfc = sortfieldcount
????????????? sortfields (SFC, 1) = SD
????????????? sortfields (SFC, 2) = sf
????????????? sortfields (SFC, 3) = SO
?????? else 'If already existed, use SO to update Sortfields (i, 3)
????????????? sortfields (rfindsortfield, 3) = SO
?????? end if
?????? response.flush
End Sub
?
?
Sub Findsortfield (sf)
?????? DIM I
?????? DIM IND 'sf in the position in sortfields, if SF is not in sortfields, return -1
??????
ind
= -1
?????? for i = 1 to sortfieldcount
????????????? IF (Sortfields (I, 2) = sf) THEN
????????????????????
ind
= I
???????????????????? EXIT for
????????????? End IF
?????? next
?????? rfindsortfield =
ind
End Sub
?
Sub Printsortfields
?????? DIM I
?????? for i = 1 to sortfieldcount
?????????????? rw "Sortfields (" & CSTR (I) & ") = [" & Sortfields (i, 1) & "], [" & Sortfields (i, 2) & "], [" & Sortfields (i, 3) & "]"
?????? next
End Sub
script>
?
?