Fire up your applications with Jetfire
RSS
Jetfire Wiki


Quick Search
»
Advanced Search »

Table of Contents [Hide/Show]


Jetfire Code: Contact

The Jetfire Code Class for Contact is shown below in the box. This class is the root class for contact management.

// C O N T A C T     I N T E R F A C E
//===================================================================================
// Contact.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.
//===================================================================================
//
// Contact: a common contact. This is inherited by Person, OrganizationUnit and Resource.  This class should not be instantiated. 
// Profile: allows a contact to be used for many purposes, e.g. worker, dad, coach, etc
// OrganizationUnit: used to create organization hierarchies
// Resource: a general class used for meeting rooms, bull-dozers

namespace JetfireContacts
{
// DisplayName = "Contact";
// ToolTip = "Interface for a contact.";
   public workflow Contact
   {
      // C O N S T R U C T O R - Instantiate the Contact
      // Contact starts in the Start State.
      public Contact()
      {
		 this.Subject = " New Contact";
		 this.InitializeContact();
      }
      public Contact(string subject)
      {
		 this.Subject = subject;
		 this.InitializeContact();
      }
      private void InitializeContact()
      {
		 profiles.Subject = "Profiles List";
		 addresses.Subject = "Address List";
		 emails.Subject = "Email List";
		 phones.Subject = "Phone List";
		 tags.Subject = "Tag List";
		 notes.Subject = "Note List";
		 enterstate this.Start();
      }
		private virtual void ResetContact()
		{
			foreach (BaseProfile profile in Profiles)
			{
				profile.ResetProfile();
			}
		}

	  // Static Properties
      private static Contact none;
      public static Contact None
      {
		 get { return none;		}
		 set { none = value;	}
      }
      
      // P R O P E R T I E S
      OrganizationUnit ou;
      ShowContactAs showContactAs = ShowContactAs.None;
      TimeZone timeZone = TimeZone.EST;
      RecordStanding rs = RecordStanding.Active;
      List profiles = new List();
      List addresses = new List();
      List emails = new List();
      List phones = new List();
      List tags = new List();
      List notes = new List();
      string homeAddress1;
      string homeAddress2;
      string homeCity;
      string homePC;
      Province homeProvince;
      string homeEmail;
      string otherEmail;
      string homePhone;
      string businessPhone;
      string mobilePhone;
      string faxPhone;
      // scratch pad variables
      Address a;
      EmailAddress e;
      Phone p;
      LocationType atType;
      string temp;
      
      public OrganizationUnit OrgUnit
      {
         get { return ou;				}
         set { ou = value;				}
      }
      public ShowContactAs ShowContactAs
      {
         get { return showContactAs;	}
         set { showContactAs = value;	}
      }
      public TimeZone TimeZone
      {
         get { return timeZone;			}
         set { timeZone = value;		}
      }
      public RecordStanding RecordStanding
      {
         get { return rs;				}
         set { rs = value;				}
      }
      public List Profiles
      {
         get { return profiles;			}
      }
      public List Addresses
      {
         get { return addresses;		}
      }
      public List EmailAddresses
      {
         get { return emails;			}
      }
      public List PhoneNumbers
      {
         get { return phones;			}
      }
      public List Tags
      {
         get { return tags;				}
      }
      public List Notes
      {
         get { return notes;			}
      }
      public string HomeAddress1
      {
         get { return homeAddress1;     }
         set
         {
			homeAddress1 = value;
			atType = LocationType.Home;
			a = this.GetAddress(atType, value);
			if (a != Address.None)
			{	a.Address1 = value;		}
         }
      }
      public string HomeAddress2
      {
         get { return homeAddress2;     }
         set
         {
			homeAddress2 = value;
			atType = LocationType.Home;
			a = this.GetAddress(atType, value);
			if (a != Address.None)
			{	a.Address2 = value;		}
         }
      }
      public string HomeCity
      {
         get { return homeCity;         }
         set
         {
			homeCity = value;
			atType = LocationType.Home;
			a = this.GetAddress(atType, value);
			if (a != Address.None)
			{	a.City = value;			}
         }
      }
      public string HomePC
      {
         get { return homePC;			}
         set
         {
			homePC = value;
			atType = LocationType.Home;
			a = this.GetAddress(atType, value);
 			if (a != Address.None)
 			{	a.PostalCode = value;	}
        }
      }
      public Province HomeProvince
      {
         get { return homeProvince;		}
         set 
         {
			temp = value.ToString();
			if (temp == "None")
			{	temp = "";		}
			homeProvince = value;
			atType = LocationType.Home;
			a = this.GetAddress(atType, temp);
 			if (a != Address.None)
 			{	a.Province = value;	}
		 }
      }
      public string HomeEmail
      {
         get { return homeEmail;		}
         set 
         {
			homeEmail = value;
			atType = LocationType.Home;
			this.GetEmailAddress(atType, value);
         }
      }
      public string OtherEmail
      {
         get { return otherEmail;		}
         set
         {
			otherEmail = value;
			atType = LocationType.Other;
			this.GetEmailAddress(atType, value);
         }
      }
      public string HomePhone
      {
         get { return homePhone;		}
         set
         {
			homePhone = value;
 			atType = LocationType.Home;
			this.GetPhone(atType, value);
         }
      }
      public string BusinessPhone
      {
         get { return businessPhone;	}
         set
         {
			businessPhone = value;
 			atType = LocationType.Business;
			this.GetPhone(atType, value);
         }
      }
      public string MobilePhone
      {
         get { return mobilePhone;		}
         set
         {
			mobilePhone = value;
 			atType = LocationType.Mobile;
			this.GetPhone(atType, value);
         }
      }
      public string FaxPhone
      {
         get { return faxPhone;		}
         set
         {
			faxPhone = value;
 			atType = LocationType.Fax;
			this.GetPhone(atType, value);
         }
      }
      
      // Private Methods
      // Tries to find the Address. If not in list, then creates Address and adds to list.
      private Address GetAddress(LocationType atType, string blank)
      {
		 Address a = null;
		 Address b;
		 int count = this.Addresses.Count;
		 while (count > 0)
		 {
			b = this.Addresses.GetValue(count-1);
			if (b.AddressType == atType)
			{	a = b;			}
			count -= 1;
		 }
		 if (a != null)
		 {	return a;			}
		 if (blank.Length == 0)
		 {	return Address.None;}
		 a = new Address();
		 a.AddressType = atType;
		 this.Addresses.Add(a);
		 return a;
      }
      // Tries to find the EmailAddress. If not in list, then creates EmailAddress and adds to list.
      private void GetEmailAddress(LocationType atType, string address)
      {
		 EmailAddress a = null;
		 EmailAddress b;
		 int count = this.EmailAddresses.Count;
		 while (count > 0)
		 {
			b = this.EmailAddresses.GetValue(count-1);
			if (b.EmailAddressType == atType)
			{	a = b;			}
			count -= 1;
		 }
		 if (a != null)
		 {
			a.Address = address;
			return;
		 }
		 if (address.Length == 0)
		 {	return;				}
		 a = new EmailAddress();
		 a.EmailAddressType = atType;
		 a.Address = address;
		 this.EmailAddresses.Add(a);
      }
      // Tries to find the Phone. If not in list, then creates Phone and adds to list.
      private void GetPhone(LocationType atType, string number)
      {
		 Phone a = null;
		 Phone b;
		 int count = this.PhoneNumbers.Count;
		 while (count > 0)
		 {
			b = this.PhoneNumbers.GetValue(count-1);
			if (b.PhoneNumberType == atType)
			{	a = b;			}
			count -= 1;
		 }
		 if (a != null)
		 {
			a.PhoneNumber = number;
			return;
		 }
		 if (number.Length == 0)
		 {	return;				}
		 a = new Phone();
		 a.PhoneNumberType = atType;
		 a.PhoneNumber = number;
		 this.PhoneNumbers.Add(a);
      }

      // 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
      //
      // S T A T E   M E T H O D S
      public Start()
      {
      }
      public Active()
      {
      }
      public Inactive()
      {
      }
      // Methods

      // C O M M A N D S
      // The Approve command
      public void Approve() : states(Start, Inactive)
      {
         enterstate this.Active();
      }
      // The Deativate command
      public void Deactivate() : states(Active)
      {
         enterstate this.Inactive();
      }
      
      // General Commands
      public BaseProfile AddProfile()
      {
		 BaseProfile a = new BaseProfile(" New Profile");
		 this.Profiles.Add(a);
		 return a;
      }
      public BaseProfile AddProfile(string name)
      {
		 BaseProfile a = new BaseProfile(name);
		 this.Profiles.Add(a);
		 return a;
      }
      public Address AddAddress()
      {
		 Address a = new Address(" New Address");
		 this.Addresses.Add(a);
		 return a;
      }
      public Address AddAddress(string address1, string city)
      {
		 Address a = this.AddAddress();
		 a.Address1 = address1;
		 a.City = city;
		 return a;
      }
      public EmailAddress AddEmailAddress()
      {
		 EmailAddress a = new EmailAddress(" New Email Address");
		 this.EmailAddresses.Add(a);
		 return a;
      }
      public EmailAddress AddEmailAddress(string ea)
      {
		 EmailAddress a = this.AddEmailAddress();
		 this.EmailAddresses.Add(a);
		 a.Address = ea;
		 return a;
      }
      public Phone AddPhoneNumber()
      {
		 Phone a = new Phone(" New Phone Number");
		 this.PhoneNumbers.Add(a);
		 return a;
      }
      public Phone AddPhoneNumber(string number)
      {
		 Phone a = this.AddPhoneNumber();
		 this.PhoneNumbers.Add(a);
		 a.PhoneNumber = number;
		 return a;
      }
      public Note AddNote()
      {
		 Note a = new Note(" New Note");
		 this.Notes.Add(a);
		 return a;
      }
      public Note AddNote(string title)
      {
		 Note a = new Note(title);
		 this.Notes.Add(a);
		 return a;
      }
   }
   
// DisplayName = "Profile";
// ToolTip = "Profile Definition.";
   public workflow BaseProfile : Profile
   {
      // C O N S T R U C T O R - Instantiate the Profile
      private BaseProfile()
      {
		 this.Subject = " New Profile";
		 tags.Subject = "Tag List";
		 notes.Subject = "Note List";
      }
      public BaseProfile(string profileName)
      {
		 this.Subject = profileName;
		 tags.Subject = "Tag List";
		 notes.Subject = "Note List";
      }

	  // Public Methods - used in derived classes to reset the profile
	  public virtual void ResetProfile()
	  {
	  }

	  // Static Properties
      private static BaseProfile none;
      public static BaseProfile None
      {
		 get { return none;		}
		 set { none = value;	}
      }
      
      // P R O P E R T I E S
      public string ProfileName
      {
         get { return this.Subject;		}
         set { this.Subject = value;	}
      }
      // Each Profile can belong to a different hierarchy, e.g. Dad belongs to family, Business Worker belongs to company, Soccer Coach belongs to a Club, etc
      OrganizationUnit ou;
      List notes = new List();
      List tags = new List();
      
      public OrganizationUnit OrgUnit
      {
         get { return ou;				}
         set { ou = value;				}
      }
      public List Notes
      {
         get { return notes;			}
      }
      public List Tags
      {
         get { return tags;				}
      }
   }

// DisplayName = "Organization Unit";
// ToolTip = "Represents an Organization Unit.";
   public workflow OrganizationUnit : Contact
   {
      // C O N S T R U C T O R - Instantiate the Organization Unit
      public OrganizationUnit()
      {
		 this.Subject = " New Organization";
         enterstate this.Start();
      }
      public OrganizationUnit(string subject)
      {
		 this.Subject = subject;
         enterstate this.Start();
      }
      public OrganizationUnit(string subject, string toolTip)
      {
		 this.Subject = subject;
		 this.ToolTip = toolTip;
         enterstate this.Start();
      }
      public OrganizationUnit(string name, string subject, string toolTip)
      {
		 this.Subject = subject;
		 this.ToolTip = toolTip;
         enterstate this.Start();
      }
      // P R O P E R T I E S
   }
// DisplayName = "Resource";
// ToolTip = "Represents an Resource.";
  public workflow Resource : Contact
  {
      // C O N S T R U C T O R - Instantiate the Resource
      public Resource()
      {
		 this.Subject = " New Resource";
         enterstate this.Start();
      }
      public Resource(string subject)
      {
		 this.Subject = subject;
         enterstate this.Start();
      }
      public Resource(string subject, string toolTip)
      {
		 this.Subject = subject;
		 this.ToolTip = toolTip;
         enterstate this.Start();
      }
      // P R O P E R T I E S
   }
}

See Also

Jetfire Code Library
Jetfire Contacts Code Library

ScrewTurn Wiki version 3.0.4.560. Some of the icons created by FamFamFam.