Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //package clientServerApp;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- import javax.swing.table.TableModel;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Properties;
- public class FirebirdTWJJ {
- /**
- * @param args
- */
- //global var
- static DBConnect dbConn;
- static JFrame frame;
- /// Depart controls
- static JTable depGrid;
- static JDialog addDepartDialog;
- static JDialog editDepartDialog;
- static JButton addDepButton;
- static JButton delDepButton;
- static JButton editDepButton;
- static JScrollPane departTableScroolPage;
- /// End Depart controls
- /// Position controls
- static JTable posGrid;
- static JDialog addPositDialog;
- static JDialog editPositDialog;
- static JButton addPosButton;
- static JButton delPosButton;
- static JButton editPosButton;
- static JScrollPane positTableScroolPage;
- /// End Position controls
- /// Employee controls
- static JTable empGrid;
- static JDialog addEmplDialog;
- static JDialog editEmplDialog;
- static JButton addEmpButton;
- static JButton delEmpButton;
- static JButton editEmpButton;
- static JScrollPane emplTableScroolPage;
- /// End Employee controls
- static JRadioButton empRB;
- static JRadioButton posRB;
- static JRadioButton depRB;
- //helpers
- static void InitDB(Properties p) throws Exception{
- dbConn = DBConnect.getInstance(p);
- }
- static DepartmentTable GetDepartData() throws SQLException {
- List<Department> dep = null;
- try {
- dep = dbConn.SelectDep();
- } catch (SQLException e) {
- e.printStackTrace();
- throw e;
- }
- DepartmentTable depTable = new DepartmentTable();
- String[] tmp = new String[depTable.getColumnCount()];
- for (int i = 0; i < dep.size(); i++) {
- Department d = dep.get(i);
- tmp[0] = "" + d.GetID();
- tmp[1] = d.GetNameDepartment();
- tmp[2] = d.GetMail();
- tmp[3] = d.GetPhone();
- depTable.AddRow(tmp);
- }
- return depTable;
- }
- static PositionTable GetPositionData() throws SQLException {
- List<Position> pos = null;
- try {
- pos = dbConn.SelectPos();
- } catch (SQLException e) {
- e.printStackTrace();
- throw e;
- }
- PositionTable posTable = new PositionTable();
- String[] tmp = new String[posTable.getColumnCount()];
- for (int i = 0; i < pos.size(); i++) {
- Position p = pos.get(i);
- tmp[0] = "" + p.GetID();
- tmp[1] = p.GetNamePosition();
- tmp[2] = ""+p.GetSalary();
- posTable.AddRow(tmp);
- }
- return posTable;
- }
- static EmployeeTable GetEmployeeData() throws SQLException {
- List<Employee> emp = null;
- try {
- emp = dbConn.SelectEmp();
- } catch (SQLException e) {
- e.printStackTrace();
- throw e;
- }
- EmployeeTable empTable = new EmployeeTable();
- String[] tmp = new String[empTable.getColumnCount()];
- for (int i = 0; i < emp.size(); i++) {
- Employee e = emp.get(i);
- tmp[0] = "" + e.getID();
- tmp[1] = e.GetFirstName();
- tmp[2] = e.GetLastName();
- tmp[3] = e.GetNameDep();
- tmp[4] = e.GetNamePos();
- tmp[5] =""+e.getSalary();
- tmp[6]=""+e.getDepID();
- tmp[7]=""+e.getPosID();
- empTable.AddRow(tmp);
- }
- return empTable;
- }
- static List<ComboItem> GetDepItems () {
- try {
- return dbConn.GetDepItems();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return new ArrayList<ComboItem> ();
- }
- static List<ComboItem> GetPosItems () {
- try {
- return dbConn.GetPosItems();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return new ArrayList<ComboItem> ();
- }
- //создаем новый Dialog при нажатие на кнопку Add для Departmena
- static void InitAddDepartDialog(){
- addDepartDialog = new JDialog(frame,"Добавить отдел",true);
- addDepartDialog.setLocationRelativeTo(frame);
- addDepartDialog.setSize(new Dimension(500,300));
- addDepartDialog.setLayout(new GridBagLayout());
- JTextField nameField=new JTextField(20);
- JTextField phoneField=new JTextField(20);
- JTextField mailField=new JTextField(20);
- JButton okButton = new JButton("OK");
- okButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String m=mailField.getText().trim();
- String p=phoneField.getText().trim();
- String n=nameField.getText().trim();
- if (m.length()>0 && p.length()>0 && n.length()>0) {
- try {
- dbConn.InsertDep(n, m, p);
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- try {
- addDepartDialog.setVisible(false);
- depGrid.setModel(GetDepartData());
- //DefaultTableModel model = (DefaultTableModel) depGrid.getModel();
- //model.fireTableDataChanged();
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- }
- addDepartDialog.setVisible(false);
- }
- });
- addDepartDialog.add( new JLabel("Имя отдела: "), new GridBagConstraints(0,0,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addDepartDialog.add(nameField, new GridBagConstraints(1,0,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addDepartDialog.add( new JLabel("Почта: "), new GridBagConstraints(0,1,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addDepartDialog.add(mailField, new GridBagConstraints(1,1,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addDepartDialog.add( new JLabel("Телефон: "), new GridBagConstraints(0,2,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addDepartDialog.add(phoneField, new GridBagConstraints(1,2,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addDepartDialog.add(okButton, new GridBagConstraints(1,3,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addDepartDialog.pack();
- }
- //создаем новый Dialog при нажатие на кнопку Add для Positiona
- static void InitAddPositionDialog(){
- addPositDialog = new JDialog(frame,"Добавить должность",true);
- addPositDialog.setLocationRelativeTo(frame);
- addPositDialog.setSize(new Dimension(500,300));
- addPositDialog.setLayout(new GridBagLayout());
- JTextField nameField=new JTextField(20);
- JTextField salaryField=new JTextField(20);
- JButton okButton = new JButton("OK");
- okButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String posn=nameField.getText().trim();
- String ss=salaryField.getText().trim();
- if (ss.length()>0 && posn.length()>0) {
- try {
- int sal = Integer.parseInt(ss);
- dbConn.InsertPos(sal,posn);
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- try {
- addPositDialog.setVisible(false);
- posGrid.setModel(GetPositionData());
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- }
- addPositDialog.setVisible(false);
- }
- });
- addPositDialog.add( new JLabel("Должность: "), new GridBagConstraints(0,0,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addPositDialog.add(nameField, new GridBagConstraints(1,0,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addPositDialog.add( new JLabel("Зарплата: "), new GridBagConstraints(0,1,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addPositDialog.add(salaryField, new GridBagConstraints(1,1,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addPositDialog.add(okButton, new GridBagConstraints(1,3,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addPositDialog.pack();
- }
- //создаем новый Dialog при нажатие на кнопку Add для Employee
- static void InitAddEmployeeDialog(){
- addEmplDialog = new JDialog(frame,"Добавить сотрудника",true);
- addEmplDialog.setLocationRelativeTo(frame);
- addEmplDialog.setSize(new Dimension(500,300));
- addEmplDialog.setLayout(new GridBagLayout());
- JTextField nameField=new JTextField(20);
- JTextField lnameField=new JTextField(20);
- JComboBox<ComboItem> pos= new JComboBox<ComboItem>();
- List <ComboItem> lp = GetPosItems();
- for (int i=0;i<lp.size();i++)
- {
- pos.addItem(lp.get(i));
- }
- JComboBox<ComboItem> dep= new JComboBox<ComboItem>();
- List <ComboItem> ld = GetDepItems();
- for (int i=0;i<ld.size();i++)
- {
- dep.addItem(ld.get(i));
- }
- JButton okButton = new JButton("OK");
- okButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String n=nameField.getText().trim();
- String ln=lnameField.getText().trim();
- int did= ((ComboItem)dep.getSelectedItem()).getValue();
- int pid= ((ComboItem)pos.getSelectedItem()).getValue();
- if ( ln.length()>0 && n.length()>0) {
- try {
- dbConn.InsertEmp(n,ln, did,pid);
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- try {
- addEmplDialog.setVisible(false);
- empGrid.setModel(GetEmployeeData());
- empGrid.getColumnModel().getColumn(7).setMinWidth(0);
- empGrid.getColumnModel().getColumn(7).setMaxWidth(0);
- empGrid.getColumnModel().getColumn(6).setMinWidth(0);
- empGrid.getColumnModel().getColumn(6).setMaxWidth(0);
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- }
- addEmplDialog.setVisible(false);
- }
- });
- addEmplDialog.add( new JLabel("Имя: "), new GridBagConstraints(0,0,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addEmplDialog.add(nameField, new GridBagConstraints(1,0,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addEmplDialog.add( new JLabel("Фамилия: "), new GridBagConstraints(0,1,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addEmplDialog.add(lnameField, new GridBagConstraints(1,1,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addEmplDialog.add( new JLabel("Отдел: "), new GridBagConstraints(0,2,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addEmplDialog.add(dep, new GridBagConstraints(1,2,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addEmplDialog.add( new JLabel("Должность: "), new GridBagConstraints(0,3,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addEmplDialog.add(pos, new GridBagConstraints(1,3,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addEmplDialog.add(okButton, new GridBagConstraints(1,4,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- addEmplDialog.pack();
- }
- static void InitEditDepartDialog(){
- editDepartDialog = new JDialog(frame,"Изменить отдел",true);
- editDepartDialog.setLocationRelativeTo(frame);
- editDepartDialog.setSize(new Dimension(500,300));
- editDepartDialog.setLayout(new GridBagLayout());
- JTextField nameField=new JTextField(20);
- JTextField phoneField=new JTextField(20);
- JTextField mailField=new JTextField(20);
- JTextField idField=new JTextField(20);
- idField.setVisible(false);
- JButton okButton = new JButton("OK");
- okButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String m=mailField.getText().trim();
- String p=phoneField.getText().trim();
- String n=nameField.getText().trim();
- String sid=idField.getText().trim();
- int id = Integer.parseInt(sid);
- if (m.length()>0 && p.length()>0 && n.length()>0) {
- try {
- dbConn.UpdateDep(id, n, m, p);
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- try {
- editDepartDialog.setVisible(false);
- depGrid.setModel(GetDepartData());
- //DefaultTableModel model = (DefaultTableModel) depGrid.getModel();
- //model.fireTableDataChanged();
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- }
- editDepartDialog.setVisible(false);
- }
- });
- editDepartDialog.add( new JLabel("Имя отдела: "), new GridBagConstraints(0,0,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editDepartDialog.add(nameField, new GridBagConstraints(1,0,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editDepartDialog.add( new JLabel("Почта: "), new GridBagConstraints(0,1,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editDepartDialog.add(mailField, new GridBagConstraints(1,1,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editDepartDialog.add( new JLabel("Телефон: "), new GridBagConstraints(0,2,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editDepartDialog.add(phoneField, new GridBagConstraints(1,2,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editDepartDialog.add(okButton, new GridBagConstraints(1,3,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editDepartDialog.add(idField, new GridBagConstraints(1,4,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editDepartDialog.pack();
- }
- static void InitEditPositDialog(){
- editPositDialog = new JDialog(frame,"Изменить должность",true);
- editPositDialog.setLocationRelativeTo(frame);
- editPositDialog.setSize(new Dimension(500,300));
- editPositDialog.setLayout(new GridBagLayout());
- JTextField nameField=new JTextField(20);
- JTextField salaryField=new JTextField(20);
- JTextField idField=new JTextField(20);
- idField.setVisible(false);
- JButton okButton = new JButton("OK");
- okButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String n=nameField.getText().trim();
- String s=salaryField.getText().trim();
- String sid=idField.getText().trim();
- int id = Integer.parseInt(sid);
- if (s.length()>0 && n.length()>0) {
- try {
- dbConn.UpdatePos(Integer.parseInt(s),n,id);
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- try {
- editPositDialog.setVisible(false);
- posGrid.setModel(GetPositionData());
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- }
- editPositDialog.setVisible(false);
- }
- });
- editPositDialog.add( new JLabel("Должность: "), new GridBagConstraints(0,0,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editPositDialog.add(nameField, new GridBagConstraints(1,0,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editPositDialog.add( new JLabel("Зарплата: "), new GridBagConstraints(0,1,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editPositDialog.add(salaryField, new GridBagConstraints(1,1,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editPositDialog.add(okButton, new GridBagConstraints(1,3,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editPositDialog.add(idField, new GridBagConstraints(1,2,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editPositDialog.pack();
- }
- static void InitEditEmployeeDialog(){
- editEmplDialog = new JDialog(frame,"Изменить сотрудника",true);
- editEmplDialog.setLocationRelativeTo(frame);
- editEmplDialog.setSize(new Dimension(500,300));
- editEmplDialog.setLayout(new GridBagLayout());
- JTextField nameField=new JTextField(20);
- JTextField lnameField=new JTextField(20);
- JTextField idField=new JTextField(20);
- idField.setVisible(false);
- JComboBox<ComboItem> pos= new JComboBox<ComboItem>();
- List <ComboItem> lp = GetPosItems();
- for (int i=0;i<lp.size();i++)
- {
- pos.addItem(lp.get(i));
- }
- JComboBox<ComboItem> dep= new JComboBox<ComboItem>();
- List <ComboItem> ld = GetDepItems();
- for (int i=0;i<ld.size();i++)
- {
- dep.addItem(ld.get(i));
- }
- JButton okButton = new JButton("OK");
- okButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String n=nameField.getText().trim();
- String ln=lnameField.getText().trim();
- int did= ((ComboItem)dep.getSelectedItem()).getValue();
- int pid= ((ComboItem)pos.getSelectedItem()).getValue();
- String sid=idField.getText().trim();
- int id = Integer.parseInt(sid);
- if ( ln.length()>0 && n.length()>0) {
- try {
- dbConn.UpdateEmp(n,ln, did,pid,id);
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- try {
- editEmplDialog.setVisible(false);
- empGrid.setModel(GetEmployeeData());
- empGrid.getColumnModel().getColumn(7).setMinWidth(0);
- empGrid.getColumnModel().getColumn(7).setMaxWidth(0);
- empGrid.getColumnModel().getColumn(6).setMinWidth(0);
- empGrid.getColumnModel().getColumn(6).setMaxWidth(0);
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- }
- editEmplDialog.setVisible(false);
- }
- });
- editEmplDialog.add( new JLabel("Имя: "), new GridBagConstraints(0,0,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editEmplDialog.add(nameField, new GridBagConstraints(1,0,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editEmplDialog.add( new JLabel("Фамилия: "), new GridBagConstraints(0,1,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editEmplDialog.add(lnameField, new GridBagConstraints(1,1,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editEmplDialog.add( new JLabel("Отдел: "), new GridBagConstraints(0,2,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editEmplDialog.add(dep, new GridBagConstraints(1,2,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editEmplDialog.add( new JLabel("Должность: "), new GridBagConstraints(0,3,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editEmplDialog.add(pos, new GridBagConstraints(1,3,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editEmplDialog.add(okButton, new GridBagConstraints(1,4,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editEmplDialog.add(idField, new GridBagConstraints(1,1,1,1,1,1,
- GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
- new Insets(2,2,2,2),0,0));
- editEmplDialog.pack();
- }
- static void InitDialogs(){
- InitAddDepartDialog();
- InitEditDepartDialog();
- InitAddPositionDialog();
- InitEditPositDialog();
- InitAddEmployeeDialog();
- InitEditEmployeeDialog();
- }
- ///////////Работа со скрытием элементов
- //dep
- static void ShowDepartment() throws SQLException {
- HidePosition();
- HideEmployee();
- frame.add(departTableScroolPage, new GridBagConstraints(0, 0, 3, 1, 0, 0,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 1, 1, 1), 0, 0));
- depGrid.setModel(GetDepartData());
- depGrid.setVisible(true);
- addDepButton.setVisible(true);
- delDepButton.setVisible(true);
- editDepButton.setVisible(true);
- departTableScroolPage.setVisible(true);
- }
- static void HideDepartment() throws SQLException{
- departTableScroolPage.setVisible(false);
- frame.remove(departTableScroolPage);
- depGrid.setVisible(false);
- addDepButton.setVisible(false);
- delDepButton.setVisible(false);
- editDepButton.setVisible(false);
- }
- //pos
- static void ShowPosition() throws SQLException{
- HideDepartment();
- HideEmployee();
- frame.add(positTableScroolPage, new GridBagConstraints(0, 0, 3, 1, 0, 0,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 1, 1, 1), 0, 0));
- posGrid.setModel(GetPositionData());
- posGrid.setVisible(true);
- addPosButton.setVisible(true);
- delPosButton.setVisible(true);
- editPosButton.setVisible(true);
- positTableScroolPage.setVisible(true);
- }
- static void HidePosition() throws SQLException{
- positTableScroolPage.setVisible(false);
- frame.remove(positTableScroolPage);
- posGrid.setVisible(false);
- addPosButton.setVisible(false);
- delPosButton.setVisible(false);
- editPosButton.setVisible(false);
- }
- //emp
- static void ShowEmployee() throws SQLException{
- HidePosition();
- HideDepartment();
- frame.add(emplTableScroolPage, new GridBagConstraints(0, 0, 3, 1, 0, 0,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 1, 1, 1), 0, 0));
- empGrid.setModel(GetEmployeeData());
- empGrid.getColumnModel().getColumn(7).setMinWidth(0);
- empGrid.getColumnModel().getColumn(7).setMaxWidth(0);
- empGrid.getColumnModel().getColumn(6).setMinWidth(0);
- empGrid.getColumnModel().getColumn(6).setMaxWidth(0);
- empGrid.setVisible(true);
- addEmpButton.setVisible(true);
- delEmpButton.setVisible(true);
- editEmpButton.setVisible(true);
- emplTableScroolPage.setVisible(true);
- }
- static void HideEmployee() throws SQLException{
- emplTableScroolPage.setVisible(false);
- frame.remove(emplTableScroolPage);
- empGrid.setVisible(false);
- addEmpButton.setVisible(false);
- delEmpButton.setVisible(false);
- editEmpButton.setVisible(false);
- }
- ///////
- static void ShowFrame()
- {
- frame.pack();
- frame.setVisible(true);
- }
- static void InitFrame(){
- frame = new JFrame("Учет сотрудников предприятия");
- frame.setSize(new Dimension(1000, 1000));
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- frame.setLayout(new GridBagLayout());
- ButtonGroup group = new ButtonGroup();
- //выполняем инизиализацию и отрисовку для
- //Department
- depRB = new JRadioButton("Отдел",true);
- depRB.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- ShowDepartment();
- }
- catch (SQLException ex)
- {
- JOptionPane.showMessageDialog(new JFrame(), ex.getMessage(), "ERROR",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
- }
- });
- group.add(depRB);
- //////
- //выполняем инизиализацию и отрисовку для
- //Position
- posRB = new JRadioButton("Должность",false);
- posRB.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- ShowPosition();
- }
- catch (SQLException ex) {
- JOptionPane.showMessageDialog(new JFrame(), ex.getMessage(), "ERROR",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
- }
- });
- group.add(posRB);
- //////
- //выполняем инизиализацию и отрисовку для
- //Employee
- empRB = new JRadioButton("Люди",false);
- //
- empRB.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- ShowEmployee();
- }
- catch (SQLException ex) {
- JOptionPane.showMessageDialog(new JFrame(), ex.getMessage(), "ERROR",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
- }
- });
- group.add(empRB);
- //////
- frame.add(depRB, new GridBagConstraints(0, 2, 1, 1, 1, 1,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 4, 1, 1), 0, 0));
- frame.add(posRB, new GridBagConstraints(1, 2, 1, 1, 1, 1,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 4, 1, 1), 0, 0));
- frame.add(empRB, new GridBagConstraints(2, 2, 1, 1, 1, 1,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 4, 1, 1), 0, 0));
- }
- static void InitDepartGrid() throws SQLException{
- //указываем модель таблицы
- try {
- depGrid = new JTable(GetDepartData());
- } catch (SQLException e) {
- e.printStackTrace();
- throw e;
- }
- depGrid.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- departTableScroolPage = new JScrollPane(depGrid);
- departTableScroolPage.setPreferredSize(new Dimension(400, 400));
- //addbut
- addDepButton = new JButton("Добавить");
- addDepButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- addDepartDialog.setVisible(true);
- }
- });
- //delbut
- delDepButton = new JButton("Удалить");
- delDepButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- int n=depGrid.getSelectedRow();
- if (n>=0){
- TableModel m=depGrid.getModel();
- String s=(String)m.getValueAt(n,0);
- int id= Integer.parseInt(s);
- try {
- dbConn.RemoveDep(id);
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- try {
- depGrid.setModel(GetDepartData());
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- }
- }
- });
- //editbut
- editDepButton = new JButton("Изменить");
- editDepButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- int n=depGrid.getSelectedRow();
- if (n>=0){
- TableModel m=depGrid.getModel();
- Component [] comp = editDepartDialog.getContentPane().getComponents();
- ((JTextField)comp[1]).setText((String)m.getValueAt(n,1));
- ((JTextField)comp[3]).setText((String)m.getValueAt(n,2));
- ((JTextField)comp[5]).setText((String)m.getValueAt(n,3));
- ((JTextField)comp[7]).setText((String)m.getValueAt(n,0));
- editDepartDialog.setVisible(true);
- }
- }
- });
- frame.add(addDepButton, new GridBagConstraints(0, 1, 1, 1, 1, 1,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 1, 1, 1), 0, 0));
- frame.add(delDepButton, new GridBagConstraints(1, 1, 1, 1, 1, 1,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 1, 1, 1), 0, 0));
- frame.add(editDepButton, new GridBagConstraints(2, 1, 1, 1, 1, 1,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 1, 1, 1), 0, 0));
- }
- static void InitPositionGrid() throws SQLException{
- //указываем модель таблицы
- try {
- posGrid = new JTable(GetPositionData());
- } catch (SQLException e) {
- e.printStackTrace();
- throw e;
- }
- posGrid.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- positTableScroolPage = new JScrollPane(posGrid);
- positTableScroolPage.setPreferredSize(new Dimension(400, 400));
- //addbut
- addPosButton = new JButton("Добавить");
- addPosButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- addPositDialog.setVisible(true);
- }
- });
- //delbut
- delPosButton = new JButton("Удалить");
- delPosButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- int n=posGrid.getSelectedRow();
- if (n>=0){
- TableModel m=posGrid.getModel();
- String s=(String)m.getValueAt(n,0);
- int id= Integer.parseInt(s);
- try {
- dbConn.RemovePos(id);
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- try {
- posGrid.setModel(GetPositionData());
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- }
- }
- });
- //editbut
- editPosButton = new JButton("Изменить");
- editPosButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- int n=posGrid.getSelectedRow();
- if (n>=0){
- TableModel m=posGrid.getModel();
- Component [] comp = editPositDialog.getContentPane().getComponents();
- ((JTextField)comp[1]).setText((String)m.getValueAt(n,1));
- ((JTextField)comp[3]).setText((String)m.getValueAt(n,2));
- ((JTextField)comp[5]).setText((String)m.getValueAt(n,0));
- editPositDialog.setVisible(true);
- }
- }
- });
- frame.add(addPosButton, new GridBagConstraints(0, 1, 1, 1, 1, 1,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 1, 1, 1), 0, 0));
- frame.add(delPosButton, new GridBagConstraints(1, 1, 1, 1, 1, 1,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 1, 1, 1), 0, 0));
- frame.add(editPosButton, new GridBagConstraints(2, 1, 1, 1, 1, 1,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 1, 1, 1), 0, 0));
- ShowFrame();
- }
- static void InitEmplnGrid() throws SQLException{
- //указываем модель таблицы
- try {
- empGrid = new JTable(GetEmployeeData());
- empGrid.getColumnModel().getColumn(7).setMinWidth(0);
- empGrid.getColumnModel().getColumn(7).setMaxWidth(0);
- empGrid.getColumnModel().getColumn(6).setMinWidth(0);
- empGrid.getColumnModel().getColumn(6).setMaxWidth(0);
- } catch (SQLException e) {
- e.printStackTrace();
- throw e;
- }
- empGrid.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- emplTableScroolPage = new JScrollPane(empGrid);
- emplTableScroolPage.setPreferredSize(new Dimension(400, 400));
- //addbut
- addEmpButton = new JButton("Добавить");
- addEmpButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- addEmplDialog.setVisible(true);
- }
- });
- //delbut
- delEmpButton = new JButton("Удалить");
- delEmpButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- int n=empGrid.getSelectedRow();
- if (n>=0){
- TableModel m=empGrid.getModel();
- String s=(String)m.getValueAt(n,0);
- int id= Integer.parseInt(s);
- try {
- dbConn.RemoveEmp(id);
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- try {
- empGrid.setModel(GetEmployeeData());
- empGrid.getColumnModel().getColumn(7).setMinWidth(0);
- empGrid.getColumnModel().getColumn(7).setMaxWidth(0);
- empGrid.getColumnModel().getColumn(6).setMinWidth(0);
- empGrid.getColumnModel().getColumn(6).setMaxWidth(0);
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- }
- }
- });
- //editbut
- editEmpButton = new JButton("Изменить");
- editEmpButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- int n=empGrid.getSelectedRow();
- if (n>=0){
- TableModel m=empGrid.getModel();
- Component [] comp = editEmplDialog.getContentPane().getComponents();
- ((JTextField)comp[1]).setText((String)m.getValueAt(n,1));
- ((JTextField)comp[3]).setText((String)m.getValueAt(n,2));
- ((JTextField)comp[9]).setText((String)m.getValueAt(n,0));
- String tmp= (String)m.getValueAt(n,6);
- String aus= (String)m.getValueAt(n,3);
- int did=Integer.parseInt(tmp);
- ComboItem itm=new ComboItem(did,aus);
- ((JComboBox)comp[5]).setSelectedItem(itm);
- tmp= (String)m.getValueAt(n,7);
- aus= (String)m.getValueAt(n,4);
- did=Integer.parseInt(tmp);
- itm=new ComboItem(did,aus);
- ((JComboBox)comp[7]).setSelectedItem(itm);
- editEmplDialog.setVisible(true);
- }
- }
- });
- frame.add(addEmpButton, new GridBagConstraints(0, 1, 1, 1, 1, 1,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 1, 1, 1), 0, 0));
- frame.add(delEmpButton, new GridBagConstraints(1, 1, 1, 1, 1, 1,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 1, 1, 1), 0, 0));
- frame.add(editEmpButton, new GridBagConstraints(2, 1, 1, 1, 1, 1,
- GridBagConstraints.NORTH,
- GridBagConstraints.BOTH,
- new Insets(1, 1, 1, 1), 0, 0));
- ShowFrame();
- }
- public static void main(String[] args) {
- Properties props = new Properties();
- try {
- props.load(new FileInputStream(new File(".\\src\\config.ini")));
- } catch (IOException e) {
- JOptionPane.showMessageDialog(new JFrame(), e.getMessage(), "ERROR",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
- try {
- InitDB(props);
- } catch (Exception e) {
- e.printStackTrace();
- JOptionPane.showMessageDialog(new JFrame(), e.getMessage(), "ERROR",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
- InitFrame();
- try {
- InitDialogs();
- InitDepartGrid();
- InitPositionGrid();
- InitEmplnGrid();
- ShowDepartment();
- ShowFrame();
- } catch (SQLException e) {
- e.printStackTrace();
- JOptionPane.showMessageDialog(new JFrame(), e.getMessage(), "ERROR",
- JOptionPane.ERROR_MESSAGE);
- return;
- };
- }
- }
- /**
- * Created by elsemTim on 14.11.2016.
- */
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Properties;
- public class DBConnect {
- private static DBConnect _ourInstance;
- private static Connection _ourCon;
- public static DBConnect getInstance(Properties p) throws Exception {
- if (_ourInstance ==null)
- {
- _ourInstance = new DBConnect(p);
- }
- return _ourInstance;
- }
- private DBConnect(Properties p) throws Exception {
- try
- {
- Class.forName("org.firebirdsql.jdbc.FBDriver");
- String strDatabasePath =p.getProperty("DBPath");
- String strUrl="jdbc:firebirdsql://"+p.getProperty("server")+":3050/"+strDatabasePath+"";
- Properties props = new Properties();
- props.setProperty("user","SYSDBA");
- props.setProperty("password","123");
- props.setProperty("encoding","UNICODE_FSS");
- //props.setProperty("encoding","ISO8859_5");
- _ourCon=DriverManager.getConnection(strUrl,props);
- }
- catch (Exception e)
- {
- throw new Exception(e);
- }
- }
- //Employee
- public List<Employee> SelectEmp() throws SQLException{
- List<Employee> employ = new ArrayList<Employee>();
- Statement stmt = null;
- ResultSet rs = null;
- try {
- stmt = _ourCon.createStatement();
- //тут нужен запрос, который свяжент все таблицы и кинет их сюда
- rs = stmt.executeQuery( "SELECT * FROM vw_Employee;");
- while (rs.next()) {
- Employee emp = new Employee();
- emp.setID(rs.getInt(1));
- emp.SetFirstName(rs.getString(2));
- emp.SetLastName(rs.getString(3));
- emp.SetNameDep(rs.getString(4));
- emp.SetNamePos(rs.getString(5));
- emp.setSalary(rs.getInt(6));
- emp.setDepID(rs.getInt(7));
- emp.setPosID(rs.getInt(8));
- employ.add(emp);
- }
- }
- catch (SQLException e)
- {
- int i=1;
- }
- finally {
- if (rs != null) {
- rs.close();
- }
- if (stmt != null) {
- stmt.close();
- }
- }
- return employ;
- }
- public void UpdateEmp(String name, String lname, int did, int pid,int id) throws SQLException
- {
- PreparedStatement stmt = null;
- try{
- stmt = _ourCon.prepareStatement(
- "UPDATE Employee SET "
- +"FIRST_NAME=?, LAST_NAME=?, POS_ID=?, DEP_ID=?"
- +"WHERE ID=?;");
- stmt.setString(1, name);
- stmt.setString(2, lname);
- stmt.setInt(3, pid);
- stmt.setInt(4, did);
- stmt.setInt(5,id);
- stmt.executeUpdate();
- }
- finally {
- if (stmt!=null){
- stmt.close();
- }
- }
- }
- public void RemoveEmp (int id) throws SQLException
- {
- PreparedStatement stmt = null;
- try{
- stmt = _ourCon.prepareStatement(
- "DELETE FROM Employee WHERE "
- +"ID=?;");
- stmt.setInt(1, id);
- stmt.executeUpdate();
- }
- finally {
- if (stmt!=null){
- stmt.close();
- }
- }
- }
- public void InsertEmp (String name, String lname, int did, int pid) throws SQLException
- {
- PreparedStatement stmt = null;
- try{
- stmt = _ourCon.prepareStatement(
- "INSERT INTO Employee "
- +"(FIRST_NAME, LAST_NAME, POS_ID, DEP_ID) "
- +"VALUES (?, ?, ?, ?);");
- stmt.setString(1, name);
- stmt.setString(2, lname);
- stmt.setInt(3, pid);
- stmt.setInt(4, did);
- stmt.executeUpdate();
- }
- finally {
- if (stmt!=null){
- stmt.close();
- }
- }
- }
- public List<ComboItem> GetDepItems() throws SQLException{
- List<ComboItem> ci = new ArrayList<ComboItem>();
- Statement stmt = null;
- ResultSet rs = null;
- try {
- stmt = _ourCon.createStatement();
- //тут нужен запрос, который свяжент все таблицы и кинет их сюда
- rs = stmt.executeQuery( "SELECT * FROM department;");
- while (rs.next()) {
- ComboItem dep = new ComboItem(rs.getInt(1),rs.getString(2));
- ci.add(dep);
- }
- }
- finally {
- if (rs != null) {
- rs.close();
- }
- if (stmt != null) {
- stmt.close();
- }
- }
- return ci;
- }
- public List<ComboItem> GetPosItems() throws SQLException{
- List<ComboItem> ci = new ArrayList<ComboItem>();
- Statement stmt = null;
- ResultSet rs = null;
- try {
- stmt = _ourCon.createStatement();
- //тут нужен запрос, который свяжент все таблицы и кинет их сюда
- rs = stmt.executeQuery( "SELECT * FROM positionn;");
- while (rs.next()) {
- int id = rs.getInt(1);
- String t=rs.getString(2);
- String nPos=rs.getString(3);
- ComboItem dep = new ComboItem(id,nPos);
- ci.add(dep);
- }
- }
- finally {
- if (rs != null) {
- rs.close();
- }
- if (stmt != null) {
- stmt.close();
- }
- }
- return ci;
- }
- //Position OK
- public List<Position> SelectPos() throws SQLException{
- List<Position> posit = new ArrayList<Position>();
- Statement stmt = null;
- ResultSet rs = null;
- try {
- stmt = _ourCon.createStatement();
- //тут нужен запрос, который свяжент все таблицы и кинет их сюда
- rs = stmt.executeQuery( "SELECT * FROM positionn;");
- while (rs.next()) {
- Position pos = new Position();
- pos.SetID(rs.getInt(1));
- pos.SetSalary(rs.getInt(2));
- pos.SetNamePosition(rs.getString(3));
- posit.add(pos);
- }
- }
- finally {
- if (rs != null) {
- rs.close();
- }
- if (stmt != null) {
- stmt.close();
- }
- }
- return posit;
- }
- public void UpdatePos(int salary, String name, int id) throws SQLException
- {
- PreparedStatement stmt = null;
- try{
- stmt = _ourCon.prepareStatement(
- "UPDATE positionn SET "
- +"SALARY=?, NAME=? "
- +"WHERE ID=?;");
- stmt.setInt(1, salary);
- stmt.setString(2,name);
- stmt.setInt(3,id);
- stmt.executeUpdate();
- }
- finally {
- if (stmt!=null){
- stmt.close();
- }
- }
- }
- public void RemovePos(int id) throws SQLException
- {
- PreparedStatement stmt = null;
- try{
- stmt = _ourCon.prepareStatement(
- "DELETE FROM positionn WHERE "
- +"ID=?;");
- stmt.setInt(1,id);
- stmt.executeUpdate();
- }
- finally {
- if (stmt!=null){
- stmt.close();
- }
- }
- }
- //
- public void InsertPos(int salary, String name) throws SQLException
- {
- PreparedStatement stmt = null;
- try{
- stmt = _ourCon.prepareStatement(
- "INSERT INTO positionn "
- +"(SALARY, NAME) "
- +"VALUES (?, ?);");
- stmt.setInt(1,salary);
- stmt.setString(2,name);
- stmt.executeUpdate();
- }
- finally {
- if (stmt!=null){
- stmt.close();
- }
- }
- }
- //Department OK
- public List<Department> SelectDep() throws SQLException{
- List<Department> depart = new ArrayList<Department>();
- Statement stmt = null;
- ResultSet rs = null;
- try {
- stmt = _ourCon.createStatement();
- //тут нужен запрос, который свяжент все таблицы и кинет их сюда
- rs = stmt.executeQuery( "SELECT * FROM department;");
- while (rs.next()) {
- Department dep = new Department();
- dep.SetID(rs.getInt(1));
- dep.SetNameDepartment(rs.getString(2));
- dep.SetMail(rs.getString(3));
- dep.SetPhone(rs.getString(4));
- depart.add(dep);
- }
- }
- finally {
- if (rs != null) {
- rs.close();
- }
- if (stmt != null) {
- stmt.close();
- }
- }
- return depart;
- }
- public void UpdateDep(int id, String name, String mail, String phone) throws SQLException
- {
- PreparedStatement stmt = null;
- try{
- stmt = _ourCon.prepareStatement(
- "UPDATE department SET "
- +"DEPARTMENT=?, MAIL=?, PHONE=? "
- +"WHERE ID=?;");
- stmt.setString(1,name);
- stmt.setString(2,mail);
- stmt.setString(3,phone);
- stmt.setInt(4,id);
- stmt.executeUpdate();
- }
- finally {
- if (stmt!=null){
- stmt.close();
- }
- }
- }
- public void RemoveDep(int id) throws SQLException
- {
- PreparedStatement stmt = null;
- try{
- stmt = _ourCon.prepareStatement(
- "DELETE FROM department WHERE "
- +"ID=?;");
- stmt.setInt(1,id);
- stmt.executeUpdate();
- }
- finally {
- if (stmt!=null){
- stmt.close();
- }
- }
- }
- public void InsertDep(String nameDep, String mail, String phone) throws SQLException
- {
- PreparedStatement stmt = null;
- try{
- stmt = _ourCon.prepareStatement(
- "INSERT INTO department "
- +"(DEPARTMENT, MAIL, PHONE) "
- +"VALUES (?, ?, ?);");
- stmt.setString(1,nameDep);
- stmt.setString(2,mail);
- stmt.setString(3,phone);
- stmt.executeUpdate();
- }
- finally {
- if (stmt!=null){
- stmt.close();
- }
- }
- }
- //Научиться создать Department;
- }
- /**
- * Created by elsemTim on 15.11.2016.
- */
- import java.text.DateFormat;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.text.Collator;
- import java.util.Date;
- import java.util.Locale;
- public class Department {
- private int ID;
- private String nameDepartment;
- private String mail;
- private String phone;
- public Department () {}
- //set
- public void SetID( int ID ){
- this.ID=ID;
- }
- public void SetNameDepartment( String nameDepartment){
- this.nameDepartment=nameDepartment;
- }
- public void SetMail( String mail ){
- this.mail=mail;
- }
- public void SetPhone( String phone ){
- this.phone=phone;
- }
- //get
- public int GetID(){
- return ID;
- }
- public String GetNameDepartment(){
- return nameDepartment;
- }
- public String GetMail(){
- return mail;
- }
- public String GetPhone(){
- return phone;
- }
- //проверяем Ид записи с Ид записанным в Employee
- public Boolean compareToDep(int ID){
- return this.ID==ID?true:false;
- }
- }
- import javax.swing.table.AbstractTableModel;
- import java.util.ArrayList;
- import java.util.Arrays;
- /**
- * Created by elsemTim on 16.11.2016.
- */
- public class DepartmentTable extends AbstractTableModel {
- private ArrayList<String[]> dataArrayList;
- private int _columnCount=4;
- public DepartmentTable (){
- dataArrayList=new ArrayList<String []>();
- }
- @Override
- public int getRowCount() {
- return dataArrayList.size();
- }
- @Override
- public int getColumnCount() {
- return _columnCount;
- }
- @Override
- public Object getValueAt(int rowIndex, int columnIndex) {
- if(rowIndex>=getRowCount() || columnIndex>=getColumnCount()){return "";}
- return dataArrayList.get(rowIndex)[columnIndex];
- }
- @Override
- public String getColumnName(int c){
- switch (c){
- case 0:
- return "ID";
- case 1:
- return "Название отдела";
- case 2:
- return "Почта";
- case 3:
- return "Телефон";
- }
- return "";
- }
- public void AddRow(String [] row){
- int n = row.length > getColumnCount()? getColumnCount() : row.length;
- dataArrayList.add(Arrays.copyOf(row, n));
- }
- }
- /**
- * Created by elsemTim on 15.11.2016.
- */
- public class Employee {
- private int ID;
- private int depID;
- private int posID;
- private String department;
- private String position;
- private int salary;
- private String firstName;
- private String lastName;
- public Employee() {}
- //set
- public void setDepID(int depID) {
- this.depID = depID;
- }
- public void setPosID(int posID) {
- this.posID = posID;
- }
- public void setSalary(int salary) {this.salary = salary;}
- public void setID(int ID) {this.ID = ID;}
- public void SetNameDep(String department){this.department=department;}
- public void SetNamePos(String position){this.position=position;}
- public void SetFirstName(String firstName) {this.firstName=firstName;}
- public void SetLastName(String lastName){this.lastName=lastName;}
- //get
- public int getSalary() {return salary;}
- public int getID() {
- return ID;
- }
- public String GetNameDep() {return department;}
- public String GetNamePos() {return position;}
- public String GetFirstName() { return firstName;}
- public String GetLastName() {return lastName;}
- public int getDepID() {
- return depID;
- }
- public int getPosID() {
- return posID;
- }
- }
- /**
- * Created by elsemTim on 17.11.2016.
- */
- import javax.swing.table.AbstractTableModel;
- import java.util.ArrayList;
- import java.util.Arrays;
- public class EmployeeTable extends AbstractTableModel {
- private ArrayList<String[]> dataArrayList;
- private int _columnCount = 8;
- public EmployeeTable() {
- dataArrayList = new ArrayList<String[]>();
- }
- @Override
- public int getRowCount() {
- return dataArrayList.size();
- }
- @Override
- public int getColumnCount() {
- return _columnCount;
- }
- @Override
- public Object getValueAt(int rowIndex, int columnIndex) {
- if (rowIndex >= getRowCount() || columnIndex >= getColumnCount()) {
- return "";
- }
- return dataArrayList.get(rowIndex)[columnIndex];
- }
- @Override
- public String getColumnName(int c) {
- switch (c) {
- case 0:
- return "ID";
- case 1:
- return "Имя";
- case 2:
- return "Фамилия";
- case 3:
- return "Отдел";
- case 4:
- return "Должность";
- case 5:
- return "Зарплата";
- }
- return "";
- }
- public void AddRow(String[] row) {
- int n = row.length > getColumnCount() ? getColumnCount() : row.length;
- dataArrayList.add(Arrays.copyOf(row, n));
- }
- }
- CREATE TABLE Department (
- ID int not null primary key,
- DEPARTMENT varchar(255) not null,
- MAIL varchar(255) not null,
- PHONE varchar(255) not null
- );
- CREATE TABLE Positionn (
- ID int not null primary key,
- SALARY varchar(255) not null,
- NAME varchar(255) not null
- );
- create table Employee (
- ID int not null primary key,
- DEP_ID INT Not Null,
- POS_ID INT Not Null,
- FIRST_NAME VARCHAR(255) Not Null,
- LAST_NAME VARCHAR(255) Not Null,
- CONSTRAINT FK_EMP_DEP
- Foreign key (DEP_ID) References DEPARTMENT (ID),
- CONSTRAINT FK_EMP_POS
- Foreign key (POS_ID) References POSITIONN (ID)
- );
- CREATE GENERATOR GenDepartmentPK;
- SET GENERATOR GenDepartmentPK TO 0;
- SET TERM ^ ;
- CREATE TRIGGER TrigIncGenPkDepartment FOR DEPARTMENT
- ACTIVE BEFORE INSERT POSITION 0
- AS
- BEGIN
- if ((new.id is null) or (new.id = 0))
- then begin
- new.id = gen_id(GenDepartmentPK, 1);
- end
- END^
- SET TERM ; ^
- CREATE GENERATOR GenPositionPK;
- SET GENERATOR GenPositionPK TO 0;
- SET TERM ^ ;
- CREATE TRIGGER TrigIncGenPkPosition FOR positionn
- ACTIVE BEFORE INSERT POSITION 0
- AS
- BEGIN
- if ((new.id is null) or (new.id = 0))
- then begin
- new.id = gen_id(GenPositionPK, 1);
- end
- END^
- SET TERM ; ^
- CREATE GENERATOR GenEmployeePK;
- SET GENERATOR GenEmployeePK TO 0;
- SET TERM ^ ;
- CREATE TRIGGER TrigIncGenPkEmployee FOR employee
- ACTIVE BEFORE INSERT POSITION 0
- AS
- BEGIN
- if ((new.id is null) or (new.id = 0))
- then begin
- new.id = gen_id(GenEmployeePK, 1);
- end
- END^
- SET TERM ; ^
- create view vw_Employee (ID, Name, LName, Department, Positionn, Salary, id_dep, id_pos)
- as
- select e.Id as ID,e.first_name as Name,
- e.Last_Name as LName, d.department as Department,
- p.Name as Positionn,
- p.Salary as Salary,
- d.id as id_dep, p.id as id_pos
- from employee as e
- left join department as d on e.DEP_ID=d.ID
- left join POSITIONN as p on e.POS_ID=p.ID
- order by d.Department, p.Name, e.First_name, e.Last_name;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- /**
- * Created by elsemTim on 15.11.2016.
- */
- public class Position {
- private int ID;
- private String namePosition;
- private int salary;
- public Position() {}
- //set
- public void SetID(int ID){this.ID=ID;}
- public void SetNamePosition(String namePosition){this.namePosition=namePosition;}
- public void SetSalary(int salary){this.salary=salary;}
- //get
- public int GetID(){return ID;}
- public String GetNamePosition(){return namePosition;}
- public int GetSalary(){return salary;}
- //проверяем Ид записи с Ид записанным в Employee
- public Boolean compareToPos(int ID){
- return this.ID==ID?true:false;
- }
- }
- /**
- * Created by elsemTim on 17.11.2016.
- */
- import javax.swing.table.AbstractTableModel;
- import java.util.ArrayList;
- import java.util.Arrays;
- public class PositionTable extends AbstractTableModel {
- private ArrayList<String[]> dataArrayList;
- private int _columnCount=3;
- public PositionTable(){dataArrayList=new ArrayList<String[]>();}
- @Override
- public int getRowCount() {
- return dataArrayList.size();
- }
- @Override
- public int getColumnCount() {
- return _columnCount;
- }
- @Override
- public Object getValueAt(int rowIndex, int columnIndex) {
- if(rowIndex>=getRowCount() || columnIndex>=getColumnCount()){return "";}
- return dataArrayList.get(rowIndex)[columnIndex];
- }
- @Override
- public String getColumnName(int c){
- switch (c) {
- case 0:
- return "ID";
- case 1:
- return "Позиция";
- case 2:
- return "Зарплата";
- }
- return "";
- }
- public void AddRow(String [] row){
- int n=row.length>getColumnCount()?getColumnCount():row.length;
- dataArrayList.add(Arrays.copyOf(row,n));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment