-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cs
More file actions
81 lines (67 loc) · 2.39 KB
/
Main.cs
File metadata and controls
81 lines (67 loc) · 2.39 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
namespace SisCon
{
public partial class MainWindow : Form
{
public MainWindow()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBoxConsumo_TextChanged(object sender, EventArgs e)
{
UpdateValorEnergia();
}
private void textBoxValorConta_TextChanged(object sender, EventArgs e)
{
UpdateValorEnergia();
}
private void UpdateValorEnergia()
{
if (decimal.TryParse(textBoxValorConta.Text, out decimal valorConta) &&
decimal.TryParse(textBoxConsumo.Text, out decimal valorConsumo) &&
valorConsumo != 0)
{
decimal resultado = valorConta / valorConsumo;
textBoxValorEnergia.Text = resultado.ToString("C");
}
else
{
textBoxValorEnergia.Text = string.Empty;
}
UpdateCustoTotal();
}
private void textBoxMargemRiscoGTD_TextChanged(object sender, EventArgs e)
{
UpdateCustoTotal();
}
private void UpdateCustoTotal()
{
// Remove o símbolo de porcentagem, espaços e outros caracteres não numéricos do campo de margem
string margemTexto = textBoxMargemRiscoGTD.Text.Replace("%", "").Trim();
// Tenta obter o valor da energia (removendo símbolo de moeda)
if (decimal.TryParse(textBoxValorEnergia.Text, System.Globalization.NumberStyles.Currency,
System.Globalization.CultureInfo.CurrentCulture, out decimal valorEnergia) &&
decimal.TryParse(margemTexto, out decimal margem))
{
// margem deve ser digitada como "10" para 10%
decimal custoTotal = valorEnergia + (valorEnergia * (margem / 100m));
textBoxCustoTotal.Text = custoTotal.ToString("C");
}
else
{
textBoxCustoTotal.Text = string.Empty;
}
}
private void textBoxCustoTotal_TextChanged(object sender, EventArgs e)
{
}
}
}