Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package productmanagement;
- import com.itextpdf.text.DocumentException;
- import com.sun.pdfview.PDFFile;
- import com.sun.pdfview.PDFPage;
- import com.sun.pdfview.PagePanel;
- import java.awt.List;
- import java.awt.PopupMenu;
- import java.awt.event.ItemEvent;
- import java.awt.event.ItemListener;
- import java.io.File;
- import java.io.IOException;
- import java.io.RandomAccessFile;
- import java.nio.ByteBuffer;
- import java.nio.channels.FileChannel;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.Vector;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- import static javax.swing.JOptionPane.ERROR_MESSAGE;
- import static javax.swing.JOptionPane.showMessageDialog;
- import javax.swing.table.DefaultTableModel;
- import javax.swing.table.TableModel;
- public class CreateInvoice extends javax.swing.JFrame {
- private static String USERNAME="root";
- private static String PASS="";
- private static String CONN="jdbc:mysql://localhost:3306/sai";
- int a=0;
- int flag;
- int totalLen=0;
- int flag1=0;
- int val=0;
- int val1=0;
- int count1=0;
- String prodID=null;
- String prodName=null;
- int prodQuantity;
- String prodQ=null;
- public CreateInvoice() throws ClassNotFoundException, SQLException {
- initComponents();
- //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- Connection con= null;
- con = (Connection) DriverManager.getConnection(CONN,USERNAME,PASS);
- Statement st = con.createStatement();
- ResultSet r=st.executeQuery("select * from product");
- while (r.next()) {
- this.jComboBox1.addItem(r.getString("prodid"));
- }
- setCombos(0, 0);
- con.close();
- }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- jLabel3 = new javax.swing.JLabel();
- jLabel10 = new javax.swing.JLabel();
- jLabel11 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- jLabel4 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jComboBox2 = new javax.swing.JComboBox<>();
- jLabel6 = new javax.swing.JLabel();
- jTextField4 = new javax.swing.JTextField();
- jComboBox1 = new javax.swing.JComboBox<>();
- jButton5 = new javax.swing.JButton();
- jButton6 = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTable1 = new javax.swing.JTable();
- jSeparator2 = new javax.swing.JSeparator();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jButton4 = new javax.swing.JButton();
- jButton3 = new javax.swing.JButton();
- jLabel1 = new javax.swing.JLabel();
- jMenuBar1 = new javax.swing.JMenuBar();
- jMenu1 = new javax.swing.JMenu();
- jMenuItem4 = new javax.swing.JMenuItem();
- jMenuItem5 = new javax.swing.JMenuItem();
- jMenuItem6 = new javax.swing.JMenuItem();
- jMenu2 = new javax.swing.JMenu();
- jMenuItem1 = new javax.swing.JMenuItem();
- jMenuItem2 = new javax.swing.JMenuItem();
- jMenuItem3 = new javax.swing.JMenuItem();
- jMenu3 = new javax.swing.JMenu();
- jMenuItem7 = new javax.swing.JMenuItem();
- jMenu4 = new javax.swing.JMenu();
- jMenuItem8 = new javax.swing.JMenuItem();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("Print Invoice/ Bill");
- setMinimumSize(new java.awt.Dimension(822, 453));
- setResizable(false);
- jPanel1.setLayout(null);
- jLabel3.setFont(new java.awt.Font("Yu Gothic", 3, 24)); // NOI18N
- jLabel3.setForeground(new java.awt.Color(255, 0, 204));
- jLabel3.setText("Invoice/Bill");
- jPanel1.add(jLabel3);
- jLabel3.setBounds(330, 30, 250, 30);
- jLabel10.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
- jLabel10.setForeground(new java.awt.Color(204, 255, 204));
- jLabel10.setText("Designed & Developed by: Parmeshwar Nawale ");
- jPanel1.add(jLabel10);
- jLabel10.setBounds(10, 0, 320, 20);
- jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
- jLabel11.setForeground(new java.awt.Color(204, 255, 204));
- jLabel11.setText("E-mail: parmeshwarnawale@gmail.com Mob:9552509589/9545072260");
- jPanel1.add(jLabel11);
- jLabel11.setBounds(290, 0, 470, 20);
- jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel2.setForeground(new java.awt.Color(255, 0, 204));
- jLabel2.setText("PRODUCT NAME");
- jPanel1.add(jLabel2);
- jLabel2.setBounds(10, 110, 130, 40);
- jTextField1.setEnabled(false);
- jPanel1.add(jTextField1);
- jTextField1.setBounds(120, 120, 180, 30);
- jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel4.setForeground(new java.awt.Color(255, 0, 204));
- jLabel4.setText("PRODUCT ID");
- jPanel1.add(jLabel4);
- jLabel4.setBounds(10, 70, 120, 30);
- jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel5.setForeground(new java.awt.Color(255, 0, 204));
- jLabel5.setText("QUANTITY");
- jPanel1.add(jLabel5);
- jLabel5.setBounds(310, 70, 110, 30);
- jComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Select Quantity" }));
- jPanel1.add(jComboBox2);
- jComboBox2.setBounds(390, 70, 180, 30);
- jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- jLabel6.setForeground(new java.awt.Color(255, 0, 204));
- jLabel6.setText("CUST NAME");
- jPanel1.add(jLabel6);
- jLabel6.setBounds(310, 120, 90, 20);
- jTextField4.addFocusListener(new java.awt.event.FocusAdapter() {
- public void focusLost(java.awt.event.FocusEvent evt) {
- jTextField4FocusLost(evt);
- }
- });
- jTextField4.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jTextField4MouseClicked(evt);
- }
- });
- jTextField4.addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyReleased(java.awt.event.KeyEvent evt) {
- jTextField4KeyReleased(evt);
- }
- });
- jPanel1.add(jTextField4);
- jTextField4.setBounds(390, 120, 180, 30);
- jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Select Product ID" }));
- jComboBox1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jComboBox1ActionPerformed(evt);
- }
- });
- jPanel1.add(jComboBox1);
- jComboBox1.setBounds(120, 70, 180, 30);
- jButton5.setBackground(new java.awt.Color(153, 255, 153));
- jButton5.setFont(new java.awt.Font("Mongolian Baiti", 1, 18)); // NOI18N
- jButton5.setText("Add To Cart");
- jButton5.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
- jButton5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton5ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton5);
- jButton5.setBounds(600, 70, 140, 30);
- jButton6.setBackground(new java.awt.Color(153, 255, 153));
- jButton6.setFont(new java.awt.Font("Mongolian Baiti", 1, 18)); // NOI18N
- jButton6.setText("Remove cart");
- jButton6.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
- jButton6.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton6ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton6);
- jButton6.setBounds(600, 120, 140, 30);
- jTable1.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- },
- new String [] {
- "Product ID", "Product Name", "Product Type", "Product Price", "Quantity"
- }
- ));
- jTable1.setSelectionForeground(new java.awt.Color(204, 204, 255));
- jScrollPane1.setViewportView(jTable1);
- jPanel1.add(jScrollPane1);
- jScrollPane1.setBounds(0, 160, 820, 190);
- jPanel1.add(jSeparator2);
- jSeparator2.setBounds(0, 350, 820, 10);
- jButton1.setBackground(new java.awt.Color(153, 255, 153));
- jButton1.setFont(new java.awt.Font("Mongolian Baiti", 1, 18)); // NOI18N
- jButton1.setText("PRINT");
- jButton1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton1);
- jButton1.setBounds(30, 370, 140, 30);
- jButton2.setBackground(new java.awt.Color(153, 255, 153));
- jButton2.setFont(new java.awt.Font("Mongolian Baiti", 1, 18)); // NOI18N
- jButton2.setText("PREVIEW ");
- jButton2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton2);
- jButton2.setBounds(190, 370, 140, 30);
- jButton4.setBackground(new java.awt.Color(153, 255, 153));
- jButton4.setFont(new java.awt.Font("Mongolian Baiti", 1, 18)); // NOI18N
- jButton4.setText("VIEW ALL PRODUCTS");
- jButton4.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
- jButton4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton4ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton4);
- jButton4.setBounds(340, 370, 220, 30);
- jButton3.setBackground(new java.awt.Color(153, 255, 153));
- jButton3.setFont(new java.awt.Font("Mongolian Baiti", 1, 18)); // NOI18N
- jButton3.setText("CANCLE");
- jButton3.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- jPanel1.add(jButton3);
- jButton3.setBounds(570, 370, 140, 30);
- jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Hardware/loginImage.jpg"))); // NOI18N
- jLabel1.setText("jLabel1");
- jPanel1.add(jLabel1);
- jLabel1.setBounds(0, 0, 820, 430);
- jMenu1.setText("File");
- jMenuItem4.setText("New Customer");
- jMenu1.add(jMenuItem4);
- jMenuItem5.setText("Update Customer");
- jMenu1.add(jMenuItem5);
- jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
- jMenuItem6.setText("Logout");
- jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem6ActionPerformed(evt);
- }
- });
- jMenu1.add(jMenuItem6);
- jMenuBar1.add(jMenu1);
- jMenu2.setText("Edit Products");
- jMenuItem1.setText("Add New Product");
- jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem1ActionPerformed(evt);
- }
- });
- jMenu2.add(jMenuItem1);
- jMenuItem2.setText("Remove Exiting Product");
- jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem2ActionPerformed(evt);
- }
- });
- jMenu2.add(jMenuItem2);
- jMenuItem3.setText("Update Product Info");
- jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem3ActionPerformed(evt);
- }
- });
- jMenu2.add(jMenuItem3);
- jMenuBar1.add(jMenu2);
- jMenu3.setText("Print");
- jMenuItem7.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
- jMenuItem7.setText("Print Bill");
- jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem7ActionPerformed(evt);
- }
- });
- jMenu3.add(jMenuItem7);
- jMenuBar1.add(jMenu3);
- jMenu4.setText("Profit");
- jMenuItem8.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
- jMenuItem8.setText("Total Income");
- jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jMenuItem8ActionPerformed(evt);
- }
- });
- jMenu4.add(jMenuItem8);
- jMenuBar1.add(jMenu4);
- setJMenuBar(jMenuBar1);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>//GEN-END:initComponents
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
- // TODO add your handling code here:
- MainFrm mainFrm=new MainFrm();
- this.hide();
- mainFrm.show();
- }//GEN-LAST:event_jButton3ActionPerformed
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
- // TODO add your handling code here:
- ArrayList<String> proId=new ArrayList<String>();
- ArrayList<String> proQ=new ArrayList<String>();
- DefaultTableModel dm = (DefaultTableModel)jTable1.getModel();
- DefaultTableModel dm1 = (DefaultTableModel)jTable1.getModel();
- Vector data = dm.getDataVector();
- int row = jTable1.getRowCount();
- if(row<=0)
- {
- showMessageDialog(null, "Cart is empty please add product items into the stack first....", "No product in cart",JOptionPane.ERROR_MESSAGE);
- }
- else
- {
- int column = jTable1.getColumnCount();
- for (int j = 0; j < row; j++) {
- for (int i = 0; i < column; i++) {
- System.out.println(jTable1.getValueAt(j, i));
- }
- proId.add((String) jTable1.getValueAt(j, 0));
- proQ.add((String) jTable1.getValueAt(j, 4));
- }
- int size1=proId.size();
- System.out.println(size1);
- for(int i=0;i<size1;i++)
- {
- try {
- DatabaseConnectionTest dbCon=new DatabaseConnectionTest();
- dbCon.soldProd(proId.get(i),proQ.get(i),jTextField4.getText());
- System.out.println(proId.get(i));
- System.out.println(proQ.get(i));
- }
- /* String custName=jTextField4.getText();
- String RESULT= "billing\\"+custName+".pdf";
- if(Files.exists(Paths.get(RESULT)))
- {
- showMessageDialog(null, "File already exist with this customer...!", "Failed creating invoice", ERROR_MESSAGE);
- }
- else
- {
- if(jTextField1.getText().length()==0 || jComboBox1.getSelectedIndex()==0 || jComboBox2.getSelectedIndex()<0 || jTextField4.getText().length()==0)
- {
- showMessageDialog(null, "Fill all the details!", "Filed Emty error", ERROR_MESSAGE);
- }
- else
- {
- String prodID= (String) jComboBox1.getSelectedItem();
- String prodName= jTextField1.getText();
- String prodQuantity = (String) jComboBox2.getSelectedItem();
- showMessageDialog(null, "Please wait we are in process....", "Waiting for Invoice ",JOptionPane.CLOSED_OPTION);
- HelloWorld printInvoice=new HelloWorld();
- try {
- printInvoice.getCust(custName, prodID, prodName, prodQuantity,0);
- this.setup1(custName,0);
- // printInvoice.createPdf(jTextField1.getText(),jTextField2.getText(),jTextField3.getText(),jTextField4.getText(),RESULT);
- } catch (DocumentException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- */ catch (SQLException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- jComboBox2.removeAllItems();
- jTextField4.setText("");
- while(dm.getRowCount()>0)
- {
- dm.removeRow(0);
- }
- showMessageDialog(null, "Product Deducted from stock successfuly....", "Invoice Generated",JOptionPane.CLOSED_OPTION);
- }
- }//GEN-LAST:event_jButton1ActionPerformed
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
- // TODO add your handling code here:
- ArrayList<String> proId=new ArrayList<String>();
- ArrayList<String> prodName=new ArrayList<String>();
- ArrayList<String> proddQ=new ArrayList<String>();
- ArrayList<String> prodPrice=new ArrayList<String>();
- DefaultTableModel dm = (DefaultTableModel)jTable1.getModel();
- Vector data = dm.getDataVector();
- int row = jTable1.getRowCount();
- if(row<=0)
- {
- showMessageDialog(null, "Cart is empty please add product items into the stack first....", "No product in cart",JOptionPane.ERROR_MESSAGE);
- }
- else
- {
- try {
- int column = jTable1.getColumnCount();
- for (int j = 0; j < row; j++) {
- proId.add((String) jTable1.getValueAt(j, 0));
- prodName.add((String) jTable1.getValueAt(j, 1));
- prodPrice.add((String) jTable1.getValueAt(j, 3));
- proddQ.add((String) jTable1.getValueAt(j, 4));
- }
- DisplayEmpData dis=new DisplayEmpData();
- dis.showTableData1(proId,prodName,prodPrice,proddQ,jTextField4.getText());
- }
- /* if(jTextField1.getText().length()==0 || jComboBox1.getSelectedIndex()==0 || jComboBox2.getSelectedIndex()==0 || jTextField4.getText().length()==0)
- {
- showMessageDialog(null, "Fill all the details!", "Filed Emty error", ERROR_MESSAGE);
- }
- else
- {
- //PriviewFrm priviewFrm=new PriviewFrm();
- String prodID= (String) jComboBox1.getSelectedItem();
- String prodName= jTextField1.getText();
- String prodQuantity = (String) jComboBox2.getSelectedItem();
- String custName=jTextField4.getText();
- String path="TempFile\\"+custName+".pdf";
- showMessageDialog(null, "Please wait we are in process...."+path, "Waiting for Invoice ",JOptionPane.CLOSED_OPTION);
- HelloWorld printInvoice=new HelloWorld();
- try {
- printInvoice.getCust(custName, prodID, prodName, prodQuantity,1);
- this.setup1(jTextField4.getText(),1);
- } catch (IOException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- } catch (DocumentException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- }
- }*/ catch (ClassNotFoundException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }//GEN-LAST:event_jButton2ActionPerformed
- private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
- // TODO add your handling code here:
- DisplayEmpData dis=new DisplayEmpData();
- try {
- dis.showTableData();
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- }
- }//GEN-LAST:event_jButton4ActionPerformed
- private void jTextField4FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField4FocusLost
- // TODO add your handling code here:
- }//GEN-LAST:event_jTextField4FocusLost
- private void jTextField4KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField4KeyReleased
- // TODO add your handling code here:
- }//GEN-LAST:event_jTextField4KeyReleased
- private void jTextField4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField4MouseClicked
- // TODO add your handling code here:
- }//GEN-LAST:event_jTextField4MouseClicked
- private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
- // TODO add your handling code here:
- }//GEN-LAST:event_jComboBox1ActionPerformed
- private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
- // TODO add your handling code here:
- if(jComboBox1.getSelectedIndex()==0 || jComboBox2.getSelectedIndex()<0 || jTextField1.getText().length()==0 || jTextField4.getText().length()==0)
- {
- showMessageDialog(null, "Fill all the details!", "Filed Emty error", ERROR_MESSAGE);
- }
- else
- {
- try {
- DefaultTableModel dm = (DefaultTableModel)jTable1.getModel();
- jTable1.setModel(dm);
- Vector<Object> data = new Vector<Object>();
- data.add(jComboBox1.getSelectedItem());
- data.add(jTextField1.getText());
- DatabaseConnectionTest dbCon=new DatabaseConnectionTest();
- data.add(dbCon.getProdType(prodID));
- data.add(dbCon.getPrice(prodID));
- prodQ=(String) jComboBox2.getSelectedItem();
- data.add(prodQ);
- dm.addRow(data);
- int item=jComboBox2.getSelectedIndex();
- int count=jComboBox2.getItemCount()-1;
- count =count-item;
- setCombos(count,1);
- // jTextField4.setText("");
- } catch (SQLException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }//GEN-LAST:event_jButton5ActionPerformed
- private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
- // TODO add your handling code here:
- DefaultTableModel dm = (DefaultTableModel)jTable1.getModel();
- jTable1.setModel(dm);
- int row;
- int cal;
- String v;
- int size1;
- if(jTable1.getSelectedRow()<0)
- {
- showMessageDialog(null, "Please select the row to remove product from cart!", "Row Select", ERROR_MESSAGE);
- }
- else
- { row=jTable1.getSelectedRow();
- v=(String) dm.getValueAt(row, 4);
- size1=jComboBox2.getItemCount();
- jComboBox2.removeAllItems();
- for(int i=1;i<=size1;i++)
- {
- jComboBox2.addItem((Integer.toString(i)));
- }
- dm.removeRow(row);
- }
- }//GEN-LAST:event_jButton6ActionPerformed
- private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
- // TODO add your handling code here:
- Login log=new Login();
- this.hide();
- log.show();
- }//GEN-LAST:event_jMenuItem6ActionPerformed
- private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
- // TODO add your handling code here:
- AddProduct addPrd=new AddProduct();
- this.hide();
- addPrd.show();
- }//GEN-LAST:event_jMenuItem1ActionPerformed
- private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
- // TODO add your handling code here:
- }//GEN-LAST:event_jMenuItem2ActionPerformed
- private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
- // TODO add your handling code here:
- UpdateProduct updateProd;
- try {
- updateProd = new UpdateProduct();
- this.hide();
- updateProd.show();
- } catch (SQLException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- }
- }//GEN-LAST:event_jMenuItem3ActionPerformed
- private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
- try {
- // TODO add your handling code here:
- this.hide();
- CreateInvoice createInvoice=new CreateInvoice();
- createInvoice.show();
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(ViewProduct.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(ViewProduct.class.getName()).log(Level.SEVERE, null, ex);
- }
- }//GEN-LAST:event_jMenuItem7ActionPerformed
- private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
- try {
- // TODO add your handling code here:
- DisplayEmpData dis=new DisplayEmpData();
- dis.showTableData2();
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex);
- }
- }//GEN-LAST:event_jMenuItem8ActionPerformed
- public boolean isNum(String str)
- {
- if(!str.matches("[0-9]+"))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public void setup1(String custName, int num) throws IOException, DocumentException, SQLException
- {
- String prodID= (String) jComboBox1.getSelectedItem();
- String prodName= jTextField1.getText();
- String prodQuantity = (String) jComboBox2.getSelectedItem();
- JFrame frame = new JFrame("PDF Test");
- PagePanel panel = new PagePanel();
- frame.add(panel);
- frame.pack();
- frame.setVisible(true);
- String path="";
- if(num==0)
- {
- path="billing\\"+custName+".pdf";
- }
- else
- {
- path="TempFile\\"+custName+".pdf";
- }
- File file = new File(path);
- if(file.exists() && num==0)
- {
- num=0;
- RandomAccessFile raf = new RandomAccessFile(file, "r");
- FileChannel channel = raf.getChannel();
- ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY,
- 0, channel.size());
- PDFFile pdffile = new PDFFile(buf);
- PDFPage page = pdffile.getPage(0);
- panel.showPage(page);
- }
- else
- {
- String path1=file.getAbsolutePath();
- RandomAccessFile raf = new RandomAccessFile(file, "r");
- FileChannel channel = raf.getChannel();
- ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY,
- 0, channel.size());
- PDFFile pdffile = new PDFFile(buf);
- PDFPage page = pdffile.getPage(0);
- panel.showPage(page);
- if(num==1)
- {
- frame.addWindowListener(new java.awt.event.WindowAdapter() {
- @Override
- public void windowClosing(java.awt.event.WindowEvent windowEvent) {
- flag=0;
- try {
- this.finalize();
- file.delete();
- } catch (Throwable ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- }
- showMessageDialog(null, "file deleted "+path1, "File deleted", JOptionPane.CLOSED_OPTION);
- }
- });
- }
- else
- {
- frame.addWindowListener(new java.awt.event.WindowAdapter() {
- @Override
- public void windowClosing(java.awt.event.WindowEvent windowEvent) {
- frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
- flag=1;
- }
- });
- }
- if(flag==0)
- {
- try {
- this.finalize();
- file.delete();
- } catch (Throwable ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- }
- public static void main(String args[]) throws SQLException {
- 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(CreateInvoice.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(CreateInvoice.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(CreateInvoice.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(CreateInvoice.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- new CreateInvoice().setVisible(true);
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- });
- }
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JButton jButton4;
- private javax.swing.JButton jButton5;
- private javax.swing.JButton jButton6;
- private javax.swing.JComboBox<String> jComboBox1;
- private javax.swing.JComboBox<String> jComboBox2;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel10;
- private javax.swing.JLabel jLabel11;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JLabel jLabel6;
- private javax.swing.JMenu jMenu1;
- private javax.swing.JMenu jMenu2;
- private javax.swing.JMenu jMenu3;
- private javax.swing.JMenu jMenu4;
- private javax.swing.JMenuBar jMenuBar1;
- private javax.swing.JMenuItem jMenuItem1;
- private javax.swing.JMenuItem jMenuItem2;
- private javax.swing.JMenuItem jMenuItem3;
- private javax.swing.JMenuItem jMenuItem4;
- private javax.swing.JMenuItem jMenuItem5;
- private javax.swing.JMenuItem jMenuItem6;
- private javax.swing.JMenuItem jMenuItem7;
- private javax.swing.JMenuItem jMenuItem8;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JSeparator jSeparator2;
- private javax.swing.JTable jTable1;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTextField jTextField4;
- // End of variables declaration//GEN-END:variables
- public void setCombos(int count, int i) throws SQLException
- {
- if(i==1)
- {
- if(count==0)
- {
- jComboBox2.removeAllItems();
- showMessageDialog(null, "No Products available in stock", "Product Stock empty.",JOptionPane.OK_CANCEL_OPTION);
- }
- else
- {
- jComboBox2.removeAllItems();
- for(int j=1;j<=count;j++)
- {
- jComboBox2.addItem(""+j);
- }
- }
- }
- else
- {
- count1=count;
- ArrayList al=new ArrayList();
- jComboBox1.addItemListener(new ItemListener() {
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- try {
- count1=getSum();
- System.out.println(count1);
- prodID=(String) jComboBox1.getSelectedItem();
- DatabaseConnectionTest dbCon=new DatabaseConnectionTest();
- prodName=dbCon.getProdName(prodID);
- prodQuantity=dbCon.getQuantity(prodID);
- totalLen=prodQuantity;
- System.out.println(totalLen);
- jTextField1.setText(prodName);
- jComboBox2.removeAllItems();
- //System.out.println(""+al.size());
- if(al.isEmpty())
- {
- for(int j=1;j<=totalLen-count1;j++)
- {
- prodQ=Integer.toString(j);
- jComboBox2.addItem(prodQ);
- }
- }
- else
- {
- // for(int p=0;p<al.size();p++)
- // System.out.println(""+al.get(p));
- for(int j=1;j<=(totalLen-count1);j++)
- {
- prodQ=Integer.toString(j);
- jComboBox2.addItem(prodQ);
- }
- }
- } catch (SQLException ex) {
- Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private int getSum() {
- int sum = 0;
- DefaultTableModel dm= (DefaultTableModel) jTable1.getModel();
- int row=dm.getRowCount();
- int col=dm.getColumnCount();
- for(int k=0;k<row;k++)
- {
- for(int m=0;m<col;m++)
- {
- if(jComboBox1.getSelectedItem().equals(dm.getValueAt(k, m)))
- {
- val=Integer.parseInt((String) dm.getValueAt(k, 4));
- sum=sum+val;
- flag1=1;
- }
- if(flag1<1)
- {
- count1=0;
- }
- }
- }
- return sum;
- }
- });
- }
- }
- }
Add Comment
Please, Sign In to add comment