ftp.nice.ch/pub/next/database/apps/Stopwatch.2.5.s.tar.gz#/Stopwatch2.5/ExpenseViewMgr.m

This is ExpenseViewMgr.m in view mode; [Download] [Up]

/*
 * For legal stuff see the file COPYRIGHT
 */
#import "ExpenseViewMgr.h"
#import "ClientInspector.h"
#import "ExpenseEditor.h"
#import "Controller.h"

@interface ExpenseViewMgr(PRIVATE)
- (void)displayTotalExpenses;
- (void)displayClientExpenses;
- (float)totalExpenses;
@end


@implementation ExpenseViewMgr

- itemEditor
{
  return [ExpenseEditor new];
}

/*
 * Provide the add, delete and sort methods to invoke on ClientInfo objects
 */
- (SEL)addMethod
{
  return @selector(addExpense:);
}

- (SEL)deleteMethod
{
  return @selector(deleteExpense:);
}

- (SEL)sortMethod
{
  return @selector(sortExpenses);
}

- info:(ClientInfo *)info itemAt:(int)position
{
  return [info expenseAt:position];
}

- (int)itemCount:(ClientInfo *)info 
{
  return [info expenseCount];
}

- (void)displaySummary
{
  [self displayClientExpenses];
  [self displayTotalExpenses];
}

/*
 * This is not very maintainable, but it will do for now...
 */
- (void)displayTitle
{
  const char *title = "      Date         Amount    Description";

  [titleText setStringValue:title];
}

@implementation ExpenseViewMgr(PRIVATE)

- (float)totalExpenses
{
  List *clientList = [[NXApp delegate] clientList];
  int i, count = [clientList count];
  float totalExp = 0.0;

  for ( i = 0; i < count; i++ )
    totalExp += [[clientList objectAt:i] totalExpenses];

  return totalExp;
}

- (void)displayClientExpenses
{
  char buf[20];
  id info = [[ClientInspector sharedInstance] selectedClient];

  if ( info ) {
    sprintf( buf, "%.2f", [info totalExpenses] );
    [clientExpensesField setStringValue:buf];
  } else
    [clientExpensesField setStringValue:""];
}

- (void)displayTotalExpenses
{
  char buf[20];

  sprintf( buf, "%.2f", [self totalExpenses] );
  [totalExpensesField setStringValue:buf];
}

@end
 

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.