This repository was archived by the owner on Jul 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.cs
More file actions
166 lines (147 loc) · 6.65 KB
/
MainForm.cs
File metadata and controls
166 lines (147 loc) · 6.65 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
using System.Globalization;
namespace SteamCurrency
{
public partial class MainForm : Form
{
float RUB_USD_Steam; // Покупка рублей за доллары (Steam)
float KZT_USD_Steam; // Покупка тенге за доллары (Steam)
float RUB_USD_Web; // Рублей за доллар (Webmoney)
float RUB_USD_Web_Real; // Рублей за доллар (Webmoney PtP)
readonly float WebPercent = 0.1593f;
public MainForm()
{
InitializeComponent();
RUB_USD_Steam = Properties.Settings.Default.RUB_USD_Steam;
KZT_USD_Steam = Properties.Settings.Default.KZT_USD_Steam;
RUB_USD_Web = Properties.Settings.Default.RUB_USD_Web;
RUB_USD_Web_Real = Properties.Settings.Default.RUB_USD_Web_Real;
if (RUB_USD_Steam > 0 && KZT_USD_Steam > 0 && RUB_USD_Web > 0)
{
if (RUB_USD_Web_Real > 0)
textBoxUsdWeb.Text = RUB_USD_Web_Real.ToString(CultureInfo.InvariantCulture);
else
textBoxUsdWeb.Text = RUB_USD_Web.ToString(CultureInfo.InvariantCulture);
pictureBoxWeb.Image = Properties.Resources.warn_c;
pictureBoxSteam.Image = Properties.Resources.warn_c;
labelCurrencyWeb.Text = "Курс USD = " + Math.Round(RUB_USD_Web, 2);
labelCurrencySteam.Text= "Курс USD = " + Math.Round(RUB_USD_Steam, 2);
labelCurrencySteamKzt.Text = "Курс KZT = " + Math.Round(KZT_USD_Steam, 2);
ButtonGetRates.Text = "Обновить";
textBoxInputWeb.Enabled = true;
textBoxUsdWeb.Enabled = true;
}
ButtonGetRates.Focus();
}
private void ButtonGet_Click(object sender, EventArgs e)
{
ButtonGetRates.Text = "Обновление";
textBoxInputWeb.Enabled = true;
textBoxUsdWeb.Enabled = true;
int ok = 0;
// Steam
pictureBoxSteam.Image = Properties.Resources.wait_c;
// Покупка рублей за доллары (Steam)
float steam1 = SteamJson.GetRate(1, 5);
// Покупка тенге за доллары (Steam)
float steam2 = SteamJson.GetRate(1, 37);
if (steam1 == 0 || steam2 == 0)
{
pictureBoxSteam.Image = Properties.Resources.no_c;
}
else
{
ok++;
RUB_USD_Steam = steam1;
KZT_USD_Steam = steam2;
Properties.Settings.Default["RUB_USD_Steam"] = RUB_USD_Steam;
Properties.Settings.Default["KZT_USD_Steam"] = KZT_USD_Steam;
labelCurrencySteam.Text = "Курс USD = " + Math.Round(RUB_USD_Steam, 2);
labelCurrencySteamKzt.Text = "Курс KZT = " + Math.Round(KZT_USD_Steam, 2);
pictureBoxSteam.Image = Properties.Resources.yes_c;
}
// Webmoney
pictureBoxWeb.Image = Properties.Resources.wait_c;
// Рублей за доллар по курсу вебмани
WMJson webmoney = WMJson.GetData();
float usdWeb = webmoney.GetRate();
if (usdWeb == 0 || usdWeb == -1)
{
pictureBoxWeb.Image = Properties.Resources.no_c;
}
else
{
ok++;
RUB_USD_Web = usdWeb;
Properties.Settings.Default["RUB_USD_Web"] = RUB_USD_Web;
labelCurrencyWeb.Text = "Курс USD = " + Math.Round(RUB_USD_Web, 2);
pictureBoxWeb.Image = Properties.Resources.yes_c;
}
if (ok == 2)
{
Properties.Settings.Default.Save();
ButtonGetRates.Enabled = true;
ButtonGetRates.Text = "Обновить";
textBoxInputWeb.Enabled = true;
textBoxUsdWeb.Enabled = true;
}
ButtonGetRates.Text = "Обновить";
}
private void TextBoxInputWeb_TextChanged(object sender, EventArgs e)
{
// Подготовка входных данных
string text = textBoxInputWeb.Text;
if (text.Length < 2)
return;
try
{
Convert.ToSingle(text, CultureInfo.InvariantCulture);
}
catch
{
textBoxConvertWebUsd.Text = "0";
textBoxOutputWebRU.Text = "0";
textBoxOutputWebKZ.Text = "0";
textBoxLostWebRU.Text = "0";
return;
}
text = text.Replace(',', '.');
float input = Convert.ToSingle(text, CultureInfo.InvariantCulture);
float outputUsd;
// Рубли в доллары
outputUsd = (input / RUB_USD_Web_Real) - (input / RUB_USD_Web_Real * WebPercent);
textBoxConvertWebUsd.Text = Math.Round(outputUsd, 2).ToString(CultureInfo.InvariantCulture);
// В итоге отправляется сумма в долларах
float output, percent;
// KZ аккаунт доллары в тенге
output = outputUsd * KZT_USD_Steam;
textBoxOutputWebKZ.Text = Math.Round(output, 2).ToString(CultureInfo.InvariantCulture);
// RU аккаунт доллары в рубли
output = outputUsd * RUB_USD_Steam;
textBoxOutputWebRU.Text = Math.Round(output, 2).ToString(CultureInfo.InvariantCulture);
textBoxLostWebRU.Text = Math.Round(input - output, 2).ToString(CultureInfo.InvariantCulture);
percent = (input / output - 1) * 100;
labelLostWebRU.Text = "₽ (" + Math.Round(percent, 2).ToString(CultureInfo.InvariantCulture) + "%)";
}
private void TextBoxUsdWeb_TextChanged(object sender, EventArgs e)
{
string text = textBoxUsdWeb.Text;
if (text.Length < 2)
return;
try
{
Convert.ToSingle(text, CultureInfo.InvariantCulture);
}
catch
{
return;
}
text = text.Replace(',', '.');
RUB_USD_Web_Real = Convert.ToSingle(text, CultureInfo.InvariantCulture);
Properties.Settings.Default["RUB_USD_Web_Real"] = RUB_USD_Web_Real;
Properties.Settings.Default.Save();
string temp = textBoxInputWeb.Text;
textBoxInputWeb.Text = string.Empty;
textBoxInputWeb.Text = temp;
}
}
}