-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditarCliente.java
More file actions
288 lines (235 loc) · 10.4 KB
/
EditarCliente.java
File metadata and controls
288 lines (235 loc) · 10.4 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
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class EditarCliente extends JFrame {
PreparedStatement psd;
// Se realiza la conexión a la BDD
public Connection getConexion() {
Connection conexion = null;
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
conexion = (Connection) DriverManager.getConnection("jdbc:derby://localhost:1527/Construct", "Adminn", "Admin");
// JOptionPane.showMessageDialog(null, "Conexion exitosa");
} catch (Exception e) {
System.out.println(e);
}
return conexion;
}
// Método para generar los Jpanel y TextField, corrrespondientes
EditarCliente() {
setSize(900, 600);
setTitle("Editar clientes");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
JPanel Clientes = new JPanel();
Clientes.setLayout(null);
Clientes.setSize(900, 768);
Clientes.setBackground(Color.black);
JLabel anuncio = new JLabel("Editar datos de los clientes:");
anuncio.setForeground(Color.decode("#049cff"));
Font fuente = new Font("Arial Black", Font.BOLD, 20);
anuncio.setFont(fuente);
anuncio.setBounds(400, 0, 400, 70);
Clientes.add(anuncio);
JLabel nombresResponsable = new JLabel("Nombre(s):");
nombresResponsable.setForeground(Color.white);
Font fuenteResponsables = new Font("Arial", Font.BOLD, 20);
nombresResponsable.setFont(fuenteResponsables);
nombresResponsable.setBounds(0, 30, 280, 230);
Clientes.add(nombresResponsable);
CampoDato NombreResponsabletxt = new CampoDato();
NombreResponsabletxt.setForeground(Color.black);
NombreResponsabletxt.setBounds(128, 135, 375, 30);
NombreResponsabletxt.setBorder(null);
NombreResponsabletxt.setTipo('T');
NombreResponsabletxt.setLongitud(20);
Clientes.add(NombreResponsabletxt);
// Boton BUSCAR para realizar las consultas en la BDD
JButton Buscar = new JButton("Bsucar");
Buscar.setBackground(Color.black);
Buscar.setBorder(new ComponenteBotonRedondo(40));
Buscar.setForeground(Color.decode("#049cff"));
Buscar.setBounds(538, 125, 125, 40);
Clientes.add(Buscar);
JLabel Telefono = new JLabel("Télefono:");
Telefono.setForeground(Color.white);
Font fuenteTelefono = new Font("Arial", Font.BOLD, 20);
Telefono.setFont(fuenteTelefono);
Telefono.setBounds(0, 70, 200, 230);
Clientes.add(Telefono);
CampoDato Telefonotxt = new CampoDato();
Telefonotxt.setForeground(Color.black);
Telefonotxt.setBounds(128, 176, 200, 30);
Telefonotxt.setBorder(null);
Telefonotxt.setTipo('E');
Telefonotxt.setLongitud(9);
Clientes.add(Telefonotxt);
JLabel Correo = new JLabel("E-mail:");
Correo.setForeground(Color.white);
Font fuenteCorreo = new Font("Arial", Font.BOLD, 20);
Correo.setFont(fuenteCorreo);
Correo.setBounds(435, 113, 260, 150);
Clientes.add(Correo);
JTextField Correotxt = new JTextField("");
Correotxt.setForeground(Color.black);
Correotxt.setBounds(502, 178, 200, 30);
Correotxt.setBorder(null);
Clientes.add(Correotxt);
JLabel Domicilio = new JLabel("Datos domiciliarios:");
Domicilio.setForeground(Color.decode("#049cff"));
Font fuenteDomicilio = new Font("Arial Black", Font.BOLD, 20);
Domicilio.setFont(fuenteDomicilio);
Domicilio.setBounds(410, 100, 300, 300);
Clientes.add(Domicilio);
JLabel Calle = new JLabel("Calle:");
Calle.setForeground(Color.white);
Font fontCalle = new Font("Arial", Font.BOLD, 20);
Calle.setFont(fontCalle);
Calle.setBounds(0, 166, 300, 300);
Clientes.add(Calle);
CampoDato Calletxt = new CampoDato();
Calletxt.setForeground(Color.black);
Calletxt.setBounds(130, 300, 200, 30);
Calletxt.setBorder(null);
Calletxt.setTipo('T');
Calletxt.setLongitud(30);
Clientes.add(Calletxt);
JLabel Numero = new JLabel("Número:");
Numero.setForeground(Color.white);
Font fontNumero = new Font("Arial", Font.BOLD, 20);
Numero.setFont(fontNumero);
Numero.setBounds(418, 166, 300, 300);
Clientes.add(Numero);
CampoDato Numtxt = new CampoDato();
Numtxt.setForeground(Color.black);
Numtxt.setBounds(503, 300, 40, 30);
Numtxt.setBorder(null);
Numtxt.setTipo('E');
Numtxt.setLongitud(2);
Clientes.add(Numtxt);
JLabel colonia = new JLabel("Colonia:");
colonia.setForeground(Color.white);
Font fontColonia = new Font("Arial", Font.BOLD, 20);
colonia.setFont(fontColonia);
colonia.setBounds(588, 166, 300, 300);
Clientes.add(colonia);
CampoDato Coltxt = new CampoDato();
Coltxt.setForeground(Color.black);
Coltxt.setBounds(670, 300, 200, 30);
Coltxt.setBorder(null);
Coltxt.setTipo('T');
Coltxt.setLongitud(30);
Clientes.add(Coltxt);
JLabel Municipio = new JLabel("Municipio:");
Municipio.setForeground(Color.white);
Font fontMunicipio = new Font("Arial", Font.BOLD, 20);
Municipio.setFont(fontMunicipio);
Municipio.setBounds(0, 210, 300, 300);
Clientes.add(Municipio);
//JComboBox Municipiotxt = new JComboBox();
CampoDato Municipiotxt = new CampoDato();
Municipiotxt.setForeground(Color.black);
Municipiotxt.setBounds(128, 350, 200, 30);
Municipiotxt.setBorder(null);
Municipiotxt.setTipo('T');
Municipiotxt.setLongitud(30);
Clientes.add(Municipiotxt);
JLabel Estado = new JLabel("Estado:");
Estado.setForeground(Color.white);
Font fontEstado = new Font("Arial", Font.BOLD, 20);
Estado.setFont(fontEstado);
Estado.setBounds(427, 210, 100, 300);
Clientes.add(Estado);
CampoDato Estadotxt = new CampoDato();
Estadotxt.setForeground(Color.black);
Estadotxt.setBounds(503, 350, 200, 30);
Estadotxt.setBorder(null);
Estadotxt.setTipo('T');
Estadotxt.setLongitud(30);
Clientes.add(Estadotxt);
JButton Agregar = new JButton("Guardar cambios");
Agregar.setBackground(Color.black);
Agregar.setBorder(new ComponenteBotonRedondo(40));
Agregar.setForeground(Color.decode("#049cff"));
Agregar.setBounds(410, 430, 250, 50);
Clientes.add(Agregar);
// Función que se le otorga al boton, siendo guardar los datos en la BDD
Agregar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Connection cn;
cn = getConexion();
// Para modificar uno o varios datos de uno o varios registros utilizamos "update" (actualizar).
psd = cn.prepareStatement("UPDATE CLIENTE SET NOMBRE_CLIENTE=?,NUMERO_CALLE=?,CALLE=?,COLONIA=?,MUNICIPIO=?,ESTADO=?,CORREO=?,TELEFONO=? WHERE NOMBRE_CLIENTE=?");
psd.setString(1, NombreResponsabletxt.getText());
psd.setString(2, Numtxt.getText());
psd.setString(3, Calletxt.getText());
psd.setString(4, Coltxt.getText());
psd.setString(5, Municipiotxt.getText());
psd.setString(6, Estadotxt.getText());
psd.setString(7, Correotxt.getText());
psd.setString(8, Telefonotxt.getText());
psd.setString(9, NombreResponsabletxt.getText());
int res = psd.executeUpdate();
if (res > 0) {
JOptionPane.showMessageDialog(null, "Registro Modificado");
} else {
JOptionPane.showMessageDialog(null, "Error al Modificar Registro");
}
cn.close();
} catch (SQLException ex) {
System.err.println("Error en: " + ex);
}
}
});
/* Función para el boton bsucar, este boton tiene la funcion de hacer la búsqueda en la BDD
tiene como objetivo buscar de acuerdo al atributo nombre, en este caso es el nombre del cliente.
*/
Buscar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Connection cn = null;
try {
cn = getConexion();
// Se realian las consultas en la BDD
psd = cn.prepareStatement("SELECT * FROM CLIENTE WHERE NOMBRE_CLIENTE =?");
psd.setString(1, NombreResponsabletxt.getText());
ResultSet res = psd.executeQuery();
if (res.next()) {
Numtxt.setText(res.getString("NUMERO_CALLE"));
Calletxt.setText(res.getString("CALLE"));
Coltxt.setText(res.getString("COLONIA"));
Municipiotxt.setText(res.getString("MUNICIPIO"));
Estadotxt.setText(res.getString("ESTADO"));
Correotxt.setText(res.getString("CORREO"));
Telefonotxt.setText(res.getString("TELEFONO"));
} else {
JOptionPane.showMessageDialog(null, "No existe un registro con el nombre de: "+NombreResponsabletxt.getText());
}
} catch (SQLException ex) {
System.err.println("Error en: " + ex);
}
}
});
JLabel background = new JLabel();
background.add(Clientes);
add(background);
setVisible(true);
}
public static void main(String[] args) {
new EditarCliente();
}
}