-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
76 lines (68 loc) · 2.08 KB
/
Form1.cs
File metadata and controls
76 lines (68 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace kolokvezba
{
public partial class Form1 : Form
{
private Dictionary<string, int> authors = new Dictionary<string, int>();
public Form1()
{
InitializeComponent();
}
private void Addpaperbtn_Click(object sender, EventArgs e)
{
Addpaper form = new Addpaper();
if(form.ShowDialog() == DialogResult.OK)
{
Allpaperslb.Items.Add(form.NewPaper);
RefreshLb(form.NewPaper, true);
}
}
private void RefreshLb(Paper paper,bool increment)
{
List<String> list = new List<String>(paper.authors);
//adding or deleting
foreach (var item in list)
{
if (authors.ContainsKey(item) && increment)
{
authors[item]++;
}
else if (!authors.ContainsKey(item) && increment)
{
authors.Add(item, 1);
}
else if (authors.ContainsKey(item) && !increment)
{
if (authors[item] > 1)
{
authors[item]--;
}
else authors.Remove(item);
}
}
//update box
Authorstb.Items.Clear();
foreach (var item in authors)
{
string toAdd = item.Key + " - " + item.Value;
Authorstb.Items.Add(toAdd);
}
}
private void Deletepaperbtn_Click(object sender, EventArgs e)
{
if(Allpaperslb.SelectedItems.Count > 0)
{
RefreshLb((Paper)Allpaperslb.SelectedItem, false);
Allpaperslb.Items.Remove(Allpaperslb.SelectedItem);
}
}
}
}