-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrmContas.cs
224 lines (171 loc) · 6.67 KB
/
FrmContas.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WaterSaving
{
public partial class FrmContas : Form
{
public EOperacao operacao;
public int codigoConta = 0;
BindingSource bsource = new BindingSource();
DataSet dsDados = new DataSet();
public FrmContas()
{
InitializeComponent();
}
private void FrmContas_Load(object sender, EventArgs e)
{
CarregarMes();
mtxtAno.Text = DateTime.Now.Year.ToString();
HabilitarDesabilitar(false);
CarregarContas();
}
private void mtxtConsumo_TextChanged(object sender, EventArgs e)
{
txtLitros.Text = Convert.ToString(Conversor.ConverterParaInteiro(mtxtConsumo.Text) * 100);
}
public void CarregarMes()
{
cbxMes.DisplayMember = "Descricao";
cbxMes.ValueMember = "Mes";
cbxMes.DataSource = Meses.CarregaMeses().Tables[0];
}
private void btnSair_Click(object sender, EventArgs e)
{
Close();
}
private void btnNovo_Click(object sender, EventArgs e)
{
LimparCampos.Limpar(this);
operacao = EOperacao.Incluir;
codigoConta = 0;
HabilitarDesabilitar(true);
cbxMes.SelectedValue = DateTime.Now.Month.ToString();
mtxtAno.Text = DateTime.Now.Year.ToString();
}
public void HabilitarDesabilitar(bool status)
{
btnNovo.Enabled = !status;
btnAlterar.Enabled = !status;
btnExcluir.Enabled = !status;
btnSalvar.Enabled = status;
btnCancelar.Enabled = status;
btnSair.Enabled = !status;
cbxMes.Enabled = status;
mtxtAno.Enabled = status;
mtxtConsumo.Enabled = status;
txtValor.Enabled = status;
dgvContas.Enabled = !status;
if (status)
{
cbxMes.Focus();
}
}
private void btnAlterar_Click(object sender, EventArgs e)
{
operacao = EOperacao.Alterar;
HabilitarDesabilitar(true);
}
private void btnExcluir_Click(object sender, EventArgs e)
{
operacao = EOperacao.Excluir;
if (MessageBox.Show("Deseja Excluir a Conta?", "Exclusão", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
ContasDOM novaConta = new ContasDOM();
novaConta.CodConta = codigoConta;
ContasCTL contasCTL = new ContasCTL();
contasCTL.ManterContas(operacao, novaConta);
}
CarregarContas();
operacao = EOperacao.Inicial;
}
public void CarregarContas()
{
FormatarGridView.Formatar(dgvContas);
ContasCTL contasCTL = new ContasCTL();
dsDados = contasCTL.ConsultarContas();
bsource.DataSource = dsDados.Tables["contas"];
dgvContas.DataSource = bsource;
}
private void btnSalvar_Click(object sender, EventArgs e)
{
try
{
ContasDOM contasDOM = new ContasDOM();
contasDOM.CodProjeto = DadosProjetoDOM.CodProjeto;
contasDOM.CodConta = codigoConta;
contasDOM.Mes = cbxMes.SelectedValue == null ? DateTime.Now.Month : Conversor.ConverterParaInteiro(cbxMes.SelectedValue);
contasDOM.Ano = Conversor.ConverterParaInteiro(mtxtAno.Text);
contasDOM.Consumo = Conversor.ConverterParaDouble(mtxtConsumo.Text);
contasDOM.Valor = Conversor.ConverterParaDouble(txtValor.Text);
ContasCTL contasCTL = new ContasCTL();
contasCTL.ManterContas(operacao, contasDOM);
CarregarContas();
HabilitarDesabilitar(false);
}
catch (Exception ex)
{
MessageBox.Show("Erro ao salvar os dados." + ex.Message.ToString());
}
}
private void btnCancelar_Click(object sender, EventArgs e)
{
operacao = EOperacao.Inicial;
CarregarContas();
HabilitarDesabilitar(false);
}
public void PosicionarRegistro()
{
if (dgvContas.Rows.Count > 0)
{
if (dgvContas.CurrentRow.Cells[0].Value != null)
codigoConta = Convert.ToInt32(dgvContas.CurrentRow.Cells[0].Value.ToString());
cbxMes.DataBindings.Clear();
cbxMes.DataBindings.Add("SelectedValue", bsource, "Mes");
mtxtAno.DataBindings.Clear();
mtxtAno.DataBindings.Add("Text", bsource, "Ano");
mtxtConsumo.DataBindings.Clear();
mtxtConsumo.DataBindings.Add("Text", bsource, "Consumo");
txtValor.DataBindings.Clear();
txtValor.DataBindings.Add("Text", bsource, "Valor");
bsource.Position = dgvContas.CurrentRow.Index;
this.BindingContext[dsDados.Tables["contas"]].Position = dgvContas.CurrentRow.Index;
txtLitros.Text = Convert.ToString(Conversor.ConverterParaDouble(mtxtConsumo.Text) * 1000);
}
else
LimparCampos.Limpar(this);
}
private void dgvContas_KeyDown(object sender, KeyEventArgs e)
{
PosicionarRegistro();
}
private void dgvContas_MouseDown(object sender, MouseEventArgs e)
{
PosicionarRegistro();
}
private void dgvContas_SelectionChanged(object sender, EventArgs e)
{
PosicionarRegistro();
}
private void mtxtConsumo_Leave(object sender, EventArgs e)
{
txtLitros.Text = Convert.ToString(Conversor.ConverterParaDouble(mtxtConsumo.Text) * 1000);
}
private void button1_Click(object sender, EventArgs e)
{
ContasCTL contasCTL = new ContasCTL();
contasCTL.Dados("R");
CarregarContas();
}
private void button2_Click(object sender, EventArgs e)
{
ContasCTL contasCTL = new ContasCTL();
contasCTL.Dados("U");
CarregarContas();
}
}
}