Permalink
Browse files

Leden selecteren, sla leden op in XML bestand.

  • Loading branch information...
1 parent 98d080f commit d8def459d42e90ffe0f046b8d9871dc253e0c6fa @Sjord committed Nov 16, 2011

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -8,12 +8,13 @@
using System.Windows.Forms;
using ScoutsOffline.Sol;
using System.Diagnostics;
+using ScoutsOffline.Model;
namespace ScoutsOffline
{
public partial class Form1 : Form
{
- List<Member> members = new List<Member>();
+ Repository repository;
public Form1()
{
@@ -24,6 +25,13 @@ protected override void OnShown(EventArgs e)
{
base.OnShown(e);
+ /*
+ var username = "Sjoerder";
+ repository = new Repository(username);
+ FilterDataSource();
+ return;
+ */
+
var login = new Login();
login.LoginClick += OnLoginClick;
login.Show(this);
@@ -37,6 +45,10 @@ protected void OnLoginClick(object sender, LoginClickEventArgs eArgs)
var sol = new ScoutsOnLine();
if (sol.Authenticate(eArgs.username, eArgs.password))
{
+ var username = eArgs.username;
+ repository = new Repository(username);
+ FilterDataSource();
+
progressBar1.Style = ProgressBarStyle.Marquee;
var getAllMembers = new GetAllMembersDelegate(GetAllMembers);
getAllMembers.BeginInvoke(sol, null, null);
@@ -56,9 +68,8 @@ private void GetAllMembers(ScoutsOnLine sol)
private void AddMembers(List<Member> newMembers, int step, int count)
{
- var allMembers = new HashSet<Member>(this.members);
- allMembers.UnionWith(newMembers);
- this.members = allMembers.OrderBy(m => m.Lidachternaam).ThenBy(m => m.Lidvoornaam).ToList();
+ repository.Model.MemberList.UpdateWith(newMembers);
+ repository.Store();
if (dataGridView1.InvokeRequired)
{
@@ -103,7 +114,7 @@ private void SearchBox_TextChanged(object sender, EventArgs e)
var searchtext = SearchBox.Text;
if (searchtext == string.Empty)
{
- dataGridView1.DataSource = this.members;
+ dataGridView1.DataSource = this.repository.Model.MemberList.Members;
}
else
{
@@ -114,12 +125,45 @@ private void SearchBox_TextChanged(object sender, EventArgs e)
}
else
{
- source = this.members;
+ source = this.repository.Model.MemberList.Members;
}
var keywords = searchtext.Split(new [] {' '}, StringSplitOptions.RemoveEmptyEntries);
dataGridView1.DataSource = source.Where(m => m.Matches(keywords)).ToList();
_previousSearchValue = searchtext;
}
}
+
+ private void MarkeerLid_Click(object sender, EventArgs e)
+ {
+ List<int> rowIndices = new List<int>();
+ foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
+ {
+ var row = cell.RowIndex;
+ if (!rowIndices.Contains(row))
+ rowIndices.Add(row);
+ }
+
+ var members = (List<Member>)dataGridView1.DataSource;
+ foreach (var index in rowIndices)
+ {
+ var member = members[index];
+ repository.Model.MemberList.ToggleSelect(member);
+ }
+ dataGridView1.Refresh();
+ }
+
+ private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
+ {
+ var members = (List<Member>)dataGridView1.DataSource;
+ var member = members[e.RowIndex];
+ if (member.Selected)
+ {
+ e.CellStyle.BackColor = Color.LightYellow;
+ }
+ else
+ {
+ e.CellStyle.BackColor = Color.White;
+ }
+ }
}
}
View
@@ -112,9 +112,31 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
- <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
- <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
+ <metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+ <value>17, 17</value>
+ </metadata>
+ <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ <data name="MarkeerLid.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>
+ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
+ YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAsRJREFUOE+Vk2tI
+ k1EYx1/RLC9Npttw6XQyp31ZhmZgEoFmJURF6gj9oI1SohpBiS0cpltJhCtmkzSdc2pLzUsmQ0TXxVx5
+ i3mrRqjvpsKmKEyn2zu3Pe0VDMJJeODA4Ty//+9wzsPxQHYZzRmIZ0Qs6zxenv0+0cVuQRy7sW73lbyj
+ ZH3X3Tp95+06JS+SvKcwDo9Lc1JWf7bNrE5IZ8bLk1L2JGhKD/VBex6XYsZvGIa+w9CWzNKmdMTnfxKP
+ ZgTxrIxD9vWXnolZ1iiGnSuj4Jxrg+XevOH+QnIMXsPfxiXy+CsbfJKQrGu7w9YrhZw51VPuwocynuHT
+ M4VV32eGRRXATDVYB66bDTURioUyAm9OeJCrLwzk6HhE9iDXLxlpLzopQj8+11oMo2bb8o8N25IGsxu/
+ OsDYB4DWA0zyAb5cBHsHw2GrJWO2F5QNi4hmRh9Ste0cggjJOnEoulGYwUfV1bObi0MAK8MAhh5XWAYw
+ 8QDg8zmA9+EACgJATRBsSsIAFdJnG6+S+FnHvKO3rhIWgBBFN+OzNa356vVfVRj8FgOM5AL0HgfoCAJ4
+ vR9AFgDrlXRMI2CqRVeCs/HMP49KRRDf4syoVG0Le8QxkAagZAK0uk7dCvuBQ8YArTh+pDgtJJVKRXzd
+ dkSaQ6TN1zJVjnYKwBtXsMEHoNYlqSSBoyoK5isSVNIbDNqu7VTzyYmm6sBpkPsByIlgbYh2WmUsJ0jo
+ AOIIMEmOTKv5UYluBRmu/k4KgvIsLylr9ldUMFYwl1QlMZ2qothOo5i1ZC+PBIuYsTYpoOfh7A5JfRZC
+ 0AkoEpMo1DolCBuT5oYUXI7zP4xP6TVawVQJfcwkCrfqHoVIcHaH4C3nQPhQfmBj9y2S/P7ZgNOu3+O/
+ DeFrfK+bS5LjDM7uENw7hQTzkrwvXWBt9dbLzT298BrO4Ox2/Q/5zGXSMq+6YQAAAABJRU5ErkJggg==
+</value>
+ </data>
</root>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using ScoutsOffline.Sol;
+using System.Collections;
+
+namespace ScoutsOffline.Model
+{
+ public class MemberList
+ {
+ public List<Member> Members { get; set; }
+
+ public MemberList()
+ {
+ this.Members = new List<Member>();
+ }
+
+ public void UpdateWith(List<Member> newMembers)
+ {
+ // TODO oude leden moeten ook verwijderd worden
+ var allMembers = new HashSet<Member>(this.Members);
+ allMembers.UnionWith(newMembers);
+ this.Members = allMembers.OrderBy(m => m.Lidachternaam).ThenBy(m => m.Lidvoornaam).ToList();
+ }
+
+ internal void ToggleSelect(Member member)
+ {
+ member.Selected = !member.Selected;
+ }
+ }
+}
@@ -0,0 +1,80 @@
+using System;
+using System.Collections.Generic;
+using System.Xml.Serialization;
+using System.IO;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Xml;
+using System.Reflection;
+
+
+namespace ScoutsOffline.Model
+{
+ public class Repository
+ {
+ private string BaseDirectory;
+ private DataContractSerializer serializer;
+ private string file;
+
+ private StoredModel _model;
+ public StoredModel Model
+ {
+ get
+ {
+ if (_model == null)
+ {
+ _model = Get();
+ }
+ return _model;
+ }
+ }
+
+ public Repository(string username)
+ {
+ this.BaseDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+ this.serializer = new DataContractSerializer(typeof(StoredModel));
+ this.file = Path.Combine(BaseDirectory, username + ".xml");
+ }
+
+ public StoredModel Get()
+ {
+ if (!File.Exists(file))
+ {
+ return new StoredModel();
+ }
+ using (var stream = File.OpenRead(file))
+ {
+ return (StoredModel)serializer.ReadObject(stream);
+ }
+ }
+
+ public void Store()
+ {
+ Store(Model);
+ }
+
+ public void Store(StoredModel model)
+ {
+ if (File.Exists(file))
+ {
+ var tmpFile = file + "~";
+ StoreToFile(model, tmpFile);
+ File.Replace(tmpFile, file, file + ".bkp");
+ }
+ else
+ {
+ StoreToFile(model, file);
+ }
+ }
+
+ private void StoreToFile(StoredModel model, string filename)
+ {
+ XmlWriterSettings settings = new XmlWriterSettings();
+ settings.Indent = true;
+ using (var xmlWriter = XmlWriter.Create(filename, settings))
+ {
+ serializer.WriteObject(xmlWriter, model);
+ }
+ }
+ }
+}
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ScoutsOffline.Model
+{
+ public class StoredModel
+ {
+ public StoredModel()
+ {
+ this.MemberList = new MemberList();
+ }
+
+ public MemberList MemberList { get; set; }
+ }
+}
Oops, something went wrong.

0 comments on commit d8def45

Please sign in to comment.