using System;
using Views;
namespace University {
///
/// The University Access Control System Bishop & Horspool 2002
/// ====================================
/// Registers details of staff and students then
/// validates who has access for the next year.
/// Illustrates defining and using interfaces.
///
interface IAccess {
bool Valid();
}
class AccessControl {
Views.Form f;
void SetUpForm() {
try {
f = new Views.Form(@"
" );
} catch( Exception e ) {
Console.WriteLine(
"Exception caught, message follows:\n{0}", e.Message);
}
}
void Go() {
SetUpForm();
string c;
for (;;) {
c = f.GetControl();
if (c==null) break;
ActionPerformed(c);
}
f.Dispose();
}
int kind;
int number;
string name;
IAccess[] register = new IAccess[100];
int count;
void HandleAppointments() {
number = int.Parse(f.GetText("Number"));
bool found = false;
int i;
Student s;
for (i = 0; i 0);
}
public override string ToString () {
if (tutorYears == 0) return "Student "
+number+"("+tutorYears+")";
else return "Tutor "+number+"("+tutorYears+")";
}
public int CompareTo(object o) {
if (o is Student)
return (number.CompareTo(((Student) o).number));
else // o is Staff; Staff always rate before students
return 1;
}
}
public class Staff : IAccess, IComparable {
string name;
int startDate;
public Staff(string n) {
name = n;
startDate = DateTime.Now.Year;
}
public string Name {
get {return name;}
}
public int StartDate {
get {return startDate;}
}
public bool Valid() {
return true;
}
public override string ToString () {
return "Staff "+name;
}
public int CompareTo(object o) {
if (o is Staff)
return (name.CompareTo(((Staff) o).name));
// o is a Student; Staff always rate before students
return -1;
}
}
}