/// <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()); } } }
/// <summary> /// A method to read the input. This method will take as its only parameter a string giving the name of the file to read. /// It will return a SearchableQueue<Worker> containing the information read. It must first construct a new SearchableQueue<Worker>. /// Then with a using statement as in Lab Assignment 14, create a StreamReader from the given file name. Then for each line of the file, /// use the line's Split method to split it into fields delimited by commas (you can pass ',' as this method's only parameter). /// This method will return a string[ ] whose elements /// </summary> /// <param name="s"></param> /// <returns></returns> private SearchableQueue <Worker> readInput(string fileName) { int count = 0; SearchableQueue <Worker> SearchQueue = new SearchableQueue <Worker>(); using (StreamReader input = new StreamReader(fileName)) { while (!input.EndOfStream) { string[] workerData = input.ReadLine().Split(','); Worker newWorkerData = new Worker(workerData); SearchQueue.Enqueue(newWorkerData); count++; } tasks = SearchQueue.CurrentElement.Data.numberOfTasks; numberOfWorkers = count; } return(SearchQueue); }