Example #1
0
        // Locate and return the index of data in the list.
        public int LinearSearch(Employee employee)
        {
            // Does not require the list to be ordered.
              int listIndex = 1;                        // Uses the Employee class CompareTo method.

              while ((listIndex <= this.count) && (this[listIndex].CompareTo(employee) != 0))  // Searching loop
            listIndex++;
              if (listIndex > this.count)
            listIndex = ~listIndex;
              return listIndex;
        }
Example #2
0
        // Locate and return the index of
        public int LinearSearch(Employee employee, CompareDelegate compareMethod)
        {
            // data in the list. Does not require
              int listIndex = 1;                                                       // the list to be ordered.
              // Uses a CompareDelegate method.

              while ((listIndex <= this.count) && (compareMethod(this[listIndex], employee) != 0))
            listIndex++;
              if (listIndex > this.count)
            listIndex = ~listIndex;
              return listIndex;
        }
Example #3
0
        // Locate and return the index of data
        public int BinarySearch(Employee employee, OrderEnum listOrder)
        {
            // in the list. The list must be ordered
              int listIndex = 0;                                             // by the value of the listOrder parameter.

              switch (listOrder)
              {
            case OrderEnum.IDOrder: listIndex = this.BinarySearch(employee); break;
            case OrderEnum.NameOrder: listIndex = this.BinarySearch(employee, Employee.CompareNames); break;
            case OrderEnum.HireDateOrder: listIndex = this.BinarySearch(employee, Employee.CompareHireDates); break;
            case OrderEnum.TypeOrder: listIndex = this.BinarySearch(employee, Employee.CompareTypes); break;
            case OrderEnum.EarningsOrder: listIndex = this.BinarySearch(employee, Employee.CompareEarnings); break;
            case OrderEnum.FICAOrder: listIndex = this.BinarySearch(employee, Employee.CompareFICAs); break;
            case OrderEnum.FedTaxOrder: listIndex = this.BinarySearch(employee, Employee.CompareFedTaxes); break;
            case OrderEnum.StateTaxOrder: listIndex = this.BinarySearch(employee, Employee.CompareStateTaxes); break;
            case OrderEnum.NetPayOrder: listIndex = this.BinarySearch(employee, Employee.CompareNetPays); break;
              }
              return listIndex;
        }
Example #4
0
        public void InsertAt(int position, Employee employee)
        {
            int i;

              if ((position >= 1) && (position <= this.count + 1))
              {
            if (this.count == this.capacity)
              this.IncreaseCapacity();
            this.count++;
            for (i = this.count; i > position; i--)
              this[i] = this[i - 1];
            this[position] = employee;
              }
              else
            ProcessError(String.Format("EmployeeList insert at index must be between 1 and {0}\n", this.count + 1));
        }
Example #5
0
        // Locate and return the index of data in the list.
        public int BinarySearch(Employee employee)
        {
            // The list must be ordered by ascending employee ID
              int listIndex, lowIndex = 1, highIndex = this.count;   // Uses the Employee class CompareTo method.

              listIndex = (lowIndex + highIndex) / 2;
              while ((lowIndex <= highIndex) && (this[listIndex].CompareTo(employee) != 0))
              {
            if (this[listIndex].CompareTo(employee) > 0)
              highIndex = listIndex - 1;
            else
              lowIndex = listIndex + 1;
            listIndex = (lowIndex + highIndex) / 2;
              }
              if (listIndex == 0)
            listIndex = 1;
              else if ((lowIndex > highIndex) && (this[listIndex].CompareTo(employee) < 0))  // Make listIndex point to element that should follow
            listIndex++;                                                             // employee, if employee is to be inserted
              if (lowIndex > highIndex)
            listIndex = ~listIndex;  // Make list index negative
              return listIndex;
        }
Example #6
0
        // Locate and return the index of data
        public int BinarySearch(Employee employee, CompareDelegate compareMethod)
        {
            // in the list. The list must be ordered
              int listIndex, lowIndex = 1, highIndex = this.count;                     // by ascending CompareDelegate category.

              listIndex = (lowIndex + highIndex) / 2;
              while ((lowIndex <= highIndex) && (compareMethod(this[listIndex], employee) != 0))
              {
            if (compareMethod(this[listIndex], employee) > 0)
              highIndex = listIndex - 1;
            else
              lowIndex = listIndex + 1;
            listIndex = (lowIndex + highIndex) / 2;
              }
              if (listIndex == 0)
            listIndex = 1;
              else if ((lowIndex > highIndex) && (compareMethod(this[listIndex], employee) < 0))  // Make listIndex point to element that should follow
            listIndex++;                                                                 // employee, if employee is to be inserted
              if (lowIndex > highIndex)
            listIndex = ~listIndex;
              return listIndex;
        }
Example #7
0
 // Copy method
 public void Copy(Employee sourceEmployee)
 {
     this.type = sourceEmployee.type; this.id = sourceEmployee.id;
       this.name = sourceEmployee.name; this.hireDate.Copy(sourceEmployee.hireDate);
 }
Example #8
0
        public static int CompareHireDates(Employee employee1, Employee employee2)
        {
            string string1, string2;

              string1 = employee1.hireDate.ToString("yyyy/MM/dd") + employee1.name + employee1.id.ToString("d4");
              string2 = employee2.hireDate.ToString("yyyy/MM/dd") + employee2.name + employee2.id.ToString("d4");

              return string1.CompareTo(string2);
        }
