-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrmInsumoReservatorio.cs
179 lines (140 loc) · 6.08 KB
/
FrmInsumoReservatorio.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WaterSaving
{
public partial class FrmInsumoReservatorio : Form
{
public EOperacao operacao;
public int codigoInsumo = 0;
BindingSource bsource = new BindingSource();
DataSet dsDados = new DataSet();
public FrmInsumoReservatorio()
{
InitializeComponent();
}
private void FrmInsumoReservatorio_Load(object sender, EventArgs e)
{
HabilitarDesabilitar(false);
CarregarInsumosReservatorio();
}
private void btnNovo_Click(object sender, EventArgs e)
{
LimparCampos.Limpar(this);
operacao = EOperacao.Incluir;
HabilitarDesabilitar(true);
}
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 o Insumo?", "Exclusão", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
InsumoReservatorioDOM insumosReservatorioDOM = new InsumoReservatorioDOM();
insumosReservatorioDOM.CodInsumo = codigoInsumo;
insumosReservatorioDOM.Descricao = txtDescricao.Text;
insumosReservatorioDOM.Quantidade = Conversor.ConverterParaDecimal(txtQuantidade.Text);
insumosReservatorioDOM.PrecoUnitario = Conversor.ConverterParaDecimal(txtPrecoUnitario.Text);
insumosReservatorioDOM.Unico = Conversor.ConverterParaBoolean(cbxUnica.Checked);
InsumoReservatorioCTL insumosReservatorioCTL = new InsumoReservatorioCTL();
insumosReservatorioCTL.ManterInsumoReservatorio(operacao, insumosReservatorioDOM);
}
CarregarInsumosReservatorio();
operacao = EOperacao.Inicial;
}
private void btnSalvar_Click(object sender, EventArgs e)
{
try
{
InsumoReservatorioDOM insumoReservatorioDOM = new InsumoReservatorioDOM();
insumoReservatorioDOM.CodInsumo = codigoInsumo;
insumoReservatorioDOM.Descricao = txtDescricao.Text;
insumoReservatorioDOM.Quantidade = Conversor.ConverterParaDecimal(txtQuantidade.Text);
insumoReservatorioDOM.PrecoUnitario = Conversor.ConverterParaDecimal(txtPrecoUnitario.Text);
insumoReservatorioDOM.Unico = Conversor.ConverterParaBoolean(cbxUnica.Checked);
InsumoReservatorioCTL insumoReservatorioCTL = new InsumoReservatorioCTL();
insumoReservatorioCTL.ManterInsumoReservatorio(operacao, insumoReservatorioDOM);
CarregarInsumosReservatorio();
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;
CarregarInsumosReservatorio();
HabilitarDesabilitar(false);
}
private void btnSair_Click(object sender, EventArgs e)
{
Close();
}
public void HabilitarDesabilitar(bool status)
{
btnNovo.Enabled = !status;
btnAlterar.Enabled = !status;
btnExcluir.Enabled = !status;
btnSalvar.Enabled = status;
btnCancelar.Enabled = status;
btnSair.Enabled = !status;
txtDescricao.Enabled = status;
txtQuantidade.Enabled = status;
txtPrecoUnitario.Enabled = status;
cbxUnica.Enabled = status;
dgvInsumos.Enabled = !status;
if (status)
{
txtDescricao.Focus();
}
}
public void CarregarInsumosReservatorio()
{
LimparCampos.Limpar(this); // novo
FormatarGridView.Formatar(dgvInsumos);
InsumoReservatorioCTL insumoReservatorioCTL = new InsumoReservatorioCTL();
dsDados = insumoReservatorioCTL.ConsultarInsumoReservatorio();
bsource.DataSource = dsDados.Tables["InsumoReservatorio"];
dgvInsumos.DataSource = bsource;
}
public void PosicionarRegistro()
{
if (dgvInsumos.Rows.Count > 0)
{
if (dgvInsumos.CurrentRow.Cells[0].Value != null)
codigoInsumo = Convert.ToInt32(dgvInsumos.CurrentRow.Cells[0].Value.ToString());
txtDescricao.DataBindings.Clear();
txtDescricao.DataBindings.Add("Text", bsource, "Descricao");
txtQuantidade.DataBindings.Clear();
txtQuantidade.DataBindings.Add("Text", bsource, "Quantidade");
txtPrecoUnitario.DataBindings.Clear();
txtPrecoUnitario.DataBindings.Add("Text", bsource, "PrecoUnitario");
cbxUnica.DataBindings.Clear();
cbxUnica.DataBindings.Add("Checked", bsource, "Unico");
bsource.Position = dgvInsumos.CurrentRow.Index;
this.BindingContext[dsDados.Tables["InsumoReservatorio"]].Position = dgvInsumos.CurrentRow.Index;
}
else
LimparCampos.Limpar(this);
}
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
PosicionarRegistro();
}
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
PosicionarRegistro();
}
}
}