public WeatherList(WeatherList w) { //copy constructor that takes in another WeatherList object // and creates a new linked list that is a copy of the parameter list if (w.Count == 0) { _head = null; _tail = null; _size = 0; } else { _head = new Node <WeatherData>(w._head.Data); _size = 1; Node <WeatherData> tempOld = _head; Node <WeatherData> temp = w._head.Next; while (temp != null) { Node <WeatherData> tempNew = new Node <WeatherData>(temp.Data); tempOld.Next = tempNew; tempOld = tempOld.Next; temp = temp.Next; if (temp != null) { _size++; } } _tail = tempOld; } }
private void FilterClick(object sender, EventArgs e) { WeatherList copy = new WeatherList(_current); wlists.Push(copy); //pushing the copy onto the stack; uxUndoButton.Enabled = true; //we can now undo changes, so make button avaliable if (uxDateRangeButton.Checked) { _current.FilterRange(uxMonthCalendar.SelectionStart, uxMonthCalendar.SelectionEnd); } else if (uxBelowTempButton.Checked) { _current.FilterTemp(Convert.ToInt32(uxNumericUpDown.Value), true); } else if (uxAboveTempButton.Checked) { _current.FilterTemp(Convert.ToInt32(uxNumericUpDown.Value), false); } else if (uxDateHistory.Checked) { _current.FilterDateHistory(uxMonthCalendar.SelectionStart); } else { MessageBox.Show("Error: Please select a filter first!"); return; } uxWeatherListBox.DataSource = null; uxWeatherListBox.DataSource = _current; }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (uxOpenFile.ShowDialog() == DialogResult.OK) { try //try to read the input file { //read in the file and put it into the listbox WeatherList temp = new WeatherList(); char[] delims = { ' ' }; using (StreamReader sr = new StreamReader(uxOpenFile.FileName)) { while (!sr.EndOfStream) { string[] pieces = (sr.ReadLine()).Split(delims, StringSplitOptions.RemoveEmptyEntries); int year = Convert.ToInt32(pieces[2]); int month = Convert.ToInt32(pieces[0]); int day = Convert.ToInt32(pieces[1]); double temperature = Convert.ToDouble(pieces[3]); DateTime date = new DateTime(year, month, day); WeatherData weather = new WeatherData(date, temperature); temp.Add(weather); } } _current = temp; uxWeatherListBox.DataSource = _current; } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
/// <summary> /// Button checks radio button and (attempts) to filter listbox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void uxFilterButton_Click(object sender, EventArgs e) { if (uxAboveTemp.Checked) { WeatherList temp = new WeatherList(wd); ws.Push(temp); wd.FilterTemp(Convert.ToDouble(uxTempSetting.Value), true); uxDatesList.DataSource = null; uxDatesList.Items.Clear(); uxDatesList.DataSource = wd; } else if (uxBelowTemp.Checked) { WeatherList temp = new WeatherList(wd); ws.Push(temp); wd.FilterTemp(Convert.ToDouble(uxTempSetting.Value), false); uxDatesList.DataSource = null; uxDatesList.Items.Clear(); uxDatesList.DataSource = wd; } else if (uxDateRange.Checked) { try { WeatherList temp = new WeatherList(wd); ws.Push(temp); wd.FilterRange(uxCalendar.SelectionRange.Start, uxCalendar.SelectionRange.End); uxDatesList.DataSource = null; uxDatesList.Items.Clear(); uxDatesList.DataSource = wd; } catch (Exception ex) { MessageBox.Show("Must select dates\n" + ex.ToString()); } } else if (uxThisDate.Checked) { try { WeatherList temp = new WeatherList(wd); ws.Push(temp); wd.FilterDateHistory(uxCalendar.SelectionRange.Start); uxDatesList.DataSource = null; uxDatesList.Items.Clear(); uxDatesList.DataSource = wd; } catch (Exception ex) { MessageBox.Show("Must select a date\n" + ex.ToString()); } } else { MessageBox.Show("Please select a filter"); } }
private void UndoClick(object sender, EventArgs e) { _current = wlists.Pop(); //_current is now the list that we just popped off uxWeatherListBox.DataSource = null; uxWeatherListBox.DataSource = _current; //updating ListBox if (wlists.Count == 0) //if we popped off the last list, disable the undo button { uxUndoButton.Enabled = false; } }
/// <summary> /// should pop previous weatherlists and use those /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void uxUndoButton_Click(object sender, EventArgs e) { if (ws.Count > 0) { wd = new WeatherList(ws.Pop()); uxDatesList.DataSource = null; uxDatesList.Items.Clear(); uxDatesList.DataSource = wd; } else { MessageBox.Show("No filters to undo"); } }
public WeatherList(WeatherList w) { _head = null; _tail = null; _size = w._size; int i = 0; Node temp = w._head; while (i < _size) { this.Add(temp.Data); temp = temp.Next; _size--; i++; } }
/// <summary> /// on open menu click, loads file and listbox contents /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void uxOpenMenu_Click(object sender, EventArgs e) //More error checking here if time { if (uxOpenFileDialog.ShowDialog() == DialogResult.OK) { //try //{ if (uxDatesList.Items.Count > 0) { uxDatesList.DataSource = null; uxDatesList.Items.Clear(); wd = new WeatherList(); } string name = uxOpenFileDialog.FileName; using (StreamReader inFile = new StreamReader(name)) { string line; char[] sep = new char[] { ' ' }; while ((line = inFile.ReadLine()) != null) { string[] data = new string[4]; data = line.Split(sep, StringSplitOptions.RemoveEmptyEntries); if (Convert.ToDouble(data[3]) != -99) { wd.Add(new WeatherData(Convert.ToInt32(data[0]), Convert.ToInt32(data[1]), Convert.ToInt32(data[2]), Convert.ToDouble(data[3]))); } } } uxDatesList.DataSource = wd; //}catch(Exception ex) //{ // MessageBox.Show("Something Went Wrong\n" + ex.ToString()); //} } }