/
Formconscliente.cs
250 lines (206 loc) · 8.99 KB
/
Formconscliente.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MasterSports
{
public partial class Formconscliente : Form
{
public Formconscliente()
{
InitializeComponent();
}
private void Formconscliente_Load(object sender, EventArgs e)
{
// carregar a combo para mostrar o tipo de pesquisa
cbopcoespesquisa.Items.Add("Nome");
cbopcoespesquisa.Items.Add("CPF");
cbopcoespesquisa.Items.Add("Status");
cbopcoespesquisa.Items.Add("Sexo");
cbopcoespesquisa.SelectedIndex = 0;
rbinicio.Checked = true;
}
private void cbopcoespesquisa_SelectedIndexChanged(object sender, EventArgs e)
{
// de acordo com a configuracao escolhida ?? desabilita alguns objetos
if (cbopcoespesquisa.SelectedIndex == 0) // Nome
{
gbpesquisa.Enabled = true;
gbsexo.Enabled = false;
gbcpf.Enabled = false;
gbstatus.Enabled = false;
txconsulta.Enabled = true;
gbpesquisa.Focus();
}
if (cbopcoespesquisa.SelectedIndex == 1) // CPF
{
gbpesquisa.Enabled = true;
gbcpf.Enabled = true;
gbsexo.Enabled = false;
gbstatus.Enabled = false;
txconsulta.Enabled = false;
}
if (cbopcoespesquisa.SelectedIndex == 2) // status
{
gbpesquisa.Enabled = false;
gbcpf.Enabled = false;
gbsexo.Enabled = false;
gbstatus.Enabled = true;
txconsulta.Enabled = false;
}
if (cbopcoespesquisa.SelectedIndex == 3) // sexo
{
gbpesquisa.Enabled = false;
gbcpf.Enabled = false;
gbsexo.Enabled = true;
gbstatus.Enabled = false;
txconsulta.Enabled = false;
}
}
private void btpesquisar_Click(object sender, EventArgs e)
{
//criando variavel para guardar as informações carregadas
string consulta = cbopcoespesquisa.SelectedItem.ToString();
classcliente consultacli = new classcliente();
switch (consulta)
{
case "Nome":
// verificar se algo foi digitado no campo nome
// se txtconsulta for igual a vazio, função messagebox mostra mensagem
if (txconsulta.Text != "")
// inicio
{
if (rbinicio.Checked)
{
consultacli.nome = txconsulta.Text;
dataGridViewcliente.DataSource = consultacli.buscaconsultainicio();
}
//contem
else
{
consultacli.nome = txconsulta.Text;
dataGridViewcliente.DataSource = consultacli.buscaconsultacontem();
}
}
else
{
MessageBox.Show("Digite um Nome", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
break;
// busca CPF
case "CPF":
//verificar se algo foi digitado
// se cpf estiver vazio, messagebox na tela
if (txcpf.Text != "")
{
consultacli.cpf = txcpf.Text;
dataGridViewcliente.DataSource = consultacli.buscaclientecpfcontem();
}
else
{
MessageBox.Show("Favor digitar o CPF ", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
break;
//verificar o status
case "Status":
if (rbativo.Checked == true)
{
consultacli.status = 1;
dataGridViewcliente.DataSource = consultacli.buscaclientestatusativo();
}
else
if (rbinativo.Checked)
{
consultacli.status = 0;
dataGridViewcliente.DataSource = consultacli.buscaclientestatusativo();
}
else
{
MessageBox.Show("Favor escolher um Status", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
break;
//Verficiar o status do sexo
case "Sexo":
if (rbmasculino.Checked == true)
{
consultacli.sexo = "M";
dataGridViewcliente.DataSource = consultacli.buscaclientessexoM();
}
else
if (rbfemenino.Checked)
{
consultacli.sexo = "F";
dataGridViewcliente.DataSource = consultacli.buscaclientesexoF();
}
else
{
MessageBox.Show("Favor ecolher um Sexo", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
break;
}
}
// botao sair
private void btsair_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Tem Certeza que Deseja sair ?", "Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
this.Close();
}
private void bteditar_Click(object sender, EventArgs e)
{
if (dataGridViewcliente.SelectedCells.Count > 0)
{
classcliente ccliente = new classcliente();
ccliente.retornarcliente(Convert.ToInt32(dataGridViewcliente.SelectedRows[0].Cells[0].Value));
fmrCliente formcliente = new fmrCliente();
// nao esquecer de mudar a propriedade de objetos do formulario do cliente = TRUE
formcliente.txtcodigo.Text = ccliente.codigocliente.ToString();
formcliente.txtnome.Text = ccliente.nome.ToString();
formcliente.mtxdatanascimento.Text = ccliente.datanascimento.ToString();
formcliente.mtxcpf.Text = ccliente.cpf.ToString();
formcliente.mtxtelefone.Text = ccliente.telefone.ToString();
formcliente.mtxcelular.Text = ccliente.celular.ToString();
formcliente.tbcidade.Text = ccliente.cidade.ToString();
formcliente.txbairro.Text = ccliente.bairro.ToString();
formcliente.txrua.Text = ccliente.rua.ToString();
formcliente.cestado.Text = ccliente.estado.ToString();
formcliente.txnumero.Text = ccliente.numerocasa.ToString();
// checando o status
if (ccliente.status == 1)
{
formcliente.cbstatuss.Checked = true;
}
else
{
formcliente.cbstatuss.Checked = false;
}
if (ccliente.sexo == "M")
{
formcliente.rbmasculino.Checked = true;
formcliente.rbfemenino.Checked = false;
}
else
if (ccliente.sexo == "F")
{
formcliente.rbmasculino.Checked = false;
formcliente.rbfemenino.Checked = true;
}
// mandar a informação de Update
// declarar variavel Tipo no Formulario do cliente
formcliente.tipo = "Atualização";
// nao repetir que outro formula seja aberto e despues de actualizar e cierre el formulario
formcliente.ShowDialog();
// llamar el metodo de pesquisa
btpesquisar_Click(this, new EventArgs());
}
else
{
MessageBox.Show("Selecione o produto a ser Atualizado !","Sistema Mastersports", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}