Link to: header | record viewer
directory
Copyright Turtle Creek Software 1996-2006. All Rights Reserved.
Comments
CCalcCustomViewer
This class manages custom calculators for the Goldenseal accounting software,
small business management software, construction
project management software and
construction estimating software.
It's a viewer for the custom calculation list. We use them primarily to
calculate values for accounting reports like the Balance Sheet and Income
Statement.
SUPERCLASS = DB_RecordViewer
Constructor
/*********************************************************************************
constructor
*********************************************************************************/
CCalcCustomViewer::CCalcCustomViewer(const SPaneInfo &inPaneInfo,
const SViewInfo &inViewInfo)
: DB_RecordViewer(inPaneInfo, inViewInfo)
{
}
Source Code
/*********************************************************************************
GetReadyToUpdateFields split TCS 4/17/00
Do prep work before updating fields
*********************************************************************************/
void CCalcCustomViewer::GetReadyToUpdateFields(const UInt8 creationMethod,
DB_PersistentObject *viewerObject)
{
// before we update regular fields, set up the details menu
CCalcCustom *calc = TCS_SAFE_CAST(viewerObject, CCalcCustom);
TCS_FailNILMsg(calc, TCS_GetErrString(errID_BadObject));
UInt8 calcType;
calc->GetMemberValue(tag_calculationtype, type_enum, &calcType);
//SetCalcDetailsMenu(calcType, false);
// and set calculator cv fields
UInt8 firstGroup = 0, secondGroup = 0;
calc->GetMemberValue(tag_firstgroup, type_enum, &firstGroup);
calc->GetMemberValue(tag_secondgroup, type_enum, &secondGroup);
SetCVClassID(tag_firstcalculation, firstGroup);
SetCVClassID(tag_secondcalculation, secondGroup);
// the superclass handles basic field updating
THE_SUPERCLASS::GetReadyToUpdateFields(creationMethod, viewerObject);
}
/*********************************************************************************
FinishUpdatingFields split TCS 4/17/00
Finish prep work after updating fields from an object, but before displaying them
*********************************************************************************/
void CCalcCustomViewer::FinishUpdatingFields(const UInt8 creationMethod,
DB_PersistentObject *viewerObject)
{
THE_SUPERCLASS::FinishUpdatingFields(creationMethod, viewerObject);
// set enablement of the second calc and constant fields
SetSecondCalcEnabled(GetFieldValue(tag_firstcalculation), GetFieldValue(tag_calculationtype));
}
/*********************************************************************************
HandleCVChanged
a cv field or popup has changed, act accordingly
*********************************************************************************/
void CCalcCustomViewer::HandleCVChanged(CTCS_CVField *cvField)
{
TCS_FailNILMsg(cvField, TCS_GetErrString(errID_BadClairvoyant));
switch (cvField->GetPaneID())
{
case tag_firstcalculation:
CheckCircularity(tag_firstgroup, tag_firstcalculation);
SetSecondCalcEnabled(cvField->GetValue(), GetPopupValue(tag_calculationtype));
break;
case tag_secondcalculation:
CheckCircularity(tag_secondgroup, tag_secondcalculation);
break;
default:
break;
}
THE_SUPERCLASS::HandleCVChanged(cvField);
UpdateValues();
}
/*********************************************************************************
HandlePopupChanged
a popup menu has been clicked, act accordingly
*********************************************************************************/
void CCalcCustomViewer::HandlePopupChanged(CTCS_StdPopupMenu *popupMenu)
{
UInt8 value = popupMenu->GetValue();
TCS_FailNILMsg(popupMenu, TCS_GetErrString(errID_BadPopup));
switch (popupMenu->GetPaneID())
{
case tag_firstgroup:
SetCVClassID(tag_firstcalculation, value, cEraseValue);
SetSecondCalcEnabled(GetFieldValue(tag_firstcalculation),
GetPopupValue(tag_calculationtype));
UpdateValues();
break;
case tag_secondgroup:
SetCVClassID(tag_secondcalculation, value, cEraseValue);
UpdateValues();
break;
case tag_calculationtype:
SetSecondCalcEnabled(GetFieldValue(tag_firstcalculation), value);
UpdateValues();
break;
case tag_calcmethod:
UpdateValues();
break;
default:
break;
}
// pass it along
THE_SUPERCLASS::HandlePopupChanged(popupMenu);
}/*********************************************************************************
HandleEditChanged TCS 9/10/99
an editfield has changed, act accordingly
*********************************************************************************/
void CCalcCustomViewer::HandleEditChanged(CTCS_EditField *editField)
{
TCS_FailNILMsg(editField, TCS_GetErrString(errID_BadField));
switch (editField->GetPaneID())
{
case tag_constant:
UpdateValues();
break;
default:
break;
}
// be sure to pass it along to the superclass
THE_SUPERCLASS::HandleEditChanged(editField);
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
CheckCircularity TCS 9/7/99
check for circular refs in the given calculator field
*********************************************************************************/
void CCalcCustomViewer::CheckCircularity(const TagType classTag, const TagType itemTag)
{
// sanity check
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
TCS_FailNILMsg(mCurrViewerObject, TCS_GetErrString(errID_BadObject));
// fetch field values
UInt8 calcClass = GetPopupValue(classTag);
DBid calcID = GetFieldValue(itemTag);
DBClass thisClass = mCurrViewerObject->GetDBClassID();
DBid thisID = mCurrViewerObject->GetDBID();
if (CCalculatorList::HasCircularReference(calcClass, calcID, thisClass, thisID)) // rev TCS 5/21/03
{
TCS_ErrorAlert(TCS_GetErrString(errID_CircularRef));
SetFieldValue(itemTag, 0);
}
// tidy up memory // TCS 11/25/03
gDBFile->ForcePurge();
}
/*********************************************************************************
SetCalcDetailsEnabled rev TCS 8/23/99
set the enablement of commands in the breakdown calc menu
*********************************************************************************/
void CCalcCustomViewer::SetSecondCalcEnabled(const DBid firstCalc, const UInt8 calcType)
{
if (firstCalc)
{
SetFieldEnabled(tag_calculationtype, true);
switch (calcType)
{
case calc_add:
case calc_subtract:
case calc_multiply:
case calc_divide:
case calc_greaterof:
case calc_lesserof:
SetCVFieldEnabled(tag_secondcalculation, true);
SetFieldEnabled(tag_secondgroup, true);
SetFieldEnabled(tag_constant, false);
break;
case calc_addconstant:
case calc_subtractconstant:
case calc_multiplyconstant:
case calc_divideconstant:
case calc_greaterofconstant:
case calc_lesserofconstant:
SetCVFieldEnabled(tag_secondcalculation, false);
SetFieldEnabled(tag_secondgroup, false);
SetFieldEnabled(tag_constant, true);
break;
default:
TCS_DebugAlert("Oops, bad case in CCalcCustomViewer::SetSecondCalcEnabled!");
break;
}
}
else // no first calculator so disable everything
{
SetFieldEnabled(tag_calculationtype, false);
SetCVFieldEnabled(tag_secondcalculation, false);
SetFieldEnabled(tag_secondgroup, false);
SetFieldEnabled(tag_constant, false);
}
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
UpdateValues
update the display values
*********************************************************************************/
void CCalcCustomViewer::UpdateValues()
{
// fetch field values
UInt8 calcType = GetFieldValue(tag_calculationtype);
UInt8 roundingType = GetFieldValue(tag_rounding);
DBid firstCalcClass = GetFieldValue(tag_firstgroup);
DBid firstCalcID = GetFieldValue(tag_firstcalculation);
CMoney constant = GetFieldValue(tag_constant);
SInt32 runLimit = 0; // TCS 4/9/02
DBid secondCalcClass = GetFieldValue(tag_secondgroup);
DBid secondCalcID = GetFieldValue(tag_secondcalculation);
CTextString outString;
CCalcCustom::GetCalculation(&outString, firstCalcClass, firstCalcID,
secondCalcClass, secondCalcID, calcType,
roundingType, constant, runLimit, cDefaultMoneyFormat);
// after all that, we're finally ready to set the string value
SetFieldCString(tag_currentvalue, outString);
}
|