using System;
using System.Collections.Generic;
using System.Text;

namespace InterfaceSample
{
    public class Company : IEmployees
    {
        #region IEmployees 成员

        public int AddEmployee(Employee emp)
        {
            //确认该员工编号未建立
            if ((emp != null) && (!employees.ContainsKey(emp.ID)))
            {
                employees.Add(emp.ID, emp);
            }
            return employees.IndexOfValue(emp); //返回索引值
        }

        public bool RemoveEmployee(string empid)
        {
            if (employees.ContainsKey(empid))
            {
                employees.Remove(empid);
                return true;
            }
            else
            {
                return false;
            }
        }

        public Employee this[string empid]
        {
            get
            {
                return employees[empid];
            }

        }

        #endregion

        #region IEnumerable<Employee> 成员

        public IEnumerator<Employee> GetEnumerator()
        {
            return employees.Values.GetEnumerator();
        }

        #endregion

        #region IEnumerable 成员

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return employees.GetEnumerator();
        }

        #endregion

        private SortedList<string, Employee> employees
            = new SortedList<string, Employee>();
    }
}

