home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Developer / StopWatch / Source / ExpenseViewMgr.m < prev    next >
Encoding:
Text File  |  1994-02-06  |  1.7 KB  |  103 lines

  1. /*
  2.  * For legal stuff see the file COPYRIGHT
  3.  */
  4. #import "ExpenseViewMgr.h"
  5. #import "ClientInspector.h"
  6. #import "ExpenseEditor.h"
  7. #import "Controller.h"
  8.  
  9. @interface ExpenseViewMgr(PRIVATE)
  10. - (void)displayTotalExpenses;
  11. - (void)displayClientExpenses;
  12. - (float)totalExpenses;
  13. @end
  14.  
  15.  
  16. @implementation ExpenseViewMgr
  17.  
  18. - itemEditor
  19. {
  20.   return [ExpenseEditor new];
  21. }
  22.  
  23. /*
  24.  * Provide the add, delete and sort methods to invoke on ClientInfo objects
  25.  */
  26. - (SEL)addMethod
  27. {
  28.   return @selector(addExpense:);
  29. }
  30.  
  31. - (SEL)deleteMethod
  32. {
  33.   return @selector(deleteExpense:);
  34. }
  35.  
  36. - (SEL)sortMethod
  37. {
  38.   return @selector(sortExpenses);
  39. }
  40.  
  41. - info:(ClientInfo *)info itemAt:(int)position
  42. {
  43.   return [info expenseAt:position];
  44. }
  45.  
  46. - (int)itemCount:(ClientInfo *)info 
  47. {
  48.   return [info expenseCount];
  49. }
  50.  
  51. - (void)displaySummary
  52. {
  53.   [self displayClientExpenses];
  54.   [self displayTotalExpenses];
  55. }
  56.  
  57. /*
  58.  * This is not very maintainable, but it will do for now...
  59.  */
  60. - (void)displayTitle
  61. {
  62.   const char *title = "      Date         Amount    Description";
  63.  
  64.   [titleText setStringValue:title];
  65. }
  66.  
  67. @implementation ExpenseViewMgr(PRIVATE)
  68.  
  69. - (float)totalExpenses
  70. {
  71.   List *clientList = [[NXApp delegate] clientList];
  72.   int i, count = [clientList count];
  73.   float totalExp = 0.0;
  74.  
  75.   for ( i = 0; i < count; i++ )
  76.     totalExp += [[clientList objectAt:i] totalExpenses];
  77.  
  78.   return totalExp;
  79. }
  80.  
  81. - (void)displayClientExpenses
  82. {
  83.   char buf[20];
  84.   id info = [[ClientInspector sharedInstance] selectedClient];
  85.  
  86.   if ( info ) {
  87.     sprintf( buf, "%.2f", [info totalExpenses] );
  88.     [clientExpensesField setStringValue:buf];
  89.   } else
  90.     [clientExpensesField setStringValue:""];
  91. }
  92.  
  93. - (void)displayTotalExpenses
  94. {
  95.   char buf[20];
  96.  
  97.   sprintf( buf, "%.2f", [self totalExpenses] );
  98.   [totalExpensesField setStringValue:buf];
  99. }
  100.  
  101. @end
  102.  
  103.