📄 addresslookup.c
字号:
Int16 column;
// If a row is selected return the record number else
// return noRecord.
table = FrmGetObjectPtr (vars->frm, FrmGetObjectIndex (vars->frm, LookupTable));
if (TblGetSelection (table, &row, &column))
{
vars->currentRecord = TblGetRowID(table, row);
vars->currentPhone = TblGetItemInt(table, row, column);
return true;
}
return false;
}
/***********************************************************************
*
* FUNCTION: PrvLookupFindPhoneField
*
* DESCRIPTION: Find a phone field from the record. The first match
* is used unless it's one of the fields displayed. In that case the
* field displayed is used.
*
* PARAMETERS: vars - variables used by the lookup code.
* recordP - the record to find the field in
* lookupField - the phone field to lookup
* phoneNum - the phone field in the record that matches
* (used when field 1 or field2 is a phone field).
*
* RETURNED: The field to use or lookupNoField if none found
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* Roger 7/18/96 Initial Revision
*
***********************************************************************/
AddressFields PrvLookupFindPhoneField (LookupVariablesPtr vars, AddrDBRecordPtr recordP, AddressLookupFields lookupField, UInt16 phoneNum)
{
int index;
int phoneType;
if (vars->params->field1 == lookupField || vars->params->field2 == lookupField)
return (AddressFields) phoneNum;
else
{
phoneType = lookupField - addrLookupWork;
// Scan through the phone fields looking for a phone of the right type
// which also contains data.
for (index = firstPhoneField; index <= lastPhoneField; index++)
{
if (GetPhoneLabel(recordP, index) == phoneType &&
recordP->fields[index] != NULL)
{
return (AddressFields) (phone1 + index - firstPhoneField);
}
}
}
return (AddressFields) addrLookupNoField;
}
/***********************************************************************
*
* FUNCTION: PrvLookupResizeResultString
*
* DESCRIPTION: Resize the lookup a result string
*
* PARAMETERS: resultStringP - result string
* newSize - new size
*
* RETURNED: pointer to the resized result of zero if the resize failed.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* Art 12/11/96 Initial Revision
*
***********************************************************************/
Char * PrvLookupResizeResultString (MemHandle resultStringH, UInt16 newSize)
{
Err err;
MemHandleUnlock (resultStringH);
err = MemHandleResize (resultStringH, newSize);
if (err)
return (0);
return (MemHandleLock (resultStringH));
}
/***********************************************************************
*
* FUNCTION: PrvLookupCreateResultString
*
* DESCRIPTION: Create a result string which includes data from the record.
*
* PARAMETERS: vars - variables used by the lookup code.
* recordNum - the record create a result string from
* phoneNum - the phone field in the record that matches
* (used when field 1 or field2 is a phone field).
*
* RETURNED: The MemHandle to the string created or NULL.
* vars->params->resultStringH is also set
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* Roger 7/9/96 Initial Revision
* Ludovic 4/27/00 Fix bug - formatStringP increment invalid for some fields
*
***********************************************************************/
MemHandle PrvLookupCreateResultString (LookupVariablesPtr vars, UInt16 recordNum, UInt16 phoneNum)
{
Char * formatStringP;
MemHandle resultStringH;
Char * resultStringP;
Int16 resultSize = 0;
Int16 nextChunkSize;
Char * nextFieldP;
Int16 field;
AddrDBRecordType record;
MemHandle recordH;
Char * fieldP;
Err error;
UInt16 separatorLength;
UInt16 phoneLabel;
// Return the record's unique ID
DmRecordInfo(vars->dbP, recordNum, NULL, &vars->params->uniqueID, NULL);
// Check if a format string was specified
formatStringP = vars->params->formatStringP;
if (formatStringP == NULL)
return 0;
// Allocate the string on the dynamic heap
resultStringH = MemHandleNew(32); // Allocate extra so there's room to grow
if (!resultStringH)
return 0; // not enough memory?
error = AddrDBGetRecord (vars->dbP, recordNum, &record, &recordH);
ErrFatalDisplayIf ((error), "Record not found");
resultStringP = MemHandleLock(resultStringH);
while (*formatStringP != '\0')
{
// Copy the next chunk (the string until a '^' or '\0'
nextFieldP = StrChr(formatStringP, '^');
if (nextFieldP)
nextChunkSize = nextFieldP - formatStringP;
else
nextChunkSize = StrLen(formatStringP);
if (nextChunkSize > 0)
{
resultStringP = PrvLookupResizeResultString (resultStringH,
resultSize + nextChunkSize);
if (! resultStringP) goto exit;
MemMove(resultStringP + resultSize, formatStringP, nextChunkSize);
resultSize += nextChunkSize;
formatStringP += nextChunkSize;
nextChunkSize = 0;
}
// determine which field to copy next
if (*formatStringP == '^')
{
formatStringP++;
field = (AddressFields) addrLookupNoField;
// Decode which field to copy next.
// Remember that the strings below can't be put into a table
// because the lookup function runs without global variables
// available with which we would store the table.
if (StrNCompareAscii(formatStringP, "name", 4) == 0)
{
field = name;
formatStringP += 4;
}
else if (StrNCompareAscii(formatStringP, "first", 5) == 0)
{
field = firstName;
formatStringP += 5;
}
else if (StrNCompareAscii(formatStringP, "company", 7) == 0)
{
field = company;
formatStringP += 7;
}
else if (StrNCompareAscii(formatStringP, "address", 7) == 0)
{
field = address;
formatStringP += 7;
}
else if (StrNCompareAscii(formatStringP, "city", 4) == 0)
{
field = city;
formatStringP += 4;
}
else if (StrNCompareAscii(formatStringP, "state", 5) == 0)
{
field = state;
formatStringP += 5;
}
else if (StrNCompareAscii(formatStringP, "zipcode", 7) == 0)
{
field = zipCode;
formatStringP += 7;
}
else if (StrNCompareAscii(formatStringP, "country", 7) == 0)
{
field = country;
formatStringP += 7;
}
else if (StrNCompareAscii(formatStringP, "title", 5) == 0)
{
field = title;
formatStringP += 5;
}
else if (StrNCompareAscii(formatStringP, "custom1", 7) == 0)
{
field = custom1;
formatStringP += 7;
}
else if (StrNCompareAscii(formatStringP, "custom2", 7) == 0)
{
field = custom2;
formatStringP += 7;
}
else if (StrNCompareAscii(formatStringP, "custom3", 7) == 0)
{
field = custom3;
formatStringP += 7;
}
else if (StrNCompareAscii(formatStringP, "custom4", 7) == 0)
{
field = custom4;
formatStringP += 7;
}
else if (StrNCompareAscii(formatStringP, "work", 4) == 0)
{
field = PrvLookupFindPhoneField(vars, &record, addrLookupWork, phoneNum);
formatStringP += 4;
}
else if (StrNCompareAscii(formatStringP, "home", 4) == 0)
{
field = PrvLookupFindPhoneField(vars, &record, addrLookupHome, phoneNum);
formatStringP += 4;
}
else if (StrNCompareAscii(formatStringP, "fax", 3) == 0)
{
field = PrvLookupFindPhoneField(vars, &record, addrLookupFax, phoneNum);
formatStringP += 3;
}
else if (StrNCompareAscii(formatStringP, "other", 5) == 0)
{
field = PrvLookupFindPhoneField(vars, &record, addrLookupOther, phoneNum);
formatStringP += 5;
}
else if (StrNCompareAscii(formatStringP, "email", 5) == 0)
{
field = PrvLookupFindPhoneField(vars, &record, addrLookupEmail, phoneNum);
formatStringP += 5;
}
else if (StrNCompareAscii(formatStringP, "main", 4) == 0)
{
field = PrvLookupFindPhoneField(vars, &record, addrLookupMain, phoneNum);
formatStringP += 4;
}
else if (StrNCompareAscii(formatStringP, "pager", 5) == 0)
{
field = PrvLookupFindPhoneField(vars, &record, addrLookupPager, phoneNum);
formatStringP += 5;
}
else if (StrNCompareAscii(formatStringP, "mobile", 6) == 0)
{
field = PrvLookupFindPhoneField(vars, &record, addrLookupMobile, phoneNum);
formatStringP += 6;
}
else if (StrNCompareAscii(formatStringP, "listname", 8) == 0)
{
formatStringP += 8;
separatorLength = 0;
// Add the company name
if ((vars->sortByCompany) || (!record.fields[name] && !record.fields[firstName]))
{
fieldP = record.fields[company];
if (fieldP)
{
nextChunkSize = StrLen(fieldP);
if (nextChunkSize > 0)
{
resultStringP = PrvLookupResizeResultString (resultStringH,
resultSize + nextChunkSize);
if (! resultStringP) goto exit;
MemMove(resultStringP + resultSize, fieldP, nextChunkSize);
resultSize += nextChunkSize;
nextChunkSize = 0;
separatorLength = fieldSeparatorLength;
}
}
}
// Add the name field
fieldP = record.fields[name];
if (fieldP)
{
nextChunkSize = StrLen(fieldP);
if (nextChunkSize > 0)
{
resultStringP = PrvLookupResizeResultString (resultStringH, resultSize + nextChunkSize + separatorLength);
if (! resultStringP) goto exit;
if (separatorLength > 0)
{
MemMove(resultStringP + resultSize, fieldSeparatorString, separatorLength);
resultSize += separatorLength;
}
MemMove(resultStringP + resultSize, fieldP, nextChunkSize);
resultSize += nextChunkSize;
nextChunkSize = 0;
separatorLength = fieldSeparatorLength;
}
}
// Add the first name field
if (!vars->sortByCompany ||
record.fields[company] == NULL)
{
fieldP = record.fields[firstName];
if (fieldP)
{
nextChunkSize = StrLen(fieldP);
if (nextChunkSize > 0)
{
Char fieldSeparatorStr[kMaxSeparatorStrLen+1];
// If we require a separator, then set up the appropriate separator
if (separatorLength > 0)
{
ToolsSetupSeparators(record.fields[name], fieldP, fieldSeparatorStr, (Int16 *)&separatorLength, true);
}
resultStringP = PrvLookupResizeResultString (resultStringH, resultSize + nextChunkSize + separatorLength);
if (! resultStringP) goto exit;
if (separatorLength > 0)
{
MemMove(resultStringP + resultSize, fieldSeparatorStr, separatorLength);
resultSize += separatorLength;
}
MemMove(resultStringP + resultSize, fieldP, nextChunkSize);
resultSize += nextChunkSize;
nextChunkSize = 0;
}
}
}
// We are done adding the data requested. Continue to the next
// chunk
continue;
}
else if (StrNCompareAscii(formatStringP, "listphone", 9) == 0)
{
formatStringP += 9;
separatorLength = 0;
// Add the list phone number with a letter after it
fieldP = record.fields[firstPhoneField +
record.options.phones.displayPhoneForList];
if (fieldP)
{
nextChunkSize = StrLen(fieldP);
if (nextChunkSize > 0)
{
Char phoneLabelBuf[6];
Int16 x, len;
phoneLabel = GetPhoneLabel(&record, firstPhoneField +
record.options.phones.displayPhoneForList);
len = TxtSetNextChar (phoneLabelBuf, 0, vars->phoneLabelLetters[phoneLabel]);
resultStringP = PrvLookupResizeResultString (resultStringH, resultSize + nextChunkSize + len + 1);
if (! resultStringP) goto exit;
MemMove(resultStringP + resultSize, fieldP, nextChunkSize);
resultSize += nextChunkSize;
resultStringP[resultSize] = ' ';
resultSize++; // This is the +1 in the above resize
for (x = 0; x < len; x++)
{
resultStringP[resultSize++] = phoneLabelBuf[x];
}
//resultSize += 2;
nextChunkSize = 0;
separatorLength = 2; // DOLATER : <vsm> why is this set to 2 ?
}
}
}
// Now copy in the correct field. lookupNoField can result from
// asking for a phone which isn't used.
if (field != (AddressFields) addrLookupNoField)
{
fieldP = record.fields[field];
if (fieldP)
{
nextChunkSize = StrLen(fieldP);
if (nextChunkSize > 0)
{
resultStringP = PrvLookupResizeResultString (resultStringH, resultSize + nextChunkSize);
if (! resultStringP) goto exit;
MemMove(resultStringP + resultSize, fieldP, nextChunkSize);
resultSize += nextChunkSize;
nextChunkSize = 0;
}
}
}
}
}
// Now null terminate the result string
resultStringP = PrvLookupResizeResultString (resultStringH, resultSize + 1);
if (! resultStringP) goto exit;
resultStringP[resultSize] = '\0';
vars->params->resultStringH = resultStringH;
MemHandleUnlock(recordH);
MemHandleUnlock(resultStringH);
return resultStringH;
exit:
// Error return
MemHandleUnlock(recordH);
MemHandleFree (resultStringH);
vars->params->resultStringH = 0;
return (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -