-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmScrape.cs
150 lines (131 loc) · 4.31 KB
/
frmScrape.cs
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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 BoardGameChooser
{
public partial class frmScrape : Form
{
List<BoardGame> games;
public frmScrape()
{
InitializeComponent();
games = new List<BoardGame>();
this.Enabled = true;
}
private void btnOK_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
private void btnScrape_Click(object sender, EventArgs e)
{
this.Enabled = false;
bgwScrape.RunWorkerAsync();
//List<BoardGame> scrape = BGGInterface.GetBoardGames(txtUser.Text);
}
private BoardGame selectedGame
{
get
{
return games.Find(x => x.Name.Equals(dataGames.SelectedRows[0].Cells[0].Value.ToString()));
}
}
private void dataGames_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
frmBoardGame dialog = new BoardGameChooser.frmBoardGame();
BoardGame temp = selectedGame;
dialog.Value = temp;
games.Remove(temp);
if (dialog.ShowDialog() == DialogResult.OK)
{
games.Add(dialog.Value);
RefreshGames();
}
else
{
games.Add(temp);
}
}
private void dataGames_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
if (MessageBox.Show("Do you really want to delete the game?", "Are you sure?", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
games.Remove(selectedGame);
RefreshGames();
}
}
}
private void RefreshGames()
{
int temp = dataGames.FirstDisplayedScrollingRowIndex;
int selected;
try
{
selected = dataGames.SelectedRows[0].Index;
}
catch
{
selected = 0;
}
games.Sort();
dataGames.DataSource = new SortableBinding.SortableBindingList<Object>(games.Select(x => x.AsRow).ToList());
try
{
dataGames.FirstDisplayedScrollingRowIndex = temp;
dataGames.Rows[selected].Selected = true;
}
catch
{
}
}
public List<BoardGame> Value { get { return this.games; } }
private bool Enabled
{
set
{
txtUser.Enabled = value;
btnOK.Enabled = value;
btnCancel.Enabled = value;
btnScrape.Enabled = value;
groupBox2.Enabled = value;
}
}
private void bgwScrape_DoWork(object sender, DoWorkEventArgs e)
{
try
{
List<BoardGame> scrape = BGGInterface.GetBoardGames(txtUser.Text);
games = new List<BoardGame>();
foreach (BoardGame game in scrape)
{
string existing = Form1.settings.BoardGames.Where(old => old.Name.Similar(game.Name, 0)).Select(x => x.Name).Aggregate("", (x, y) => x + "," + y);
if (true || existing.Length == 0)
//|| MessageBox.Show("Are " + game.Name + " and any of " + existing + " the same game?", game.ToString() + " may already exist.", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
games.Add(game);
}
}
}
catch(Exception exc)
{
MessageBox.Show(exc.ToString());
}
}
private void bgwScrape_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
private void bgwScrape_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
RefreshGames();
this.Enabled = true;
}
}
}