Page History: Jetfire Code: Person
Compare Page Revisions
Page Revision: 2010/01/19 21:42
Jetfire Code: Person
The Jetfire Code Class for Person is shown below in the box. This class is used for a person.
// P E R S O N
//===================================================================================
// Person.txt
//===================================================================================
// Copyright (C) 2007 TrackerRealm Corporation
// This file is part of Jetfire. http://Jetfire.ca
//
// Jetfire is open software: you can redistribute it and/or modify it under the terms of the
// GNU General Public License as published by the Free Software Foundation, version 3 of the License.
//
// Jetfire is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with Jetfire.
// If not, see http://www.gnu.org/licenses.
// REMOVAL OF THIS NOTICE IS VIOLATION OF THE COPYRIGHT.
//===================================================================================
//
// Person: Person is a contact that describes people.
// Worker: Worker is a class used to describe a worker in a Workflow
// DisplayName = "Person";
// ToolTip = "Configuration for a person contact.";
//
namespace JetfireContacts
{
public workflow Person : Contact
{
// C O N S T R U C T O R - Instantiate the Person
// Person starts in the Start State.
public Person()
{
this.Subject = " New Person";
}
public Person(string subject)
{
this.Subject = subject;
}
public Person(string subject, string first, string middle, string last)
{
this.Subject = subject;
this.FirstName = first;
this.MiddleName = middle;
this.LastName = last;
}
// P R O P E R T I E S
string first;
string middle;
string last;
Gender gender = Gender.na;
Salutation salutation = Salutation.None;
Date dob;
public string FirstName
{
get { return this.first; }
set
{
this.first = value;
this.SetSubject();
}
}
public string MiddleName
{
get { return this.middle; }
set
{
this.middle = value;
this.SetSubject();
}
}
public string LastName
{
get { return this.last; }
set
{
this.last = value;
this.SetSubject();
}
}
public Gender Gender
{
get { return this.gender; }
set { this.gender = value; }
}
public Salutation Salutation
{
get { return this.salutation; }
set { this.salutation = value; }
}
public Date DOB
{
get { return this.dob; }
set { this.dob = value; }
}
// S T A T E T R A N S I T I O N S
// State Transition Command Comment
// Start -> Active Approve The contact is added to the contact list
// Active -> Inactive Deactivate The contact is deactivated
// Inactive -> Active Activate The contact is re-activated
// Active -> PendingVacation VacationRequest A person requests a vacation
// PendingVacation -> Vacation VacationApproved The vacation is approved
// Vacation -> Active Activate The contact is re-activated
//
// S T A T E M E T H O D S
public VacationPending()
{
}
public Vacation()
{
}
// Methods
public void AddName(string first, string middle, string last)
{
this.FirstName = first;
this.MiddleName = middle;
this.LastName = last;
}
// Private Methods
// Set the Subject when the name of the person changes
private void SetSubject()
{
string ou;
if (this.ShowContactAs == ShowContactAs.FirstName_LastName)
{
this.GetFirstNameLastName();
}
else
{
if (this.ShowContactAs == ShowContactAs.LastName_FirstName_Company)
{
if (this.OrgUnit == null)
{
this.GetLastNameFirstName();
}
else
{
this.GetLastNameFirstName();
Subject += " (";
Subject += OrgUnit.Subject;
Subject += ")";
}
}
else
{
this.GetLastNameFirstName();
}
}
if (Subject == ",")
{
Subject = " Person";
}
}
private void GetLastNameFirstName()
{
if (FirstName.Length == 0)
{
if (LastName.Length == 0)
{
Subject = " Person";
return;
}
Subject = LastName;
return;
}
else
{
if (LastName.Length == 0)
{
Subject = FirstName;
return;
}
}
Subject = (LastName + "," + FirstName);
}
private void GetFirstNameLastName()
{
if (FirstName.Length == 0)
{
if (LastName.Length == 0)
{
Subject = " Person";
return;
}
Subject = LastName;
return;
}
else
{
if (LastName.Length == 0)
{
Subject = FirstName;
return;
}
}
Subject = (FirstName + " " + LastName);
}
// C O M M A N D S
// The Vacation Request command
public void VacationRequest() //: states(Active)
{
enterstate this.VacationPending();
}
// The Vacation Approved command
public void VacationApproved() : states(VacationPending)
{
enterstate this.Vacation();
}
}
// Workflow Name = "Worker";
// ToolTip = "Represents a Worker.";
public workflow Worker
{
// C O N S T R U C T O R - Instantiate the Worker
public Worker()
{
Subject = " New Worker";
}
public Worker(string subject)
{
Contact = new Person(subject);
}
public Worker(Contact contact)
{
Contact = contact;
}
// P R O P E R T I E S
Contact contact = Contact.None;
public Contact Contact
{
get { return contact; }
set
{
contact = value;
this.UpdateSubject();
}
}
public bool IsMandatoryAttendee
{
get;
set;
}
public uint PercentageAllocation
{
get;
set;
}
// Private Methods
private void UpdateSubject()
{
this.Subject = "Worker: " + this.Contact.Subject;
}
}
}