-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
195 lines (169 loc) · 6.05 KB
/
Form1.cs
File metadata and controls
195 lines (169 loc) · 6.05 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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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;
using HorseRacingAutoPurchaser.Models;
using HorseRacingAutoPurchaser.Domain;
using HorseRacingAutoPurchaser.Infrastructures;
namespace HorseRacingAutoPurchaser
{
public partial class Form1 : Form
{
private AutoPurchaserMainTask AutoPurchaserMainTask;
private SimulatorMainTask SimulatorMainTask;
public Form1()
{
InitializeComponent();
AutoPurchaserMainTask = new AutoPurchaserMainTask();
SimulatorMainTask = new SimulatorMainTask();
var betConfigRepository = new BetConfigRepository();
var betConfig = betConfigRepository.ReadAll();
if (betConfig == null)
{
betConfig = new BetConfig();
betConfigRepository.Store(betConfig);
}
SetBetConfig(betConfig);
}
/// <summary>
/// 大金を賭ける可能性があれば警告を表示する。
/// 警告を表示する必要がないか、ユーザーが承認した場合true。
/// </summary>
/// <returns></returns>
private bool AlertIfNeed()
{
if (oddsConfigForTicketTypeUserControl_Quinella.NeedAlert() ||
oddsConfigForTicketTypeUserControl_Wide.NeedAlert())
{
var result = MessageBox.Show("ベット額が大きくなる可能性があります。構いませんか?",
"警告",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Exclamation);
if (result == DialogResult.Yes)
{
return true;
}
else
{
return false;
}
}
return true;
}
private void Button_LoginConfig_Click(object sender, EventArgs e)
{
var loginConfigForm = new LoginConfigForm();
loginConfigForm.Show();
}
private void Button_AutoPurchase_Click(object sender, EventArgs e)
{
if (!SimulatorMainTask.Running && !AutoPurchaserMainTask.Running)
{
var isIntendedSetting = AlertIfNeed();
if (isIntendedSetting)
{
StoreCurrentConfig();
AutoPurchaserMainTask.Run();
label_Running.Visible = true;
}
}
}
private void Button_AutoPurchase_Cancel_Click(object sender, EventArgs e)
{
if (AutoPurchaserMainTask.Running)
{
AutoPurchaserMainTask.Stop();
label_Running.Visible = false;
}
}
private void Button_SavePurchaseSetting_Click(object sender, EventArgs e)
{
var isIntendedSetting = AlertIfNeed();
if (isIntendedSetting)
{
StoreCurrentConfig();
}
}
private void StoreCurrentConfig()
{
var betConfig = new BetConfig
{
QuinellaBetConfig = oddsConfigForTicketTypeUserControl_Quinella.GetCurrentConfig(),
WideBetConfig = oddsConfigForTicketTypeUserControl_Wide.GetCurrentConfig()
};
new BetConfigRepository().Store(betConfig);
}
private void Button_ResetPurchaseSetting_Click(object sender, EventArgs e)
{
SetBetConfig(new BetConfig());
}
private void SetBetConfig(BetConfig betConfig)
{
oddsConfigForTicketTypeUserControl_Quinella.SetBetConfigForTicketType(betConfig.QuinellaBetConfig);
oddsConfigForTicketTypeUserControl_Wide.SetBetConfigForTicketType(betConfig.WideBetConfig);
}
private void Button_ExecSimulation_Click(object sender, EventArgs e)
{
if (!SimulatorMainTask.Running && !AutoPurchaserMainTask.Running)
{
StoreCurrentConfig();
var from = dateTimePicker_SimulateFrom.Value;
var to = dateTimePicker_SimulateTo.Value;
var useOnlySavedData = checkBox_SimulateBySavedData.Checked;
SimulatorMainTask.Run(from, to, useOnlySavedData);
label_RunningSimulation.Visible = true;
}
}
private void Button_StopSimulation_Click(object sender, EventArgs e)
{
if (SimulatorMainTask.Running)
{
SimulatorMainTask.Stop();
label_RunningSimulation.Visible = false;
}
}
private void Label1_Click(object sender, EventArgs e)
{
}
private void Timer1_Tick(object sender, EventArgs e)
{
if (SimulatorMainTask.Running)
{
label_RunningSimulation.Visible = true;
}
else
{
label_RunningSimulation.Visible = false;
}
if (AutoPurchaserMainTask.Running)
{
label_Running.Visible = true;
}
else
{
label_Running.Visible = false;
}
if (SimulatorMainTask.Running || AutoPurchaserMainTask.Running)
{
button_LoginConfig.Enabled = false;
button_SavePurchaseSetting.Enabled = false;
button_ResetPurchaseSetting.Enabled = false;
button_AutoPurchase.Enabled = false;
button_ExecSimulation.Enabled = false;
}
else
{
button_LoginConfig.Enabled = true;
button_SavePurchaseSetting.Enabled = true;
button_ResetPurchaseSetting.Enabled = true;
button_AutoPurchase.Enabled = true;
button_ExecSimulation.Enabled = true;
}
}
}
}