home *** CD-ROM | disk | FTP | other *** search
- /* Department.m
- * A simple enterprise object.
- *
- * You may freely copy, distribute, and reuse the code in this example.
- * NeXT disclaims any warranty of any kind, expressed or implied, as to its
- * fitness for any particular use.
- *
- * Written by Mai Nguyen, NeXT Developer Support
- */
-
- #import "Department.h"
- #import "strings.h"
-
-
- @implementation Department
-
- - init
- {
- [super init];
- // You can add additional intialization here.
- return self;
- }
-
- - (void)dealloc
- {
- [DepartmentName autorelease];
- [FacilityLocation autorelease];
- [toEmployee autorelease];
- [super dealloc];
-
- }
-
-
- // Accessor methods
-
- - (void) setDepartmentName:(NSString *)newName
- {
- [DepartmentName autorelease];
- DepartmentName = [newName retain];
- return;
- }
-
- - (NSString *)DepartmentName { return DepartmentName; }
-
- - (void) setDeptId:(int)newId
- {
- DeptId = newId;
- return;
- }
-
- - (int)DeptId { return DeptId; }
-
-
- - (void) setLocationId:(int)newLocation
- {
- LocationId = newLocation;
- return;
- }
-
- - (int)LocationId { return LocationId; }
-
- - (void)setToFacility:value
- {
- // A TO-ONE relationship.
- [toFacility autorelease];
- toFacility = [value retain];
- return;
- }
- - toFacility { return toFacility; }
-
- - (void)setFacilityLocation:(NSString *)value
- {
- [FacilityLocation autorelease];
- FacilityLocation = [value retain];
- return;
- }
- - (NSString *)FacilityLocation { return FacilityLocation; }
-
- - (void)setToEmployee:(NSArray *)value
- {
- // A TO-MANY relationship.
- [toEmployee autorelease];
- toEmployee = [value retain];
- return;
- }
- - (NSArray *)toEmployee { return toEmployee; }
-
- - (void) setAverageSalary:(int)aSalary
- {
- averageSalary = aSalary;
- return;
- }
-
- - (int)averageSalary
- {
- int i;
- unsigned count = 0;
- id anEmployee, value;
- int totalSalaries = 0;
-
- averageSalary = 0;
- if (toEmployee) {
- count = [toEmployee count];
- totalSalaries = 0;
- for (i = 0; i < count; i++) {
- anEmployee = [toEmployee objectAtIndex:i];
- value = [anEmployee objectForKey:@"Salary"];
- // skip Salary with Null values
- if (![value isEqual:[EONull null]])
- totalSalaries += [[anEmployee objectForKey:@"Salary"] intValue];
- }
- }
- if (count > 0)
- averageSalary = totalSalaries/count;
-
- return averageSalary;
- }
-
- - (oneway void)printDepartmentReport: sender
- {
- }
-
- @end
-