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

Time Arrays (Source Code)

Link to: header | other data directory

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

Comments

DB_TimeArrayOwner

This class manages time values for the Goldenseal job cost accounting software,
project management software, construction estimating software
and construction project estimating software.

It's the owner of an array of times that things are due. We create instances of this
class to manage due items such as appointments and recurring transactions.

Time management itself happens thru DB_TimeManager

SUPERCLASS = DB_PersistentObject

Constructor

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

Source Code

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

GetFileLength 2/1/01

get the file length of the object
*********************************************************************************/
NeoSize DB_TimeArrayOwner::GetFileLength(const CNeoFormat *aFormat) const
{
return THE_SUPERCLASS::GetFileLength(aFormat) +
ARRAY_FILE_SIZE(mTimeArray) +
cFileLength;
}
/*********************************************************************************

GetMemberValue

return the value of the member with the given tag

*********************************************************************************/
Boolean DB_TimeArrayOwner::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 2/1/01

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

CNeoDebugImport checker(aStream, this, cCheckTooSmall);

THE_SUPERCLASS::ReadObject(aStream, aTag);

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

ReadTimeArrayFromStream(aStream, mTimeArray, cHasSafetyTag);

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

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

WriteObject 2/1/01

write the object to the db stream
*********************************************************************************/
void DB_TimeArrayOwner::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);

WriteTimeArrayToStream(aStream, mTimeArray, cHasSafetyTag);

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

FindItemByID TCS 2/1/01

Check if the given ID is already in the array, and return its index
*********************************************************************************/
SInt32 DB_TimeArrayOwner::FindItemByID(const DBid compareID)
{
STimeInfo info;
TTimeArrayIterator iterator(mTimeArray);

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

GetIDArray TCS 11/11/01

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

TTimeArrayIterator iterator(mTimeArray);
STimeInfo info;

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

AddToArray 2/1/01

add an object to the array of time-based items.
*********************************************************************************/
Boolean DB_TimeArrayOwner::AddToArray(const DB_PersistentObject *object)
{
TCS_FailNILMsg(object, TCS_GetErrString(errID_BadObject));

// skip void and completed appointments
if (object->GetDBClassID() == id_Appointment) // rev TCS 8/22/01
{
UInt8 status = object->GetStatus();
if (status != status_Planned && status != status_Urgent)
return false;
}

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

if (itemIndex) // it's already there
return false;
// do prep work
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
STimeInfo info;

info.advanceDate = object->GetAdvanceReminderDate();
info.basicDate = object->GetReminderDate();

// we only add if there's a valid date to store
if (info.advanceDate.IsValidDate(false, false) ||
info.basicDate.IsValidDate(false,false))
{
DB_ObjectTempRemover remover (this); // TCS 8/26/03

if (remover.WasRemoved())
{
info.id = id;
mTimeArray.Append(info);
}
}

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

RemoveFromArray 2/1/01

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

RemoveObjectByID(id);
}

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

RemoveObjectByID 2/5/00

remove an object from this item's array.
*********************************************************************************/
void DB_TimeArrayOwner::RemoveObjectByID(const DBid id)
{
SInt32 itemIndex = FindItemByID(id);

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

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

HandleObjectChanged TCS 2/1/01

update status for an object in this item's array. This is used for an object
change
*********************************************************************************/
void DB_TimeArrayOwner::HandleObjectChanged(const DB_PersistentObject *object)
{
// skip void and completed appointments
if (object->GetDBClassID() == id_Appointment) // rev TCS 8/22/01
{
UInt8 status = object->GetStatus();
if (status != status_Planned && status != status_Urgent)
{
RemoveFromArray(object);
return;
}
}

TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));

STimeInfo info;
info.advanceDate = object->GetAdvanceReminderDate();
info.basicDate = object->GetReminderDate();

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

if (itemIndex == LArray::index_Bad)
{ // object is not stored, so add it
AddToArray(object);
}
else
{ // object is here, so update it.
// the array change shouldn't change object length but we will
// be safe and remove it from the database first, anyhow
DB_ObjectTempRemover remover (this); // TCS 8/26/03

if (remover.WasRemoved())
{
info.id = id;
mTimeArray.AssignItemAt(itemIndex, info);
}
}

MakeDirty();
}
/*********************************************************************************

FillDataReport TCS 9/7/02

fill in a diagnostic table that shows data field values.

*********************************************************************************/
void DB_TimeArrayOwner::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, "TTimeArray", mTimeArray);

FillEndSafetyTag(table, stream, mEndSafetyTag);
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*****************************************************************************
CTimeComparator Compare TCS 2/1/01
Compare two accounts by their time
******************************************************************************/
SInt32 CTimeComparator::Compare(const void *inItemOne, const void *inItemTwo,
UInt32 inSizeOne, UInt32 inSizeTwo) const
{
// We want to be sure we are being passed the correct pointers
TCS_ASSERTMsg(inSizeOne == sizeof(STimeInfo) &&
inSizeTwo == sizeof(STimeInfo), TCS_GetErrString(errID_ProblemDataSize));
TCS_FailNILMsg(inItemOne, TCS_GetErrString(errID_BadComparator));
TCS_FailNILMsg(inItemTwo, TCS_GetErrString(errID_BadComparator));
// Get the structs
STimeInfo *structOne = ((STimeInfo *)inItemOne);
STimeInfo *structTwo = ((STimeInfo *)inItemTwo);

TCS_FailNILMsg(structOne, TCS_GetErrString(errID_BadComparator)); // TCS 12/2/02
TCS_FailNILMsg(structTwo, TCS_GetErrString(errID_BadComparator));
// Compare the basic dates
if (structOne->basicDate < structTwo->basicDate)
{
return compare_Less;
}
else if (structOne->basicDate == structTwo->basicDate)
{
return compare_Equal;
}
else
{
return compare_Greater;
}
}