-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrellenoInventario.java
More file actions
173 lines (136 loc) · 5.3 KB
/
Copy pathrellenoInventario.java
File metadata and controls
173 lines (136 loc) · 5.3 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
package Interfaces;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JOptionPane;
import java.awt.event.ActionListener;
import java.sql.PreparedStatement;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
public class rellenoInventario implements ActionListener{
public JButton btnVolver, btnActualizar;
public JFrame frame;
public JTextField textClave;
public JTextField textCantidad;
/**
* Launch the application.
*/
// CONECTA A LA BASE DE DATOS Y CONSIGUE EL CON
private Connection con = ConexionBD.conectar();
public PreparedStatement pstm = null;
ResultSet rs = null;
String query="";
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
rellenoInventario window = new rellenoInventario();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public rellenoInventario() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
public void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 960, 640);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(960,640);
frame.getContentPane().setLayout(null);
frame.getContentPane().setBackground(new Color(72,81,84));
JLabel lblRellenoInventario = new JLabel("Relleno de inventario");
lblRellenoInventario.setForeground(Color.WHITE);
lblRellenoInventario.setFont(new Font("Arial", Font.BOLD, 40));
lblRellenoInventario.setBounds(283, 53, 420, 72);
frame.getContentPane().add(lblRellenoInventario);
btnVolver = new JButton("Volver");
btnVolver.setForeground(Color.WHITE);
btnVolver.setFont(new Font("Arial", Font.PLAIN, 20));
btnVolver.setFocusPainted(false);
btnVolver.setBorderPainted(false);
btnVolver.setBackground(new Color(171, 0, 51));
btnVolver.setBounds(10, 562, 139, 31);
frame.getContentPane().add(btnVolver);
btnVolver.addActionListener(this);
textClave = new JTextField();
textClave.setColumns(10);
textClave.setBounds(255, 135, 158, 19);
frame.getContentPane().add(textClave);
JLabel lblClave = new JLabel("ID del articulo:");
lblClave.setForeground(Color.WHITE);
lblClave.setFont(new Font("Arial", Font.PLAIN, 20));
lblClave.setBounds(90, 135, 170, 16);
frame.getContentPane().add(lblClave);
textCantidad = new JTextField();
textCantidad.setColumns(10);
textCantidad.setBounds(647, 137, 208, 19);
frame.getContentPane().add(textCantidad);
JLabel lblCantidad = new JLabel("Cantidad:");
lblCantidad.setForeground(Color.WHITE);
lblCantidad.setFont(new Font("Arial", Font.PLAIN, 20));
lblCantidad.setBounds(554, 135, 149, 16);
frame.getContentPane().add(lblCantidad);
btnActualizar = new JButton("Actualizar");
btnActualizar.setForeground(Color.WHITE);
btnActualizar.setFont(new Font("Arial", Font.PLAIN, 17));
btnActualizar.setFocusPainted(false);
btnActualizar.setBorderPainted(false);
btnActualizar.setBackground(new Color(171, 0, 51));
btnActualizar.setBounds(413, 224, 149, 39);
frame.getContentPane().add(btnActualizar);
btnActualizar.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
menuInventario menuInventario = new menuInventario();
if(e.getSource()==btnVolver) {
menuInventario.frame.setVisible(true);
frame.dispose();
}
else if(e.getSource()==btnActualizar) {
if(textClave.getText().isEmpty() || textCantidad.getText().isEmpty())
{
JOptionPane.showMessageDialog(null, "Faltan datos.");
} else {
int id = Integer.parseInt(textClave.getText());
int cantidad = Integer.parseInt(textCantidad.getText());
try {
query="UPDATE `Producto Dulceria` SET `Existencias`= ? WHERE `ID_Producto`=?";
pstm = con.prepareStatement(query);
pstm.setInt(1,cantidad);
pstm.setInt(2, id);
pstm.executeUpdate();
JOptionPane.showMessageDialog(null, "listo!");
pstm.close();
con.close();
} catch (SQLException e1) {
}
}
int opcion = JOptionPane.showConfirmDialog(null, "Actualizado correctamente!, quiere rellenar otro producto?","Actualizado",JOptionPane.YES_NO_OPTION);
if(opcion == JOptionPane.YES_OPTION) {
textClave.setText("");
textCantidad.setText("");
}
else {
menuInventario.frame.setVisible(true);
frame.dispose();
}
}
}
}