Example #9
0
        public static int CompareTypes(Employee employee1, Employee employee2)
        {
            string string1, string2;

              string1 = employee1.type + employee1.name + employee1.id.ToString("d4");
              string2 = employee2.type + employee2.name + employee2.id.ToString("d4");
              return string1.CompareTo(string2);
        }
Example #10
0
 public int CompareTo(Employee employee)
 {
     return this["ID"].CompareTo(employee["ID"]);
 }
Example #11
0
        public static int CompareStateTaxes(Employee employee1, Employee employee2)
        {
            string string1, string2;

              string1 = employee1.StateTax.ToString("0000.00") + employee1.name + employee1.id.ToString("d4");
              string2 = employee2.StateTax.ToString("0000.00") + employee2.name + employee2.id.ToString("d4");

              return string1.CompareTo(string2);
        }
Example #12
0
        public static int CompareNames(Employee employee1, Employee employee2)
        {
            string string1, string2;

              string1 = employee1.name + employee1["ID"];
              string2 = employee2.name + employee2["ID"];
              return string1.CompareTo(string2);
        }
Example #13
0
 public static int CompareIDs(Employee employee1, Employee employee2)
 {
     return employee1["ID"].CompareTo(employee2["ID"]);
 }
Example #14
0
        private void findTextBox_DoubleClick(object sender, System.EventArgs e)
        {
            bool valueOk = true; int listIndex = 1, id; Date hireDate;
              string name; Employee emp = new Employee();

              if (this.listOrder == EmployeeList.OrderEnum.IDOrder &&
              this.findETextBox.ReadInt(out id, TBounds.Both, 1, 9999))
            emp.ID = id;
              else if (this.listOrder == EmployeeList.OrderEnum.NameOrder &&
               this.findETextBox.ReadString(out name))
            emp.Name = name.Trim();
              else if (this.listOrder == EmployeeList.OrderEnum.HireDateOrder &&
               this.findETextBox.ReadDate(out hireDate))
            emp.HireDate = hireDate;
              else
            valueOk = false;
              if (valueOk)
              {
            listIndex = this.empList.BinarySearch(emp, listOrder);
            if (listIndex < 0)
              listIndex = ~listIndex;
            this.ProcessSelectedRowChanged(listIndex);
              }
        }
Example #15
0
 public void Add(Employee employee)
 {
     this.InsertAt(this.count + 1, employee);
 }
Example #16
0
 static void Main()
 {
     ConsoleApp.ClrScr();
       IdentifyApplication();
       OpenFiles();
       employeeList1.Fill(fileIn);
       employeeList1.SelectionSort(Employee.CompareIDs);        employeeList1.AppendReport(fileOut, "All Employees in List One - ID Order");
       employeeList1.SelectionSort(Employee.CompareNames);      employeeList1.AppendReport(fileOut, "All Employees in List One - Name Order");
       employeeList1.SelectionSort(Employee.CompareHireDates);  employeeList1.AppendReport(fileOut, "All Employees in List One - Hire Date Order");
       employeeList1.SelectionSort(Employee.CompareEarnings);   employeeList1.AppendReport(fileOut, "All Employees in List One - Earnings Order");
       employeeList1.SelectionSort(Employee.CompareTypes);      employeeList1.AppendReport(fileOut, "All Employees in List One - Type Order");
       foreach (Employee employee in employeeList1)
     if (employee is Supervisor)
       employeeSublist.Add(((Supervisor) employee).Clone());
       employeeSublist.AppendReport(fileOut, "Supervisor Employees in List One - Name Order");
       employeeSublist.Clear();
       foreach (Employee employee in employeeList1)
     if (employee is Hourly)
       employeeSublist.Add(employee);
       employeeSublist.AppendReport(fileOut, "Hourly Employees in List One - Name Order");
       employeeSublist.Clear();
       foreach (Employee employee in employeeList1)
     if (employee is Commission)
       employeeSublist.Add(employee);
       employeeSublist.AppendReport(fileOut, "Commission Employees in List One - Name Order");
       employeeSublist.Clear();
       foreach (Employee employee in employeeList1)
     if (employee is Piece)
       employeeSublist.Add(employee);
       employeeSublist.AppendReport(fileOut, "Piece Employees in List One - Name Order");
       employeeList1.SelectionSort(Employee.CompareNames);
       //employeeList1.SelectionSort(EmployeeList.OrderEnum.NameOrder);
       employee1 = new Supervisor(employeeList1.AssignID(), "Lawson, LeAnn", "Jun 15, 1989", 1500.00);
       index = ~employeeList1.BinarySearch(employee1, Employee.CompareNames);
       //index = ~employeeList1.BinarySearch(employee1, EmployeeList.OrderEnum.NameOrder);
       employeeList1.InsertAt(index, employee1);
       employeeList1.AppendReport(fileOut, "All Employees in List One - Name Order");
       employeeList2 = employeeList1.Clone();
       employeeList2.RemoveAt(index);
       employeeList2.AppendReport(fileOut, "All Employees in List Two - Name Order");
       CloseFiles();
 }
Example #17
0
 // Copy constructor
 public Employee(Employee sourceEmployee)
 {
     this.hireDate = new Date();
       this.Copy(sourceEmployee);
 }