-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
171 lines (138 loc) · 4.79 KB
/
Form1.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using MaterialSkin;
using MaterialSkin.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CynosureScraper
{
public delegate void ItemAdded();
public partial class Form1 : MaterialForm
{
int mItemCount;
private readonly SynchronizationContext synchronizationContext;
public Form1()
{
InitializeComponent();
synchronizationContext = SynchronizationContext.Current;
MaterialSkinManager materialSkinManager = MaterialSkinManager.Instance;
materialSkinManager.AddFormToManage(this);
materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT;
// Configure color schema
materialSkinManager.ColorScheme = new ColorScheme(
Primary.Blue400, Primary.Blue500,
Primary.Blue500, Accent.LightBlue200,
TextShade.WHITE
);
}
private void btnAllCheck_Click(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
{
if (c is CheckBox)
{
CheckBox cb = (CheckBox)c;
cb.Checked = true;
}
}
}
private void btnAllUncheck_Click(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
{
if (c is CheckBox)
{
CheckBox cb = (CheckBox)c;
cb.Checked = false;
}
}
}
private void btnSelFile_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "CSV Format|*.csv";
if (DialogResult.OK != sfd.ShowDialog())
return;
leOutputFile.Text = sfd.FileName;
}
[Obsolete]
private async void btnStart_Click(object sender, EventArgs e)
{
List<int> treatmentIds = new List<int>();
string filePath = leOutputFile.Text;
string inputFilePath = leInputFile.Text;
if ("" == inputFilePath)
{
MessageBox.Show("Select zipcode file.");
return;
}
if ("" == filePath)
{
MessageBox.Show("Select file to save.");
return;
}
foreach (Control c in this.Controls)
{
if (c is CheckBox)
{
CheckBox cb = (CheckBox)c;
if (!cb.Checked)
continue;
treatmentIds.Add(int.Parse(cb.Name.Split('_')[1]));
}
}
if (treatmentIds.Count == 0)
{
MessageBox.Show("Select at least one treatment.");
return;
}
btnStart.Enabled = false;
btnStart.Text = "Processing";
string country = rbCountryUSA.Checked ? "US" : "CA";
ServicePointManager.Expect100Continue = true;
ServicePointManager.DefaultConnectionLimit = 9999;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12;
await Task.Run(() =>
{
mItemCount = 0;
Engine engine = new Engine();
string[] zipCodes = File.ReadAllLines(inputFilePath);
for (int i = 0; i < zipCodes.Length; ++ i)
{
string zipcode = zipCodes[i].Trim();
synchronizationContext.Post(new SendOrPostCallback(o =>
{
leProcess.Text = "Zip Code: " + zipcode;
}), null);
engine.Process(zipcode, country, 300, treatmentIds.ToArray(), filePath, onNewItemAdded);
}
});
btnStart.Enabled = true;
btnStart.Text = "Start";
MessageBox.Show( mItemCount + " Results Found");
}
private void onNewItemAdded()
{
synchronizationContext.Post(new SendOrPostCallback(o =>
{
btnStart.Text = o + " Results Found";
}), ++mItemCount);
}
private void btnSelInputFile_Click(object sender, EventArgs e)
{
OpenFileDialog sfd = new OpenFileDialog();
sfd.Filter = "Text Format|*.txt";
if (DialogResult.OK != sfd.ShowDialog())
return;
leInputFile.Text = sfd.FileName;
}
}
}