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

To/From Tables (Source Code)

Link to: header | tables directory

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

Comments

CToFromTable

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

It's a member table that displays to/from columns. Used for payroll tax tables and other
tables that show a series of ranges

SUPERCLASS = CMemberTable

Constructor

/*********************************************************************************
constructor TCS 3/6/00
*********************************************************************************/
CToFromTable::CToFromTable(const SPaneInfo &inPaneInfo,
const SViewInfo &inViewInfo)
: CMemberTable(inPaneInfo, inViewInfo)
{
mToColumn = mFromColumn = 0;
}

Source Code

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

ValidateToFromValues rev TCS 12/4/99

validate values in to/from columns

*********************************************************************************/
void CToFromTable::ValidateToFromValues(const Boolean isMoney)
{
TableIndexT toCol = GetToColumn(),
fromCol = GetFromColumn(); // rev TCS 3/6/00

if (SelectedColumn() == toCol)
{
TableIndexT thisRow = SelectedRow();
CMoney thisValue,
lastValue = 0,
fromValue;

// first we get numbers for validating
thisValue = GetCellMoneyValue(thisRow, toCol);
if (thisRow > 1)
lastValue = GetCellMoneyValue(thisRow-1, toCol);
fromValue = lastValue;
fromValue.AddPennies(1);

// is it smaller than row above?
if (thisValue < lastValue)
{
if (thisRow == LastRow())
{ // for the last row we can just go back to 'and up'
SetCellText(thisRow, toCol, TCS_GetStockString(stockID_AndUp));
RefreshCell(thisRow, toCol);
}
else
{ // set the value equal to the row above
if (isMoney)
{
SetCellText(thisRow, toCol, lastValue.GetCurrencyString());
if (thisRow < LastRow())
{
SetCellText(thisRow + 1, fromCol, fromValue.GetCurrencyString());
RefreshCell(thisRow + 1, fromCol);
}
}
else
{
SetCellText(thisRow, toCol, lastValue.GetNumberString());
if (thisRow < LastRow())
{
SetCellText(thisRow + 1, fromCol, fromValue.GetNumberString());
RefreshCell(thisRow + 1, fromCol);
}
}
}
}
else if (thisRow < LastRow())
{ // not the last row, so let's make sure it's not bigger than next row
CMoney nextValue = GetCellMoneyValue(thisRow+1, toCol);
if (thisValue > nextValue && nextValue.IsPositive())
{
fromValue = nextValue;
fromValue.AddPennies(1);

if (isMoney) // set the value equal to the row below
{
SetCellText(thisRow, toCol, nextValue.GetCurrencyString());
SetCellText(thisRow + 1, fromCol, fromValue.GetCurrencyString());
RefreshCell(thisRow + 1, fromCol);
}
else
{
SetCellText(thisRow, toCol, nextValue.GetNumberString());
SetCellText(thisRow + 1, fromCol, fromValue.GetNumberString());
RefreshCell(thisRow + 1, fromCol);
}
}
else
{
fromValue = thisValue;
fromValue.AddPennies(1);

if (isMoney) // fill in the current value
{
SetCellText(thisRow + 1, fromCol, fromValue.GetCurrencyString());
RefreshCell(thisRow + 1, fromCol);
}
else
{
SetCellText(thisRow + 1, fromCol, fromValue.GetNumberString());
RefreshCell(thisRow + 1, fromCol);
}
}
}
else // it's the last row. Don't need to do anything?
{
}
}
}
/*********************************************************************************

FillToFromValues rev TCS 12/4/99

fill in to/from values for a new row

*********************************************************************************/
void CToFromTable::FillToFromValues(const Boolean isMoney)
{
TableIndexT newRow = LastRow();
CMoney priorValue(0,0);

// calculate the value
if (newRow > 1)
{
priorValue = GetCellMoneyValue(newRow - 1, GetToColumn());
priorValue.AddPennies(1);
}

// fill in cell text
if (isMoney)
SetCellText(newRow, GetFromColumn(), priorValue.GetCurrencyString());
else
SetCellText(newRow, GetFromColumn(), priorValue.GetNumberString());

SetCellText(newRow, GetToColumn(), TCS_GetStockString(stockID_AndUp));
}/*********************************************************************************

HandleReturnKey

handle the return or enter key being pressed

*********************************************************************************/
Boolean CToFromTable::HandleReturnKey()
{
CMoney thisValue;
// if the last row 'to' value is not higher than the prev row,
// we beep and don't add a row
if (SelectedRow() == LastRow() && LastRow() > 1)
{
thisValue = GetCellMoneyValue(LastRow(), 2);
CMoney lastValue = GetCellMoneyValue(LastRow() - 1, 2);
if (thisValue <= lastValue)
{
TCS_SysBeep();
return true;
}
}
else if (SelectedRow() == LastRow()) // we're on the first row
{
thisValue = GetCellMoneyValue(1, 2);
if (!thisValue.IsPositive())
{
TCS_SysBeep();
return true;
}
}
// it's OK, so let the superclass handle the return
return THE_SUPERCLASS::HandleReturnKey();
}
/*********************************************************************************

DoHilitePrep TCS 3/6/00

prepare after hiliting. We override to fill in the 'and up' string again

*********************************************************************************/
void CToFromTable::DoHilitePrep(const TableIndexT row, const TableIndexT col,
const Boolean hiliting)
{
if (row == LastRow() && col == GetToColumn())
{
if (!hiliting)
{
CMoney moneyValue = GetCellMoneyValue(row, col);
if (moneyValue.IsZero())
{
SetCellText(row, col, TCS_GetStockString(stockID_AndUp));
RefreshCell(row, col);
}
}
}
}