|
public void generateDocKey(This invokes DocKey_V2 and stores the return value in 3 (most likely the current record or so).
String storeID,
String sessionID,
String newDocKey)
throws Exception {
String dk =
DocKey_V2(storeID,sessionID);
set(3,dk);
return;
}
Accumulates all digits in "sessionID" to "sessionIDNumeric". Other characters are silently discared.
private String DocKey_V2(String vID, String sessionID) {
String sTmp;
String DocKey_V2 = "";
String sessionIDNumericOnly = "";
int i = 0;
for (i = 0; i <= sessionID.length();
i++) {
try {
int x =
Integer.parseInt(sessionID.substring(i, i + 1));
sessionIDNumericOnly =
sessionIDNumericOnly + Integer.toString(x);
} catch (Exception e) {
}
}
if (sessionIDNumericOnly.length() < 6) {Pad sessionIDNumericOnly with "9" characters (trailing) if needed up to the length 6.
for
(i=sessionIDNumericOnly.length(); i <= 6; i++) {
sessionIDNumericOnly =
sessionIDNumericOnly + "9";
}
}
try {
int length = 0;
int position = 0;
int nID = 0;
try {
nID =
Integer.valueOf(vID).intValue() * 3;
} catch (Exception e) {
nID = 0;
}
DecimalFormat df = new
DecimalFormat("00");
double sessionLength =
sessionIDNumericOnly.length();
String storeString =
Integer.toString(nID);
double storeIDLength =
storeString.length();
sTmp = "2" +
df.format(sessionLength) + df.format(storeIDLength);
This is rather unconventional. My best guess is that the loop adds to "sTmp" the _merged_ content of sessionIDNumeric and storeString (by first taking the first character of sessionIDnumeric, the first cahracter of storeString, the second character of sessionIDNumeric etc until all characters have been used. If the given string is not long enough for a given position, it is skipped).
for (position = 0;
length
<= (sessionLength + storeIDLength);
length++) {
if
(!(position >= sessionLength)) {
sTmp =
sTmp
+ sessionIDNumericOnly.substring(
position,
position + 1);
}
if
(!(position >= storeIDLength)) {
sTmp = sTmp + storeString.substring(position, position + 1);
}
position
= position + 1;
}
and finally add the number of milliseconds since 30/11 1899 (a VB peculiarity?) divided by number of seconds in 10 days to sTmp.
java.util.Calendar c =
new
java.util.GregorianCalendar(1899, 11, 30);
long millis =
c.getTimeInMillis();
long milliseconds =
System.currentTimeMillis();
//long newDate =
milliseconds - millis + 600000;
long newDate =
milliseconds - millis;
long dateInVBFormat =
(newDate / 864000);
sTmp = sTmp +
Long.toString(dateInVBFormat);
DocKey_V2 =The sTmp string is then processed by MakeMod10 to create the DocKey_V2 value.
MakeMOD10(sTmp);
} catch (Exception _e_) {If anything fails, the value is null.
DocKey_V2 = null;
}
return DocKey_V2;
}
private boolean IsMOD10(String sValue) {
boolean IsMOD10 = false;
try {
int nDx = 0;
int nTotal = 0;
int nVal = 0;
nTotal = 0;
for (nDx = 0; nDx <
sValue.length(); nDx++) {
ifif the character at position nDx is less thatn "0" (!"#€(=/( or similar) then just use its ascii value as nVal.
(sValue.substring(nDx, nDx + 1).compareTo("0") < 0) {
char c = sValue.charAt(nDx);
nVal = c;
} else {Same thing for characters larger than "9"
if (sValue.substring(nDx, nDx + 1).compareTo("9") > 0) {
char c = sValue.charAt(nDx);
nVal = c;
} else {if "0".."9" use the integer value as nVal.
nVal =
Integer
.valueOf(sValue.substring(nDx, nDx + 1))
.intValue();
}Sum them up in nTotal.
}
nTotal =
nTotal + nVal;
}And return true if nTotal divided by 10 has a remainder of 0. False otherwise.
IsMOD10 = (nTotal % 10)
== 0;
} catch (Exception e) {
System.out.println("Error with MOD10");
return false;
}
return IsMOD10;
}
private String MakeMOD10(String sValue) {
String MakeMOD10 = "";
try {
int nDx = 0;Might this be a port of a similar mechanism from a Visual Basic program?
for (nDx = 0; nDx <= 9;
nDx++) {
if
(IsMOD10(sValue + nDx)) {
break;
}
}
MakeMOD10 = sValue +
nDx;
} catch (Exception e) {
System.out.println("Error with MOD10");
}
return MakeMOD10;
}
}
Chris Bipes
Director of Information Services
CrossCheck, Inc.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.