|
|
1.1 ! root 1: /* Department.m ! 2: * A simple enterprise object. ! 3: * ! 4: * You may freely copy, distribute, and reuse the code in this example. ! 5: * NeXT disclaims any warranty of any kind, expressed or implied, as to its ! 6: * fitness for any particular use. ! 7: * ! 8: * Written by Mai Nguyen, NeXT Developer Support ! 9: */ ! 10: ! 11: #import "Department.h" ! 12: #import "strings.h" ! 13: ! 14: ! 15: @implementation Department ! 16: ! 17: - init ! 18: { ! 19: [super init]; ! 20: // You can add additional intialization here. ! 21: return self; ! 22: } ! 23: ! 24: - (void)dealloc ! 25: { ! 26: [DepartmentName autorelease]; ! 27: [FacilityLocation autorelease]; ! 28: [toEmployee autorelease]; ! 29: [super dealloc]; ! 30: ! 31: } ! 32: ! 33: ! 34: // Accessor methods ! 35: ! 36: - (void) setDepartmentName:(NSString *)newName ! 37: { ! 38: [DepartmentName autorelease]; ! 39: DepartmentName = [newName retain]; ! 40: return; ! 41: } ! 42: ! 43: - (NSString *)DepartmentName { return DepartmentName; } ! 44: ! 45: - (void) setDeptId:(int)newId ! 46: { ! 47: DeptId = newId; ! 48: return; ! 49: } ! 50: ! 51: - (int)DeptId { return DeptId; } ! 52: ! 53: ! 54: - (void) setLocationId:(int)newLocation ! 55: { ! 56: LocationId = newLocation; ! 57: return; ! 58: } ! 59: ! 60: - (int)LocationId { return LocationId; } ! 61: ! 62: - (void)setToFacility:value ! 63: { ! 64: // A TO-ONE relationship. ! 65: [toFacility autorelease]; ! 66: toFacility = [value retain]; ! 67: return; ! 68: } ! 69: - toFacility { return toFacility; } ! 70: ! 71: - (void)setFacilityLocation:(NSString *)value ! 72: { ! 73: [FacilityLocation autorelease]; ! 74: FacilityLocation = [value retain]; ! 75: return; ! 76: } ! 77: - (NSString *)FacilityLocation { return FacilityLocation; } ! 78: ! 79: - (void)setToEmployee:(NSArray *)value ! 80: { ! 81: // A TO-MANY relationship. ! 82: [toEmployee autorelease]; ! 83: toEmployee = [value retain]; ! 84: return; ! 85: } ! 86: - (NSArray *)toEmployee { return toEmployee; } ! 87: ! 88: - (void) setAverageSalary:(int)aSalary ! 89: { ! 90: averageSalary = aSalary; ! 91: return; ! 92: } ! 93: ! 94: - (int)averageSalary ! 95: { ! 96: int i; ! 97: unsigned count = 0; ! 98: id anEmployee, value; ! 99: int totalSalaries = 0; ! 100: ! 101: averageSalary = 0; ! 102: if (toEmployee) { ! 103: count = [toEmployee count]; ! 104: totalSalaries = 0; ! 105: for (i = 0; i < count; i++) { ! 106: anEmployee = [toEmployee objectAtIndex:i]; ! 107: value = [anEmployee objectForKey:@"Salary"]; ! 108: // skip Salary with Null values ! 109: if (![value isEqual:[EONull null]]) ! 110: totalSalaries += [[anEmployee objectForKey:@"Salary"] intValue]; ! 111: } ! 112: } ! 113: if (count > 0) ! 114: averageSalary = totalSalaries/count; ! 115: ! 116: return averageSalary; ! 117: } ! 118: ! 119: ! 120: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.