Foro sobre Java SE > el formulario no corre con el proyecto
Hola, que ide usas? Netbeans, Eclipse, Intellij, ....
hola, uso netbeans
hice un nuevo proyecto de una forma similar, un formulario principal y uno que es llamado desde este, el segundo formulario se conecta a una base mysql, me paso lo mismo: con run file funciona pero ejecutando el proyecto completo no.... Entonces elimine el formulario principal dejando solo al otro y funciona perfectamente. Pero esa no es la idea.
muchas gracias
Bien, siempre que creas un proyecto, debes indicar cual sera la clase principal que se ejecutara al ejecutar el proyecto. Normalmente netbeans, ya crea y configura una clase principal dependiendo del tipo de proyecto. Por eso, al crear un nuevo proyecto, y ejecutarlo, sin cambiar nada, siempre se va a ejecutar la clase que netbeans configuro, no las nuevas clases que vayas añadiendo.
Para configurarlo, pincha con el boton derecho sobre tu proyecto y dale a propiedades, en la izquierda, pincha sobre el apartado Run. Y a la derecha, donde pone "Main Class:", es donde se indica cual será la clase que se ejecutará al ejecutar el proyecto. Solo se puede poner 1 clase.
Si lo que quieres es que se abran varios formularios a la vez al ejecutar, tendras que crear una nueva clase, con un metodo main, donde crees los formularios que quieres que se abran y los hagas visibles.... Algo asi:
public class MainClass{
public static void main(String[] arg){
Formulario1 form1=new Formulario1();
Formulario2 form2=new Formulario2();
....
form1.setVisible(true);
form2.setVisible(true);
}
}
y tras crear esta clase, pues configuras el proyecto para que eta nueva clase, sea la clase principal.
Bueno espero que te sirva, un saludo.
hola, gracias por tu respuesta, perdón la demora estaba un poco desconectada,
en realidad lo que quiero es llamar a mi formulario desde otro formulario con un botón, el formulario que hace el llamado solo tiene un botón y ya, y el segundo es el que hace todo el trabajo (es un formulario de facturación; se conecta a una base de datos y factura) este formulario funciona muy bien pero necesito poderlo llamar de otro lado.
hice esto en el botón del primer formulario:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
NuevaFactura form2=new NuevaFactura();
form2.setVisible(true);
}
es lo único que debe hacer, llamar al otro formulario (facturación), pero cuando facturación es llamado con otro formulario entonces ya no se conecta a la base y me sale:
java.lang.NullPointerException
t modulofacturacion.NuevaFactura.conteo(NuevaFactura.java:968)
at modulofacturacion.NuevaFactura.CargarTablaInventario(NuevaFactura.java:125)
at modulofacturacion.NuevaFactura.BotonBuscarArtActionPerformed(NuevaFactura.java:848)
at modulofacturacion.NuevaFactura.access$000(NuevaFactura.java:21)
at modulofacturacion.NuevaFactura$1.actionPerformed(NuevaFactura.java:492)
que estaria apuntando aqui:
public void conteo(String secuencia){
String secuencia1;
secuencia1=secuencia;
try {
rs = stmt.executeQuery(secuencia1); AQUI
// get the number of rows from the result set
rs.next();
contador = rs.getInt(1);
}
catch (Exception e) {
e.printStackTrace();
}//fin catch
}
estoy muy confundida, gracias por la ayuda
hola, podrías poner el código completo del segundo formulario(NuevaFactura)?
El problema es que algo esta saltando nulo cuando se crea el segundo formulario, si pones el código completo, quizá pudiéramos decirte donde esta el problema.
Un saludo.
perdón el desorden:
public class NuevaFactura extends javax.swing.JFrame {
public static Connection con = null;
public static ResultSet rs = null;
public static Statement stmt = null;
int contador;
static String password;
static String usuario;
/*public static String bd="test";
public static String url="jdbc:mysql://localhost/"+bd;
public static String user = "root";
public static String password = "Administrador2015";*/
int filas = 0;
DefaultTableModel modelo;
/**
* Creates new form NuevaFactura
*/
public NuevaFactura() {
initComponents();
tblInventario.setVisible(false);
jLabel3.setVisible(false);
ComboCantidad.setVisible(false);
CheckBoxTecnico.setVisible(false);
BotonAgregar.setVisible(false);
jLabel4.setVisible(false);
tblCesta.setVisible(false);
BotonEliminar.setVisible(false);
BotonTotal.setVisible(false);
jLabel5.setVisible(false);
TextTotal.setVisible(false);
jLabel6.setVisible(false);
jRadioButton2.setVisible(false);
jRadioButton4.setVisible(false);
jLabel7.setVisible(false);
TxtDescuentos.setVisible(false);
BotonFacturar.setVisible(false);
}
void limpiarformulario(){
txtArticulo.setText("");
txtServicio.setText("");
TxtNFactura.setText("");
int totalRow= tblInventario.getRowCount();
totalRow-=1;
for (int i=0;i<(totalRow);i++){
tblInventario.setValueAt("", i, 0);
tblInventario.setValueAt("", i, 1);
tblInventario.setValueAt("", i, 2);
tblInventario.setValueAt("", i, 3);
tblInventario.setValueAt("", i, 4);
tblInventario.setValueAt("", i, 5);
tblInventario.setValueAt("", i, 6);
tblInventario.setValueAt("", i, 7);
}
tblInventario.setVisible(false);
jLabel3.setVisible(false);
ComboCantidad.setVisible(false);
CheckBoxTecnico.setVisible(false);
BotonAgregar.setVisible(false);
jLabel4.setVisible(false);
tblCesta.setVisible(false);
BotonEliminar.setVisible(false);
BotonTotal.setVisible(false);
jLabel5.setVisible(false);
TextTotal.setVisible(false);
jLabel6.setVisible(false);
jRadioButton2.setVisible(false);
jRadioButton4.setVisible(false);
jLabel7.setVisible(false);
TxtDescuentos.setVisible(false);
BotonFacturar.setVisible(false);
//verificar el rowlistener
//limpiarTabla();
//clearTable(tblCesta);
}
void CargarTablaInventario(String valor, String valor2){
//carga la tabla con los articulos que correspondan a la busqueda
int totalRow= tblInventario.getRowCount();
totalRow-=1;
for (int i=0;i<(totalRow);i++){
tblInventario.setValueAt("", i, 0);
tblInventario.setValueAt("", i, 1);
tblInventario.setValueAt("", i, 2);
tblInventario.setValueAt("", i, 3);
tblInventario.setValueAt("", i, 4);
tblInventario.setValueAt("", i, 5);
tblInventario.setValueAt("", i, 6);
tblInventario.setValueAt("", i, 7);
}
String sentencia;
sentencia = "SELECT count(*) FROM inventario WHERE producto LIKE '%"+valor+"%' AND clase LIKE '%"+valor2+"%'";
conteo(sentencia);
sentencia = "SELECT producto, clase, marca, modelo, stock, precio_compra, precio_venta_unidad, precio_venta_cantidad FROM inventario " +
"WHERE CONCAT(producto, ' ',marca) LIKE '%"+valor+"%' AND clase LIKE '%"+valor2+"%'";
setsqlc(sentencia);
String datas;
for(int j=0;j<contador;j++){ //llenado de la tabla
try {
rs.next();
if (rs!=null){
datas=getbasedato(1);
tblInventario.setValueAt(datas, j, 0);//agrega el dato a la columna 0 de la fila j
datas=getbasedato(2);
tblInventario.setValueAt(datas, j, 1);
datas=getbasedato(3);
tblInventario.setValueAt(datas, j, 2);
datas=getbasedato(4);
tblInventario.setValueAt(datas, j, 3);
datas=getbasedato(5);
tblInventario.setValueAt(datas, j, 4);
datas=getbasedato(6);
tblInventario.setValueAt(datas, j, 5);
datas=getbasedato(7);
tblInventario.setValueAt(datas, j, 6);
datas=getbasedato(8);
tblInventario.setValueAt(datas, j, 7);
}
else{
break;
}
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
}
}
void CargarTablaServicio(String valor3, String valor4){
int totalRow= tblInventario.getRowCount();
totalRow-=1;
for (int i=0;i<(totalRow);i++){
tblInventario.setValueAt("", i, 0);
tblInventario.setValueAt("", i, 1);
tblInventario.setValueAt("", i, 2);
tblInventario.setValueAt("", i, 3);
}
String sentencia;
sentencia = "SELECT count(*) FROM servicios WHERE nombre LIKE '%"+valor3+"%' AND clase LIKE '%"+valor4+"%'";
conteo(sentencia);
sentencia = "SELECT nombre, clase, valor, descripcion FROM servicios WHERE nombre LIKE '%"+valor3+"%' AND clase LIKE '%"+valor4+"%'";
setsqlc(sentencia);
String datas;
for(int j=0;j<contador;j++){ //llenado de la tabla
try {
rs.next();
if (rs!=null){
datas=getbasedato(1);
tblInventario.setValueAt(datas, j, 0);//agrega el dato a la columna 0 de la fila j
datas=getbasedato(2);
tblInventario.setValueAt(datas, j, 1);
datas=getbasedato(3);
tblInventario.setValueAt(datas, j, 2);
datas=getbasedato(4);
tblInventario.setValueAt(datas, j, 3);
}
else{
break;
}
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
}
}
void CargarTablaCesta(String nombre, String clase, String cantidad, String costo){
modelo= (DefaultTableModel)this.tblCesta.getModel();
modelo.addRow(new Object[filas]);
for (int x=0; x<this.tblCesta.getColumnCount()-1;x++)
{
modelo.setValueAt(cantidad, filas, 0);
modelo.setValueAt(nombre, filas, 1);
modelo.setValueAt(clase, filas, 2);
modelo.setValueAt(costo, filas, 3);
}
filas++;
}
void nfactura(){
//trae el numero en el que va la factura
String nfactura = null;
int numfactura =0;
String sentencia;
sentencia = "SELECT MAX(numero_factura) as numero_factura FROM facturas;";
setsqlc(sentencia);
try {
rs.next();
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
nfactura=getbasedato(1);
numfactura = Integer.valueOf(nfactura);
numfactura = numfactura+1;
TxtNFactura.setText(String.valueOf(numfactura));
}
void factura(){
//toma cada uno de los valores de la cesta para registrar la factura
//llama al metodo registrar_producto
int totalRow= tblCesta.getRowCount();
totalRow-=1;
for(int i=0;i<=(totalRow);i++)
{
int cantidad = Integer.parseInt(String.valueOf(tblCesta.getValueAt(i,0)));
String nombre = String.valueOf(tblCesta.getValueAt(i,1));
String valor = String.valueOf(tblCesta.getValueAt(i,3));
String stock = null;
int nstock = 0;
String sentencia;
sentencia = "SELECT stock FROM inventario WHERE producto ='"+nombre+"';";
setsqlc(sentencia);
try {
rs.next();
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
stock=getbasedato(1);
nstock=Integer.valueOf(stock);
if(nstock>cantidad){
registrar_producto((TxtNFactura.getText()),nombre,String.valueOf(cantidad),valor);
}
else{
JOptionPane.showMessageDialog(this, "el stock no soporta la cantidad");
}
}
}
void venta(){
//toma el numero de la factura actual
//toma el valor total, si se aplicaron descuentos registra tambien el valor con descuento
//registro del cliente
//registro del vendedor
//pide los datos del cliente
String numero_factura = TxtNFactura.getText();
String valor;
String vdescuento;
String nombre = "";
String apellido = "";
String telefono = "";
int dialogButton = JOptionPane.YES_NO_OPTION;
int dialogResult =JOptionPane.showConfirmDialog(null, "¿desea registrar el cliente?","Atencion",dialogButton);
if(dialogResult == JOptionPane.YES_OPTION){
nombre= JOptionPane.showInputDialog(null,"nombre del cliente", "nombre", JOptionPane.QUESTION_MESSAGE);
apellido= JOptionPane.showInputDialog(null,"apellido del cliente", "apellido", JOptionPane.QUESTION_MESSAGE);
telefono= JOptionPane.showInputDialog(null,"telefono del cliente", "telefono", JOptionPane.QUESTION_MESSAGE);
}else{
nombre="default";
apellido="default";
telefono="00000";
}
registro_cliente(nombre, apellido, telefono);
String id = null;
String sentencia;
sentencia="SELECT MAX(ID) as ID FROM clientes;";
setsqlc(sentencia);
try {
rs.next();
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
id=getbasedato(1);
//cproducto = String.valueOf(dos);
String[] vendedores = {
"David Cabral",
"Carlos Andres Gomez",
"Carolina Velasquez",
};
String nvendedor = (String) JOptionPane.showInputDialog(null, "Seleccione un vendedor", "Vendedor", JOptionPane.DEFAULT_OPTION,null,vendedores,vendedores[0]);
String vendedor = "";
switch(nvendedor){
case "David Cabral":
vendedor="1";
break;
case "Carlos Andres Gomez":
vendedor ="4";
break;
case "Carolina Velasquez":
vendedor = "2";
break;
}
valor = TextTotal.getText();
if (jRadioButton2.isSelected()){
vdescuento = TxtDescuentos.getText();
}else{
vdescuento = "0";
}
registrar_venta((TxtNFactura.getText()),valor,vdescuento,id,vendedor);
}
void registro_cliente(String nombre, String apellido, String telefono){
String sentencia_sql;
sentencia_sql= "insert into clientes(NOMBRE,APELLIDO,TELEFONO) values('"+nombre+"','"+apellido+"','"+telefono+"');";
setsqlr(sentencia_sql);
}
void registrar_venta(String numero_factura, String valor, String vdescuento, String id, String vendedor){
String sentencia_sql;
sentencia_sql= "insert into ventas(numero_factura,valor,vdescuento,cliente,vendedor) values('"+numero_factura+"','"+valor+"','"+vdescuento+"','"+id+"','"+vendedor+"');";
setsqlr(sentencia_sql);
}
void registrar_producto(String numero_factura,String producto,String cantidad, String v_venta){
//llama a los metodos update e insertar
update(cantidad,producto);
//se trae el codigo segun el producto de la tabla inventario
String cproducto = null;
//String dos;
String sentencia;
sentencia="SELECT count(*) FROM inventario WHERE producto='"+producto+"';";
conteo(sentencia);
if (contador==1){
sentencia="SELECT codigo FROM inventario WHERE producto='"+producto+"';";
setsqlc(sentencia);
try {
rs.next();
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
cproducto=getbasedato(1);
//cproducto = String.valueOf(dos);
}
else{
JOptionPane.showMessageDialog(null, "mas de un registro coincide", "Error", JOptionPane.ERROR_MESSAGE);
}
insertar(numero_factura,cproducto,cantidad,v_venta);
}
void update(String cantidad,String producto){
//actualiza el inventario
String sentencia_sql;
sentencia_sql = "update inventario set stock=stock-('"+cantidad+"') where producto=('"+producto+"');";
setsqlr(sentencia_sql);
}
void insertar(String numero_factura,String producto,String cantidad, String v_venta){
//realiza el insert de la factura
//cod_productoo servicio es un numero, opcion traer el codigo segun el nombre antes de hacer el insert
String sentencia_sql;
sentencia_sql= "insert into facturas(numero_factura,cod_prod_o_servicio,cantidad,v_venta) values('"+numero_factura+"','"+producto+"','"+cantidad+"','"+v_venta+"');";
setsqlr(sentencia_sql);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jCPanel2 = new com.bolivia.panel.JCPanel();
txtArticulo = new javax.swing.JTextField();
txtServicio = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
ComboClaseArticulo = new javax.swing.JComboBox();
ComboClaseServicio = new javax.swing.JComboBox();
BotonBuscarArt = new org.edisoncor.gui.button.ButtonAeroRound();
BotonBuscarSer = new org.edisoncor.gui.button.ButtonAeroRound();
jScrollPane1 = new javax.swing.JScrollPane();
tblInventario = new javax.swing.JTable();
jLabel3 = new javax.swing.JLabel();
ComboCantidad = new javax.swing.JComboBox();
BotonAgregar = new org.edisoncor.gui.button.ButtonAeroRound();
jLabel4 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
tblCesta = new javax.swing.JTable();
jLabel5 = new javax.swing.JLabel();
TextTotal = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jRadioButton2 = new javax.swing.JRadioButton();
jRadioButton4 = new javax.swing.JRadioButton();
jLabel7 = new javax.swing.JLabel();
TxtDescuentos = new javax.swing.JTextField();
BotonFacturar = new org.edisoncor.gui.button.ButtonAeroRound();
BotonCancelar = new org.edisoncor.gui.button.ButtonAeroRound();
BotonEliminar = new org.edisoncor.gui.button.ButtonAeroRound();
BotonCancelar1 = new org.edisoncor.gui.button.ButtonAeroRound();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
CheckBoxTecnico = new javax.swing.JCheckBox();
BotonTotal = new org.edisoncor.gui.button.ButtonAeroRound();
TxtNFactura = new javax.swing.JTextField();
jLabel10 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jCPanel2.setdarker(false);
jCPanel2.setFirstColor(new java.awt.Color(0, 51, 204));
jCPanel2.setSecondColor(new java.awt.Color(102, 204, 255));
jCPanel2.setUseMode(com.bolivia.panel.USEMODE.DEGRADED);
jCPanel2.setVisibleLogo(false);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("CLASE");
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText("CLASE");
ComboClaseArticulo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Lavadoras", "Neveras", "Ozonizadores", "Licuadoras", "Ollas" }));
ComboClaseServicio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Lavadoras", "Neveras", "Ozonizadores", "Licuadoras", "Ollas" }));
BotonBuscarArt.setForeground(new java.awt.Color(0, 0, 204));
BotonBuscarArt.setText("BUSCAR");
BotonBuscarArt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonBuscarArtActionPerformed(evt);
}
});
BotonBuscarSer.setForeground(new java.awt.Color(0, 0, 204));
BotonBuscarSer.setText("BUSCAR");
BotonBuscarSer.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonBuscarSerActionPerformed(evt);
}
});
tblInventario.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null}
},
new String [] {
"NOMBRE", "CLASE", "MARCA", "MODELO", "STOCK", "P_COMPRA", "P_VENTA UNIDAD", "P_VENTA TECNICO"
}
));
jScrollPane1.setViewportView(tblInventario);
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setText("CANTIDAD");
ComboCantidad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", " " }));
BotonAgregar.setForeground(new java.awt.Color(0, 0, 204));
BotonAgregar.setText("AGREGAR");
BotonAgregar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonAgregarActionPerformed(evt);
}
});
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setText("ELEMENTOS AGREGADOS");
tblCesta.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"CANTIDAD", "NOMBRE", "CLASE", "VALOR"
}
) {
boolean[] canEdit = new boolean [] {
false, false, false, false
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane2.setViewportView(tblCesta);
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
jLabel5.setForeground(new java.awt.Color(255, 255, 255));
jLabel5.setText("$");
TextTotal.setEditable(false);
TextTotal.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel6.setForeground(new java.awt.Color(255, 255, 255));
jLabel6.setText("SE APLICARÁN DESCUENTOS?");
jRadioButton2.setBackground(new java.awt.Color(0, 95, 204));
jRadioButton2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jRadioButton2.setForeground(new java.awt.Color(255, 255, 255));
jRadioButton2.setText("SI");
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
}
});
jRadioButton4.setBackground(new java.awt.Color(20, 100, 250));
jRadioButton4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jRadioButton4.setForeground(new java.awt.Color(255, 255, 255));
jRadioButton4.setText("NO");
jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton4ActionPerformed(evt);
}
});
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
jLabel7.setForeground(new java.awt.Color(255, 255, 255));
jLabel7.setText("TOTAL CON DESCUENTO: $");
BotonFacturar.setForeground(new java.awt.Color(0, 0, 204));
BotonFacturar.setText("FACTURAR");
BotonFacturar.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
BotonFacturar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonFacturarActionPerformed(evt);
}
});
BotonCancelar.setForeground(new java.awt.Color(0, 0, 204));
BotonCancelar.setText("CANCELAR");
BotonCancelar.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
BotonCancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonCancelarActionPerformed(evt);
}
});
BotonEliminar.setForeground(new java.awt.Color(0, 0, 204));
BotonEliminar.setText("ELIMINAR");
BotonEliminar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonEliminarActionPerformed(evt);
}
});
BotonCancelar1.setForeground(new java.awt.Color(0, 0, 204));
BotonCancelar1.setText("SALIR");
BotonCancelar1.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
BotonCancelar1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonCancelar1ActionPerformed(evt);
}
});
jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel8.setForeground(new java.awt.Color(255, 255, 255));
jLabel8.setText("ARTICULO");
jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel9.setForeground(new java.awt.Color(255, 255, 255));
jLabel9.setText("SERVICIO");
CheckBoxTecnico.setBackground(new java.awt.Color(0, 95, 204));
CheckBoxTecnico.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
CheckBoxTecnico.setForeground(new java.awt.Color(255, 255, 255));
CheckBoxTecnico.setText("Precio Técnico");
CheckBoxTecnico.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CheckBoxTecnicoActionPerformed(evt);
}
});
BotonTotal.setForeground(new java.awt.Color(0, 0, 204));
BotonTotal.setText("TOTAL");
BotonTotal.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
BotonTotal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonTotalActionPerformed(evt);
}
});
TxtNFactura.setEditable(false);
jLabel10.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel10.setForeground(new java.awt.Color(255, 0, 0));
jLabel10.setText("# FACTURA");
javax.swing.GroupLayout jCPanel2Layout = new javax.swing.GroupLayout(jCPanel2);
jCPanel2.setLayout(jCPanel2Layout);
jCPanel2Layout.setHorizontalGroup(
jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel8)
.addComponent(jLabel9))
.addGap(18, 18, 18)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtArticulo, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtServicio, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(32, 32, 32)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(ComboClaseServicio, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ComboClaseArticulo, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(BotonBuscarSer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BotonBuscarArt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jCPanel2Layout.createSequentialGroup()
.addComponent(TxtNFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(21, 21, 21))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jCPanel2Layout.createSequentialGroup()
.addComponent(jLabel10)
.addGap(37, 37, 37))))
.addGroup(jCPanel2Layout.createSequentialGroup()
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addComponent(jLabel6)
.addGap(18, 18, 18)
.addComponent(jRadioButton2)
.addGap(18, 18, 18)
.addComponent(jRadioButton4))
.addGroup(jCPanel2Layout.createSequentialGroup()
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addComponent(BotonFacturar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(29, 29, 29)
.addComponent(BotonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(30, 30, 30)
.addComponent(BotonCancelar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(TxtDescuentos, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addComponent(BotonEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(BotonTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addGap(18, 18, 18)
.addComponent(TextTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 862, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 862, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(ComboCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(50, 50, 50)
.addComponent(CheckBoxTecnico)
.addGap(116, 116, 116)
.addComponent(BotonAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(17, Short.MAX_VALUE))))
);
jCPanel2Layout.setVerticalGroup(
jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtArticulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)
.addComponent(ComboClaseArticulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BotonBuscarArt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtServicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(ComboClaseServicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BotonBuscarSer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jCPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(TxtNFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(15, 15, 15)))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(ComboCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BotonAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(CheckBoxTecnico))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel4)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(TextTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addComponent(BotonEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jCPanel2Layout.createSequentialGroup()
.addGap(143, 143, 143)
.addComponent(BotonTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(jRadioButton2)
.addComponent(jRadioButton4))
.addGap(18, 18, 18)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(TxtDescuentos)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(BotonFacturar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BotonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BotonCancelar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 889, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jCPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 889, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 573, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jCPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 573, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
);
pack();
}// </editor-fold>
private void BotonBuscarArtActionPerformed(java.awt.event.ActionEvent evt) {
tblInventario.setVisible(true);
jLabel3.setVisible(true);
ComboCantidad.setVisible(true);
CheckBoxTecnico.setVisible(true);
BotonAgregar.setVisible(true);
jLabel4.setVisible(true);
tblCesta.setVisible(true);
String valor = txtArticulo.getText();
String valor2 = ComboClaseArticulo.getSelectedItem().toString();
CargarTablaInventario(valor, valor2);
}
private void BotonBuscarSerActionPerformed(java.awt.event.ActionEvent evt) {
String valor3 = txtServicio.getText();
String valor4 = ComboClaseServicio.getSelectedItem().toString();
CargarTablaServicio(valor3, valor4);
}
private void BotonAgregarActionPerformed(java.awt.event.ActionEvent evt) {
BotonEliminar.setVisible(true);
BotonTotal.setVisible(true);
jLabel5.setVisible(true);
TextTotal.setVisible(true);
jLabel6.setVisible(true);
jRadioButton2.setVisible(true);
jRadioButton4.setVisible(true);
int row = tblInventario.getSelectedRow();
String nombre=tblInventario.getValueAt(row, 0).toString();
String clase=tblInventario.getValueAt(row, 1).toString();
String cantidad= ComboCantidad.getSelectedItem().toString();
String costo=" ";
int ncol = tblInventario.getColumnCount();
boolean selected = CheckBoxTecnico.isSelected();
if(ncol==4){
costo=tblInventario.getValueAt(row, 2).toString();
}else if(selected){
costo=tblInventario.getValueAt(row, 7).toString();
}else{
costo=tblInventario.getValueAt(row, 6).toString();
}
CargarTablaCesta(nombre, clase, cantidad, costo);
}
private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//si está seleccionado mostrar el txt para ingresar valor con descuento
if (jRadioButton2.isSelected()){
jRadioButton4.setSelected(false);
jLabel7.setVisible(true);
TxtDescuentos.setVisible(true);
BotonFacturar.setVisible(true);
}
}
private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (jRadioButton4.isSelected()){
jRadioButton2.setSelected(false);
jLabel7.setVisible(false);
TxtDescuentos.setVisible(false);
BotonFacturar.setVisible(true);
}
}
private void BotonFacturarActionPerformed(java.awt.event.ActionEvent evt) {
//si no lleva una orden de servicio pregunta si desea registrar el cliente, de lo contrario lo debe registrar
// crear los registros correspondientes a factura y venta, verifica si es producto o servicio,
//para orden de servicio crea el registro. despues realiza update en inventario
factura();
venta();
limpiarformulario();
}
private void BotonCancelarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
limpiarformulario();
}
private void BotonEliminarActionPerformed(java.awt.event.ActionEvent evt) {
/*modelo= (DefaultTableModel)this.tblCesta.getModel();
modelo.removeRow(this.tblCesta.getSelectedRow());*/
int cantCol = tblCesta.getColumnCount();
int row = tblInventario.getSelectedRow();
DefaultTableModel tabla = (DefaultTableModel) tblCesta.getModel();
for(int i=0;i<cantCol;i++){
tabla.setValueAt("", row, i);//los parámetros son: valor, fila y columna respectivamente
}
}
private void BotonCancelar1ActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}
private void CheckBoxTecnicoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void BotonTotalActionPerformed(java.awt.event.ActionEvent evt) {
nfactura();
double sumatoria=0;
double cant=0;
double sumatoria1=0;
double mult=0;
int totalRow= tblCesta.getRowCount();
totalRow-=1;
for(int i=0;i<=(totalRow);i++)
{
sumatoria= Double.parseDouble(String.valueOf(tblCesta.getValueAt(i,3)));
cant= Double.parseDouble(String.valueOf(tblCesta.getValueAt(i,0)));
mult = (cant)*sumatoria;
sumatoria1+= mult;
TextTotal.setText(String.valueOf(sumatoria1));
}
BotonFacturar.setVisible(true);
}
public void conteo(String secuencia){
String secuencia1;
secuencia1=secuencia;
try {
rs = stmt.executeQuery(secuencia1);
// get the number of rows from the result set
rs.next();
contador = rs.getInt(1);
}
catch (Exception e) {
e.printStackTrace();
}//fin catch
}
// metodo que retorna un dato de la base de datos
public String getbasedato(int p){
String dato=null;
try{
dato=String.valueOf(rs.getObject(p));
}
catch (Exception e){
e.printStackTrace();
}
return dato;
}
///ejecuta sentencia sql consulta
public void setsqlc(String orden_sql){
try {
rs = stmt.executeQuery (orden_sql);
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
}
//ejecuta sentencia sql insertar o cambiar datos
public void setsqlr(String orden_sql){
try {
stmt.executeUpdate(orden_sql);
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NuevaFactura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NuevaFactura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NuevaFactura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NuevaFactura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
try{
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","Administrador2015");
stmt = con.createStatement();
}
catch(Exception e){
e.printStackTrace();
}
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NuevaFactura().setVisible(true);
}
});
}
public class NuevaFactura extends javax.swing.JFrame {
public static Connection con = null;
public static ResultSet rs = null;
public static Statement stmt = null;
int contador;
static String password;
static String usuario;
/*public static String bd="test";
public static String url="jdbc:mysql://localhost/"+bd;
public static String user = "root";
public static String password = "Administrador2015";*/
int filas = 0;
DefaultTableModel modelo;
/**
* Creates new form NuevaFactura
*/
public NuevaFactura() {
initComponents();
try{
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","Administrador2015");
stmt = con.createStatement();
}
catch(Exception e){
e.printStackTrace();
}
tblInventario.setVisible(false);
jLabel3.setVisible(false);
ComboCantidad.setVisible(false);
CheckBoxTecnico.setVisible(false);
BotonAgregar.setVisible(false);
jLabel4.setVisible(false);
tblCesta.setVisible(false);
BotonEliminar.setVisible(false);
BotonTotal.setVisible(false);
jLabel5.setVisible(false);
TextTotal.setVisible(false);
jLabel6.setVisible(false);
jRadioButton2.setVisible(false);
jRadioButton4.setVisible(false);
jLabel7.setVisible(false);
TxtDescuentos.setVisible(false);
BotonFacturar.setVisible(false);
}
void limpiarformulario(){
txtArticulo.setText("");
txtServicio.setText("");
TxtNFactura.setText("");
int totalRow= tblInventario.getRowCount();
totalRow-=1;
for (int i=0;i<(totalRow);i++){
tblInventario.setValueAt("", i, 0);
tblInventario.setValueAt("", i, 1);
tblInventario.setValueAt("", i, 2);
tblInventario.setValueAt("", i, 3);
tblInventario.setValueAt("", i, 4);
tblInventario.setValueAt("", i, 5);
tblInventario.setValueAt("", i, 6);
tblInventario.setValueAt("", i, 7);
}
tblInventario.setVisible(false);
jLabel3.setVisible(false);
ComboCantidad.setVisible(false);
CheckBoxTecnico.setVisible(false);
BotonAgregar.setVisible(false);
jLabel4.setVisible(false);
tblCesta.setVisible(false);
BotonEliminar.setVisible(false);
BotonTotal.setVisible(false);
jLabel5.setVisible(false);
TextTotal.setVisible(false);
jLabel6.setVisible(false);
jRadioButton2.setVisible(false);
jRadioButton4.setVisible(false);
jLabel7.setVisible(false);
TxtDescuentos.setVisible(false);
BotonFacturar.setVisible(false);
//verificar el rowlistener
//limpiarTabla();
//clearTable(tblCesta);
}
void CargarTablaInventario(String valor, String valor2){
//carga la tabla con los articulos que correspondan a la busqueda
int totalRow= tblInventario.getRowCount();
totalRow-=1;
for (int i=0;i<(totalRow);i++){
tblInventario.setValueAt("", i, 0);
tblInventario.setValueAt("", i, 1);
tblInventario.setValueAt("", i, 2);
tblInventario.setValueAt("", i, 3);
tblInventario.setValueAt("", i, 4);
tblInventario.setValueAt("", i, 5);
tblInventario.setValueAt("", i, 6);
tblInventario.setValueAt("", i, 7);
}
String sentencia;
sentencia = "SELECT count(*) FROM inventario WHERE producto LIKE '%"+valor+"%' AND clase LIKE '%"+valor2+"%'";
conteo(sentencia);
sentencia = "SELECT producto, clase, marca, modelo, stock, precio_compra, precio_venta_unidad, precio_venta_cantidad FROM inventario " +
"WHERE CONCAT(producto, ' ',marca) LIKE '%"+valor+"%' AND clase LIKE '%"+valor2+"%'";
setsqlc(sentencia);
String datas;
for(int j=0;j<contador;j++){ //llenado de la tabla
try {
rs.next();
if (rs!=null){
datas=getbasedato(1);
tblInventario.setValueAt(datas, j, 0);//agrega el dato a la columna 0 de la fila j
datas=getbasedato(2);
tblInventario.setValueAt(datas, j, 1);
datas=getbasedato(3);
tblInventario.setValueAt(datas, j, 2);
datas=getbasedato(4);
tblInventario.setValueAt(datas, j, 3);
datas=getbasedato(5);
tblInventario.setValueAt(datas, j, 4);
datas=getbasedato(6);
tblInventario.setValueAt(datas, j, 5);
datas=getbasedato(7);
tblInventario.setValueAt(datas, j, 6);
datas=getbasedato(8);
tblInventario.setValueAt(datas, j, 7);
}
else{
break;
}
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
}
}
void CargarTablaServicio(String valor3, String valor4){
int totalRow= tblInventario.getRowCount();
totalRow-=1;
for (int i=0;i<(totalRow);i++){
tblInventario.setValueAt("", i, 0);
tblInventario.setValueAt("", i, 1);
tblInventario.setValueAt("", i, 2);
tblInventario.setValueAt("", i, 3);
}
String sentencia;
sentencia = "SELECT count(*) FROM servicios WHERE nombre LIKE '%"+valor3+"%' AND clase LIKE '%"+valor4+"%'";
conteo(sentencia);
sentencia = "SELECT nombre, clase, valor, descripcion FROM servicios WHERE nombre LIKE '%"+valor3+"%' AND clase LIKE '%"+valor4+"%'";
setsqlc(sentencia);
String datas;
for(int j=0;j<contador;j++){ //llenado de la tabla
try {
rs.next();
if (rs!=null){
datas=getbasedato(1);
tblInventario.setValueAt(datas, j, 0);//agrega el dato a la columna 0 de la fila j
datas=getbasedato(2);
tblInventario.setValueAt(datas, j, 1);
datas=getbasedato(3);
tblInventario.setValueAt(datas, j, 2);
datas=getbasedato(4);
tblInventario.setValueAt(datas, j, 3);
}
else{
break;
}
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
}
}
void CargarTablaCesta(String nombre, String clase, String cantidad, String costo){
modelo= (DefaultTableModel)this.tblCesta.getModel();
modelo.addRow(new Object[filas]);
for (int x=0; x<this.tblCesta.getColumnCount()-1;x++)
{
modelo.setValueAt(cantidad, filas, 0);
modelo.setValueAt(nombre, filas, 1);
modelo.setValueAt(clase, filas, 2);
modelo.setValueAt(costo, filas, 3);
}
filas++;
}
void nfactura(){
//trae el numero en el que va la factura
String nfactura = null;
int numfactura =0;
String sentencia;
sentencia = "SELECT MAX(numero_factura) as numero_factura FROM facturas;";
setsqlc(sentencia);
try {
rs.next();
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
nfactura=getbasedato(1);
numfactura = Integer.valueOf(nfactura);
numfactura = numfactura+1;
TxtNFactura.setText(String.valueOf(numfactura));
}
void factura(){
//toma cada uno de los valores de la cesta para registrar la factura
//llama al metodo registrar_producto
int totalRow= tblCesta.getRowCount();
totalRow-=1;
for(int i=0;i<=(totalRow);i++)
{
int cantidad = Integer.parseInt(String.valueOf(tblCesta.getValueAt(i,0)));
String nombre = String.valueOf(tblCesta.getValueAt(i,1));
String valor = String.valueOf(tblCesta.getValueAt(i,3));
String stock = null;
int nstock = 0;
String sentencia;
sentencia = "SELECT stock FROM inventario WHERE producto ='"+nombre+"';";
setsqlc(sentencia);
try {
rs.next();
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
stock=getbasedato(1);
nstock=Integer.valueOf(stock);
if(nstock>cantidad){
registrar_producto((TxtNFactura.getText()),nombre,String.valueOf(cantidad),valor);
}
else{
JOptionPane.showMessageDialog(this, "el stock no soporta la cantidad");
}
}
}
void venta(){
//toma el numero de la factura actual
//toma el valor total, si se aplicaron descuentos registra tambien el valor con descuento
//registro del cliente
//registro del vendedor
//pide los datos del cliente
String numero_factura = TxtNFactura.getText();
String valor;
String vdescuento;
String nombre = "";
String apellido = "";
String telefono = "";
int dialogButton = JOptionPane.YES_NO_OPTION;
int dialogResult =JOptionPane.showConfirmDialog(null, "¿desea registrar el cliente?","Atencion",dialogButton);
if(dialogResult == JOptionPane.YES_OPTION){
nombre= JOptionPane.showInputDialog(null,"nombre del cliente", "nombre", JOptionPane.QUESTION_MESSAGE);
apellido= JOptionPane.showInputDialog(null,"apellido del cliente", "apellido", JOptionPane.QUESTION_MESSAGE);
telefono= JOptionPane.showInputDialog(null,"telefono del cliente", "telefono", JOptionPane.QUESTION_MESSAGE);
}else{
nombre="default";
apellido="default";
telefono="00000";
}
registro_cliente(nombre, apellido, telefono);
String id = null;
String sentencia;
sentencia="SELECT MAX(ID) as ID FROM clientes;";
setsqlc(sentencia);
try {
rs.next();
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
id=getbasedato(1);
//cproducto = String.valueOf(dos);
String[] vendedores = {
"David Cabral",
"Carlos Andres Gomez",
"Carolina Velasquez",
};
String nvendedor = (String) JOptionPane.showInputDialog(null, "Seleccione un vendedor", "Vendedor", JOptionPane.DEFAULT_OPTION,null,vendedores,vendedores[0]);
String vendedor = "";
switch(nvendedor){
case "David Cabral":
vendedor="1";
break;
case "Carlos Andres Gomez":
vendedor ="4";
break;
case "Carolina Velasquez":
vendedor = "2";
break;
}
valor = TextTotal.getText();
if (jRadioButton2.isSelected()){
vdescuento = TxtDescuentos.getText();
}else{
vdescuento = "0";
}
registrar_venta((TxtNFactura.getText()),valor,vdescuento,id,vendedor);
}
void registro_cliente(String nombre, String apellido, String telefono){
String sentencia_sql;
sentencia_sql= "insert into clientes(NOMBRE,APELLIDO,TELEFONO) values('"+nombre+"','"+apellido+"','"+telefono+"');";
setsqlr(sentencia_sql);
}
void registrar_venta(String numero_factura, String valor, String vdescuento, String id, String vendedor){
String sentencia_sql;
sentencia_sql= "insert into ventas(numero_factura,valor,vdescuento,cliente,vendedor) values('"+numero_factura+"','"+valor+"','"+vdescuento+"','"+id+"','"+vendedor+"');";
setsqlr(sentencia_sql);
}
void registrar_producto(String numero_factura,String producto,String cantidad, String v_venta){
//llama a los metodos update e insertar
update(cantidad,producto);
//se trae el codigo segun el producto de la tabla inventario
String cproducto = null;
//String dos;
String sentencia;
sentencia="SELECT count(*) FROM inventario WHERE producto='"+producto+"';";
conteo(sentencia);
if (contador==1){
sentencia="SELECT codigo FROM inventario WHERE producto='"+producto+"';";
setsqlc(sentencia);
try {
rs.next();
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
cproducto=getbasedato(1);
//cproducto = String.valueOf(dos);
}
else{
JOptionPane.showMessageDialog(null, "mas de un registro coincide", "Error", JOptionPane.ERROR_MESSAGE);
}
insertar(numero_factura,cproducto,cantidad,v_venta);
}
void update(String cantidad,String producto){
//actualiza el inventario
String sentencia_sql;
sentencia_sql = "update inventario set stock=stock-('"+cantidad+"') where producto=('"+producto+"');";
setsqlr(sentencia_sql);
}
void insertar(String numero_factura,String producto,String cantidad, String v_venta){
//realiza el insert de la factura
//cod_productoo servicio es un numero, opcion traer el codigo segun el nombre antes de hacer el insert
String sentencia_sql;
sentencia_sql= "insert into facturas(numero_factura,cod_prod_o_servicio,cantidad,v_venta) values('"+numero_factura+"','"+producto+"','"+cantidad+"','"+v_venta+"');";
setsqlr(sentencia_sql);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jCPanel2 = new com.bolivia.panel.JCPanel();
txtArticulo = new javax.swing.JTextField();
txtServicio = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
ComboClaseArticulo = new javax.swing.JComboBox();
ComboClaseServicio = new javax.swing.JComboBox();
BotonBuscarArt = new org.edisoncor.gui.button.ButtonAeroRound();
BotonBuscarSer = new org.edisoncor.gui.button.ButtonAeroRound();
jScrollPane1 = new javax.swing.JScrollPane();
tblInventario = new javax.swing.JTable();
jLabel3 = new javax.swing.JLabel();
ComboCantidad = new javax.swing.JComboBox();
BotonAgregar = new org.edisoncor.gui.button.ButtonAeroRound();
jLabel4 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
tblCesta = new javax.swing.JTable();
jLabel5 = new javax.swing.JLabel();
TextTotal = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jRadioButton2 = new javax.swing.JRadioButton();
jRadioButton4 = new javax.swing.JRadioButton();
jLabel7 = new javax.swing.JLabel();
TxtDescuentos = new javax.swing.JTextField();
BotonFacturar = new org.edisoncor.gui.button.ButtonAeroRound();
BotonCancelar = new org.edisoncor.gui.button.ButtonAeroRound();
BotonEliminar = new org.edisoncor.gui.button.ButtonAeroRound();
BotonCancelar1 = new org.edisoncor.gui.button.ButtonAeroRound();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
CheckBoxTecnico = new javax.swing.JCheckBox();
BotonTotal = new org.edisoncor.gui.button.ButtonAeroRound();
TxtNFactura = new javax.swing.JTextField();
jLabel10 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jCPanel2.setdarker(false);
jCPanel2.setFirstColor(new java.awt.Color(0, 51, 204));
jCPanel2.setSecondColor(new java.awt.Color(102, 204, 255));
jCPanel2.setUseMode(com.bolivia.panel.USEMODE.DEGRADED);
jCPanel2.setVisibleLogo(false);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("CLASE");
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText("CLASE");
ComboClaseArticulo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Lavadoras", "Neveras", "Ozonizadores", "Licuadoras", "Ollas" }));
ComboClaseServicio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Lavadoras", "Neveras", "Ozonizadores", "Licuadoras", "Ollas" }));
BotonBuscarArt.setForeground(new java.awt.Color(0, 0, 204));
BotonBuscarArt.setText("BUSCAR");
BotonBuscarArt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonBuscarArtActionPerformed(evt);
}
});
BotonBuscarSer.setForeground(new java.awt.Color(0, 0, 204));
BotonBuscarSer.setText("BUSCAR");
BotonBuscarSer.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonBuscarSerActionPerformed(evt);
}
});
tblInventario.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null}
},
new String [] {
"NOMBRE", "CLASE", "MARCA", "MODELO", "STOCK", "P_COMPRA", "P_VENTA UNIDAD", "P_VENTA TECNICO"
}
));
jScrollPane1.setViewportView(tblInventario);
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setText("CANTIDAD");
ComboCantidad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", " " }));
BotonAgregar.setForeground(new java.awt.Color(0, 0, 204));
BotonAgregar.setText("AGREGAR");
BotonAgregar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonAgregarActionPerformed(evt);
}
});
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setText("ELEMENTOS AGREGADOS");
tblCesta.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"CANTIDAD", "NOMBRE", "CLASE", "VALOR"
}
) {
boolean[] canEdit = new boolean [] {
false, false, false, false
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane2.setViewportView(tblCesta);
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
jLabel5.setForeground(new java.awt.Color(255, 255, 255));
jLabel5.setText("$");
TextTotal.setEditable(false);
TextTotal.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel6.setForeground(new java.awt.Color(255, 255, 255));
jLabel6.setText("SE APLICARÁN DESCUENTOS?");
jRadioButton2.setBackground(new java.awt.Color(0, 95, 204));
jRadioButton2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jRadioButton2.setForeground(new java.awt.Color(255, 255, 255));
jRadioButton2.setText("SI");
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
}
});
jRadioButton4.setBackground(new java.awt.Color(20, 100, 250));
jRadioButton4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jRadioButton4.setForeground(new java.awt.Color(255, 255, 255));
jRadioButton4.setText("NO");
jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton4ActionPerformed(evt);
}
});
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
jLabel7.setForeground(new java.awt.Color(255, 255, 255));
jLabel7.setText("TOTAL CON DESCUENTO: $");
BotonFacturar.setForeground(new java.awt.Color(0, 0, 204));
BotonFacturar.setText("FACTURAR");
BotonFacturar.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
BotonFacturar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonFacturarActionPerformed(evt);
}
});
BotonCancelar.setForeground(new java.awt.Color(0, 0, 204));
BotonCancelar.setText("CANCELAR");
BotonCancelar.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
BotonCancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonCancelarActionPerformed(evt);
}
});
BotonEliminar.setForeground(new java.awt.Color(0, 0, 204));
BotonEliminar.setText("ELIMINAR");
BotonEliminar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonEliminarActionPerformed(evt);
}
});
BotonCancelar1.setForeground(new java.awt.Color(0, 0, 204));
BotonCancelar1.setText("SALIR");
BotonCancelar1.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
BotonCancelar1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonCancelar1ActionPerformed(evt);
}
});
jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel8.setForeground(new java.awt.Color(255, 255, 255));
jLabel8.setText("ARTICULO");
jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel9.setForeground(new java.awt.Color(255, 255, 255));
jLabel9.setText("SERVICIO");
CheckBoxTecnico.setBackground(new java.awt.Color(0, 95, 204));
CheckBoxTecnico.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
CheckBoxTecnico.setForeground(new java.awt.Color(255, 255, 255));
CheckBoxTecnico.setText("Precio Técnico");
CheckBoxTecnico.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CheckBoxTecnicoActionPerformed(evt);
}
});
BotonTotal.setForeground(new java.awt.Color(0, 0, 204));
BotonTotal.setText("TOTAL");
BotonTotal.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
BotonTotal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BotonTotalActionPerformed(evt);
}
});
TxtNFactura.setEditable(false);
jLabel10.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel10.setForeground(new java.awt.Color(255, 0, 0));
jLabel10.setText("# FACTURA");
javax.swing.GroupLayout jCPanel2Layout = new javax.swing.GroupLayout(jCPanel2);
jCPanel2.setLayout(jCPanel2Layout);
jCPanel2Layout.setHorizontalGroup(
jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel8)
.addComponent(jLabel9))
.addGap(18, 18, 18)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtArticulo, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtServicio, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(32, 32, 32)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(ComboClaseServicio, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ComboClaseArticulo, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(BotonBuscarSer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BotonBuscarArt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jCPanel2Layout.createSequentialGroup()
.addComponent(TxtNFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(21, 21, 21))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jCPanel2Layout.createSequentialGroup()
.addComponent(jLabel10)
.addGap(37, 37, 37))))
.addGroup(jCPanel2Layout.createSequentialGroup()
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addComponent(jLabel6)
.addGap(18, 18, 18)
.addComponent(jRadioButton2)
.addGap(18, 18, 18)
.addComponent(jRadioButton4))
.addGroup(jCPanel2Layout.createSequentialGroup()
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addComponent(BotonFacturar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(29, 29, 29)
.addComponent(BotonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(30, 30, 30)
.addComponent(BotonCancelar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(TxtDescuentos, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addComponent(BotonEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(BotonTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addGap(18, 18, 18)
.addComponent(TextTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 862, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 862, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(ComboCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(50, 50, 50)
.addComponent(CheckBoxTecnico)
.addGap(116, 116, 116)
.addComponent(BotonAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(17, Short.MAX_VALUE))))
);
jCPanel2Layout.setVerticalGroup(
jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtArticulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)
.addComponent(ComboClaseArticulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BotonBuscarArt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtServicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(ComboClaseServicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BotonBuscarSer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jCPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(TxtNFactura, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(15, 15, 15)))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(ComboCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BotonAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(CheckBoxTecnico))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel4)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(TextTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addComponent(BotonEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jCPanel2Layout.createSequentialGroup()
.addGap(143, 143, 143)
.addComponent(BotonTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(jRadioButton2)
.addComponent(jRadioButton4))
.addGap(18, 18, 18)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(TxtDescuentos)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
.addGroup(jCPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(BotonFacturar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BotonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(BotonCancelar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 889, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jCPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 889, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 573, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jCPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 573, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
);
pack();
}// </editor-fold>
private void BotonBuscarArtActionPerformed(java.awt.event.ActionEvent evt) {
tblInventario.setVisible(true);
jLabel3.setVisible(true);
ComboCantidad.setVisible(true);
CheckBoxTecnico.setVisible(true);
BotonAgregar.setVisible(true);
jLabel4.setVisible(true);
tblCesta.setVisible(true);
String valor = txtArticulo.getText();
String valor2 = ComboClaseArticulo.getSelectedItem().toString();
CargarTablaInventario(valor, valor2);
}
private void BotonBuscarSerActionPerformed(java.awt.event.ActionEvent evt) {
String valor3 = txtServicio.getText();
String valor4 = ComboClaseServicio.getSelectedItem().toString();
CargarTablaServicio(valor3, valor4);
}
private void BotonAgregarActionPerformed(java.awt.event.ActionEvent evt) {
BotonEliminar.setVisible(true);
BotonTotal.setVisible(true);
jLabel5.setVisible(true);
TextTotal.setVisible(true);
jLabel6.setVisible(true);
jRadioButton2.setVisible(true);
jRadioButton4.setVisible(true);
int row = tblInventario.getSelectedRow();
String nombre=tblInventario.getValueAt(row, 0).toString();
String clase=tblInventario.getValueAt(row, 1).toString();
String cantidad= ComboCantidad.getSelectedItem().toString();
String costo=" ";
int ncol = tblInventario.getColumnCount();
boolean selected = CheckBoxTecnico.isSelected();
if(ncol==4){
costo=tblInventario.getValueAt(row, 2).toString();
}else if(selected){
costo=tblInventario.getValueAt(row, 7).toString();
}else{
costo=tblInventario.getValueAt(row, 6).toString();
}
CargarTablaCesta(nombre, clase, cantidad, costo);
}
private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//si está seleccionado mostrar el txt para ingresar valor con descuento
if (jRadioButton2.isSelected()){
jRadioButton4.setSelected(false);
jLabel7.setVisible(true);
TxtDescuentos.setVisible(true);
BotonFacturar.setVisible(true);
}
}
private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (jRadioButton4.isSelected()){
jRadioButton2.setSelected(false);
jLabel7.setVisible(false);
TxtDescuentos.setVisible(false);
BotonFacturar.setVisible(true);
}
}
private void BotonFacturarActionPerformed(java.awt.event.ActionEvent evt) {
//si no lleva una orden de servicio pregunta si desea registrar el cliente, de lo contrario lo debe registrar
// crear los registros correspondientes a factura y venta, verifica si es producto o servicio,
//para orden de servicio crea el registro. despues realiza update en inventario
factura();
venta();
limpiarformulario();
}
private void BotonCancelarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
limpiarformulario();
}
private void BotonEliminarActionPerformed(java.awt.event.ActionEvent evt) {
/*modelo= (DefaultTableModel)this.tblCesta.getModel();
modelo.removeRow(this.tblCesta.getSelectedRow());*/
int cantCol = tblCesta.getColumnCount();
int row = tblInventario.getSelectedRow();
DefaultTableModel tabla = (DefaultTableModel) tblCesta.getModel();
for(int i=0;i<cantCol;i++){
tabla.setValueAt("", row, i);//los parámetros son: valor, fila y columna respectivamente
}
}
private void BotonCancelar1ActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}
private void CheckBoxTecnicoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void BotonTotalActionPerformed(java.awt.event.ActionEvent evt) {
nfactura();
double sumatoria=0;
double cant=0;
double sumatoria1=0;
double mult=0;
int totalRow= tblCesta.getRowCount();
totalRow-=1;
for(int i=0;i<=(totalRow);i++)
{
sumatoria= Double.parseDouble(String.valueOf(tblCesta.getValueAt(i,3)));
cant= Double.parseDouble(String.valueOf(tblCesta.getValueAt(i,0)));
mult = (cant)*sumatoria;
sumatoria1+= mult;
TextTotal.setText(String.valueOf(sumatoria1));
}
BotonFacturar.setVisible(true);
}
public void conteo(String secuencia){
String secuencia1;
secuencia1=secuencia;
try {
rs = stmt.executeQuery(secuencia1);
// get the number of rows from the result set
rs.next();
contador = rs.getInt(1);
}
catch (Exception e) {
e.printStackTrace();
}//fin catch
}
// metodo que retorna un dato de la base de datos
public String getbasedato(int p){
String dato=null;
try{
dato=String.valueOf(rs.getObject(p));
}
catch (Exception e){
e.printStackTrace();
}
return dato;
}
///ejecuta sentencia sql consulta
public void setsqlc(String orden_sql){
try {
rs = stmt.executeQuery (orden_sql);
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
}
//ejecuta sentencia sql insertar o cambiar datos
public void setsqlr(String orden_sql){
try {
stmt.executeUpdate(orden_sql);
} //fin try
catch (Exception e) {
e.printStackTrace();
}//fin catch
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NuevaFactura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NuevaFactura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NuevaFactura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NuevaFactura.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
try{
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","Administrador2015");
stmt = con.createStatement();
}
catch(Exception e){
e.printStackTrace();
}
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NuevaFactura().setVisible(true);
}
});
}
Hola de nuevo, prueba el codigo que te pongo. Si te fijas, lo que te esta pasando, es que el objeto Connection y el objeto Statement los estas iniciando en el metodo main, ese metodo, solo se ejecuta cuando le das como tu dices boton derecho, run file, si lo que estas haciendo es llamando ese formulario desde otra clase, mediante el constructor, la inicializacion de con y stmt deben estar en el constructor.
Bueno, prueba con ese codigo y ya nos cuentas. Un saludo
graaaacias loderain puse lo que modificaste, (menos lo ultimo que ya estaba pero que yo no lo había visto, jeje), el caso es que era lo que dijiste del constructor, muchísimas gracias, ahí voy aprendiendo. Cada vez me doy cuenta de lo mucho que hay por aprender y en serio gracias por el tiempo que dedican a ayudar.
hola todos
auxilio!!!, tengo un formulario que funciona muy bien solo osea clic derecho run file, pero con el run project no y me salen errores de nullpointerexception en el formulario... ¿porque?,
pd: no puse el codigo porque es super largo, pero si es necesario lo pongo
muchas gracias de antemano