Guest User

Untitled

a guest
Feb 2nd, 2018
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.71 KB | None | 0 0
  1. package productmanagement;
  2.  
  3. import com.itextpdf.text.DocumentException;
  4. import com.sun.pdfview.PDFFile;
  5. import com.sun.pdfview.PDFPage;
  6. import com.sun.pdfview.PagePanel;
  7. import java.awt.List;
  8. import java.awt.PopupMenu;
  9. import java.awt.event.ItemEvent;
  10. import java.awt.event.ItemListener;
  11. import java.io.File;
  12. import java.io.IOException;
  13. import java.io.RandomAccessFile;
  14. import java.nio.ByteBuffer;
  15. import java.nio.channels.FileChannel;
  16. import java.nio.file.Files;
  17. import java.nio.file.Paths;
  18. import java.sql.Connection;
  19. import java.sql.DriverManager;
  20. import java.sql.ResultSet;
  21. import java.sql.SQLException;
  22. import java.sql.Statement;
  23. import java.util.ArrayList;
  24. import java.util.Vector;
  25. import java.util.logging.Level;
  26. import java.util.logging.Logger;
  27. import javax.swing.JComboBox;
  28. import javax.swing.JFrame;
  29. import javax.swing.JOptionPane;
  30. import static javax.swing.JOptionPane.ERROR_MESSAGE;
  31. import static javax.swing.JOptionPane.showMessageDialog;
  32. import javax.swing.table.DefaultTableModel;
  33. import javax.swing.table.TableModel;
  34.  
  35. public class CreateInvoice extends javax.swing.JFrame {
  36.  
  37. private static String USERNAME="root";
  38. private static String PASS="";
  39. private static String CONN="jdbc:mysql://localhost:3306/sai";
  40. int a=0;
  41. int flag;
  42. int totalLen=0;
  43. int flag1=0;
  44. int val=0;
  45. int val1=0;
  46. int count1=0;
  47. String prodID=null;
  48. String prodName=null;
  49. int prodQuantity;
  50. String prodQ=null;
  51. public CreateInvoice() throws ClassNotFoundException, SQLException {
  52. initComponents();
  53. //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  54. Connection con= null;
  55.  
  56. con = (Connection) DriverManager.getConnection(CONN,USERNAME,PASS);
  57. Statement st = con.createStatement();
  58. ResultSet r=st.executeQuery("select * from product");
  59.  
  60. while (r.next()) {
  61.  
  62. this.jComboBox1.addItem(r.getString("prodid"));
  63. }
  64. setCombos(0, 0);
  65.  
  66. con.close();
  67.  
  68. }
  69.  
  70.  
  71. @SuppressWarnings("unchecked")
  72. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  73. private void initComponents() {
  74.  
  75. jPanel1 = new javax.swing.JPanel();
  76. jLabel3 = new javax.swing.JLabel();
  77. jLabel10 = new javax.swing.JLabel();
  78. jLabel11 = new javax.swing.JLabel();
  79. jLabel2 = new javax.swing.JLabel();
  80. jTextField1 = new javax.swing.JTextField();
  81. jLabel4 = new javax.swing.JLabel();
  82. jLabel5 = new javax.swing.JLabel();
  83. jComboBox2 = new javax.swing.JComboBox<>();
  84. jLabel6 = new javax.swing.JLabel();
  85. jTextField4 = new javax.swing.JTextField();
  86. jComboBox1 = new javax.swing.JComboBox<>();
  87. jButton5 = new javax.swing.JButton();
  88. jButton6 = new javax.swing.JButton();
  89. jScrollPane1 = new javax.swing.JScrollPane();
  90. jTable1 = new javax.swing.JTable();
  91. jSeparator2 = new javax.swing.JSeparator();
  92. jButton1 = new javax.swing.JButton();
  93. jButton2 = new javax.swing.JButton();
  94. jButton4 = new javax.swing.JButton();
  95. jButton3 = new javax.swing.JButton();
  96. jLabel1 = new javax.swing.JLabel();
  97. jMenuBar1 = new javax.swing.JMenuBar();
  98. jMenu1 = new javax.swing.JMenu();
  99. jMenuItem4 = new javax.swing.JMenuItem();
  100. jMenuItem5 = new javax.swing.JMenuItem();
  101. jMenuItem6 = new javax.swing.JMenuItem();
  102. jMenu2 = new javax.swing.JMenu();
  103. jMenuItem1 = new javax.swing.JMenuItem();
  104. jMenuItem2 = new javax.swing.JMenuItem();
  105. jMenuItem3 = new javax.swing.JMenuItem();
  106. jMenu3 = new javax.swing.JMenu();
  107. jMenuItem7 = new javax.swing.JMenuItem();
  108. jMenu4 = new javax.swing.JMenu();
  109. jMenuItem8 = new javax.swing.JMenuItem();
  110.  
  111. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  112. setTitle("Print Invoice/ Bill");
  113. setMinimumSize(new java.awt.Dimension(822, 453));
  114. setResizable(false);
  115.  
  116. jPanel1.setLayout(null);
  117.  
  118. jLabel3.setFont(new java.awt.Font("Yu Gothic", 3, 24)); // NOI18N
  119. jLabel3.setForeground(new java.awt.Color(255, 0, 204));
  120. jLabel3.setText("Invoice/Bill");
  121. jPanel1.add(jLabel3);
  122. jLabel3.setBounds(330, 30, 250, 30);
  123.  
  124. jLabel10.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
  125. jLabel10.setForeground(new java.awt.Color(204, 255, 204));
  126. jLabel10.setText("Designed & Developed by: Parmeshwar Nawale ");
  127. jPanel1.add(jLabel10);
  128. jLabel10.setBounds(10, 0, 320, 20);
  129.  
  130. jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
  131. jLabel11.setForeground(new java.awt.Color(204, 255, 204));
  132. jLabel11.setText("E-mail: parmeshwarnawale@gmail.com Mob:9552509589/9545072260");
  133. jPanel1.add(jLabel11);
  134. jLabel11.setBounds(290, 0, 470, 20);
  135.  
  136. jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  137. jLabel2.setForeground(new java.awt.Color(255, 0, 204));
  138. jLabel2.setText("PRODUCT NAME");
  139. jPanel1.add(jLabel2);
  140. jLabel2.setBounds(10, 110, 130, 40);
  141.  
  142. jTextField1.setEnabled(false);
  143. jPanel1.add(jTextField1);
  144. jTextField1.setBounds(120, 120, 180, 30);
  145.  
  146. jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  147. jLabel4.setForeground(new java.awt.Color(255, 0, 204));
  148. jLabel4.setText("PRODUCT ID");
  149. jPanel1.add(jLabel4);
  150. jLabel4.setBounds(10, 70, 120, 30);
  151.  
  152. jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  153. jLabel5.setForeground(new java.awt.Color(255, 0, 204));
  154. jLabel5.setText("QUANTITY");
  155. jPanel1.add(jLabel5);
  156. jLabel5.setBounds(310, 70, 110, 30);
  157.  
  158. jComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Select Quantity" }));
  159. jPanel1.add(jComboBox2);
  160. jComboBox2.setBounds(390, 70, 180, 30);
  161.  
  162. jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  163. jLabel6.setForeground(new java.awt.Color(255, 0, 204));
  164. jLabel6.setText("CUST NAME");
  165. jPanel1.add(jLabel6);
  166. jLabel6.setBounds(310, 120, 90, 20);
  167.  
  168. jTextField4.addFocusListener(new java.awt.event.FocusAdapter() {
  169. public void focusLost(java.awt.event.FocusEvent evt) {
  170. jTextField4FocusLost(evt);
  171. }
  172. });
  173. jTextField4.addMouseListener(new java.awt.event.MouseAdapter() {
  174. public void mouseClicked(java.awt.event.MouseEvent evt) {
  175. jTextField4MouseClicked(evt);
  176. }
  177. });
  178. jTextField4.addKeyListener(new java.awt.event.KeyAdapter() {
  179. public void keyReleased(java.awt.event.KeyEvent evt) {
  180. jTextField4KeyReleased(evt);
  181. }
  182. });
  183. jPanel1.add(jTextField4);
  184. jTextField4.setBounds(390, 120, 180, 30);
  185.  
  186. jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Select Product ID" }));
  187. jComboBox1.addActionListener(new java.awt.event.ActionListener() {
  188. public void actionPerformed(java.awt.event.ActionEvent evt) {
  189. jComboBox1ActionPerformed(evt);
  190. }
  191. });
  192. jPanel1.add(jComboBox1);
  193. jComboBox1.setBounds(120, 70, 180, 30);
  194.  
  195. jButton5.setBackground(new java.awt.Color(153, 255, 153));
  196. jButton5.setFont(new java.awt.Font("Mongolian Baiti", 1, 18)); // NOI18N
  197. jButton5.setText("Add To Cart");
  198. jButton5.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  199. jButton5.addActionListener(new java.awt.event.ActionListener() {
  200. public void actionPerformed(java.awt.event.ActionEvent evt) {
  201. jButton5ActionPerformed(evt);
  202. }
  203. });
  204. jPanel1.add(jButton5);
  205. jButton5.setBounds(600, 70, 140, 30);
  206.  
  207. jButton6.setBackground(new java.awt.Color(153, 255, 153));
  208. jButton6.setFont(new java.awt.Font("Mongolian Baiti", 1, 18)); // NOI18N
  209. jButton6.setText("Remove cart");
  210. jButton6.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  211. jButton6.addActionListener(new java.awt.event.ActionListener() {
  212. public void actionPerformed(java.awt.event.ActionEvent evt) {
  213. jButton6ActionPerformed(evt);
  214. }
  215. });
  216. jPanel1.add(jButton6);
  217. jButton6.setBounds(600, 120, 140, 30);
  218.  
  219. jTable1.setModel(new javax.swing.table.DefaultTableModel(
  220. new Object [][] {
  221.  
  222. },
  223. new String [] {
  224. "Product ID", "Product Name", "Product Type", "Product Price", "Quantity"
  225. }
  226. ));
  227. jTable1.setSelectionForeground(new java.awt.Color(204, 204, 255));
  228. jScrollPane1.setViewportView(jTable1);
  229.  
  230. jPanel1.add(jScrollPane1);
  231. jScrollPane1.setBounds(0, 160, 820, 190);
  232. jPanel1.add(jSeparator2);
  233. jSeparator2.setBounds(0, 350, 820, 10);
  234.  
  235. jButton1.setBackground(new java.awt.Color(153, 255, 153));
  236. jButton1.setFont(new java.awt.Font("Mongolian Baiti", 1, 18)); // NOI18N
  237. jButton1.setText("PRINT");
  238. jButton1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  239. jButton1.addActionListener(new java.awt.event.ActionListener() {
  240. public void actionPerformed(java.awt.event.ActionEvent evt) {
  241. jButton1ActionPerformed(evt);
  242. }
  243. });
  244. jPanel1.add(jButton1);
  245. jButton1.setBounds(30, 370, 140, 30);
  246.  
  247. jButton2.setBackground(new java.awt.Color(153, 255, 153));
  248. jButton2.setFont(new java.awt.Font("Mongolian Baiti", 1, 18)); // NOI18N
  249. jButton2.setText("PREVIEW ");
  250. jButton2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  251. jButton2.addActionListener(new java.awt.event.ActionListener() {
  252. public void actionPerformed(java.awt.event.ActionEvent evt) {
  253. jButton2ActionPerformed(evt);
  254. }
  255. });
  256. jPanel1.add(jButton2);
  257. jButton2.setBounds(190, 370, 140, 30);
  258.  
  259. jButton4.setBackground(new java.awt.Color(153, 255, 153));
  260. jButton4.setFont(new java.awt.Font("Mongolian Baiti", 1, 18)); // NOI18N
  261. jButton4.setText("VIEW ALL PRODUCTS");
  262. jButton4.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  263. jButton4.addActionListener(new java.awt.event.ActionListener() {
  264. public void actionPerformed(java.awt.event.ActionEvent evt) {
  265. jButton4ActionPerformed(evt);
  266. }
  267. });
  268. jPanel1.add(jButton4);
  269. jButton4.setBounds(340, 370, 220, 30);
  270.  
  271. jButton3.setBackground(new java.awt.Color(153, 255, 153));
  272. jButton3.setFont(new java.awt.Font("Mongolian Baiti", 1, 18)); // NOI18N
  273. jButton3.setText("CANCLE");
  274. jButton3.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  275. jButton3.addActionListener(new java.awt.event.ActionListener() {
  276. public void actionPerformed(java.awt.event.ActionEvent evt) {
  277. jButton3ActionPerformed(evt);
  278. }
  279. });
  280. jPanel1.add(jButton3);
  281. jButton3.setBounds(570, 370, 140, 30);
  282.  
  283. jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Hardware/loginImage.jpg"))); // NOI18N
  284. jLabel1.setText("jLabel1");
  285. jPanel1.add(jLabel1);
  286. jLabel1.setBounds(0, 0, 820, 430);
  287.  
  288. jMenu1.setText("File");
  289.  
  290. jMenuItem4.setText("New Customer");
  291. jMenu1.add(jMenuItem4);
  292.  
  293. jMenuItem5.setText("Update Customer");
  294. jMenu1.add(jMenuItem5);
  295.  
  296. jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
  297. jMenuItem6.setText("Logout");
  298. jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
  299. public void actionPerformed(java.awt.event.ActionEvent evt) {
  300. jMenuItem6ActionPerformed(evt);
  301. }
  302. });
  303. jMenu1.add(jMenuItem6);
  304.  
  305. jMenuBar1.add(jMenu1);
  306.  
  307. jMenu2.setText("Edit Products");
  308.  
  309. jMenuItem1.setText("Add New Product");
  310. jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
  311. public void actionPerformed(java.awt.event.ActionEvent evt) {
  312. jMenuItem1ActionPerformed(evt);
  313. }
  314. });
  315. jMenu2.add(jMenuItem1);
  316.  
  317. jMenuItem2.setText("Remove Exiting Product");
  318. jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
  319. public void actionPerformed(java.awt.event.ActionEvent evt) {
  320. jMenuItem2ActionPerformed(evt);
  321. }
  322. });
  323. jMenu2.add(jMenuItem2);
  324.  
  325. jMenuItem3.setText("Update Product Info");
  326. jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
  327. public void actionPerformed(java.awt.event.ActionEvent evt) {
  328. jMenuItem3ActionPerformed(evt);
  329. }
  330. });
  331. jMenu2.add(jMenuItem3);
  332.  
  333. jMenuBar1.add(jMenu2);
  334.  
  335. jMenu3.setText("Print");
  336.  
  337. jMenuItem7.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
  338. jMenuItem7.setText("Print Bill");
  339. jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
  340. public void actionPerformed(java.awt.event.ActionEvent evt) {
  341. jMenuItem7ActionPerformed(evt);
  342. }
  343. });
  344. jMenu3.add(jMenuItem7);
  345.  
  346. jMenuBar1.add(jMenu3);
  347.  
  348. jMenu4.setText("Profit");
  349.  
  350. jMenuItem8.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
  351. jMenuItem8.setText("Total Income");
  352. jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
  353. public void actionPerformed(java.awt.event.ActionEvent evt) {
  354. jMenuItem8ActionPerformed(evt);
  355. }
  356. });
  357. jMenu4.add(jMenuItem8);
  358.  
  359. jMenuBar1.add(jMenu4);
  360.  
  361. setJMenuBar(jMenuBar1);
  362.  
  363. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  364. getContentPane().setLayout(layout);
  365. layout.setHorizontalGroup(
  366. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  367. .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  368. );
  369. layout.setVerticalGroup(
  370. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  371. .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  372. );
  373.  
  374. pack();
  375. }// </editor-fold>//GEN-END:initComponents
  376.  
  377. private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
  378. // TODO add your handling code here:
  379. MainFrm mainFrm=new MainFrm();
  380. this.hide();
  381. mainFrm.show();
  382. }//GEN-LAST:event_jButton3ActionPerformed
  383.  
  384. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  385. // TODO add your handling code here:
  386.  
  387. ArrayList<String> proId=new ArrayList<String>();
  388. ArrayList<String> proQ=new ArrayList<String>();
  389.  
  390. DefaultTableModel dm = (DefaultTableModel)jTable1.getModel();
  391. DefaultTableModel dm1 = (DefaultTableModel)jTable1.getModel();
  392. Vector data = dm.getDataVector();
  393.  
  394. int row = jTable1.getRowCount();
  395. if(row<=0)
  396. {
  397. showMessageDialog(null, "Cart is empty please add product items into the stack first....", "No product in cart",JOptionPane.ERROR_MESSAGE);
  398. }
  399. else
  400. {
  401. int column = jTable1.getColumnCount();
  402. for (int j = 0; j < row; j++) {
  403. for (int i = 0; i < column; i++) {
  404. System.out.println(jTable1.getValueAt(j, i));
  405. }
  406. proId.add((String) jTable1.getValueAt(j, 0));
  407. proQ.add((String) jTable1.getValueAt(j, 4));
  408. }
  409. int size1=proId.size();
  410. System.out.println(size1);
  411. for(int i=0;i<size1;i++)
  412. {
  413. try {
  414. DatabaseConnectionTest dbCon=new DatabaseConnectionTest();
  415. dbCon.soldProd(proId.get(i),proQ.get(i),jTextField4.getText());
  416. System.out.println(proId.get(i));
  417. System.out.println(proQ.get(i));
  418.  
  419. }
  420. /* String custName=jTextField4.getText();
  421. String RESULT= "billing\\"+custName+".pdf";
  422. if(Files.exists(Paths.get(RESULT)))
  423. {
  424. showMessageDialog(null, "File already exist with this customer...!", "Failed creating invoice", ERROR_MESSAGE);
  425. }
  426. else
  427. {
  428. if(jTextField1.getText().length()==0 || jComboBox1.getSelectedIndex()==0 || jComboBox2.getSelectedIndex()<0 || jTextField4.getText().length()==0)
  429. {
  430. showMessageDialog(null, "Fill all the details!", "Filed Emty error", ERROR_MESSAGE);
  431. }
  432. else
  433. {
  434. String prodID= (String) jComboBox1.getSelectedItem();
  435. String prodName= jTextField1.getText();
  436. String prodQuantity = (String) jComboBox2.getSelectedItem();
  437. showMessageDialog(null, "Please wait we are in process....", "Waiting for Invoice ",JOptionPane.CLOSED_OPTION);
  438. HelloWorld printInvoice=new HelloWorld();
  439. try {
  440. printInvoice.getCust(custName, prodID, prodName, prodQuantity,0);
  441. this.setup1(custName,0);
  442. // printInvoice.createPdf(jTextField1.getText(),jTextField2.getText(),jTextField3.getText(),jTextField4.getText(),RESULT);
  443. } catch (DocumentException ex) {
  444. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  445. } catch (IOException ex) {
  446. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  447. } catch (SQLException ex) {
  448. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  449. }
  450. }
  451. }
  452. */ catch (SQLException ex) {
  453. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  454. }
  455. }
  456. jComboBox2.removeAllItems();
  457. jTextField4.setText("");
  458. while(dm.getRowCount()>0)
  459. {
  460. dm.removeRow(0);
  461. }
  462. showMessageDialog(null, "Product Deducted from stock successfuly....", "Invoice Generated",JOptionPane.CLOSED_OPTION);
  463. }
  464. }//GEN-LAST:event_jButton1ActionPerformed
  465.  
  466. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
  467. // TODO add your handling code here:
  468. ArrayList<String> proId=new ArrayList<String>();
  469. ArrayList<String> prodName=new ArrayList<String>();
  470. ArrayList<String> proddQ=new ArrayList<String>();
  471. ArrayList<String> prodPrice=new ArrayList<String>();
  472. DefaultTableModel dm = (DefaultTableModel)jTable1.getModel();
  473. Vector data = dm.getDataVector();
  474. int row = jTable1.getRowCount();
  475. if(row<=0)
  476. {
  477. showMessageDialog(null, "Cart is empty please add product items into the stack first....", "No product in cart",JOptionPane.ERROR_MESSAGE);
  478. }
  479. else
  480. {
  481. try {
  482. int column = jTable1.getColumnCount();
  483. for (int j = 0; j < row; j++) {
  484. proId.add((String) jTable1.getValueAt(j, 0));
  485. prodName.add((String) jTable1.getValueAt(j, 1));
  486. prodPrice.add((String) jTable1.getValueAt(j, 3));
  487. proddQ.add((String) jTable1.getValueAt(j, 4));
  488. }
  489. DisplayEmpData dis=new DisplayEmpData();
  490. dis.showTableData1(proId,prodName,prodPrice,proddQ,jTextField4.getText());
  491. }
  492. /* if(jTextField1.getText().length()==0 || jComboBox1.getSelectedIndex()==0 || jComboBox2.getSelectedIndex()==0 || jTextField4.getText().length()==0)
  493. {
  494. showMessageDialog(null, "Fill all the details!", "Filed Emty error", ERROR_MESSAGE);
  495. }
  496. else
  497. {
  498. //PriviewFrm priviewFrm=new PriviewFrm();
  499. String prodID= (String) jComboBox1.getSelectedItem();
  500. String prodName= jTextField1.getText();
  501. String prodQuantity = (String) jComboBox2.getSelectedItem();
  502. String custName=jTextField4.getText();
  503. String path="TempFile\\"+custName+".pdf";
  504. showMessageDialog(null, "Please wait we are in process...."+path, "Waiting for Invoice ",JOptionPane.CLOSED_OPTION);
  505. HelloWorld printInvoice=new HelloWorld();
  506. try {
  507. printInvoice.getCust(custName, prodID, prodName, prodQuantity,1);
  508. this.setup1(jTextField4.getText(),1);
  509. } catch (IOException ex) {
  510. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  511. } catch (DocumentException ex) {
  512. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  513. } catch (SQLException ex) {
  514. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  515. }
  516. }*/ catch (ClassNotFoundException ex) {
  517. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  518. } catch (SQLException ex) {
  519. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  520. }
  521. }
  522.  
  523.  
  524.  
  525. }//GEN-LAST:event_jButton2ActionPerformed
  526.  
  527. private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
  528. // TODO add your handling code here:
  529. DisplayEmpData dis=new DisplayEmpData();
  530. try {
  531. dis.showTableData();
  532. } catch (ClassNotFoundException ex) {
  533. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  534. } catch (SQLException ex) {
  535. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  536. }
  537. }//GEN-LAST:event_jButton4ActionPerformed
  538.  
  539. private void jTextField4FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField4FocusLost
  540. // TODO add your handling code here:
  541.  
  542. }//GEN-LAST:event_jTextField4FocusLost
  543.  
  544. private void jTextField4KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField4KeyReleased
  545. // TODO add your handling code here:
  546.  
  547. }//GEN-LAST:event_jTextField4KeyReleased
  548.  
  549. private void jTextField4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField4MouseClicked
  550. // TODO add your handling code here:
  551.  
  552. }//GEN-LAST:event_jTextField4MouseClicked
  553.  
  554. private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
  555. // TODO add your handling code here:
  556. }//GEN-LAST:event_jComboBox1ActionPerformed
  557.  
  558. private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
  559. // TODO add your handling code here:
  560. if(jComboBox1.getSelectedIndex()==0 || jComboBox2.getSelectedIndex()<0 || jTextField1.getText().length()==0 || jTextField4.getText().length()==0)
  561. {
  562. showMessageDialog(null, "Fill all the details!", "Filed Emty error", ERROR_MESSAGE);
  563. }
  564. else
  565. {
  566. try {
  567. DefaultTableModel dm = (DefaultTableModel)jTable1.getModel();
  568. jTable1.setModel(dm);
  569. Vector<Object> data = new Vector<Object>();
  570. data.add(jComboBox1.getSelectedItem());
  571. data.add(jTextField1.getText());
  572. DatabaseConnectionTest dbCon=new DatabaseConnectionTest();
  573. data.add(dbCon.getProdType(prodID));
  574. data.add(dbCon.getPrice(prodID));
  575. prodQ=(String) jComboBox2.getSelectedItem();
  576. data.add(prodQ);
  577. dm.addRow(data);
  578. int item=jComboBox2.getSelectedIndex();
  579. int count=jComboBox2.getItemCount()-1;
  580. count =count-item;
  581. setCombos(count,1);
  582. // jTextField4.setText("");
  583. } catch (SQLException ex) {
  584. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  585. }
  586.  
  587. }
  588. }//GEN-LAST:event_jButton5ActionPerformed
  589.  
  590. private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
  591. // TODO add your handling code here:
  592. DefaultTableModel dm = (DefaultTableModel)jTable1.getModel();
  593. jTable1.setModel(dm);
  594. int row;
  595. int cal;
  596. String v;
  597. int size1;
  598. if(jTable1.getSelectedRow()<0)
  599. {
  600. showMessageDialog(null, "Please select the row to remove product from cart!", "Row Select", ERROR_MESSAGE);
  601. }
  602. else
  603. { row=jTable1.getSelectedRow();
  604. v=(String) dm.getValueAt(row, 4);
  605. size1=jComboBox2.getItemCount();
  606. jComboBox2.removeAllItems();
  607. for(int i=1;i<=size1;i++)
  608. {
  609. jComboBox2.addItem((Integer.toString(i)));
  610. }
  611. dm.removeRow(row);
  612. }
  613. }//GEN-LAST:event_jButton6ActionPerformed
  614.  
  615. private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
  616. // TODO add your handling code here:
  617. Login log=new Login();
  618. this.hide();
  619. log.show();
  620. }//GEN-LAST:event_jMenuItem6ActionPerformed
  621.  
  622. private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
  623. // TODO add your handling code here:
  624. AddProduct addPrd=new AddProduct();
  625. this.hide();
  626. addPrd.show();
  627. }//GEN-LAST:event_jMenuItem1ActionPerformed
  628.  
  629. private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
  630. // TODO add your handling code here:
  631. }//GEN-LAST:event_jMenuItem2ActionPerformed
  632.  
  633. private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
  634. // TODO add your handling code here:
  635. UpdateProduct updateProd;
  636. try {
  637. updateProd = new UpdateProduct();
  638. this.hide();
  639. updateProd.show();
  640. } catch (SQLException ex) {
  641. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  642. }
  643. }//GEN-LAST:event_jMenuItem3ActionPerformed
  644.  
  645. private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
  646. try {
  647. // TODO add your handling code here:
  648. this.hide();
  649. CreateInvoice createInvoice=new CreateInvoice();
  650. createInvoice.show();
  651. } catch (ClassNotFoundException ex) {
  652. Logger.getLogger(ViewProduct.class.getName()).log(Level.SEVERE, null, ex);
  653. } catch (SQLException ex) {
  654. Logger.getLogger(ViewProduct.class.getName()).log(Level.SEVERE, null, ex);
  655. }
  656. }//GEN-LAST:event_jMenuItem7ActionPerformed
  657.  
  658. private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
  659. try {
  660. // TODO add your handling code here:
  661. DisplayEmpData dis=new DisplayEmpData();
  662. dis.showTableData2();
  663. } catch (ClassNotFoundException ex) {
  664. Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex);
  665. } catch (SQLException ex) {
  666. Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex);
  667. }
  668. }//GEN-LAST:event_jMenuItem8ActionPerformed
  669. public boolean isNum(String str)
  670. {
  671. if(!str.matches("[0-9]+"))
  672. {
  673. return true;
  674. }
  675. else
  676. {
  677. return false;
  678. }
  679. }
  680. public void setup1(String custName, int num) throws IOException, DocumentException, SQLException
  681. {
  682. String prodID= (String) jComboBox1.getSelectedItem();
  683. String prodName= jTextField1.getText();
  684. String prodQuantity = (String) jComboBox2.getSelectedItem();
  685. JFrame frame = new JFrame("PDF Test");
  686. PagePanel panel = new PagePanel();
  687. frame.add(panel);
  688. frame.pack();
  689. frame.setVisible(true);
  690. String path="";
  691. if(num==0)
  692. {
  693. path="billing\\"+custName+".pdf";
  694. }
  695. else
  696. {
  697. path="TempFile\\"+custName+".pdf";
  698. }
  699. File file = new File(path);
  700. if(file.exists() && num==0)
  701. {
  702. num=0;
  703. RandomAccessFile raf = new RandomAccessFile(file, "r");
  704. FileChannel channel = raf.getChannel();
  705. ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY,
  706. 0, channel.size());
  707. PDFFile pdffile = new PDFFile(buf);
  708. PDFPage page = pdffile.getPage(0);
  709. panel.showPage(page);
  710. }
  711. else
  712. {
  713. String path1=file.getAbsolutePath();
  714. RandomAccessFile raf = new RandomAccessFile(file, "r");
  715. FileChannel channel = raf.getChannel();
  716. ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY,
  717. 0, channel.size());
  718. PDFFile pdffile = new PDFFile(buf);
  719. PDFPage page = pdffile.getPage(0);
  720. panel.showPage(page);
  721. if(num==1)
  722. {
  723. frame.addWindowListener(new java.awt.event.WindowAdapter() {
  724. @Override
  725. public void windowClosing(java.awt.event.WindowEvent windowEvent) {
  726. flag=0;
  727. try {
  728. this.finalize();
  729. file.delete();
  730. } catch (Throwable ex) {
  731. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  732. }
  733. showMessageDialog(null, "file deleted "+path1, "File deleted", JOptionPane.CLOSED_OPTION);
  734. }
  735. });
  736. }
  737. else
  738. {
  739. frame.addWindowListener(new java.awt.event.WindowAdapter() {
  740. @Override
  741. public void windowClosing(java.awt.event.WindowEvent windowEvent) {
  742. frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
  743. flag=1;
  744. }
  745. });
  746. }
  747. if(flag==0)
  748. {
  749. try {
  750. this.finalize();
  751. file.delete();
  752. } catch (Throwable ex) {
  753. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  754. }
  755. }
  756. }
  757. }
  758.  
  759. public static void main(String args[]) throws SQLException {
  760. try {
  761. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  762. if ("Nimbus".equals(info.getName())) {
  763. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  764. break;
  765. }
  766. }
  767. } catch (ClassNotFoundException ex) {
  768. java.util.logging.Logger.getLogger(CreateInvoice.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  769. } catch (InstantiationException ex) {
  770. java.util.logging.Logger.getLogger(CreateInvoice.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  771. } catch (IllegalAccessException ex) {
  772. java.util.logging.Logger.getLogger(CreateInvoice.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  773. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  774. java.util.logging.Logger.getLogger(CreateInvoice.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  775. }
  776. java.awt.EventQueue.invokeLater(new Runnable() {
  777. public void run() {
  778. try {
  779. new CreateInvoice().setVisible(true);
  780. } catch (ClassNotFoundException ex) {
  781. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  782. } catch (SQLException ex) {
  783. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  784. }
  785. }
  786. });
  787. }
  788.  
  789. // Variables declaration - do not modify//GEN-BEGIN:variables
  790. private javax.swing.JButton jButton1;
  791. private javax.swing.JButton jButton2;
  792. private javax.swing.JButton jButton3;
  793. private javax.swing.JButton jButton4;
  794. private javax.swing.JButton jButton5;
  795. private javax.swing.JButton jButton6;
  796. private javax.swing.JComboBox<String> jComboBox1;
  797. private javax.swing.JComboBox<String> jComboBox2;
  798. private javax.swing.JLabel jLabel1;
  799. private javax.swing.JLabel jLabel10;
  800. private javax.swing.JLabel jLabel11;
  801. private javax.swing.JLabel jLabel2;
  802. private javax.swing.JLabel jLabel3;
  803. private javax.swing.JLabel jLabel4;
  804. private javax.swing.JLabel jLabel5;
  805. private javax.swing.JLabel jLabel6;
  806. private javax.swing.JMenu jMenu1;
  807. private javax.swing.JMenu jMenu2;
  808. private javax.swing.JMenu jMenu3;
  809. private javax.swing.JMenu jMenu4;
  810. private javax.swing.JMenuBar jMenuBar1;
  811. private javax.swing.JMenuItem jMenuItem1;
  812. private javax.swing.JMenuItem jMenuItem2;
  813. private javax.swing.JMenuItem jMenuItem3;
  814. private javax.swing.JMenuItem jMenuItem4;
  815. private javax.swing.JMenuItem jMenuItem5;
  816. private javax.swing.JMenuItem jMenuItem6;
  817. private javax.swing.JMenuItem jMenuItem7;
  818. private javax.swing.JMenuItem jMenuItem8;
  819. private javax.swing.JPanel jPanel1;
  820. private javax.swing.JScrollPane jScrollPane1;
  821. private javax.swing.JSeparator jSeparator2;
  822. private javax.swing.JTable jTable1;
  823. private javax.swing.JTextField jTextField1;
  824. private javax.swing.JTextField jTextField4;
  825. // End of variables declaration//GEN-END:variables
  826.  
  827. public void setCombos(int count, int i) throws SQLException
  828. {
  829. if(i==1)
  830. {
  831. if(count==0)
  832. {
  833. jComboBox2.removeAllItems();
  834. showMessageDialog(null, "No Products available in stock", "Product Stock empty.",JOptionPane.OK_CANCEL_OPTION);
  835. }
  836. else
  837. {
  838. jComboBox2.removeAllItems();
  839. for(int j=1;j<=count;j++)
  840. {
  841. jComboBox2.addItem(""+j);
  842. }
  843. }
  844. }
  845. else
  846. {
  847. count1=count;
  848.  
  849. ArrayList al=new ArrayList();
  850. jComboBox1.addItemListener(new ItemListener() {
  851. @Override
  852. public void itemStateChanged(ItemEvent e)
  853. {
  854.  
  855. try {
  856. count1=getSum();
  857.  
  858. System.out.println(count1);
  859.  
  860. prodID=(String) jComboBox1.getSelectedItem();
  861. DatabaseConnectionTest dbCon=new DatabaseConnectionTest();
  862. prodName=dbCon.getProdName(prodID);
  863. prodQuantity=dbCon.getQuantity(prodID);
  864. totalLen=prodQuantity;
  865.  
  866.  
  867. System.out.println(totalLen);
  868.  
  869. jTextField1.setText(prodName);
  870. jComboBox2.removeAllItems();
  871. //System.out.println(""+al.size());
  872. if(al.isEmpty())
  873. {
  874. for(int j=1;j<=totalLen-count1;j++)
  875. {
  876. prodQ=Integer.toString(j);
  877. jComboBox2.addItem(prodQ);
  878. }
  879. }
  880. else
  881. {
  882. // for(int p=0;p<al.size();p++)
  883. // System.out.println(""+al.get(p));
  884. for(int j=1;j<=(totalLen-count1);j++)
  885. {
  886. prodQ=Integer.toString(j);
  887. jComboBox2.addItem(prodQ);
  888. }
  889. }
  890. } catch (SQLException ex) {
  891. Logger.getLogger(CreateInvoice.class.getName()).log(Level.SEVERE, null, ex);
  892. }
  893.  
  894.  
  895. }
  896.  
  897. private int getSum() {
  898. int sum = 0;
  899. DefaultTableModel dm= (DefaultTableModel) jTable1.getModel();
  900. int row=dm.getRowCount();
  901. int col=dm.getColumnCount();
  902. for(int k=0;k<row;k++)
  903. {
  904. for(int m=0;m<col;m++)
  905. {
  906. if(jComboBox1.getSelectedItem().equals(dm.getValueAt(k, m)))
  907. {
  908. val=Integer.parseInt((String) dm.getValueAt(k, 4));
  909. sum=sum+val;
  910. flag1=1;
  911. }
  912. if(flag1<1)
  913. {
  914. count1=0;
  915. }
  916. }
  917. }
  918.  
  919. return sum;
  920. }
  921. });
  922. }
  923.  
  924. }
  925.  
  926. }
Add Comment
Please, Sign In to add comment