-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmCadastroCategoria.cs
132 lines (112 loc) · 3.71 KB
/
frmCadastroCategoria.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Modelo;
using DAL;
using BLL;
namespace GUI
{
public partial class frmCadastroCategoria : GUI.frmModeloFormularioCadastro
{
public frmCadastroCategoria()
{
InitializeComponent();
}
public void LimpaTela()
{
txtCodigo.Clear();
txtNome.Clear();
}
private void btInserir_Click(object sender, EventArgs e)
{
this.operacao = "inserir";
this.alteraBotoes(2);
}
private void btCancelar_Click(object sender, EventArgs e)
{
this.LimpaTela(); //limpar tela
this.alteraBotoes(1);
}
public void btSalvar_Click(object sender, EventArgs e)
{
try
{
//leitura dos dados
ModeloCategoria modelo = new ModeloCategoria();
modelo.CatNome = txtNome.Text;
//obj para gravar os dados no banco
DALConexao cx = new DALConexao(DadosConexao.StringDeConexao);
BLLCategoria bll = new BLLCategoria(cx);
if (this.operacao == "inserir")
{
//cadastrar uma categoria
bll.Incluir(modelo);
MessageBox.Show("Cadastro efetuado: Código: "+modelo.CatCod.ToString());
}
else
{
//alterar uma categoria
modelo.CatCod = Convert.ToInt32(txtCodigo.Text);
bll.Alterar(modelo);
MessageBox.Show("Cadastro alterado");
}
this.LimpaTela();
this.alteraBotoes(1);
}
catch(Exception erro)
{
MessageBox.Show(erro.Message);
}
}
private void btAlterar_Click(object sender, EventArgs e)
{
this.operacao = "alterar";
this.alteraBotoes(2);
}
private void btExcluir_Click(object sender, EventArgs e)
{
try
{
DialogResult d = MessageBox.Show("Deseja excluir o registro?", "Aviso", MessageBoxButtons.YesNo);
if (d.ToString() == "Yes")
{
DALConexao cx = new DALConexao(DadosConexao.StringDeConexao);
BLLCategoria bll = new BLLCategoria(cx);
bll.Excluir(Convert.ToInt32(txtCodigo.Text));
this.LimpaTela();
this.alteraBotoes(1);
}
}
catch
{
MessageBox.Show("Impossível excluir o registro.\n Pois o mesmo está sendo utilizado em outro local.");
this.alteraBotoes(3);
}
}
private void btLocalizar_Click(object sender, EventArgs e)
{
frmConsultaCategoria f = new frmConsultaCategoria();
f.ShowDialog();
f.Dispose();
if (f.codigo != 0)
{
DALConexao cx = new DALConexao(DadosConexao.StringDeConexao);
BLLCategoria bll = new BLLCategoria(cx);
ModeloCategoria modelo = bll.CarregaModeloCategoria(f.codigo);
txtCodigo.Text = modelo.CatCod.ToString();
txtNome.Text = modelo.CatNome;
alteraBotoes(3);
}
else
{
this.LimpaTela();
this.alteraBotoes(1);
}
f.Dispose();
}
}
}