Skip to content

Commit

Permalink
Moved sorting to presenter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocke-G committed Apr 26, 2017
1 parent a0b161b commit b49477c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
15 changes: 14 additions & 1 deletion src/SportidentLapCounter/Controls/MainForm/MainFormPresenter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using SportidentLapCounter.Services;
using System.ComponentModel;
using System.Linq;
using SportidentLapCounter.DataTypes;
using SportidentLapCounter.Services;

namespace SportidentLapCounter.Controls.MainForm
{
Expand All @@ -13,6 +16,16 @@ public MainFormPresenter()
Model = PersistenceService.Load();
}

public void SortTeams()
{
Model.Teams = new BindingList<Team>(
Model.Teams
.OrderByDescending(x => x.Laps)
.ThenBy(x => x.LatestPunchTime)
.ThenBy(x => x.Number)
.ToList());
}

public void PersistModel()
{
PersistenceService.Save(Model);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions src/SportidentLapCounter/Controls/MainForm/MainFormView.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
Expand All @@ -26,7 +25,7 @@ public MainFormView()

dataGridView.AutoGenerateColumns = false;

dataGridView.DataSource = Presenter.Model.Teams;
UpdateFromModel();
SetFontSize(Presenter.Model.FontSize);
}

Expand Down Expand Up @@ -79,16 +78,21 @@ private void ReaderOnOnlineStampRead(object sender, SportidentDataEventArgs e)
x.LatestPunchTime = punchData.PunchDateTime;
}

Presenter.Model.Teams = new BindingList<Team>(Presenter.Model.Teams.OrderByDescending(x => x.Laps).ThenBy(x => x.LatestPunchTime).ToList());
Presenter.SortTeams();

dataGridView.DataSource = null;
dataGridView.DataSource = Presenter.Model.Teams;
UpdateFromModel();
dataGridView.ClearSelection();

Presenter.PersistModel();
});
}

private void UpdateFromModel()
{
dataGridView.DataSource = null;
dataGridView.DataSource = Presenter.Model.Teams;
}

private void Connect()
{
var readerDeviceInfo = (ReaderDeviceInfo)(comboBox_sportidentDevices.SelectedItem);
Expand Down Expand Up @@ -123,15 +127,15 @@ private void button_sportidentDisconnect_Click(object sender, EventArgs e)
}


private void SaveFile(object sender, DataGridViewCellEventArgs e)
private void CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (Presenter.Model == null)
return;

Presenter.PersistModel();
}

private void SaveFile(object sender, DataGridViewRowEventArgs e)
private void RowAddedOrDeleted(object sender, DataGridViewRowEventArgs e)
{
Presenter.PersistModel();
}
Expand Down

0 comments on commit b49477c

Please sign in to comment.