elsemTim

ready project

Nov 17th, 2016
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 62.86 KB | None | 0 0
  1. //package clientServerApp;
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import javax.swing.*;
  6. import javax.swing.table.TableModel;
  7. import java.io.File;
  8. import java.io.FileInputStream;
  9. import java.io.IOException;
  10. import java.sql.SQLException;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13. import java.util.Properties;
  14.  
  15.  
  16. public class FirebirdTWJJ {
  17.  
  18.     /**
  19.      * @param args
  20.      */
  21.     //global var
  22.     static DBConnect dbConn;
  23.  
  24.     static JFrame frame;
  25.     /// Depart controls
  26.     static JTable depGrid;
  27.  
  28.     static JDialog addDepartDialog;
  29.     static JDialog editDepartDialog;
  30.  
  31.     static JButton addDepButton;
  32.     static JButton delDepButton;
  33.     static JButton editDepButton;
  34.  
  35.     static JScrollPane departTableScroolPage;
  36.     /// End Depart controls
  37.  
  38.     /// Position controls
  39.     static JTable posGrid;
  40.  
  41.     static JDialog addPositDialog;
  42.     static JDialog editPositDialog;
  43.  
  44.     static JButton addPosButton;
  45.     static JButton delPosButton;
  46.     static JButton editPosButton;
  47.  
  48.     static JScrollPane positTableScroolPage;
  49.     /// End Position controls
  50.  
  51.     /// Employee controls
  52.     static JTable empGrid;
  53.  
  54.     static JDialog addEmplDialog;
  55.     static JDialog editEmplDialog;
  56.  
  57.     static JButton addEmpButton;
  58.     static JButton delEmpButton;
  59.     static JButton editEmpButton;
  60.  
  61.     static JScrollPane emplTableScroolPage;
  62.     /// End Employee controls
  63.  
  64.     static JRadioButton empRB;
  65.     static JRadioButton posRB;
  66.     static JRadioButton depRB;
  67.  
  68.  
  69.  
  70.     //helpers
  71.     static void InitDB(Properties p) throws Exception{
  72.         dbConn = DBConnect.getInstance(p);
  73.     }
  74.  
  75.     static DepartmentTable GetDepartData() throws SQLException {
  76.         List<Department> dep = null;
  77.         try {
  78.             dep = dbConn.SelectDep();
  79.         } catch (SQLException e) {
  80.             e.printStackTrace();
  81.             throw e;
  82.         }
  83.         DepartmentTable depTable = new DepartmentTable();
  84.         String[] tmp = new String[depTable.getColumnCount()];
  85.         for (int i = 0; i < dep.size(); i++) {
  86.             Department d = dep.get(i);
  87.             tmp[0] = "" + d.GetID();
  88.             tmp[1] = d.GetNameDepartment();
  89.             tmp[2] = d.GetMail();
  90.             tmp[3] = d.GetPhone();
  91.             depTable.AddRow(tmp);
  92.         }
  93.         return depTable;
  94.     }
  95.  
  96.     static PositionTable GetPositionData() throws SQLException {
  97.         List<Position> pos = null;
  98.         try {
  99.             pos = dbConn.SelectPos();
  100.         } catch (SQLException e) {
  101.             e.printStackTrace();
  102.             throw e;
  103.         }
  104.         PositionTable posTable = new PositionTable();
  105.         String[] tmp = new String[posTable.getColumnCount()];
  106.         for (int i = 0; i < pos.size(); i++) {
  107.             Position p = pos.get(i);
  108.             tmp[0] = "" + p.GetID();
  109.             tmp[1] = p.GetNamePosition();
  110.             tmp[2] = ""+p.GetSalary();
  111.             posTable.AddRow(tmp);
  112.         }
  113.         return posTable;
  114.     }
  115.  
  116.     static EmployeeTable GetEmployeeData() throws SQLException {
  117.         List<Employee> emp = null;
  118.         try {
  119.             emp = dbConn.SelectEmp();
  120.         } catch (SQLException e) {
  121.             e.printStackTrace();
  122.             throw e;
  123.         }
  124.         EmployeeTable empTable = new EmployeeTable();
  125.         String[] tmp = new String[empTable.getColumnCount()];
  126.         for (int i = 0; i < emp.size(); i++) {
  127.             Employee e = emp.get(i);
  128.             tmp[0] = "" + e.getID();
  129.             tmp[1] = e.GetFirstName();
  130.             tmp[2] = e.GetLastName();
  131.             tmp[3] = e.GetNameDep();
  132.             tmp[4] = e.GetNamePos();
  133.             tmp[5] =""+e.getSalary();
  134.             tmp[6]=""+e.getDepID();
  135.             tmp[7]=""+e.getPosID();
  136.             empTable.AddRow(tmp);
  137.  
  138.         }
  139.         return empTable;
  140.     }
  141.  
  142.     static List<ComboItem> GetDepItems () {
  143.         try {
  144.             return dbConn.GetDepItems();
  145.         } catch (SQLException e) {
  146.             e.printStackTrace();
  147.         }
  148.         return new ArrayList<ComboItem> ();
  149.     }
  150.  
  151.     static List<ComboItem> GetPosItems () {
  152.         try {
  153.             return dbConn.GetPosItems();
  154.         } catch (SQLException e) {
  155.             e.printStackTrace();
  156.         }
  157.         return new ArrayList<ComboItem> ();
  158.     }
  159.  
  160.     //создаем новый Dialog при нажатие на кнопку Add для Departmena
  161.     static void InitAddDepartDialog(){
  162.         addDepartDialog = new JDialog(frame,"Добавить отдел",true);
  163.         addDepartDialog.setLocationRelativeTo(frame);
  164.         addDepartDialog.setSize(new Dimension(500,300));
  165.         addDepartDialog.setLayout(new GridBagLayout());
  166.         JTextField nameField=new JTextField(20);
  167.         JTextField phoneField=new JTextField(20);
  168.         JTextField mailField=new JTextField(20);
  169.         JButton okButton = new JButton("OK");
  170.         okButton.addActionListener(new ActionListener() {
  171.             @Override
  172.             public void actionPerformed(ActionEvent e) {
  173.                 String m=mailField.getText().trim();
  174.                 String p=phoneField.getText().trim();
  175.                 String n=nameField.getText().trim();
  176.                 if (m.length()>0 && p.length()>0 && n.length()>0) {
  177.                     try {
  178.                         dbConn.InsertDep(n, m, p);
  179.  
  180.                     } catch (SQLException e1) {
  181.                         e1.printStackTrace();
  182.                     }
  183.  
  184.                     try {
  185.                         addDepartDialog.setVisible(false);
  186.                         depGrid.setModel(GetDepartData());
  187.                         //DefaultTableModel model = (DefaultTableModel) depGrid.getModel();
  188.                         //model.fireTableDataChanged();
  189.                     } catch (SQLException e1) {
  190.                         e1.printStackTrace();
  191.                     }
  192.                 }
  193.                 addDepartDialog.setVisible(false);
  194.             }
  195.         });
  196.         addDepartDialog.add( new JLabel("Имя отдела: "), new GridBagConstraints(0,0,1,1,1,1,
  197.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  198.                 new Insets(2,2,2,2),0,0));
  199.  
  200.         addDepartDialog.add(nameField, new GridBagConstraints(1,0,1,1,1,1,
  201.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  202.                 new Insets(2,2,2,2),0,0));
  203.  
  204.         addDepartDialog.add( new JLabel("Почта: "), new GridBagConstraints(0,1,1,1,1,1,
  205.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  206.                 new Insets(2,2,2,2),0,0));
  207.  
  208.         addDepartDialog.add(mailField, new GridBagConstraints(1,1,1,1,1,1,
  209.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  210.                 new Insets(2,2,2,2),0,0));
  211.  
  212.         addDepartDialog.add( new JLabel("Телефон: "), new GridBagConstraints(0,2,1,1,1,1,
  213.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  214.                 new Insets(2,2,2,2),0,0));
  215.  
  216.         addDepartDialog.add(phoneField, new GridBagConstraints(1,2,1,1,1,1,
  217.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  218.                 new Insets(2,2,2,2),0,0));
  219.  
  220.         addDepartDialog.add(okButton, new GridBagConstraints(1,3,1,1,1,1,
  221.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  222.                 new Insets(2,2,2,2),0,0));
  223.  
  224.         addDepartDialog.pack();
  225.     }
  226.  
  227.     //создаем новый Dialog при нажатие на кнопку Add для Positiona
  228.     static void InitAddPositionDialog(){
  229.         addPositDialog = new JDialog(frame,"Добавить должность",true);
  230.         addPositDialog.setLocationRelativeTo(frame);
  231.         addPositDialog.setSize(new Dimension(500,300));
  232.         addPositDialog.setLayout(new GridBagLayout());
  233.         JTextField nameField=new JTextField(20);
  234.         JTextField salaryField=new JTextField(20);
  235.         JButton okButton = new JButton("OK");
  236.         okButton.addActionListener(new ActionListener() {
  237.             @Override
  238.             public void actionPerformed(ActionEvent e) {
  239.  
  240.                 String posn=nameField.getText().trim();
  241.                 String ss=salaryField.getText().trim();
  242.  
  243.                 if (ss.length()>0 && posn.length()>0) {
  244.                     try {
  245.                         int sal = Integer.parseInt(ss);
  246.                         dbConn.InsertPos(sal,posn);
  247.  
  248.                     } catch (SQLException e1) {
  249.                         e1.printStackTrace();
  250.                     }
  251.  
  252.                     try {
  253.                         addPositDialog.setVisible(false);
  254.                         posGrid.setModel(GetPositionData());
  255.                     } catch (SQLException e1) {
  256.                         e1.printStackTrace();
  257.                     }
  258.                 }
  259.                 addPositDialog.setVisible(false);
  260.             }
  261.         });
  262.         addPositDialog.add( new JLabel("Должность: "), new GridBagConstraints(0,0,1,1,1,1,
  263.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  264.                 new Insets(2,2,2,2),0,0));
  265.  
  266.         addPositDialog.add(nameField, new GridBagConstraints(1,0,1,1,1,1,
  267.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  268.                 new Insets(2,2,2,2),0,0));
  269.  
  270.         addPositDialog.add( new JLabel("Зарплата: "), new GridBagConstraints(0,1,1,1,1,1,
  271.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  272.                 new Insets(2,2,2,2),0,0));
  273.  
  274.         addPositDialog.add(salaryField, new GridBagConstraints(1,1,1,1,1,1,
  275.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  276.                 new Insets(2,2,2,2),0,0));
  277.  
  278.         addPositDialog.add(okButton, new GridBagConstraints(1,3,1,1,1,1,
  279.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  280.                 new Insets(2,2,2,2),0,0));
  281.  
  282.         addPositDialog.pack();
  283.     }
  284.  
  285.     //создаем новый Dialog при нажатие на кнопку Add для Employee
  286.     static void InitAddEmployeeDialog(){
  287.         addEmplDialog = new JDialog(frame,"Добавить сотрудника",true);
  288.         addEmplDialog.setLocationRelativeTo(frame);
  289.         addEmplDialog.setSize(new Dimension(500,300));
  290.         addEmplDialog.setLayout(new GridBagLayout());
  291.  
  292.         JTextField nameField=new JTextField(20);
  293.         JTextField lnameField=new JTextField(20);
  294.         JComboBox<ComboItem> pos= new JComboBox<ComboItem>();
  295.         List <ComboItem> lp = GetPosItems();
  296.         for (int i=0;i<lp.size();i++)
  297.         {
  298.             pos.addItem(lp.get(i));
  299.         }
  300.         JComboBox<ComboItem> dep= new JComboBox<ComboItem>();
  301.         List <ComboItem> ld = GetDepItems();
  302.         for (int i=0;i<ld.size();i++)
  303.         {
  304.             dep.addItem(ld.get(i));
  305.         }
  306.         JButton okButton = new JButton("OK");
  307.         okButton.addActionListener(new ActionListener() {
  308.             @Override
  309.             public void actionPerformed(ActionEvent e) {
  310.  
  311.                 String n=nameField.getText().trim();
  312.                 String ln=lnameField.getText().trim();
  313.                 int did= ((ComboItem)dep.getSelectedItem()).getValue();
  314.                 int pid= ((ComboItem)pos.getSelectedItem()).getValue();
  315.                 if ( ln.length()>0 && n.length()>0) {
  316.                     try {
  317.                         dbConn.InsertEmp(n,ln, did,pid);
  318.  
  319.                     } catch (SQLException e1) {
  320.                         e1.printStackTrace();
  321.                     }
  322.  
  323.                     try {
  324.                         addEmplDialog.setVisible(false);
  325.                         empGrid.setModel(GetEmployeeData());
  326.                         empGrid.getColumnModel().getColumn(7).setMinWidth(0);
  327.                         empGrid.getColumnModel().getColumn(7).setMaxWidth(0);
  328.                         empGrid.getColumnModel().getColumn(6).setMinWidth(0);
  329.                         empGrid.getColumnModel().getColumn(6).setMaxWidth(0);
  330.                     } catch (SQLException e1) {
  331.                         e1.printStackTrace();
  332.                     }
  333.                 }
  334.                 addEmplDialog.setVisible(false);
  335.  
  336.             }
  337.         });
  338.         addEmplDialog.add( new JLabel("Имя: "), new GridBagConstraints(0,0,1,1,1,1,
  339.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  340.                 new Insets(2,2,2,2),0,0));
  341.  
  342.         addEmplDialog.add(nameField, new GridBagConstraints(1,0,1,1,1,1,
  343.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  344.                 new Insets(2,2,2,2),0,0));
  345.  
  346.         addEmplDialog.add( new JLabel("Фамилия: "), new GridBagConstraints(0,1,1,1,1,1,
  347.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  348.                 new Insets(2,2,2,2),0,0));
  349.  
  350.         addEmplDialog.add(lnameField, new GridBagConstraints(1,1,1,1,1,1,
  351.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  352.                 new Insets(2,2,2,2),0,0));
  353.  
  354.         addEmplDialog.add( new JLabel("Отдел: "), new GridBagConstraints(0,2,1,1,1,1,
  355.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  356.                 new Insets(2,2,2,2),0,0));
  357.  
  358.         addEmplDialog.add(dep, new GridBagConstraints(1,2,1,1,1,1,
  359.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  360.                 new Insets(2,2,2,2),0,0));
  361.  
  362.         addEmplDialog.add( new JLabel("Должность: "), new GridBagConstraints(0,3,1,1,1,1,
  363.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  364.                 new Insets(2,2,2,2),0,0));
  365.  
  366.         addEmplDialog.add(pos, new GridBagConstraints(1,3,1,1,1,1,
  367.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  368.                 new Insets(2,2,2,2),0,0));
  369.  
  370.         addEmplDialog.add(okButton, new GridBagConstraints(1,4,1,1,1,1,
  371.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  372.                 new Insets(2,2,2,2),0,0));
  373.  
  374.         addEmplDialog.pack();
  375.     }
  376.  
  377.     static void InitEditDepartDialog(){
  378.         editDepartDialog = new JDialog(frame,"Изменить отдел",true);
  379.         editDepartDialog.setLocationRelativeTo(frame);
  380.         editDepartDialog.setSize(new Dimension(500,300));
  381.         editDepartDialog.setLayout(new GridBagLayout());
  382.         JTextField nameField=new JTextField(20);
  383.         JTextField phoneField=new JTextField(20);
  384.         JTextField mailField=new JTextField(20);
  385.         JTextField idField=new JTextField(20);
  386.         idField.setVisible(false);
  387.         JButton okButton = new JButton("OK");
  388.         okButton.addActionListener(new ActionListener() {
  389.             @Override
  390.             public void actionPerformed(ActionEvent e) {
  391.                 String m=mailField.getText().trim();
  392.                 String p=phoneField.getText().trim();
  393.                 String n=nameField.getText().trim();
  394.                 String sid=idField.getText().trim();
  395.                 int id = Integer.parseInt(sid);
  396.                 if (m.length()>0 && p.length()>0 && n.length()>0) {
  397.                     try {
  398.                         dbConn.UpdateDep(id, n, m, p);
  399.  
  400.                     } catch (SQLException e1) {
  401.                         e1.printStackTrace();
  402.                     }
  403.  
  404.                     try {
  405.                         editDepartDialog.setVisible(false);
  406.                         depGrid.setModel(GetDepartData());
  407.                         //DefaultTableModel model = (DefaultTableModel) depGrid.getModel();
  408.                         //model.fireTableDataChanged();
  409.                     } catch (SQLException e1) {
  410.                         e1.printStackTrace();
  411.                     }
  412.                 }
  413.                 editDepartDialog.setVisible(false);
  414.             }
  415.         });
  416.         editDepartDialog.add( new JLabel("Имя отдела: "), new GridBagConstraints(0,0,1,1,1,1,
  417.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  418.                 new Insets(2,2,2,2),0,0));
  419.  
  420.         editDepartDialog.add(nameField, new GridBagConstraints(1,0,1,1,1,1,
  421.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  422.                 new Insets(2,2,2,2),0,0));
  423.  
  424.         editDepartDialog.add( new JLabel("Почта: "), new GridBagConstraints(0,1,1,1,1,1,
  425.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  426.                 new Insets(2,2,2,2),0,0));
  427.  
  428.         editDepartDialog.add(mailField, new GridBagConstraints(1,1,1,1,1,1,
  429.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  430.                 new Insets(2,2,2,2),0,0));
  431.  
  432.         editDepartDialog.add( new JLabel("Телефон: "), new GridBagConstraints(0,2,1,1,1,1,
  433.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  434.                 new Insets(2,2,2,2),0,0));
  435.  
  436.         editDepartDialog.add(phoneField, new GridBagConstraints(1,2,1,1,1,1,
  437.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  438.                 new Insets(2,2,2,2),0,0));
  439.  
  440.         editDepartDialog.add(okButton, new GridBagConstraints(1,3,1,1,1,1,
  441.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  442.                 new Insets(2,2,2,2),0,0));
  443.  
  444.         editDepartDialog.add(idField, new GridBagConstraints(1,4,1,1,1,1,
  445.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  446.                 new Insets(2,2,2,2),0,0));
  447.  
  448.  
  449.         editDepartDialog.pack();
  450.     }
  451.  
  452.     static void InitEditPositDialog(){
  453.         editPositDialog = new JDialog(frame,"Изменить должность",true);
  454.         editPositDialog.setLocationRelativeTo(frame);
  455.         editPositDialog.setSize(new Dimension(500,300));
  456.         editPositDialog.setLayout(new GridBagLayout());
  457.         JTextField nameField=new JTextField(20);
  458.         JTextField salaryField=new JTextField(20);
  459.         JTextField idField=new JTextField(20);
  460.         idField.setVisible(false);
  461.         JButton okButton = new JButton("OK");
  462.         okButton.addActionListener(new ActionListener() {
  463.             @Override
  464.             public void actionPerformed(ActionEvent e) {
  465.                 String n=nameField.getText().trim();
  466.                 String s=salaryField.getText().trim();
  467.                 String sid=idField.getText().trim();
  468.                 int id = Integer.parseInt(sid);
  469.                 if (s.length()>0 && n.length()>0) {
  470.                     try {
  471.                         dbConn.UpdatePos(Integer.parseInt(s),n,id);
  472.  
  473.                     } catch (SQLException e1) {
  474.                         e1.printStackTrace();
  475.                     }
  476.  
  477.                     try {
  478.                         editPositDialog.setVisible(false);
  479.                         posGrid.setModel(GetPositionData());
  480.                     } catch (SQLException e1) {
  481.                         e1.printStackTrace();
  482.                     }
  483.                 }
  484.                 editPositDialog.setVisible(false);
  485.             }
  486.         });
  487.  
  488.         editPositDialog.add( new JLabel("Должность: "), new GridBagConstraints(0,0,1,1,1,1,
  489.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  490.                 new Insets(2,2,2,2),0,0));
  491.  
  492.         editPositDialog.add(nameField, new GridBagConstraints(1,0,1,1,1,1,
  493.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  494.                 new Insets(2,2,2,2),0,0));
  495.  
  496.         editPositDialog.add( new JLabel("Зарплата: "), new GridBagConstraints(0,1,1,1,1,1,
  497.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  498.                 new Insets(2,2,2,2),0,0));
  499.  
  500.         editPositDialog.add(salaryField, new GridBagConstraints(1,1,1,1,1,1,
  501.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  502.                 new Insets(2,2,2,2),0,0));
  503.  
  504.  
  505.  
  506.         editPositDialog.add(okButton, new GridBagConstraints(1,3,1,1,1,1,
  507.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  508.                 new Insets(2,2,2,2),0,0));
  509.  
  510.         editPositDialog.add(idField, new GridBagConstraints(1,2,1,1,1,1,
  511.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  512.                 new Insets(2,2,2,2),0,0));
  513.  
  514.         editPositDialog.pack();
  515.     }
  516.  
  517.     static void InitEditEmployeeDialog(){
  518.         editEmplDialog = new JDialog(frame,"Изменить сотрудника",true);
  519.         editEmplDialog.setLocationRelativeTo(frame);
  520.         editEmplDialog.setSize(new Dimension(500,300));
  521.         editEmplDialog.setLayout(new GridBagLayout());
  522.  
  523.         JTextField nameField=new JTextField(20);
  524.         JTextField lnameField=new JTextField(20);
  525.         JTextField idField=new JTextField(20);
  526.         idField.setVisible(false);
  527.         JComboBox<ComboItem> pos= new JComboBox<ComboItem>();
  528.         List <ComboItem> lp = GetPosItems();
  529.         for (int i=0;i<lp.size();i++)
  530.         {
  531.             pos.addItem(lp.get(i));
  532.         }
  533.         JComboBox<ComboItem> dep= new JComboBox<ComboItem>();
  534.         List <ComboItem> ld = GetDepItems();
  535.         for (int i=0;i<ld.size();i++)
  536.         {
  537.             dep.addItem(ld.get(i));
  538.         }
  539.         JButton okButton = new JButton("OK");
  540.         okButton.addActionListener(new ActionListener() {
  541.             @Override
  542.             public void actionPerformed(ActionEvent e) {
  543.  
  544.                 String n=nameField.getText().trim();
  545.                 String ln=lnameField.getText().trim();
  546.                 int did= ((ComboItem)dep.getSelectedItem()).getValue();
  547.                 int pid= ((ComboItem)pos.getSelectedItem()).getValue();
  548.                 String sid=idField.getText().trim();
  549.                 int id = Integer.parseInt(sid);
  550.                 if ( ln.length()>0 && n.length()>0) {
  551.                     try {
  552.                         dbConn.UpdateEmp(n,ln, did,pid,id);
  553.  
  554.                     } catch (SQLException e1) {
  555.                         e1.printStackTrace();
  556.                     }
  557.  
  558.                     try {
  559.                         editEmplDialog.setVisible(false);
  560.                         empGrid.setModel(GetEmployeeData());
  561.                         empGrid.getColumnModel().getColumn(7).setMinWidth(0);
  562.                         empGrid.getColumnModel().getColumn(7).setMaxWidth(0);
  563.                         empGrid.getColumnModel().getColumn(6).setMinWidth(0);
  564.                         empGrid.getColumnModel().getColumn(6).setMaxWidth(0);
  565.                     } catch (SQLException e1) {
  566.                         e1.printStackTrace();
  567.                     }
  568.                 }
  569.                 editEmplDialog.setVisible(false);
  570.  
  571.             }
  572.         });
  573.         editEmplDialog.add( new JLabel("Имя: "), new GridBagConstraints(0,0,1,1,1,1,
  574.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  575.                 new Insets(2,2,2,2),0,0));
  576.  
  577.         editEmplDialog.add(nameField, new GridBagConstraints(1,0,1,1,1,1,
  578.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  579.                 new Insets(2,2,2,2),0,0));
  580.  
  581.         editEmplDialog.add( new JLabel("Фамилия: "), new GridBagConstraints(0,1,1,1,1,1,
  582.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  583.                 new Insets(2,2,2,2),0,0));
  584.  
  585.         editEmplDialog.add(lnameField, new GridBagConstraints(1,1,1,1,1,1,
  586.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  587.                 new Insets(2,2,2,2),0,0));
  588.  
  589.         editEmplDialog.add( new JLabel("Отдел: "), new GridBagConstraints(0,2,1,1,1,1,
  590.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  591.                 new Insets(2,2,2,2),0,0));
  592.  
  593.         editEmplDialog.add(dep, new GridBagConstraints(1,2,1,1,1,1,
  594.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  595.                 new Insets(2,2,2,2),0,0));
  596.  
  597.         editEmplDialog.add( new JLabel("Должность: "), new GridBagConstraints(0,3,1,1,1,1,
  598.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  599.                 new Insets(2,2,2,2),0,0));
  600.  
  601.         editEmplDialog.add(pos, new GridBagConstraints(1,3,1,1,1,1,
  602.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  603.                 new Insets(2,2,2,2),0,0));
  604.  
  605.         editEmplDialog.add(okButton, new GridBagConstraints(1,4,1,1,1,1,
  606.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  607.                 new Insets(2,2,2,2),0,0));
  608.         editEmplDialog.add(idField, new GridBagConstraints(1,1,1,1,1,1,
  609.                 GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
  610.                 new Insets(2,2,2,2),0,0));
  611.  
  612.         editEmplDialog.pack();
  613.     }
  614.  
  615.     static void InitDialogs(){
  616.         InitAddDepartDialog();
  617.         InitEditDepartDialog();
  618.         InitAddPositionDialog();
  619.         InitEditPositDialog();
  620.         InitAddEmployeeDialog();
  621.         InitEditEmployeeDialog();
  622.     }
  623. ///////////Работа со скрытием элементов
  624. //dep
  625.     static void ShowDepartment() throws SQLException {
  626.         HidePosition();
  627.         HideEmployee();
  628.         frame.add(departTableScroolPage, new GridBagConstraints(0, 0, 3, 1, 0, 0,
  629.                 GridBagConstraints.NORTH,
  630.                 GridBagConstraints.BOTH,
  631.                 new Insets(1, 1, 1, 1), 0, 0));
  632.         depGrid.setModel(GetDepartData());
  633.         depGrid.setVisible(true);
  634.         addDepButton.setVisible(true);
  635.         delDepButton.setVisible(true);
  636.         editDepButton.setVisible(true);
  637.         departTableScroolPage.setVisible(true);
  638.     }
  639.  
  640.     static void HideDepartment() throws SQLException{
  641.         departTableScroolPage.setVisible(false);
  642.         frame.remove(departTableScroolPage);
  643.         depGrid.setVisible(false);
  644.         addDepButton.setVisible(false);
  645.         delDepButton.setVisible(false);
  646.         editDepButton.setVisible(false);
  647.     }
  648. //pos
  649.     static void ShowPosition() throws SQLException{
  650.         HideDepartment();
  651.         HideEmployee();
  652.         frame.add(positTableScroolPage, new GridBagConstraints(0, 0, 3, 1, 0, 0,
  653.                 GridBagConstraints.NORTH,
  654.                 GridBagConstraints.BOTH,
  655.                 new Insets(1, 1, 1, 1), 0, 0));
  656.         posGrid.setModel(GetPositionData());
  657.         posGrid.setVisible(true);
  658.         addPosButton.setVisible(true);
  659.         delPosButton.setVisible(true);
  660.         editPosButton.setVisible(true);
  661.         positTableScroolPage.setVisible(true);
  662.     }
  663.  
  664.     static void HidePosition() throws SQLException{
  665.         positTableScroolPage.setVisible(false);
  666.         frame.remove(positTableScroolPage);
  667.         posGrid.setVisible(false);
  668.         addPosButton.setVisible(false);
  669.         delPosButton.setVisible(false);
  670.         editPosButton.setVisible(false);
  671.     }
  672. //emp
  673.     static void ShowEmployee() throws SQLException{
  674.         HidePosition();
  675.         HideDepartment();
  676.         frame.add(emplTableScroolPage, new GridBagConstraints(0, 0, 3, 1, 0, 0,
  677.                 GridBagConstraints.NORTH,
  678.                 GridBagConstraints.BOTH,
  679.                 new Insets(1, 1, 1, 1), 0, 0));
  680.         empGrid.setModel(GetEmployeeData());
  681.         empGrid.getColumnModel().getColumn(7).setMinWidth(0);
  682.         empGrid.getColumnModel().getColumn(7).setMaxWidth(0);
  683.         empGrid.getColumnModel().getColumn(6).setMinWidth(0);
  684.         empGrid.getColumnModel().getColumn(6).setMaxWidth(0);
  685.         empGrid.setVisible(true);
  686.         addEmpButton.setVisible(true);
  687.         delEmpButton.setVisible(true);
  688.         editEmpButton.setVisible(true);
  689.         emplTableScroolPage.setVisible(true);
  690.     }
  691.  
  692.     static void HideEmployee() throws SQLException{
  693.         emplTableScroolPage.setVisible(false);
  694.         frame.remove(emplTableScroolPage);
  695.         empGrid.setVisible(false);
  696.         addEmpButton.setVisible(false);
  697.         delEmpButton.setVisible(false);
  698.         editEmpButton.setVisible(false);
  699.     }
  700.  
  701. ///////
  702.     static void ShowFrame()
  703.     {
  704.         frame.pack();
  705.         frame.setVisible(true);
  706.     }
  707.     static void InitFrame(){
  708.         frame = new JFrame("Учет сотрудников предприятия");
  709.         frame.setSize(new Dimension(1000, 1000));
  710.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  711.         frame.setLocationRelativeTo(null);
  712.         frame.setLayout(new GridBagLayout());
  713.  
  714.         ButtonGroup group = new ButtonGroup();
  715.         //выполняем инизиализацию и отрисовку для
  716.         //Department
  717.          depRB = new JRadioButton("Отдел",true);
  718.  
  719.         depRB.addActionListener(new ActionListener() {
  720.             @Override
  721.             public void actionPerformed(ActionEvent e) {
  722.                 try {
  723.                     ShowDepartment();
  724.                 }
  725.                 catch (SQLException ex)
  726.                 {
  727.                     JOptionPane.showMessageDialog(new JFrame(), ex.getMessage(), "ERROR",
  728.                             JOptionPane.ERROR_MESSAGE);
  729.                     return;
  730.                 }
  731.             }
  732.         });
  733.         group.add(depRB);
  734.         //////
  735.  
  736.         //выполняем инизиализацию и отрисовку для
  737.         //Position
  738.          posRB = new JRadioButton("Должность",false);
  739.  
  740.         posRB.addActionListener(new ActionListener() {
  741.             @Override
  742.             public void actionPerformed(ActionEvent e) {
  743.                 try {
  744.                     ShowPosition();
  745.                 }
  746.                 catch (SQLException ex) {
  747.  
  748.                 JOptionPane.showMessageDialog(new JFrame(), ex.getMessage(), "ERROR",
  749.                         JOptionPane.ERROR_MESSAGE);
  750.                 return;
  751.                 }
  752.             }
  753.         });
  754.         group.add(posRB);
  755.         //////
  756.  
  757.         //выполняем инизиализацию и отрисовку для
  758.         //Employee
  759.          empRB = new JRadioButton("Люди",false);
  760.         //
  761.         empRB.addActionListener(new ActionListener() {
  762.             @Override
  763.             public void actionPerformed(ActionEvent e) {
  764.                 try {
  765.                     ShowEmployee();
  766.                 }
  767.                 catch (SQLException ex) {
  768.  
  769.                     JOptionPane.showMessageDialog(new JFrame(), ex.getMessage(), "ERROR",
  770.                             JOptionPane.ERROR_MESSAGE);
  771.                     return;
  772.                 }
  773.             }
  774.         });
  775.         group.add(empRB);
  776.         //////
  777.         frame.add(depRB, new GridBagConstraints(0, 2, 1, 1, 1, 1,
  778.                 GridBagConstraints.NORTH,
  779.                 GridBagConstraints.BOTH,
  780.                 new Insets(1, 4, 1, 1), 0, 0));
  781.         frame.add(posRB, new GridBagConstraints(1, 2, 1, 1, 1, 1,
  782.                 GridBagConstraints.NORTH,
  783.                 GridBagConstraints.BOTH,
  784.                 new Insets(1, 4, 1, 1), 0, 0));
  785.  
  786.         frame.add(empRB, new GridBagConstraints(2, 2, 1, 1, 1, 1,
  787.                 GridBagConstraints.NORTH,
  788.                 GridBagConstraints.BOTH,
  789.                 new Insets(1, 4, 1, 1), 0, 0));
  790.  
  791.     }
  792.  
  793.     static void InitDepartGrid() throws SQLException{
  794.         //указываем модель таблицы
  795.  
  796.         try {
  797.             depGrid = new JTable(GetDepartData());
  798.         } catch (SQLException e) {
  799.             e.printStackTrace();
  800.             throw e;
  801.         }
  802.         depGrid.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  803.         departTableScroolPage = new JScrollPane(depGrid);
  804.         departTableScroolPage.setPreferredSize(new Dimension(400, 400));
  805.         //addbut
  806.         addDepButton = new JButton("Добавить");
  807.         addDepButton.addActionListener(new ActionListener() {
  808.             @Override
  809.             public void actionPerformed(ActionEvent e) {
  810.                 addDepartDialog.setVisible(true);
  811.             }
  812.         });
  813.  
  814.         //delbut
  815.         delDepButton = new JButton("Удалить");
  816.         delDepButton.addActionListener(new ActionListener() {
  817.             @Override
  818.             public void actionPerformed(ActionEvent e) {
  819.                 int n=depGrid.getSelectedRow();
  820.                 if (n>=0){
  821.                     TableModel m=depGrid.getModel();
  822.                     String s=(String)m.getValueAt(n,0);
  823.                     int id= Integer.parseInt(s);
  824.                     try {
  825.                         dbConn.RemoveDep(id);
  826.                     } catch (SQLException e1) {
  827.                         e1.printStackTrace();
  828.                     }
  829.  
  830.                     try {
  831.                         depGrid.setModel(GetDepartData());
  832.                         } catch (SQLException e1) {
  833.                         e1.printStackTrace();
  834.                     }
  835.                 }
  836.  
  837.             }
  838.         });
  839.  
  840.         //editbut
  841.         editDepButton = new JButton("Изменить");
  842.         editDepButton.addActionListener(new ActionListener() {
  843.             @Override
  844.             public void actionPerformed(ActionEvent e) {
  845.                 int n=depGrid.getSelectedRow();
  846.                 if (n>=0){
  847.                     TableModel m=depGrid.getModel();
  848.                     Component [] comp = editDepartDialog.getContentPane().getComponents();
  849.                     ((JTextField)comp[1]).setText((String)m.getValueAt(n,1));
  850.                     ((JTextField)comp[3]).setText((String)m.getValueAt(n,2));
  851.                     ((JTextField)comp[5]).setText((String)m.getValueAt(n,3));
  852.                     ((JTextField)comp[7]).setText((String)m.getValueAt(n,0));
  853.  
  854.                     editDepartDialog.setVisible(true);
  855.                 }
  856.  
  857.             }
  858.         });
  859.  
  860.         frame.add(addDepButton, new GridBagConstraints(0, 1, 1, 1, 1, 1,
  861.                 GridBagConstraints.NORTH,
  862.                 GridBagConstraints.BOTH,
  863.                 new Insets(1, 1, 1, 1), 0, 0));
  864.  
  865.         frame.add(delDepButton, new GridBagConstraints(1, 1, 1, 1, 1, 1,
  866.                 GridBagConstraints.NORTH,
  867.                 GridBagConstraints.BOTH,
  868.                 new Insets(1, 1, 1, 1), 0, 0));
  869.  
  870.         frame.add(editDepButton, new GridBagConstraints(2, 1, 1, 1, 1, 1,
  871.                 GridBagConstraints.NORTH,
  872.                 GridBagConstraints.BOTH,
  873.                 new Insets(1, 1, 1, 1), 0, 0));
  874.     }
  875.  
  876.     static void InitPositionGrid() throws SQLException{
  877.         //указываем модель таблицы
  878.  
  879.         try {
  880.             posGrid = new JTable(GetPositionData());
  881.         } catch (SQLException e) {
  882.             e.printStackTrace();
  883.             throw e;
  884.         }
  885.         posGrid.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  886.         positTableScroolPage = new JScrollPane(posGrid);
  887.         positTableScroolPage.setPreferredSize(new Dimension(400, 400));
  888.         //addbut
  889.         addPosButton = new JButton("Добавить");
  890.         addPosButton.addActionListener(new ActionListener() {
  891.             @Override
  892.             public void actionPerformed(ActionEvent e) {
  893.                 addPositDialog.setVisible(true);
  894.             }
  895.         });
  896.  
  897.         //delbut
  898.         delPosButton = new JButton("Удалить");
  899.         delPosButton.addActionListener(new ActionListener() {
  900.             @Override
  901.             public void actionPerformed(ActionEvent e) {
  902.                 int n=posGrid.getSelectedRow();
  903.                 if (n>=0){
  904.                     TableModel m=posGrid.getModel();
  905.                     String s=(String)m.getValueAt(n,0);
  906.                     int id= Integer.parseInt(s);
  907.                     try {
  908.                         dbConn.RemovePos(id);
  909.                     } catch (SQLException e1) {
  910.                         e1.printStackTrace();
  911.                     }
  912.  
  913.                     try {
  914.                         posGrid.setModel(GetPositionData());
  915.                     } catch (SQLException e1) {
  916.                         e1.printStackTrace();
  917.                     }
  918.                 }
  919.  
  920.             }
  921.         });
  922.  
  923.         //editbut
  924.         editPosButton = new JButton("Изменить");
  925.         editPosButton.addActionListener(new ActionListener() {
  926.             @Override
  927.             public void actionPerformed(ActionEvent e) {
  928.                 int n=posGrid.getSelectedRow();
  929.                 if (n>=0){
  930.                     TableModel m=posGrid.getModel();
  931.                     Component [] comp = editPositDialog.getContentPane().getComponents();
  932.                     ((JTextField)comp[1]).setText((String)m.getValueAt(n,1));
  933.                     ((JTextField)comp[3]).setText((String)m.getValueAt(n,2));
  934.                     ((JTextField)comp[5]).setText((String)m.getValueAt(n,0));
  935.                     editPositDialog.setVisible(true);
  936.                 }
  937.  
  938.             }
  939.         });
  940.  
  941.  
  942.         frame.add(addPosButton, new GridBagConstraints(0, 1, 1, 1, 1, 1,
  943.                 GridBagConstraints.NORTH,
  944.                 GridBagConstraints.BOTH,
  945.                 new Insets(1, 1, 1, 1), 0, 0));
  946.  
  947.         frame.add(delPosButton, new GridBagConstraints(1, 1, 1, 1, 1, 1,
  948.                 GridBagConstraints.NORTH,
  949.                 GridBagConstraints.BOTH,
  950.                 new Insets(1, 1, 1, 1), 0, 0));
  951.  
  952.         frame.add(editPosButton, new GridBagConstraints(2, 1, 1, 1, 1, 1,
  953.                 GridBagConstraints.NORTH,
  954.                 GridBagConstraints.BOTH,
  955.                 new Insets(1, 1, 1, 1), 0, 0));
  956.         ShowFrame();
  957.     }
  958.  
  959.     static void InitEmplnGrid() throws SQLException{
  960.         //указываем модель таблицы
  961.  
  962.         try {
  963.             empGrid = new JTable(GetEmployeeData());
  964.             empGrid.getColumnModel().getColumn(7).setMinWidth(0);
  965.             empGrid.getColumnModel().getColumn(7).setMaxWidth(0);
  966.             empGrid.getColumnModel().getColumn(6).setMinWidth(0);
  967.             empGrid.getColumnModel().getColumn(6).setMaxWidth(0);
  968.         } catch (SQLException e) {
  969.             e.printStackTrace();
  970.             throw e;
  971.         }
  972.         empGrid.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  973.         emplTableScroolPage = new JScrollPane(empGrid);
  974.         emplTableScroolPage.setPreferredSize(new Dimension(400, 400));
  975.         //addbut
  976.         addEmpButton = new JButton("Добавить");
  977.         addEmpButton.addActionListener(new ActionListener() {
  978.             @Override
  979.             public void actionPerformed(ActionEvent e) {
  980.                 addEmplDialog.setVisible(true);
  981.             }
  982.         });
  983.  
  984.         //delbut
  985.         delEmpButton = new JButton("Удалить");
  986.         delEmpButton.addActionListener(new ActionListener() {
  987.             @Override
  988.             public void actionPerformed(ActionEvent e) {
  989.                 int n=empGrid.getSelectedRow();
  990.                 if (n>=0){
  991.                     TableModel m=empGrid.getModel();
  992.                     String s=(String)m.getValueAt(n,0);
  993.                     int id= Integer.parseInt(s);
  994.                     try {
  995.                         dbConn.RemoveEmp(id);
  996.                     } catch (SQLException e1) {
  997.                         e1.printStackTrace();
  998.                     }
  999.  
  1000.                     try {
  1001.                         empGrid.setModel(GetEmployeeData());
  1002.                         empGrid.getColumnModel().getColumn(7).setMinWidth(0);
  1003.                         empGrid.getColumnModel().getColumn(7).setMaxWidth(0);
  1004.                         empGrid.getColumnModel().getColumn(6).setMinWidth(0);
  1005.                         empGrid.getColumnModel().getColumn(6).setMaxWidth(0);
  1006.                     } catch (SQLException e1) {
  1007.                         e1.printStackTrace();
  1008.                     }
  1009.                 }
  1010.  
  1011.             }
  1012.         });
  1013.  
  1014.         //editbut
  1015.         editEmpButton = new JButton("Изменить");
  1016.         editEmpButton.addActionListener(new ActionListener() {
  1017.             @Override
  1018.             public void actionPerformed(ActionEvent e) {
  1019.                 int n=empGrid.getSelectedRow();
  1020.                 if (n>=0){
  1021.                     TableModel m=empGrid.getModel();
  1022.                     Component [] comp = editEmplDialog.getContentPane().getComponents();
  1023.                     ((JTextField)comp[1]).setText((String)m.getValueAt(n,1));
  1024.                     ((JTextField)comp[3]).setText((String)m.getValueAt(n,2));
  1025.                     ((JTextField)comp[9]).setText((String)m.getValueAt(n,0));
  1026.                     String tmp= (String)m.getValueAt(n,6);
  1027.                     String aus= (String)m.getValueAt(n,3);
  1028.                     int did=Integer.parseInt(tmp);
  1029.                     ComboItem itm=new ComboItem(did,aus);
  1030.                     ((JComboBox)comp[5]).setSelectedItem(itm);
  1031.                      tmp= (String)m.getValueAt(n,7);
  1032.                      aus= (String)m.getValueAt(n,4);
  1033.                      did=Integer.parseInt(tmp);
  1034.                      itm=new ComboItem(did,aus);
  1035.                     ((JComboBox)comp[7]).setSelectedItem(itm);
  1036.  
  1037.                     editEmplDialog.setVisible(true);
  1038.                 }
  1039.  
  1040.             }
  1041.         });
  1042.  
  1043.  
  1044.         frame.add(addEmpButton, new GridBagConstraints(0, 1, 1, 1, 1, 1,
  1045.                 GridBagConstraints.NORTH,
  1046.                 GridBagConstraints.BOTH,
  1047.                 new Insets(1, 1, 1, 1), 0, 0));
  1048.  
  1049.         frame.add(delEmpButton, new GridBagConstraints(1, 1, 1, 1, 1, 1,
  1050.                 GridBagConstraints.NORTH,
  1051.                 GridBagConstraints.BOTH,
  1052.                 new Insets(1, 1, 1, 1), 0, 0));
  1053.  
  1054.         frame.add(editEmpButton, new GridBagConstraints(2, 1, 1, 1, 1, 1,
  1055.                 GridBagConstraints.NORTH,
  1056.                 GridBagConstraints.BOTH,
  1057.                 new Insets(1, 1, 1, 1), 0, 0));
  1058.         ShowFrame();
  1059.     }
  1060.  
  1061.     public static void main(String[] args) {
  1062.         Properties props = new Properties();
  1063.         try {
  1064.             props.load(new FileInputStream(new File(".\\src\\config.ini")));
  1065.         } catch (IOException e) {
  1066.             JOptionPane.showMessageDialog(new JFrame(), e.getMessage(), "ERROR",
  1067.                     JOptionPane.ERROR_MESSAGE);
  1068.             return;
  1069.         }
  1070.         try {
  1071.             InitDB(props);
  1072.         } catch (Exception e) {
  1073.             e.printStackTrace();
  1074.             JOptionPane.showMessageDialog(new JFrame(), e.getMessage(), "ERROR",
  1075.                     JOptionPane.ERROR_MESSAGE);
  1076.             return;
  1077.         }
  1078.         InitFrame();
  1079.  
  1080.         try {
  1081.  
  1082.             InitDialogs();
  1083.             InitDepartGrid();
  1084.             InitPositionGrid();
  1085.             InitEmplnGrid();
  1086.  
  1087.  
  1088.             ShowDepartment();
  1089.             ShowFrame();
  1090.  
  1091.         } catch (SQLException e) {
  1092.             e.printStackTrace();
  1093.             JOptionPane.showMessageDialog(new JFrame(), e.getMessage(), "ERROR",
  1094.                     JOptionPane.ERROR_MESSAGE);
  1095.             return;
  1096.         };
  1097.     }
  1098. }
  1099.  
  1100. /**
  1101.  * Created by elsemTim on 14.11.2016.
  1102.  */
  1103.  
  1104. import java.sql.Connection;
  1105. import java.sql.DriverManager;
  1106. import java.sql.PreparedStatement;
  1107. import java.sql.ResultSet;
  1108. import java.sql.SQLException;
  1109. import java.sql.Statement;
  1110. import java.util.ArrayList;
  1111. import java.util.List;
  1112. import java.util.Properties;
  1113.  
  1114.  
  1115. public class DBConnect {
  1116.  
  1117.     private static DBConnect _ourInstance;
  1118.     private static Connection _ourCon;
  1119.  
  1120.  
  1121.     public static DBConnect getInstance(Properties p) throws Exception {
  1122.         if (_ourInstance ==null)
  1123.         {
  1124.             _ourInstance = new DBConnect(p);
  1125.         }
  1126.         return _ourInstance;
  1127.     }
  1128.  
  1129.     private DBConnect(Properties p) throws Exception {
  1130.         try
  1131.         {
  1132.             Class.forName("org.firebirdsql.jdbc.FBDriver");
  1133.             String strDatabasePath =p.getProperty("DBPath");
  1134.             String strUrl="jdbc:firebirdsql://"+p.getProperty("server")+":3050/"+strDatabasePath+"";
  1135.             Properties props = new Properties();
  1136.             props.setProperty("user","SYSDBA");
  1137.             props.setProperty("password","123");
  1138.             props.setProperty("encoding","UNICODE_FSS");
  1139.             //props.setProperty("encoding","ISO8859_5");
  1140.             _ourCon=DriverManager.getConnection(strUrl,props);
  1141.         }
  1142.         catch (Exception e)
  1143.         {
  1144.             throw new Exception(e);
  1145.         }
  1146.     }
  1147.  
  1148.     //Employee
  1149.     public List<Employee> SelectEmp() throws SQLException{
  1150.         List<Employee> employ = new ArrayList<Employee>();
  1151.         Statement stmt = null;
  1152.         ResultSet rs = null;
  1153.         try {
  1154.             stmt = _ourCon.createStatement();
  1155.             //тут нужен запрос, который свяжент все таблицы и кинет их сюда
  1156.             rs = stmt.executeQuery( "SELECT * FROM vw_Employee;");
  1157.             while (rs.next()) {
  1158.                 Employee emp = new Employee();
  1159.                 emp.setID(rs.getInt(1));
  1160.                 emp.SetFirstName(rs.getString(2));
  1161.                 emp.SetLastName(rs.getString(3));
  1162.                 emp.SetNameDep(rs.getString(4));
  1163.                 emp.SetNamePos(rs.getString(5));
  1164.                 emp.setSalary(rs.getInt(6));
  1165.                 emp.setDepID(rs.getInt(7));
  1166.                 emp.setPosID(rs.getInt(8));
  1167.                 employ.add(emp);
  1168.             }
  1169.         }
  1170.         catch (SQLException e)
  1171.         {
  1172.             int i=1;
  1173.         }
  1174.         finally {
  1175.             if (rs != null) {
  1176.                 rs.close();
  1177.             }
  1178.             if (stmt != null) {
  1179.                 stmt.close();
  1180.             }
  1181.         }
  1182.         return employ;
  1183.     }
  1184.  
  1185.     public void UpdateEmp(String name, String lname, int did, int pid,int id) throws SQLException
  1186.     {
  1187.         PreparedStatement stmt = null;
  1188.         try{
  1189.             stmt = _ourCon.prepareStatement(
  1190.                     "UPDATE Employee SET "
  1191.                             +"FIRST_NAME=?, LAST_NAME=?, POS_ID=?, DEP_ID=?"
  1192.                             +"WHERE ID=?;");
  1193.             stmt.setString(1, name);
  1194.             stmt.setString(2, lname);
  1195.             stmt.setInt(3, pid);
  1196.             stmt.setInt(4, did);
  1197.             stmt.setInt(5,id);
  1198.             stmt.executeUpdate();
  1199.         }
  1200.         finally {
  1201.             if (stmt!=null){
  1202.                 stmt.close();
  1203.             }
  1204.         }
  1205.     }
  1206.  
  1207.     public void RemoveEmp (int id) throws  SQLException
  1208.     {
  1209.         PreparedStatement stmt = null;
  1210.         try{
  1211.             stmt = _ourCon.prepareStatement(
  1212.                     "DELETE FROM Employee WHERE "
  1213.                             +"ID=?;");
  1214.             stmt.setInt(1, id);
  1215.             stmt.executeUpdate();
  1216.         }
  1217.         finally {
  1218.             if (stmt!=null){
  1219.                 stmt.close();
  1220.             }
  1221.         }
  1222.     }
  1223.  
  1224.     public void InsertEmp (String name, String lname, int did, int pid) throws SQLException
  1225.     {
  1226.         PreparedStatement stmt = null;
  1227.         try{
  1228.             stmt = _ourCon.prepareStatement(
  1229.                     "INSERT INTO Employee "
  1230.                             +"(FIRST_NAME, LAST_NAME, POS_ID, DEP_ID) "
  1231.                             +"VALUES (?, ?, ?, ?);");
  1232.             stmt.setString(1, name);
  1233.             stmt.setString(2, lname);
  1234.             stmt.setInt(3, pid);
  1235.             stmt.setInt(4, did);
  1236.             stmt.executeUpdate();
  1237.         }
  1238.         finally {
  1239.             if (stmt!=null){
  1240.                 stmt.close();
  1241.             }
  1242.         }
  1243.     }
  1244.  
  1245.     public List<ComboItem> GetDepItems() throws SQLException{
  1246.         List<ComboItem> ci = new ArrayList<ComboItem>();
  1247.         Statement stmt = null;
  1248.         ResultSet rs = null;
  1249.         try {
  1250.             stmt = _ourCon.createStatement();
  1251.             //тут нужен запрос, который свяжент все таблицы и кинет их сюда
  1252.             rs = stmt.executeQuery( "SELECT * FROM department;");
  1253.             while (rs.next()) {
  1254.                 ComboItem dep = new ComboItem(rs.getInt(1),rs.getString(2));
  1255.                 ci.add(dep);
  1256.             }
  1257.         }
  1258.         finally {
  1259.             if (rs != null) {
  1260.                 rs.close();
  1261.             }
  1262.             if (stmt != null) {
  1263.                 stmt.close();
  1264.             }
  1265.         }
  1266.         return ci;
  1267.     }
  1268.  
  1269.     public List<ComboItem> GetPosItems() throws SQLException{
  1270.         List<ComboItem> ci = new ArrayList<ComboItem>();
  1271.         Statement stmt = null;
  1272.         ResultSet rs = null;
  1273.         try {
  1274.             stmt = _ourCon.createStatement();
  1275.             //тут нужен запрос, который свяжент все таблицы и кинет их сюда
  1276.             rs = stmt.executeQuery( "SELECT * FROM positionn;");
  1277.             while (rs.next()) {
  1278.                 int id = rs.getInt(1);
  1279.                 String t=rs.getString(2);
  1280.                 String nPos=rs.getString(3);
  1281.                 ComboItem dep = new ComboItem(id,nPos);
  1282.                 ci.add(dep);
  1283.             }
  1284.         }
  1285.  
  1286.         finally {
  1287.             if (rs != null) {
  1288.                 rs.close();
  1289.             }
  1290.             if (stmt != null) {
  1291.                 stmt.close();
  1292.             }
  1293.         }
  1294.         return ci;
  1295.     }
  1296.  
  1297.     //Position OK
  1298.     public List<Position> SelectPos() throws SQLException{
  1299.         List<Position> posit = new ArrayList<Position>();
  1300.         Statement stmt = null;
  1301.         ResultSet rs = null;
  1302.         try {
  1303.             stmt = _ourCon.createStatement();
  1304.             //тут нужен запрос, который свяжент все таблицы и кинет их сюда
  1305.             rs = stmt.executeQuery( "SELECT * FROM positionn;");
  1306.             while (rs.next()) {
  1307.                 Position pos = new Position();
  1308.                 pos.SetID(rs.getInt(1));
  1309.                 pos.SetSalary(rs.getInt(2));
  1310.                 pos.SetNamePosition(rs.getString(3));
  1311.                 posit.add(pos);
  1312.             }
  1313.         }
  1314.         finally {
  1315.             if (rs != null) {
  1316.                 rs.close();
  1317.             }
  1318.             if (stmt != null) {
  1319.                 stmt.close();
  1320.             }
  1321.         }
  1322.         return posit;
  1323.     }
  1324.  
  1325.     public void UpdatePos(int salary, String name, int id) throws SQLException
  1326.     {
  1327.         PreparedStatement stmt = null;
  1328.         try{
  1329.             stmt = _ourCon.prepareStatement(
  1330.                     "UPDATE positionn SET "
  1331.                     +"SALARY=?, NAME=?  "
  1332.                     +"WHERE ID=?;");
  1333.             stmt.setInt(1, salary);
  1334.             stmt.setString(2,name);
  1335.             stmt.setInt(3,id);
  1336.             stmt.executeUpdate();
  1337.         }
  1338.         finally {
  1339.             if (stmt!=null){
  1340.                 stmt.close();
  1341.             }
  1342.         }
  1343.  
  1344.     }
  1345.  
  1346.     public void RemovePos(int id) throws SQLException
  1347.     {
  1348.         PreparedStatement stmt = null;
  1349.         try{
  1350.             stmt = _ourCon.prepareStatement(
  1351.                     "DELETE FROM positionn WHERE "
  1352.                     +"ID=?;");
  1353.             stmt.setInt(1,id);
  1354.             stmt.executeUpdate();
  1355.         }
  1356.         finally {
  1357.             if (stmt!=null){
  1358.                 stmt.close();
  1359.             }
  1360.         }
  1361.     }
  1362.  
  1363.     //
  1364.     public void InsertPos(int salary, String name) throws SQLException
  1365.     {
  1366.         PreparedStatement stmt = null;
  1367.         try{
  1368.             stmt = _ourCon.prepareStatement(
  1369.                     "INSERT INTO positionn "
  1370.                     +"(SALARY, NAME) "
  1371.                     +"VALUES (?, ?);");
  1372.             stmt.setInt(1,salary);
  1373.             stmt.setString(2,name);
  1374.             stmt.executeUpdate();
  1375.         }
  1376.         finally {
  1377.             if (stmt!=null){
  1378.                 stmt.close();
  1379.             }
  1380.         }
  1381.     }
  1382.  
  1383.  
  1384.     //Department OK
  1385.     public List<Department> SelectDep() throws SQLException{
  1386.         List<Department> depart = new ArrayList<Department>();
  1387.         Statement stmt = null;
  1388.         ResultSet rs = null;
  1389.         try {
  1390.             stmt = _ourCon.createStatement();
  1391.             //тут нужен запрос, который свяжент все таблицы и кинет их сюда
  1392.             rs = stmt.executeQuery( "SELECT * FROM department;");
  1393.             while (rs.next()) {
  1394.                 Department dep = new Department();
  1395.                 dep.SetID(rs.getInt(1));
  1396.                 dep.SetNameDepartment(rs.getString(2));
  1397.                 dep.SetMail(rs.getString(3));
  1398.                 dep.SetPhone(rs.getString(4));
  1399.                 depart.add(dep);
  1400.             }
  1401.         }
  1402.         finally {
  1403.             if (rs != null) {
  1404.                 rs.close();
  1405.             }
  1406.             if (stmt != null) {
  1407.                 stmt.close();
  1408.             }
  1409.         }
  1410.         return depart;
  1411.     }
  1412.  
  1413.     public void UpdateDep(int id, String name, String mail, String phone) throws SQLException
  1414.     {
  1415.         PreparedStatement stmt = null;
  1416.         try{
  1417.             stmt = _ourCon.prepareStatement(
  1418.                     "UPDATE department SET "
  1419.                             +"DEPARTMENT=?, MAIL=?, PHONE=? "
  1420.                             +"WHERE ID=?;");
  1421.             stmt.setString(1,name);
  1422.             stmt.setString(2,mail);
  1423.             stmt.setString(3,phone);
  1424.             stmt.setInt(4,id);
  1425.             stmt.executeUpdate();
  1426.         }
  1427.         finally {
  1428.             if (stmt!=null){
  1429.                 stmt.close();
  1430.             }
  1431.         }
  1432.     }
  1433.  
  1434.     public void RemoveDep(int id) throws SQLException
  1435.     {
  1436.         PreparedStatement stmt = null;
  1437.         try{
  1438.             stmt = _ourCon.prepareStatement(
  1439.                     "DELETE FROM department WHERE "
  1440.                             +"ID=?;");
  1441.             stmt.setInt(1,id);
  1442.             stmt.executeUpdate();
  1443.         }
  1444.         finally {
  1445.             if (stmt!=null){
  1446.                 stmt.close();
  1447.             }
  1448.         }
  1449.     }
  1450.  
  1451.     public void InsertDep(String nameDep, String mail, String phone) throws SQLException
  1452.     {
  1453.         PreparedStatement stmt = null;
  1454.         try{
  1455.             stmt = _ourCon.prepareStatement(
  1456.                     "INSERT INTO department "
  1457.                             +"(DEPARTMENT, MAIL, PHONE) "
  1458.                             +"VALUES (?, ?, ?);");
  1459.             stmt.setString(1,nameDep);
  1460.             stmt.setString(2,mail);
  1461.             stmt.setString(3,phone);
  1462.             stmt.executeUpdate();
  1463.         }
  1464.         finally {
  1465.             if (stmt!=null){
  1466.                 stmt.close();
  1467.             }
  1468.         }
  1469.     }
  1470.  
  1471.     //Научиться создать Department;
  1472. }
  1473.  
  1474. /**
  1475.  * Created by elsemTim on 15.11.2016.
  1476.  */
  1477.  
  1478. import java.text.DateFormat;
  1479. import java.sql.ResultSet;
  1480. import java.sql.SQLException;
  1481. import java.text.Collator;
  1482. import java.util.Date;
  1483. import java.util.Locale;
  1484.  
  1485. public class Department {
  1486.     private int ID;
  1487.     private String nameDepartment;
  1488.     private String mail;
  1489.     private String phone;
  1490.  
  1491.     public Department () {}
  1492.  
  1493.     //set
  1494.     public void SetID( int ID ){
  1495.         this.ID=ID;
  1496.     }
  1497.  
  1498.     public void SetNameDepartment( String nameDepartment){
  1499.         this.nameDepartment=nameDepartment;
  1500.     }
  1501.  
  1502.     public void SetMail( String mail ){
  1503.         this.mail=mail;
  1504.     }
  1505.  
  1506.     public void SetPhone( String phone ){
  1507.         this.phone=phone;
  1508.     }
  1509.  
  1510.     //get
  1511.     public int GetID(){
  1512.         return ID;
  1513.     }
  1514.  
  1515.     public String GetNameDepartment(){
  1516.         return nameDepartment;
  1517.     }
  1518.  
  1519.     public String GetMail(){
  1520.         return mail;
  1521.     }
  1522.  
  1523.     public String GetPhone(){
  1524.         return phone;
  1525.     }
  1526.  
  1527.     //проверяем Ид записи с Ид записанным в Employee
  1528.     public Boolean compareToDep(int ID){
  1529.         return this.ID==ID?true:false;
  1530.     }
  1531. }
  1532.  
  1533. import javax.swing.table.AbstractTableModel;
  1534. import java.util.ArrayList;
  1535. import java.util.Arrays;
  1536.  
  1537. /**
  1538.  * Created by elsemTim on 16.11.2016.
  1539.  */
  1540. public class DepartmentTable extends AbstractTableModel {
  1541.     private ArrayList<String[]> dataArrayList;
  1542.     private int _columnCount=4;
  1543.  
  1544.     public DepartmentTable (){
  1545.         dataArrayList=new ArrayList<String []>();
  1546.     }
  1547.  
  1548.     @Override
  1549.     public int getRowCount() {
  1550.         return dataArrayList.size();
  1551.     }
  1552.  
  1553.     @Override
  1554.     public int getColumnCount() {
  1555.         return _columnCount;
  1556.     }
  1557.  
  1558.     @Override
  1559.     public Object getValueAt(int rowIndex, int columnIndex) {
  1560.         if(rowIndex>=getRowCount() || columnIndex>=getColumnCount()){return "";}
  1561.         return dataArrayList.get(rowIndex)[columnIndex];
  1562.     }
  1563.  
  1564.     @Override
  1565.     public String getColumnName(int c){
  1566.         switch (c){
  1567.             case 0:
  1568.                 return "ID";
  1569.             case 1:
  1570.                 return "Название отдела";
  1571.             case 2:
  1572.                 return "Почта";
  1573.             case 3:
  1574.                 return "Телефон";
  1575.         }
  1576.         return "";
  1577.     }
  1578.  
  1579.     public void AddRow(String [] row){
  1580.         int n = row.length > getColumnCount()? getColumnCount() : row.length;
  1581.         dataArrayList.add(Arrays.copyOf(row, n));
  1582.     }
  1583.  
  1584. }
  1585.  
  1586. /**
  1587.  * Created by elsemTim on 15.11.2016.
  1588.  */
  1589. public class Employee {
  1590.     private int ID;
  1591.     private int depID;
  1592.     private int posID;
  1593.     private String department;
  1594.     private String position;
  1595.     private int salary;
  1596.     private String firstName;
  1597.     private String lastName;
  1598.  
  1599.     public Employee() {}
  1600.  
  1601.     //set
  1602.  
  1603.  
  1604.     public void setDepID(int depID) {
  1605.         this.depID = depID;
  1606.     }
  1607.  
  1608.     public void setPosID(int posID) {
  1609.         this.posID = posID;
  1610.     }
  1611.  
  1612.     public void setSalary(int salary) {this.salary = salary;}
  1613.  
  1614.     public void setID(int ID) {this.ID = ID;}
  1615.  
  1616.     public void SetNameDep(String department){this.department=department;}
  1617.  
  1618.     public void SetNamePos(String position){this.position=position;}
  1619.  
  1620.     public void SetFirstName(String firstName) {this.firstName=firstName;}
  1621.  
  1622.     public void SetLastName(String lastName){this.lastName=lastName;}
  1623.  
  1624.     //get
  1625.     public int getSalary() {return salary;}
  1626.  
  1627.     public int getID() {
  1628.         return ID;
  1629.     }
  1630.  
  1631.     public String GetNameDep() {return department;}
  1632.  
  1633.     public String GetNamePos() {return  position;}
  1634.  
  1635.     public String GetFirstName() { return firstName;}
  1636.  
  1637.     public String GetLastName() {return lastName;}
  1638.  
  1639.     public int getDepID() {
  1640.         return depID;
  1641.     }
  1642.  
  1643.     public int getPosID() {
  1644.         return posID;
  1645.     }
  1646. }
  1647.  
  1648. /**
  1649.  * Created by elsemTim on 17.11.2016.
  1650.  */
  1651. import javax.swing.table.AbstractTableModel;
  1652. import java.util.ArrayList;
  1653. import java.util.Arrays;
  1654.  
  1655. public class EmployeeTable extends AbstractTableModel {
  1656.     private ArrayList<String[]> dataArrayList;
  1657.     private int _columnCount = 8;
  1658.  
  1659.     public EmployeeTable() {
  1660.         dataArrayList = new ArrayList<String[]>();
  1661.     }
  1662.  
  1663.     @Override
  1664.     public int getRowCount() {
  1665.         return dataArrayList.size();
  1666.     }
  1667.  
  1668.     @Override
  1669.     public int getColumnCount() {
  1670.         return _columnCount;
  1671.     }
  1672.  
  1673.     @Override
  1674.     public Object getValueAt(int rowIndex, int columnIndex) {
  1675.         if (rowIndex >= getRowCount() || columnIndex >= getColumnCount()) {
  1676.             return "";
  1677.         }
  1678.         return dataArrayList.get(rowIndex)[columnIndex];
  1679.     }
  1680.  
  1681.     @Override
  1682.     public String getColumnName(int c) {
  1683.         switch (c) {
  1684.             case 0:
  1685.                 return "ID";
  1686.             case 1:
  1687.                 return "Имя";
  1688.             case 2:
  1689.                 return "Фамилия";
  1690.             case 3:
  1691.                 return "Отдел";
  1692.             case 4:
  1693.                 return "Должность";
  1694.             case 5:
  1695.                 return "Зарплата";
  1696.         }
  1697.         return "";
  1698.     }
  1699.  
  1700.     public void AddRow(String[] row) {
  1701.         int n = row.length > getColumnCount() ? getColumnCount() : row.length;
  1702.         dataArrayList.add(Arrays.copyOf(row, n));
  1703.     }
  1704. }
  1705.  
  1706.  
  1707. CREATE TABLE Department (
  1708. ID int not null primary key,
  1709. DEPARTMENT varchar(255) not null,
  1710. MAIL varchar(255) not null,
  1711. PHONE varchar(255) not null
  1712. );
  1713.  
  1714. CREATE TABLE Positionn (
  1715. ID int not null primary key,
  1716. SALARY varchar(255) not null,
  1717. NAME varchar(255) not null
  1718. );
  1719.  
  1720. create table Employee (
  1721. ID int not null primary key,
  1722. DEP_ID                          INT Not Null,
  1723. POS_ID                          INT Not Null,
  1724. FIRST_NAME                      VARCHAR(255) Not Null,
  1725. LAST_NAME                       VARCHAR(255) Not Null,
  1726. CONSTRAINT FK_EMP_DEP
  1727.   Foreign key (DEP_ID)    References DEPARTMENT (ID),
  1728. CONSTRAINT FK_EMP_POS
  1729.   Foreign key (POS_ID)    References POSITIONN (ID)
  1730. );
  1731.  
  1732. CREATE GENERATOR GenDepartmentPK;
  1733. SET GENERATOR GenDepartmentPK TO 0;
  1734.  
  1735. SET TERM ^ ;
  1736. CREATE TRIGGER TrigIncGenPkDepartment FOR DEPARTMENT
  1737. ACTIVE BEFORE INSERT POSITION 0
  1738.  AS
  1739. BEGIN
  1740.     if ((new.id is null) or (new.id = 0))
  1741.     then begin
  1742.             new.id = gen_id(GenDepartmentPK, 1);
  1743.     end
  1744. END^
  1745. SET TERM ; ^
  1746.  
  1747. CREATE GENERATOR GenPositionPK;
  1748. SET GENERATOR GenPositionPK TO 0;
  1749.  
  1750. SET TERM ^ ;
  1751. CREATE TRIGGER TrigIncGenPkPosition FOR positionn
  1752. ACTIVE BEFORE INSERT POSITION 0
  1753.  AS
  1754. BEGIN
  1755.     if ((new.id is null) or (new.id = 0))
  1756.     then begin
  1757.             new.id = gen_id(GenPositionPK, 1);
  1758.     end
  1759. END^
  1760. SET TERM ; ^
  1761.  
  1762. CREATE GENERATOR GenEmployeePK;
  1763. SET GENERATOR GenEmployeePK TO 0;
  1764.  
  1765. SET TERM ^ ;
  1766. CREATE TRIGGER TrigIncGenPkEmployee FOR employee
  1767. ACTIVE BEFORE INSERT POSITION 0
  1768.  AS
  1769. BEGIN
  1770.     if ((new.id is null) or (new.id = 0))
  1771.     then begin
  1772.             new.id = gen_id(GenEmployeePK, 1);
  1773.     end
  1774. END^
  1775. SET TERM ; ^
  1776.  
  1777.   create view vw_Employee (ID, Name, LName, Department, Positionn, Salary, id_dep, id_pos)
  1778.     as
  1779.     select e.Id as ID,e.first_name as Name,
  1780.         e.Last_Name as LName, d.department as Department,
  1781.         p.Name as Positionn,
  1782.         p.Salary as Salary,
  1783.         d.id as id_dep, p.id as id_pos
  1784.     from  employee as e
  1785.       left join department as d on e.DEP_ID=d.ID
  1786.       left join POSITIONN as p on e.POS_ID=p.ID
  1787.     order by d.Department, p.Name, e.First_name, e.Last_name;
  1788.  
  1789. import java.sql.ResultSet;
  1790. import java.sql.SQLException;
  1791.  
  1792. /**
  1793.  * Created by elsemTim on 15.11.2016.
  1794.  */
  1795. public class Position {
  1796.     private int ID;
  1797.     private String namePosition;
  1798.     private int salary;
  1799.  
  1800.     public Position() {}
  1801.  
  1802.     //set
  1803.     public void SetID(int ID){this.ID=ID;}
  1804.  
  1805.     public void SetNamePosition(String namePosition){this.namePosition=namePosition;}
  1806.  
  1807.     public void SetSalary(int salary){this.salary=salary;}
  1808.  
  1809.     //get
  1810.     public int GetID(){return ID;}
  1811.  
  1812.     public String GetNamePosition(){return  namePosition;}
  1813.  
  1814.     public int GetSalary(){return salary;}
  1815.  
  1816.     //проверяем Ид записи с Ид записанным в Employee
  1817.     public Boolean compareToPos(int ID){
  1818.         return this.ID==ID?true:false;
  1819.     }
  1820.  
  1821. }
  1822.  
  1823. /**
  1824.  * Created by elsemTim on 17.11.2016.
  1825.  */
  1826. import javax.swing.table.AbstractTableModel;
  1827. import java.util.ArrayList;
  1828. import java.util.Arrays;
  1829.  
  1830. public class PositionTable extends AbstractTableModel {
  1831.     private ArrayList<String[]> dataArrayList;
  1832.     private int _columnCount=3;
  1833.  
  1834.     public PositionTable(){dataArrayList=new ArrayList<String[]>();}
  1835.  
  1836.     @Override
  1837.     public int getRowCount() {
  1838.         return dataArrayList.size();
  1839.     }
  1840.  
  1841.     @Override
  1842.     public int getColumnCount() {
  1843.         return _columnCount;
  1844.     }
  1845.  
  1846.     @Override
  1847.     public Object getValueAt(int rowIndex, int columnIndex) {
  1848.         if(rowIndex>=getRowCount() || columnIndex>=getColumnCount()){return "";}
  1849.         return dataArrayList.get(rowIndex)[columnIndex];
  1850.     }
  1851.  
  1852.     @Override
  1853.     public String getColumnName(int c){
  1854.         switch (c) {
  1855.             case 0:
  1856.                 return "ID";
  1857.             case 1:
  1858.                 return "Позиция";
  1859.             case 2:
  1860.                 return "Зарплата";
  1861.         }
  1862.         return "";
  1863.     }
  1864.  
  1865.     public void AddRow(String [] row){
  1866.         int n=row.length>getColumnCount()?getColumnCount():row.length;
  1867.         dataArrayList.add(Arrays.copyOf(row,n));
  1868.     }
  1869. }
Advertisement
Add Comment
Please, Sign In to add comment