Quipex

mainform

Jun 5th, 2017
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.79 KB | None | 0 0
  1. package bdhw;
  2.  
  3. import classes.Database;
  4. import classes.Goods;
  5. import classes.Sale;
  6. import java.sql.SQLException;
  7. import java.util.logging.Level;
  8. import java.util.logging.Logger;
  9. import javax.swing.JOptionPane;
  10.  
  11. /**
  12.  *
  13.  * @author User
  14.  */
  15. public class bdHW extends javax.swing.JFrame {
  16.     Goods[] goods = null;
  17.     Sale[] sales = null;
  18.     int numGoods = 0;
  19.     private int indexSelected = 0;
  20.     private int indexPage;
  21.     /**
  22.      * Creates new form bdHW
  23.      */
  24.     public bdHW() {
  25.         initComponents();
  26.         try {
  27.             Database.conn();
  28.             numGoods = (int) Database.getRowFromTable("goods", "count()", 1);
  29.         } catch (ClassNotFoundException | SQLException ex) {
  30.             Logger.getLogger(bdHW.class.getName()).log(Level.SEVERE, null, ex);
  31.         }
  32.         goods = new Goods[numGoods];
  33.         for (int i = 0; i < numGoods; i++)
  34.             goods[i] = new Goods(i+1);
  35.         initContent();
  36.         jDialogSearch.pack();
  37.     }
  38.                          
  39.     private void initComponents() {...}// </editor-fold>                        
  40.  
  41.     private void jButtonNextActionPerformed(java.awt.event.ActionEvent evt) {                                            
  42.         indexPage++;
  43.         setBottomValues(indexPage);
  44.         jButtonPrev.setEnabled(true);
  45.         if(indexPage+1 == sales.length)
  46.             jButtonNext.setEnabled(false);
  47.     }                                          
  48.  
  49.     private void jListGoodsValueChanged(javax.swing.event.ListSelectionEvent evt) {                                        
  50.         indexSelected = jListGoods.getSelectedIndex();
  51.         jTextFieldGnumSales.setText(Integer.toString(goods[indexSelected].getNumSales()));
  52.         jTextFieldGnumWarehouse.setText(Integer.toString(goods[indexSelected].getNumWarehouse()));
  53.         if(indexSelected != -1)
  54.             jButtonFind.setEnabled(true);
  55.     }                                      
  56.  
  57.     private void jButtonFindActionPerformed(java.awt.event.ActionEvent evt) {                                            
  58.         initSearch();
  59.     }                                          
  60.  
  61.     private void jTextFieldGDateActionPerformed(java.awt.event.ActionEvent evt) {                                                
  62.         // TODO add your handling code here:
  63.     }                                              
  64.  
  65.     private void jButtonDoFindActionPerformed(java.awt.event.ActionEvent evt) {                                              
  66.         String dateStart = String.valueOf(jSpinner1.getValue())+"-"+(String)jComboBoxMonths1.getSelectedItem()+"-"+(String)jComboBoxDays1.getSelectedItem();
  67.         String dateEnd = String.valueOf(jSpinner2.getValue())+"-"+(String)jComboBoxMonths2.getSelectedItem()+"-"+(String)jComboBoxDays2.getSelectedItem();
  68.         if((int) jSpinner1.getValue() > (int) jSpinner2.getValue())
  69.             JOptionPane.showMessageDialog(jDialogSearch, "Дата начала не может быть позже конца.");
  70.         else
  71.             if( ((int) jSpinner1.getValue() == (int) jSpinner2.getValue())
  72.                 &&(Integer.parseInt((String) jComboBoxMonths1.getSelectedItem()) > Integer.parseInt((String)jComboBoxMonths2.getSelectedItem())) )
  73.                 JOptionPane.showMessageDialog(jDialogSearch, "Дата начала не может быть позже конца.");
  74.             else
  75.                 if(Integer.parseInt((String) jComboBoxMonths1.getSelectedItem()) == Integer.parseInt((String)jComboBoxMonths2.getSelectedItem())
  76.                     &&(Integer.parseInt((String)jComboBoxDays1.getSelectedItem()) > Integer.parseInt((String)jComboBoxDays2.getSelectedItem())) )
  77.                     JOptionPane.showMessageDialog(jDialogSearch, "Дата начала не может быть позже конца.");
  78.                 else {
  79.                    
  80.                     int numSales = 0;
  81.                     try {
  82.                         numSales = Database.getSaleInfoNum(goods[indexSelected].getId_goods(), dateStart, dateEnd, indexSelected);
  83.                         System.out.println("numSales="+numSales);
  84.                     } catch (SQLException ex) {
  85.                         Logger.getLogger(bdHW.class.getName()).log(Level.SEVERE, null, ex);
  86.                     }
  87.                     if(numSales == 0) {
  88.                         JOptionPane.showMessageDialog(jDialogSearch, "На данном промежутке времени продаж нет.");
  89.                     } else {
  90.                         sales = new Sale[numSales];
  91.                         System.out.println(numSales);
  92.                         for (int i = 0; i < numSales; i++){
  93.                             sales[i] = new Sale(goods[indexSelected].getId_goods(), dateStart, dateEnd, i+1);
  94.                         }
  95.                         jDialogSearch.dispose();
  96.                         initBottom();
  97.                     }
  98.                 }
  99.     }                                            
  100.  
  101.     private void jButtonPrevActionPerformed(java.awt.event.ActionEvent evt) {                                            
  102.         indexPage--;
  103.         jButtonNext.setEnabled(true);
  104.         if(indexPage == 0)
  105.             jButtonPrev.setEnabled(false);
  106.         setBottomValues(indexPage);
  107.     }                                          
  108.  
  109.     public static void main(String args[]) {...}
  110.     // Variables declaration - do not modify                    
  111.     {...}
  112.     // End of variables declaration                  
  113.  
  114.     private void initContent() {
  115.         String[] listData = new String[numGoods];
  116.         for(int i = 0; i < numGoods; i++){
  117.             listData[i] = goods[i].getName();
  118.         }
  119.         jListGoods.setListData(listData);
  120.     }
  121.  
  122.     private void initSearch() {
  123.         jTextFieldSelectedName.setText(goods[indexSelected].getName());
  124.         jDialogSearch.setVisible(true);
  125.     }
  126.    
  127.     private void bottomVisible(boolean visSwitch){
  128.         jButtonNext.setVisible(visSwitch);
  129.         jButtonPrev.setVisible(visSwitch);
  130.         jTextFieldGQuantity.setVisible(visSwitch);
  131.         jTextFieldGPrice.setVisible(visSwitch);
  132.         jTextFieldGDate.setVisible(visSwitch);
  133.         jTextFieldGEmployee.setVisible(visSwitch);
  134.     }
  135.  
  136.     private void initBottom() {
  137.         indexPage = 0;
  138.         jButtonPrev.setEnabled(false);
  139.         jButtonNext.setEnabled(true);
  140.         if(sales.length==1)
  141.             jButtonNext.setEnabled(false);
  142.         setBottomValues(indexPage);
  143.         bottomVisible(true);
  144.     }
  145.    
  146.     private void setBottomValues(int index){
  147.         jTextFieldGEmployee.setText(sales[index].getEmployee());
  148.         jTextFieldGDate.setText(sales[index].getDate());
  149.         jTextFieldGQuantity.setText(String.valueOf(sales[index].getQuantity()));
  150.         jTextFieldGPrice.setText(String.valueOf(sales[index].getPrice()));
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment