Accounting Software
Small Business Software Estimating Software
Inventory SoftwareInventory Control SoftwareInventory Tracking SoftwareInventory Management SoftwareConstruction Management SoftwareProject Management SoftwareBusiness Management Software

Schedule Name Array (Source Code)

Link to: header | other data directory

Copyright Turtle Creek Software 1996-2006. All Rights Reserved.

Comments

DB_SchedNameArrayOwner

This class manages scheduled item names for the Goldenseal scheduling software,
project scheduling software, construction scheduling software
and construction management software.

It's the owner of an array of scheduled item names and other info.
We store them in the database, for speed.

SUPERCLASS = DB_PersistentObject

Constructor

/*********************************************************************************
Constructor
*********************************************************************************/
DB_SchedNameArrayOwner::DB_SchedNameArrayOwner()
{
mEndSafetyTag = tag_endsafetytag; // TCS 9/8/02

// we used to set comparator and sorting here, but now it's done
// in AddObject TCS rev 9/20/00
}

Source Code

/*********************************************************************************

GetFileLength

read the object from the db stream
*********************************************************************************/
NeoSize DB_SchedNameArrayOwner::GetFileLength(const CNeoFormat *aFormat) const
{
return THE_SUPERCLASS::GetFileLength(aFormat) +
ARRAY_FILE_SIZE(mSchedNameArray) +
cFileLength;
}
/*********************************************************************************

GetMemberValue

return the value of the member with the given tag

*********************************************************************************/
Boolean DB_SchedNameArrayOwner::GetMemberValue(const NeoTag aTag, const NeoTag aType,
void *aValue) const
{
switch (aTag)
{
case tag_menuname: // get the name of the class TCS 9/30/02
{
CTextString className = DB_ClassDescriptor::GetClassNamePlural(GetDBID());
return ConvertMember(&className, type_cstring, aValue, aType);
}
break;

default:
return THE_SUPERCLASS::GetMemberValue(aTag, aType, aValue);
break;
}
}

/*********************************************************************************

ReadObject

read the object from the db stream
*********************************************************************************/
void DB_SchedNameArrayOwner::ReadObject(CNeoStream *aStream, const TagType aTag)
{
TCS_FailNILMsg(aStream, TCS_GetErrString(errID_BadStream));

CNeoDebugImport checker(aStream, this, cCheckTooSmall); // TCS 2/24/00

THE_SUPERCLASS::ReadObject(aStream, aTag);

if (!IsIOValid()) // TCS 2/5/02
return;

ReadSchedNameArrayFromStream(aStream, mSchedNameArray, cHasSafetyTag);

mEndSafetyTag = aStream->ReadEndSafetyTag(this); // mfs_sa rev 20feb2k3

if (!IsValidEndTag(mEndSafetyTag))
ReportDamagedObject(GetDBClassID(), GetDBID());
}
/*********************************************************************************

WriteObject

write the object to the db stream
*********************************************************************************/
void DB_SchedNameArrayOwner::WriteObject(CNeoStream *aStream, const TagType aTag)
{
TCS_FailNILMsg(aStream, TCS_GetErrString(errID_BadStream));

// make sure we have valid data to write TCS 9/8/02
if (!IsValidEndTag(mEndSafetyTag))
{
ReportDamagedObject(GetDBClassID(), GetDBID());
mEndSafetyTag = tag_endsafetytag; // rev TCS 11/26/02
}

CNeoDebugExport checker(aStream, this, cCheckTooSmall);
THE_SUPERCLASS::WriteObject(aStream, aTag);

WriteSchedNameArrayToStream(aStream, mSchedNameArray, cHasSafetyTag);

aStream->WriteEndSafetyTag(mEndSafetyTag, this); // mfs_sa rev 20feb2k3
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

GetSchedNameArray

fill in the array of transaction item names
*********************************************************************************/
Boolean DB_SchedNameArrayOwner::GetSchedNameArray(TSchedNameArray *array)
{
*array = mSchedNameArray;
return true;
}
/*********************************************************************************

GetNameArray 10/25/00

fill in a simple cv array of all item names
*********************************************************************************/
Boolean DB_SchedNameArrayOwner::GetNameArray(TNameIDArray *array, const Boolean forPopup)
{
SNameIDInfo menuInfo;
SSchedNameInfo schedInfo;
TSchedNameArrayIterator iterator(mSchedNameArray);

TCS_TRY // TCS 1/12/03
{
while (iterator.Next(schedInfo))
{
menuInfo.id = schedInfo.id;

// we can direct copy the name
TCS_StringCopy(menuInfo.itemName, schedInfo.itemName);

array->Append(menuInfo);

if (forPopup && iterator.GetCurrentIndex() > cMaxPopupCount) // TCS 1/12/03
break;
}
return true;
}
TCS_CATCH {}

return false;
}
/*********************************************************************************

GetIDArray TCS 3/28/99

fill in the array of object id's
*********************************************************************************/
Boolean DB_SchedNameArrayOwner::GetIDArray(TObjectIDArray &array)
{
array.RemoveAllItems();

TSchedNameArrayIterator iterator(mSchedNameArray);
SSchedNameInfo info;
DBid id;

while (iterator.Next(info))
{
id = info.id;
array.Append(id);
}
return true;
}
/*********************************************************************************

FindItemByID TCS 3/20/99

Check if the given ID is already in the array, and return its index
*********************************************************************************/
SInt32 DB_SchedNameArrayOwner::FindItemByID(const DBid compareID)
{
SSchedNameInfo info;
TSchedNameArrayIterator iterator(mSchedNameArray);

while (iterator.Next(info))
{
if (info.id == compareID)
return iterator.GetCurrentIndex();
}
// if we got this far, it's not included
return 0;
}
/*********************************************************************************

FetchObjectWithName TCS 7/25/01 rev 1/15/02

Return whether the given name already exists here.
*********************************************************************************/
DBid DB_SchedNameArrayOwner::FetchObjectWithName(const CTextString &matchName, const DBid skipID)
{
SSchedNameInfo info;
TSchedNameArrayIterator iterator(mSchedNameArray);
char *matchText = matchName.GetCharPtr();

while (iterator.Next(info))
{
if (info.id != skipID)
{
if (TCS_EqualStrings(matchText, info.itemName))
return info.id;
}
}
// if we got this far, it's not included
return 0;
}
/*********************************************************************************

ClearArray 8/13/01

remove all items from this item's array.
*********************************************************************************/
void DB_SchedNameArrayOwner::ClearArray()
{
DB_ObjectTempRemover remover (this); // TCS 8/26/03

if (remover.WasRemoved())
{
mSchedNameArray.RemoveAllItems();
}
}
/*********************************************************************************

SortMenuArray TCS 12/20/02

sort the items in this item's array.
*********************************************************************************/
void DB_SchedNameArrayOwner::SortMenuArray()
{
DB_ObjectTempRemover remover (this); // TCS 8/26/03

if (remover.WasRemoved())
{
mSchedNameArray.SortWithComparator(NEW CSchedNameComparator);
}
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

AddToArray

add an object to this item's array.
*********************************************************************************/
Boolean DB_SchedNameArrayOwner::AddToArray(const DB_PersistentObject *object,
const Boolean sortArray)
{
TCS_FailNILMsg(object, TCS_GetErrString(errID_BadObject));

if (!object->ShouldBeListed()) // should it be listed?
return false;

DBid id = object->GetDBID();
SInt32 itemIndex = FindItemByID(id);

if (itemIndex) // is it already there?
return false;

TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
SSchedNameInfo info;

// remove from the database, since length will change
DB_ObjectTempRemover remover (this); // TCS 8/26/03

if (remover.WasRemoved())
{
// fill in data
CTextString menuName = object->GetMenuName(); // rev TCS 2/28/99
menuName.Truncate(cMenuTextLen - 1);
TCS_BufferFromText(info.itemName, menuName);

object->GetMemberValue(tag_date, type_date, &info.date);
object->GetMemberValue(tag_time, type_time, &info.date);
object->GetMemberValue(tag_schedaction, type_enum, &info.action);
object->GetMemberValue(tag_frequency, type_enum, &info.frequency);

info.id = id;

// add to the array and sort by name rev TCS 9/20/00
mSchedNameArray.Append(info);

if (sortArray) // TCS 12/20/02
mSchedNameArray.SortWithComparator(NEW CSchedNameComparator);
}

return true;
}/*********************************************************************************

RemoveFromArray

remove an object from this item's array.
*********************************************************************************/
void DB_SchedNameArrayOwner::RemoveFromArray(const DB_PersistentObject *object)
{
TCS_FailNILMsg(object, TCS_GetErrString(errID_BadObject));
DBid id = object->GetDBID();

if (id)
RemoveObjectByID(id);
}
/*********************************************************************************

RemoveObjectByID TCS split 10/17/03

remove an object id from this item's array. Use this form directly to remove
an object that doesn't exist
*********************************************************************************/
void DB_SchedNameArrayOwner::RemoveObjectByID(const DBid id)
{
SInt32 itemIndex = FindItemByID(id);

if (itemIndex)
{
DB_ObjectTempRemover remover (this); // TCS 8/26/03

if (remover.WasRemoved())
{
mSchedNameArray.RemoveItemAt(itemIndex);
}
}
}
/*********************************************************************************

HandleObjectChanged TCS 3/22/00

update status for an object in this item's array. This is used for an object
change
*********************************************************************************/
void DB_SchedNameArrayOwner::HandleObjectChanged(const DB_PersistentObject *object,
const Boolean doSort)
{
if (object->ShouldBeListed())
{
DBid id = object->GetDBID();
SInt32 itemIndex = FindItemByID(id);

if (itemIndex == LArray::index_Bad)
{ // object is not here, so add it
AddToArray(object);
}
else
{ // object is here, so update it. Object length may change,
// so we need to remove temporarily from the dbase TCS 10/3/00
DB_ObjectTempRemover remover (this); // TCS 8/26/03

if (remover.WasRemoved())
{
SSchedNameInfo info;
mSchedNameArray.FetchItemAt(itemIndex, info);

CTextString menuName = object->GetMenuName();
menuName.Truncate(cMenuTextLen - 1);

Boolean needsSort = !TCS_EqualStrings(info.itemName, menuName.GetCharPtr());

if (needsSort) // TCS 12/18/02
TCS_BufferFromText(info.itemName, menuName);

object->GetMemberValue(tag_date, type_date, &info.date);
object->GetMemberValue(tag_time, type_time, &info.date);
object->GetMemberValue(tag_schedaction, type_enum, &info.action);
object->GetMemberValue(tag_frequency, type_enum, &info.frequency);

mSchedNameArray.AssignItemAt(itemIndex, info);

if (doSort && needsSort)
{ // rev TCS 10/3/00
mSchedNameArray.SortWithComparator(NEW CSchedNameComparator);
}
}
}
}
else // object should not be listed, so remove it
RemoveFromArray(object);

MakeDirty();
}
/*********************************************************************************
FindListMatches TCS 12/18/02

doing a find. For some tags, we can search in the menu array and/or
indexed fields in the object class info (future upgrade). That's much faster
than looking through every object.

*********************************************************************************/
Boolean DB_SchedNameArrayOwner::FindListMatches(CTCS_Array &selectorArray,
TObjectIDArray &matchArray, const Boolean matchAny)
{
DB_MemberSelector *selector = nil;
CTCS_ArrayIterator iterator (selectorArray, iter_from_end);
Boolean success = false;
UInt8 matchCount = 0;
// loop through the selectors
while (iterator.Previous(&selector))
{
TCS_FailNILMsg(selector, TCS_GetErrString(errID_BadSelector));

if (selector->IsFromTable()) // TCS 1/16/03
continue;

// we can do a quick find for name, id or status
switch (selector->getSelectTag())
{
case tag_name:
case tag_objectid:

// we have values here, so fetch them
// from the array
FillListMatches(selector, matchArray, matchAny, matchCount);
success = true;

// remove the selector so we don't
// repeat the search later on
TCS_Forget(selector);
selectorArray.RemoveItemAt(iterator.GetCurrentIndex());
break;

default:
break;
}
}

// sort the list by object ID so we
// stay in the order originally entered TCS 12/23/02
if (matchArray.GetCount() > 0)
matchArray.SortWithComparator(NEW LLongComparator);

return success;
}
/*********************************************************************************
FillListMatches TCS 12/23/02

fill in matches for the given selector

*********************************************************************************/
Boolean DB_SchedNameArrayOwner::FillListMatches(DB_MemberSelector *selector,
TObjectIDArray &matchArray, const Boolean matchAny, UInt8 &matchCount)
{
TCS_FailNILMsg(selector, TCS_GetErrString(errID_BadSelector));

TSchedNameArrayIterator iterator (mSchedNameArray);
SSchedNameInfo info;

Boolean gaveWarning = false;
NeoTag tag;

// we first fill matches into a temporary array
TObjectIDArray tempArray;
matchCount++;

while (iterator.Next(info))
{
tag = selector->getSelectTag();

switch (tag)
{
case tag_name:
if (selector->MatchesString(CTextString(info.itemName)))
tempArray.Append(info.id);
break;

case tag_objectid:
if (selector->MatchesLong(info.id))
tempArray.Append(info.id);
break;

default:
if (!gaveWarning) // TCS 5/20/03
{
TCS_ErrorAlert(CTextString("Oops, bad case in DB_SchedNameArrayOwner::FillListMatches ") + TCS_GetTagMessage(tag));
gaveWarning = true;
}
break;
}
}

// fill in the actual match array. How we do that depends
// on the type of match, and whether this is the first match
if (matchCount < 2) // TCS 12/23/02
matchArray = tempArray; // first match
else if (matchAny)
matchArray.Add(tempArray); // do a 'union'
else
matchArray.Collapse(tempArray); // do an 'intersection'

return (matchArray.GetCount() > 0);
}
/*********************************************************************************

FillDataReport TCS 9/7/02

fill in a diagnostic table that shows data field values.

*********************************************************************************/
void DB_SchedNameArrayOwner::FillDataReport(CTCS_Table *table, CNeoStream *stream) const
{
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
TCS_FailNILMsg(stream, TCS_GetErrString(errID_BadStream));

THE_SUPERCLASS::FillDataReport(table, stream);

FillFieldArrayRow(table, stream, "TSchedNameArray", mSchedNameArray);

FillEndSafetyTag(table, stream, mEndSafetyTag);
}