Beispiel #1
0
        /// <summary>
        /// A method to search the queue for the first worker qualified for a given task, and move that worker to the end of the queue.
        /// This method will take as its only parameter an int identifying the task. It will return the worker it found. If you get to
        /// the end of the queue without finding a qualified worker, throw an InvalidOperationException containing an appropriate message
        /// (you will need to use the constructor that takes a string parameter).
        /// </summary>
        private LinkedListCell <Worker> Search(int task)
        {
            LinkedListCell <Worker> SearchCell = workerQueue.SetToFront();

            for (int i = 0; i < numberOfWorkers; i++)
            {
                if (SearchCell.Data.qualified(task))
                {
                    workerQueue.CurrentElement.Data.oneMoreTime();
                    return(SearchCell);
                }
                SearchCell = workerQueue.AdvanceElement();
            }
            throw new InvalidOperationException("Unable to find Qualified worker for task " + task);
        }
Beispiel #2
0
        /// <summary>
        /// Event Handler for Compute Schedule Button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uxComputeSchedule_Click(object sender, EventArgs e)
        {
            string fileName = uxTextBox.Text;

            workerQueue = readInput(fileName);
            int daysTotal = (int)uxNumericUpDown.Value;

            if (uxSaveDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string saveFile = uxSaveDialog.FileName;

                    using (StreamWriter output = new StreamWriter(saveFile))
                    {
                        // Starts first row of CSV File
                        output.Write(",");
                        for (int i = 0; i < tasks; i++)
                        {
                            output.Write(i + ",");
                        }
                        output.WriteLine();
                        LinkedListCell <Worker> SearchCell = workerQueue.SetToFront();
                        for (int days = 1; days <= daysTotal; days++)
                        {
                            output.Write((days).ToString() + ',');
                            for (int j = 0; j < tasks; j++)
                            {
                                SearchCell = Search(j);
                                output.Write(SearchCell.Data.Name + ',');
                                SearchCell = workerQueue.MoveToBack();
                                SearchCell = workerQueue.SetToFront();
                            }
                            output.WriteLine();
                        }
                        timesScheduled();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }