Accounting Software
Small Business Software Estimating Software
Time Tracking SoftwareTime Management SoftwareTime Billing SoftwareContact Management SoftwareCustomer Management SoftwareProject Management SoftwareBusiness Management Software

Member List Tables (Source Code)

Link to: header | tables directory

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

Comments

CMemberTable

This class manages member tables for the Goldenseal estimating software,
small business management software, construction project management software and
construction estimating software.

It's a table which is a member of a db class. We use these for lists and accounts,
where we define the table via a descriptor in the object. Column titles and data
fill happen directly from code in the object, which stores table info in a
member array (unlike breakdown tables, which store data in separate breakdown
objects).

SUPERCLASS = CSpreadsheetTable

Related Classes: CBreakdownTable handles tables in transactions, with data
stored in separate objects.

Constructor

/*********************************************************************************
constructor
*********************************************************************************/
CMemberTable::CMemberTable(const SPaneInfo &inPaneInfo,
const SViewInfo &inViewInfo)
: CSpreadsheetTable(inPaneInfo, inViewInfo)
{
mDescriptor = nil;
}

Source Code

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

CreateMemberTable (static)

create a member table. The actual table created depends on the pane tag

*********************************************************************************/
CMemberTable *CMemberTable::CreateMemberTable(const SPaneInfo &paneInfo,
const SViewInfo &viewInfo,
const SMemberInfo &memberInfo,
const DB_ClassDescriptor &descriptor,
SInt16 rowHeight)
{
CMemberTable *table = nil;

switch (memberInfo.tag)
{
case tag_taxpackagetable: // tables that show a checklist
case tag_vacationpackagetable:
case tag_benefitpackagetable:
case tag_contractpackagetable:
case tag_locationpackagetable: // TCS 11/6/02
table = NEW CChecklistMemberTable(paneInfo, viewInfo);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
table->SetRowHeight(rowHeight + cTightRowPadding);
break;

case tag_deptable: // tables that show a non-editable list
case tag_itemdiscounttable:
case tag_custdiscounttable:
case tag_categorytable:
table = NEW CFixedMemberTable(paneInfo, viewInfo);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
table->SetRowHeight(rowHeight + cRowHeightPadding);
break;

case tag_roundingtable: // table for rounding methods
// automatically fills in some values
table = NEW CRoundingTable(paneInfo, viewInfo);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
table->SetRowHeight(rowHeight + cRowHeightPadding);
break;

case tag_estordertable: // table for est order, fills in row number
// and has cat and subcat cv's
table = NEW CEstimateOrderTable(paneInfo, viewInfo);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
table->SetRowHeight(rowHeight + cRowHeightPadding);
break;

case tag_chargetable: // tables that show to/from values
case tag_withholdtable:
table = NEW CToFromTable(paneInfo, viewInfo);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
table->SetRowHeight(rowHeight + cRowHeightPadding);
break;

case tag_summationstable: // table for calc summations TCS 7/13/98
// these have cv's with variable class ID
table = NEW CCalcSummationTable(paneInfo, viewInfo);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
table->SetRowHeight(rowHeight + cRowHeightPadding);
break;

case tag_calctaxtable: // tables for tax calculator fields TCS 9/8/99 rev 1/13/02
// these have cv's with variable class ID
table = NEW CTaxFieldMemberTable(paneInfo, viewInfo);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
table->SetRowHeight(rowHeight + cRowHeightPadding);
break;

case tag_workcrewtable: // tables for work crews TCS 5/28/02
// these have cv's with variable class ID
table = NEW CWorkCrewMemberTable(paneInfo, viewInfo);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
table->SetRowHeight(rowHeight + cRowHeightPadding);
break;

case tag_cattable: // these have special category cv's
table = NEW CCatSystemCatTable(paneInfo, viewInfo);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
table->SetRowHeight(rowHeight + cRowHeightPadding);
break;

case tag_subcattable: // these have special subcategory cv's
table = NEW CCatSystemSubcatTable(paneInfo, viewInfo);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
table->SetRowHeight(rowHeight + cRowHeightPadding);
break;

case tag_rentalunittable: // these have special rental unit cv's
table = NEW CRentalUnitTable(paneInfo, viewInfo);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
table->SetRowHeight(rowHeight + cRowHeightPadding);
break;

case tag_promotiontable: // with cat, subcat & cost item cv's TCS 10/8/99
table = NEW CPromotionTable(paneInfo, viewInfo);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
table->SetRowHeight(rowHeight + cRowHeightPadding);
break;
case tag_locationtable: // rev TCS 11/6/02
default:
table = NEW CMemberTable(paneInfo, viewInfo);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
table->SetRowHeight(rowHeight + cRowHeightPadding);
break;
}

table->SetClassDescriptor(&descriptor);

return table;
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

GetColTitle

return the column title

*********************************************************************************/
CTextString CMemberTable::GetColTitle(const TableIndexT column) const
{
// if we have a user-entered title, use that TCS 7/2/99
SLETableColInfo colInfo;
if (GetColInfo(column, colInfo))
{
if (colInfo.colTitle[0])
{
CTextString colTitle(colInfo.colTitle);
return colTitle;
}
}

// if we got this far, use the default title
return GetStockColTitle(column);
}
/*********************************************************************************

GetStockColTitle

return the title of the given column

*********************************************************************************/
CTextString CMemberTable::GetStockColTitle(const TableIndexT col) const
{
STableColInfo colInfo;
TCS_FailNILMsg(mDescriptor, TCS_GetErrString(errID_BadDescriptor));
TCS_ASSERTMsg(mDescriptor->GetTableColInfo(GetPaneID(), col, &colInfo),
TCS_GetErrString(errID_BadColumn));
return CTextString(colInfo.colName);
}/*********************************************************************************

GetCellCVClassID

return the cv class id for the cv in the column

*********************************************************************************/
DBid CMemberTable::GetCellCVClassID(const TableCellT &inCell) const
{
// the cv class is is the same as the data for this cell
return GetColData(COL(inCell));
}/*********************************************************************************

GetMenuCVClassID

return the cv class id for the cv in the column

*********************************************************************************/
DBid CMemberTable::GetMenuCVClassID(const TableCellT &inCell) const
{
// the cv class is is the same as the data for this cell
return GetColData(COL(inCell));
}
#if CAN_USE_MARK
#pragma mark -
#endif/*********************************************************************************

GetColType

return the column type for the given column
TCS changed so it uses array 2/4/98

*********************************************************************************/
SInt32 CMemberTable::GetColType(const TableIndexT col) const
{
SMemberTableInfo tableInfo;
mTableInfo.FetchItemAt(col, tableInfo);
return tableInfo.colType;
}/*********************************************************************************

SetColType

set the column type for the given column TCS 3/9/98

*********************************************************************************/
void CMemberTable::SetColType(const TableIndexT col, const SInt32 inType, Boolean refresh)
{
// update the array
SMemberTableInfo colInfo;
// we only allow coltype to be changed to caption or edit
TCS_ASSERTMsg(inType == coltype_caption || inType == coltype_edit,
CTextString("Oops, invalid call to SetColType"));
// change the data
TCS_ASSERTMsg(mTableInfo.FetchItemAt(col, colInfo), TCS_GetErrString(errID_BadColumn));
colInfo.colType = inType;
mTableInfo.AssignItemAt(col, colInfo);

if (refresh)
{
if (inType == coltype_caption)
{ // we need to disable any edit fields
TableCellT activeCell;
GetSelectedCell(&activeCell);
if (COL(activeCell) == col)
{
// select nil cells to deselect any active edit field
CTCS_Table::SelectCell(0,0, false);
}
}
// update the table display
RefreshColumn(col);
}
}/*********************************************************************************

GetColData

return the column data for the given column
TCS changed so it uses array 2/4/98

*********************************************************************************/
SInt16 CMemberTable::GetColData(const TableIndexT col) const
{
SMemberTableInfo tableInfo;
mTableInfo.FetchItemAt(col, tableInfo);
return tableInfo.colData;
}/*********************************************************************************

SetColData

set the column data for the given column. This would be used to change the displayed
class id of all cv's or the menu for all popups in a column. This may never be used-
if it is, there may be some more drastic processing needed to refresh all menus TCS 2/12/98

*********************************************************************************/
void CMemberTable::SetColData(const TableIndexT col, const char inData, Boolean refresh)
{
// update the array
SMemberTableInfo colInfo;
TCS_ASSERTMsg(mTableInfo.FetchItemAt(col, colInfo), TCS_GetErrString(errID_BadColumn));
colInfo.colData = inData;
mTableInfo.AssignItemAt(col, colInfo);

if (refresh)
{ // update the table display
UpdateDataHolders(col);

// change any edit fields
TableCellT activeCell;
GetSelectedCell(&activeCell);
if (COL(activeCell) == col)
{
// we turn off target to avoid unnecessary messages
LCommander::SwitchTarget(nil);

// select nil cells to deselect all
// the inherited method takes care of selecting
// the cell, which will create an edit field (via HiliteCell)
// and that will become the target
CDataTable::SelectCell(activeCell, refresh);
}
}
}/*********************************************************************************

GetFieldType TCS changed so it uses array 2/4/98

return the field type for the given column

*********************************************************************************/
UInt8 CMemberTable::GetFieldType(const TableIndexT col) const
{
SMemberTableInfo tableInfo;
mTableInfo.FetchItemAt(col, tableInfo);
return tableInfo.fieldType;
}/*********************************************************************************

SetFieldType

set the field type for the given column TCS 2/12/98

*********************************************************************************/
void CMemberTable::SetFieldType(const TableIndexT col, const char inType, Boolean refresh)
{
// update the array
SMemberTableInfo colInfo;
TCS_ASSERTMsg(mTableInfo.FetchItemAt(col, colInfo), TCS_GetErrString(errID_BadColumn));
colInfo.fieldType = inType;
mTableInfo.AssignItemAt(col, colInfo);

if (refresh)
{ // update the table display
UpdateDataHolders(col);
// change any edit fields
TableCellT activeCell;
GetSelectedCell(&activeCell);
// set the edit field if it's in this column
if (COL(activeCell) == col)
{
CTCS_EditField *field = (TCS_SAFE_CAST(FetchActiveField(),CTCS_EditField));
TCS_FailNILMsg(field, TCS_GetErrString(errID_BadField));
field->SetFieldType(inType);
}
}
}/*********************************************************************************

AllowNegatives

return whether negatives are allowed in this column

*********************************************************************************/
Boolean CMemberTable::AllowNegatives(TableIndexT col) const
{
SMemberTableInfo tableInfo;
mTableInfo.FetchItemAt(col, tableInfo);
return tableInfo.allowNegatives;
}/*********************************************************************************

SetAllowNegatives

set whether negatives are allowed in this column

*********************************************************************************/
void CMemberTable::SetAllowNegatives(const TableIndexT col, const Boolean inValue)
{
SMemberTableInfo colInfo;
// change the data
TCS_ASSERTMsg(mTableInfo.FetchItemAt(col, colInfo), TCS_GetErrString(errID_BadColumn));
colInfo.allowNegatives = inValue;
mTableInfo.AssignItemAt(col, colInfo);
}#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

UpdateDataHolders

change the data holders for a column

*********************************************************************************/
void CMemberTable::UpdateDataHolders(const TableIndexT col)
{
for ( TableIndexT row = 1 ; row <= GetNumRows() ; row++ )
{
CHolder *newHolder = GetNewDataHolder(row, col);
TCS_FailNILMsg(newHolder, TCS_GetErrString(errID_BadCell));

const CHolder *currentHolder = GetCellDataHolder(row, col);
TCS_FailNILMsg(currentHolder, TCS_GetErrString(errID_BadCell));

// transfer value into the newly created holder
newHolder->SetCString(currentHolder->GetCString());

SetCellDataHolder( row, col, newHolder);
RefreshCell( row, col);
//TCS_Forget(currentHolder);
}
}
/*********************************************************************************

CreateNewCellCVField TCS 7/9/00

create a cv field for the given cell. We create a short clairvoyant
with no enclosure
*********************************************************************************/
CTCS_CVField *CMemberTable::CreateNewCellCVField(const TableCellT &inCell,
const SPaneInfo &inPaneInfo)
{
return NEW DB_ShortClairvoyant(inPaneInfo, mTextInfo, GetCellCVClassID(inCell), cHasPopup);
}
/*********************************************************************************

PrepareSubcatCV TCS 7/9/00

set up a subcategory cv field
*********************************************************************************/
void CMemberTable::PrepareSubcatCV(const DBid catSystemID, const TableIndexT catCol,
const UInt8 jobClass, const DBid jobID)
{
// first find the subcat cv
TableCellT selection = GetSelectedCell();
CSubcatCV *cv = TCS_SAFE_CAST(FetchCellCVField(selection), CSubcatCV);
if (cv)
{ // set the category system
cv->SetCatSystem(catSystemID);

// now set the category reference
DBid cat = 0;
if (catCol)
{ // a category column exists, so set the reference
cat = GetCellValue(ROW(selection), catCol);
cv->SetCatRef(cat);
}

// now set the job references TCS 12/18/98
cv->SetJobClass(jobClass);
cv->SetJob(jobID);
}
}/*********************************************************************************

InsertCols

we override to store column info in our array

*********************************************************************************/
void CMemberTable::InsertCols(const TableIndexT howMany, const SInt32 inColWidth,
const Boolean redraw)
{
// first we get column info from the descriptor
SMemberTableInfo tableInfo;
STableColInfo colInfo;
TCS_FailNILMsg(mDescriptor, TCS_GetErrString(errID_BadDescriptor));
SInt32 numCols = mDescriptor->GetNumTableCols(GetPaneID());
if (numCols)
{
// LOOP thru all columns
for (TableIndexT col = 1; col <= numCols; col++)
{
TCS_ASSERTMsg(mDescriptor->GetTableColInfo(GetPaneID(), col, &colInfo),
TCS_GetErrString(errID_BadColumn));
// fill in basic data
tableInfo.colType = colInfo.colType;
tableInfo.fieldType = colInfo.fieldType;
tableInfo.colData = colInfo.colData;

// can we accept negatives?
tableInfo.allowNegatives = mDescriptor->GetTableColNegativeIsOK(GetPaneID(), col);

// then we add it to the array
mTableInfo.Append(tableInfo);
}
}
// the inherited method will add actual columns to the table
THE_SUPERCLASS::InsertCols(howMany, inColWidth, redraw);
}
/*********************************************************************************

ResetColValues TCS moved 9/17/01

reset the text string for all cells in a column. This is used to convert
between percent values and dollar values, for tables that can show both.

*********************************************************************************/
void CMemberTable::ResetColValues(const TableIndexT col, const UInt8 fieldType)
{
CMoney cellValue;

// loop through each row and reset the cell value
for (TableIndexT row = 1; row <= LastRow(); row++)
{
cellValue = GetCellMoneyValue(row, col);

switch (fieldType)
{
case fieldtype_money:
SetCellText(row, col, cellValue.GetCurrencyString());
break;

case fieldtype_emoney:
SetCellText(row, col, cellValue.GetExtendedCurrencyString());
break;

case fieldtype_percent:
SetCellText(row, col, cellValue.GetPercentString());
break;

case fieldtype_number:
SetCellText(row, col, cellValue.GetNumberString());
break;

default:
break;
}

RefreshCell(row, col);
}
}