-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgregarCliente.java
More file actions
250 lines (202 loc) · 8.75 KB
/
AgregarCliente.java
File metadata and controls
250 lines (202 loc) · 8.75 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
import java.awt.*;
import javax.swing.*;
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.SQLException;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class AgregarCliente 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,
// "¡Registro guardado exitosamente!");
} catch (ClassNotFoundException | SQLException | HeadlessException e) {
JOptionPane.showMessageDialog(null,
"Hubo un error en la instalacion" + e);
}
return conexion;
}
// Método para generar los Jpanel y TextField, corrrespondientes
AgregarCliente() {
setSize(900, 600);
setTitle("Agregar clientes");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
JPanel Clientes = new JPanel();
Clientes.setLayout(null);
Clientes.setSize(900, 600);
Clientes.setBackground(Color.black);
JLabel anuncio = new JLabel("Agregar datos de los clientes:");
anuncio.setForeground(Color.white);
Font fuente = new Font("Arial Black", Font.BOLD, 20);
anuncio.setFont(fuente);
anuncio.setBounds(370, 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, 575, 30);
NombreResponsabletxt.setBorder(null);
NombreResponsabletxt.setTipo('T');
NombreResponsabletxt.setLongitud(20);
Clientes.add(NombreResponsabletxt);
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.white);
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);
JTextField Calletxt = new JTextField("");
Calletxt.setForeground(Color.black);
Calletxt.setBounds(130, 300, 200, 30);
Calletxt.setBorder(null);
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(5);
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);
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, 170, 30);
Estadotxt.setBorder(null);
Estadotxt.setTipo('T');
Estadotxt.setLongitud(30);
Clientes.add(Estadotxt);
JButton Agregar = new JButton("Agregar cliente");
Agregar.setBackground(Color.black);
Font fontBoton = new Font("Arial", Font.BOLD, 20);
Agregar.setFont(fontBoton);
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();
// Se realian las consultas en la BDD
psd = cn.prepareStatement("INSERT INTO CLIENTE (NOMBRE_CLIENTE,NUMERO_CALLE,CALLE,COLONIA,MUNICIPIO,ESTADO,CORREO,TELEFONO) VALUES(?,?,?,?,?,?,?,?)");
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());
int res = psd.executeUpdate();
if(res>0 ){
JOptionPane.showMessageDialog(null, "Registro Guardado Exitosamente");
} else {
JOptionPane.showMessageDialog(null, "Error");
}
cn.close();
} catch (SQLException ex) {
System.err.println("Error en: " + ex);
}
// se agregan datos a la tabla de clientes de la interfaz PrincipalOriginal en el
// apartado de clientes:
PrincipalOriginal p = new PrincipalOriginal();
//p.Clientes();
}
});
JLabel background = new JLabel();
background.add(Clientes);
add(background);
setVisible(true);
}
public static void main(String[] args) {
new AgregarCliente();
}
}