public void display(ResultSet rs) {
    try {
      boolean recordNumber = rs.next();
      if (recordNumber) {
        payNo = rs.getString(1);
        pasNo = rs.getString(2);
        pasName = rs.getString(3);
        mode = rs.getString(4);
        dt = rs.getString(5);
        amount = rs.getString(6);
        rev = rs.getString(7);

        text1.setText(payNo);
        combo1.setSelectedItem(pasNo);
        combo2.setSelectedItem(pasName);
        combo4.setSelectedItem(mode);
        p_date.setText(dt);
        combo8.setSelectedItem(amount);
        combo3.setSelectedItem(rev);

      } else {
        JOptionPane.showMessageDialog(
            null, "Record Not found", "ERROR", JOptionPane.DEFAULT_OPTION);
      }
    } catch (SQLException sqlex) {
      sqlex.printStackTrace();
    }
  }
예제 #2
0
  public CopyFileToTable() {
    JPanel jPane1 = new JPanel();
    jPane1.setLayout(new BorderLayout());
    jPane1.add(new JLabel("Filename"), BorderLayout.WEST);
    jPane1.add(jbtViewFile, BorderLayout.EAST);
    jPane1.add(jtfFilename, BorderLayout.CENTER);

    JPanel jPane2 = new JPanel();
    jPane2.setLayout(new BorderLayout());
    jPane2.setBorder(new TitledBorder("Source Text File"));
    jPane2.add(jPane1, BorderLayout.NORTH);
    jPane2.add(new JScrollPane(jtaFile), BorderLayout.CENTER);

    JPanel jPane3 = new JPanel();
    jPane3.setLayout(new GridLayout(5, 0));
    jPane3.add(new JLabel("JDBC Driver"));
    jPane3.add(new JLabel("Database URL"));
    jPane3.add(new JLabel("Username"));
    jPane3.add(new JLabel("Password"));
    jPane3.add(new JLabel("Table Name"));

    JPanel jPane4 = new JPanel();
    jPane4.setLayout(new GridLayout(5, 0));
    jcboDriver.setEditable(true);
    jPane4.add(jcboDriver);
    jcboURL.setEditable(true);
    jPane4.add(jcboURL);
    jPane4.add(jtfUsername);
    jPane4.add(jtfPassword);
    jPane4.add(jtfTableName);

    JPanel jPane5 = new JPanel();
    jPane5.setLayout(new BorderLayout());
    jPane5.setBorder(new TitledBorder("Target Database Table"));
    jPane5.add(jbtCopy, BorderLayout.SOUTH);
    jPane5.add(jPane3, BorderLayout.WEST);
    jPane5.add(jPane4, BorderLayout.CENTER);

    add(jlblStatus, BorderLayout.SOUTH);
    add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jPane2, jPane5), BorderLayout.CENTER);

    jbtViewFile.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            showFile();
          }
        });

    jbtCopy.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            try {
              copyFile();
            } catch (Exception ex) {
              jlblStatus.setText(ex.toString());
            }
          }
        });
  }
  private void setamount() {

    try {
      ResultSet rst =
          DBConnection.getDBConnection()
              .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)
              .executeQuery(
                  "SELECT Amount FROM BOOKING  where Pass_No='" + combo1.getSelectedItem() + "'");
      while (rst.next()) {
        combo8.addItem(rst.getString(1));
      }
    } catch (Exception n) {
      n.printStackTrace();
    }
  }
예제 #4
0
  private void copyFile() throws Exception {
    // Load the JDBC driver
    Class.forName(((String) jcboDriver.getSelectedItem()).trim());
    System.out.println("Driver loaded");

    // Establish a connection
    Connection conn =
        DriverManager.getConnection(
            ((String) jcboURL.getSelectedItem()).trim(),
            jtfUsername.getText().trim(),
            String.valueOf(jtfPassword.getPassword()).trim());
    System.out.println("Database connected");

    // Read each line from the text file and insert it to the table
    insertRows(conn);
  }
예제 #5
0
  public static void updateKvalification() {
    try {

      DBClass db2 = new DBClass();
      ArrayList<Kvalification> k = db2.kvalificationFromDB();
      comboBox_kvalification.removeAllItems();
      for (int i = 0; i < k.size(); i++) {
        comboBox_kvalification.addItem(k.get(i));
      }
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, e.getMessage());
    } catch (SQLException ee) {
      ee.printStackTrace();
      JOptionPane.showMessageDialog(null, ee.getMessage());
    }
  }
예제 #6
0
  public static void updateDoljnost() {
    try {
      DBClass db = new DBClass();
      ArrayList<Doljnost> d = db.doljnostFromDB();
      comboBox_doljnost.removeAllItems();
      for (int i = 0; i < d.size(); i++) {
        comboBox_doljnost.addItem(d.get(i));
      }

    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, e.getMessage());
    } catch (SQLException ee) {
      ee.printStackTrace();
      JOptionPane.showMessageDialog(null, ee.getMessage());
    }
  }
  private void setcbr() {

    try {
      ResultSet rst =
          DBConnection.getDBConnection()
              .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)
              .executeQuery(
                  "SELECT * FROM Passenger where Booked_status='Booked' and Pay_Status='Not_Paid'");
      System.out.println("Hello");
      while (rst.next()) {

        combo1.addItem(rst.getString(1));
        combo2.addItem(rst.getString(2));
      }
    } catch (Exception n) {
      n.printStackTrace();
    }
  }
예제 #8
0
  // Вид формы при добавлении нового сотрудника
  public void sotrDiaInsert() {
    label_id_hidden.setText("Новый сотрудник");
    textField_familiya.setText("");
    textField_imya.setText("");
    textField_otchestvo.setText("");
    textField_phone.setText("");
    comboBox_doljnost.removeAllItems();
    comboBox_kvalification.removeAllItems();

    Calendar calend = Calendar.getInstance();
    if (calend.get(Calendar.MONTH) <= 9) {
      textField_date.setText(
          String.valueOf(
              (calend.get(Calendar.YEAR) + "-" + ("0" + (1 + calend.get(Calendar.MONTH))) + "-")
                  + (calend.get(Calendar.DATE))));
    } else
      textField_date.setText(
          String.valueOf(
              ((calend.get(Calendar.YEAR)) + "-" + (1 + calend.get(Calendar.MONTH)) + "-")
                  + (calend.get(Calendar.DATE))));
    textField_date.setEnabled(false);

    try {
      DBClass db = new DBClass();
      ArrayList<Doljnost> d = db.doljnostFromDB();
      for (int i = 0; i < d.size(); i++) {
        comboBox_doljnost.addItem(d.get(i));
      }
      DBClass db2 = new DBClass();
      ArrayList<Kvalification> k = db2.kvalificationFromDB();
      for (int i = 0; i < k.size(); i++) {
        comboBox_kvalification.addItem(k.get(i));
      }
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(panelException, e.getMessage());
    } catch (SQLException ee) {
      ee.printStackTrace();
      JOptionPane.showMessageDialog(panelException, ee.getMessage());
    }
  }
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();

    if (source == bRes) {
      tname.setText("");
      textra.setText("");
    } else {
      if (it.isSelected()) field = 1;
      else if (civil.isSelected()) field = 2;
      else if (mech.isSelected()) field = 3;

      if (tname.getText().equals("") | textra.getText().equals("") | field == 0)
        JOptionPane.showMessageDialog(null, "Please Fill in All Entries!!");
      else {
        String sal = (String) cbsal.getSelectedItem();

        try {
          // Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          // Connection conn=DriverManager.getConnection("jdbc:odbc:go");
          Class.forName("com.mysql.jdbc.Driver").newInstance();
          Connection conn = DriverManager.getConnection("jdbc:mysql:///go", "root", "");
          Statement pst = conn.createStatement();

          pst.executeUpdate(
              "Insert into company values('"
                  + tname.getText()
                  + "','"
                  + textra.getText()
                  + "','"
                  + (String) sal
                  + "','"
                  + field
                  + "','"
                  + tusr.getText()
                  + "','"
                  + tpwd.getText()
                  + "')");
          conn.close();
          String msg =
              "Your Details are Stored. Login again to View Related applicants!  Thank You!!";
          JOptionPane.showMessageDialog(null, msg);
          setVisible(false);
          login ab = new login();

        } catch (Exception exc) {
          JOptionPane.showMessageDialog(null, tname.getText() + " : " + exc);
          System.exit(0);
        }
      }
    }
  }
  public void actionPerformed(ActionEvent ae) {
    String str = ae.getActionCommand();
    if (str.equals("Ok")) {
      String str1 = (String) jcmname.getSelectedItem();

      Connection con = null;
      Statement stat = null;

      if (str1.equals("Pulsar")
          || str1.equals("CT 100")
          || str1.equals("Discover DTS-i")
          || str1.equals("Wave DTS-i")) {
        try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          con = DriverManager.getConnection("Jdbc:Odbc:showroom");
          System.out.println("Got Connection :" + con);
          stat = con.createStatement();
          ResultSet rs = stat.executeQuery("select * from vehicle");
          System.out.println("chk1");
          while (rs.next()) {
            if (str1.equals(rs.getString(1))) {

              tfcap.setText("" + rs.getInt(2));
              tfeng.setText("" + rs.getInt(3));
              tfbhp.setText("" + rs.getInt(4));
              tfvolt.setText("" + rs.getInt(5));
              tfrpm.setText("" + rs.getInt(6));
              tfweight.setText("" + rs.getInt(7));
              tfgear.setText("" + rs.getInt(8));
            }
          }

          stat.close();
          con.close();

        } catch (Exception ex) {
        }

      } else {
        JOptionPane.showMessageDialog(
            null, "Please Choose Model Name", "Error", JOptionPane.ERROR_MESSAGE);
      }
    }

    if (str.equals("can")) {
      this.dispose();
      // new menu(1);
    }
  }
예제 #11
0
  private void setCombo() {

    try {
      ResultSet rst =
          DBConnection.getDBConnection()
              .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)
              .executeQuery(
                  "SELECT Emp.empNo, Emp.Sname, Emp.Fname, Emp.Lname, Emp.Designation FROM Emp WHERE Emp.Designation='Booking Clerk'");
      while (rst.next()) {
        combo3.addItem(rst.getString(3));
      }
    } catch (Exception n) {
      n.printStackTrace();
    }
  }
예제 #12
0
  // Вид формы при изменении сотрудника
  public void sotrDiaUpdate(Sotrudnik s) {
    label_id_hidden.setText(Integer.toString(s.getId_sotrudnika()));
    textField_familiya.setText(s.getFamiliya());
    textField_imya.setText(s.getImya());
    textField_otchestvo.setText(s.getOtchestvo());
    textField_phone.setText(s.getPhone());
    textField_date.setText(s.getData_priema().toString());
    comboBox_doljnost.removeAllItems();
    comboBox_kvalification.removeAllItems();

    try {
      DBClass db = new DBClass();
      ArrayList<Doljnost> d = db.doljnostFromDB();
      DBClass db2 = new DBClass();
      Doljnost dd = db2.doljnostFromDB(s);
      for (int i = 0; i < d.size(); i++) {
        comboBox_doljnost.addItem(d.get(i));
        Doljnost ddd = (Doljnost) comboBox_doljnost.getItemAt(i);
        if (dd.getNazvanie_doljnosti().equals(ddd.getNazvanie_doljnosti())) dd = ddd;
      }
      comboBox_doljnost.setSelectedItem(dd);

      DBClass db3 = new DBClass();
      ArrayList<Kvalification> k = db3.kvalificationFromDB();
      DBClass db4 = new DBClass();
      Kvalification kk = db4.kvalificationFromDB(s);
      for (int i = 0; i < k.size(); i++) {
        comboBox_kvalification.addItem(k.get(i));
        Kvalification kkk = (Kvalification) comboBox_kvalification.getItemAt(i);
        if (kk.getNazvanie_kvalification().equals(kkk.getNazvanie_kvalification())) kk = kkk;
      }

      comboBox_kvalification.setSelectedItem(kk);

    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(panelException, e.getMessage());
    } catch (SQLException ee) {
      ee.printStackTrace();
      JOptionPane.showMessageDialog(panelException, ee.getMessage());
    }
  }
  public Assi() {
    c = getContentPane();

    c.setLayout(new BorderLayout());
    c.add(pnn, BorderLayout.NORTH);
    c.add(pns, BorderLayout.SOUTH);
    c.add(pnc, BorderLayout.CENTER);
    c.add(pne, BorderLayout.EAST);

    pne.setLayout(new GridLayout(2, 1));
    pne.add(pne1);
    pne.add(pne2);
    pne1.setLayout(new FlowLayout());
    pne1.add(go);
    go.addItem("Student");
    go.addItem("Teacher");
    go.addItem("Course");
    go.addItem("Result");
    pne1.add(b6);
    pne2.setLayout(cl2);

    pns.add(b1);
    pns.add(b2);
    pns.add(b3);
    pns.add(b4);
    pns.add(b5);

    setJMenuBar(m);
    m.add(student);
    m.add(teacher);
    m.add(course);
    m.add(result);

    stu.setLayout(new GridLayout(8, 2));
    stu.add(l1);
    stu.add(t1);
    stu.add(l2);
    stu.add(t2);
    stu.add(l3);
    stu.add(t3);
    stu.add(l4);
    stu.add(t4);
    stu.add(l5);
    stu.add(t5);
    stu.add(l6);
    stu.add(t6);

    cou.setLayout(new GridLayout(4, 2));
    cou.add(l7);
    cou.add(t7);
    cou.add(l8);
    cou.add(t8);
    cou.add(l9);
    cou.add(t9);
    cou.add(l0);
    cou.add(t0);

    tea.setLayout(new GridLayout(4, 2));
    tea.add(l11);
    tea.add(t11);
    tea.add(l12);
    tea.add(t12);
    tea.add(l13);
    tea.add(t13);
    tea.add(l14);
    tea.add(t14);

    res.setLayout(new GridLayout(15, 3));
    res.add(l15);
    res.add(t15);
    res.add(l16);
    res.add(t16);
    res.add(l17);
    res.add(t17);
    res.add(lg);
    res.add(l);
    res.add(l18);
    res.add(t18);
    res.add(l19);
    res.add(t19);
    res.add(l20);
    res.add(t20);
    res.add(l21);
    res.add(t21);
    res.add(l22);
    res.add(t22);
    res.add(l23);
    res.add(t23);
    res.add(l24);
    res.add(t24);
    res.add(l25);
    res.add(t25);
    res.add(l26);
    res.add(t26);
    res.add(l27);
    res.add(t27);
    res.add(l28);
    res.add(t28);

    pnc.setLayout(cl);
    pnc.add(blk, "cblk");
    pnc.add(stu, "cstu");
    pnc.add(tea, "ctea");
    pnc.add(cou, "ccou");
    pnc.add(res, "cres");

    b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);
    b4.addActionListener(this);
    b5.addActionListener(this);
    b6.addActionListener(this);

    student.addActionListener(this);
    teacher.addActionListener(this);
    course.addActionListener(this);
    result.addActionListener(this);

    go.addItemListener(this);
  }
예제 #14
0
  public Payment() {
    super("Payment Process", false, true, false, true);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    label1 = new JLabel("Paymnent Number");
    label2 = new JLabel("Passenger Number");
    label3 = new JLabel("Passenger Name");
    label6 = new JLabel("Mode of Payment");
    label4 = new JLabel("Date of Payment");
    label5 = new JLabel("Amount Paid");
    label7 = new JLabel("Received By");
    text1 = new JTextField(10);
    text5 = new JTextField(10);
    p_date = new DateButton();
    p_date.setForeground(Color.red);
    combo1 = new JComboBox();
    combo2 = new JComboBox();
    combo3 = new JComboBox();
    combo4 = new JComboBox();

    combo4.addItem("Cash");
    combo4.addItem("Bank");
    combo8 = new JComboBox();
    button1 =
        new JButton("Pay", new ImageIcon(ClassLoader.getSystemResource("Images/payments.png")));
    button2 =
        new JButton(
            "Print Receipt", new ImageIcon(ClassLoader.getSystemResource("Images/print.png")));
    button3 =
        new JButton("Cancel", new ImageIcon(ClassLoader.getSystemResource("Images/exit.png")));
    button4 =
        new JButton("Search", new ImageIcon(ClassLoader.getSystemResource("Images/search.png")));
    button5 =
        new JButton("Delete", new ImageIcon(ClassLoader.getSystemResource("Images/delete.png")));
    // combo3.addItem(new)
    panel1 = new JPanel(new GridLayout(7, 2));
    panel1.setPreferredSize(new Dimension(350, 250));
    panel1.add(label1);
    panel1.add(text1);
    panel1.add(label2);
    panel1.add(combo1);
    panel1.add(label3);
    panel1.add(combo2);
    panel1.add(label6);
    panel1.add(combo4);
    panel1.add(label4);
    panel1.add(p_date);
    panel1.add(label5);
    panel1.add(combo8);
    panel1.add(label7);
    panel1.add(combo3);
    // combo8.removeAllItems();
    pane = new JPanel();
    pane.add(button1);

    pane.add(button2);
    pane.add(button3);
    pane.add(button4);

    panel3 = new JPanel();
    panel3.add(panel1);
    panel3.add(pane);

    button2.setEnabled(false);
    add(panel3);
    setSize(500, 350);
    setCombo();
    setcbr();
    generator();
    setamount();
    setLocation((screen.width - 300) / 2, ((screen.height - 300) / 2));
    setResizable(false);
    combo1.addActionListener(
        new java.awt.event.ActionListener() {

          public void actionPerformed(java.awt.event.ActionEvent e) {
            combo2.setSelectedIndex(combo1.getSelectedIndex());
            combo8.removeItem(combo8.getSelectedItem());
            setamount();
          }
        });

    button3.addActionListener(
        new java.awt.event.ActionListener() {

          public void actionPerformed(java.awt.event.ActionEvent e) {
            setVisible(true);
            dispose();
          }
        });
    button2.addActionListener(
        new java.awt.event.ActionListener() {

          public void actionPerformed(java.awt.event.ActionEvent e) {
            Receipt frm = new Receipt();
            MDIWindow.desktop.add(frm);
            frm.setVisible(true);
            button2.setEnabled(false);
          }
        });

    button1.addActionListener(
        new java.awt.event.ActionListener() {

          public void actionPerformed(java.awt.event.ActionEvent e) {

            if (combo1.getSelectedItem() == null) {
              JOptionPane.showMessageDialog(
                  null, "All Passenger have paid", "Error", JOptionPane.DEFAULT_OPTION);
              return;
            }
            if (combo2.getSelectedItem() == null) {
              JOptionPane.showMessageDialog(
                  null, "All Passenger have paid", "Error", JOptionPane.DEFAULT_OPTION);
              return;
            }
            generator();

            if (combo8.getSelectedItem() == null) {
              JOptionPane.showMessageDialog(
                  null, "The Passenger has not been booked", "ERROR", JOptionPane.DEFAULT_OPTION);
              return;
            }
            try {
              Statement statement = DBConnection.getDBConnection().createStatement();
              {
                String temp =
                    "INSERT INTO Payment (Payment_No, Pass_No, Pass_Name, Payment_Mode, Date_Payment,Amount_Paid,Received_By) VALUES ('"
                        + text1.getText()
                        + "', '"
                        + combo1.getSelectedItem()
                        + "', '"
                        + combo2.getSelectedItem()
                        + "', '"
                        + combo4.getSelectedItem()
                        + "', '"
                        + p_date.getText()
                        + "', '"
                        + combo8.getSelectedItem()
                        + "', '"
                        + combo3.getSelectedItem()
                        + "')";
                combo1.removeItem(combo1.getSelectedItem());
                combo2.removeItem(combo2.getSelectedItem());
                int result = statement.executeUpdate(temp);
                JOptionPane.showMessageDialog(
                    null, "Passenger Account updated", "Updated", JOptionPane.DEFAULT_OPTION);
              }

            } catch (SQLException sqlex) {
              sqlex.printStackTrace();
            }
            try {
              Statement statement = DBConnection.getDBConnection().createStatement();
              {
                String temp =
                    "UPDATE Passenger SET Pay_Status='Paid'"
                        + "WHERE Pass_NO LIKE  '"
                        + combo1.getSelectedItem()
                        + "'";
                int result = statement.executeUpdate(temp);
              }

            } catch (SQLException sqlex) {
              sqlex.printStackTrace();
            }
            button1.setEnabled(false);
            button2.setEnabled(true);
          }
        });
    button4.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            try {
              if (!text1.equals("")) {

                Statement statement = DBConnection.getDBConnection().createStatement();
                String query =
                    ("SELECT * FROM Payment where Payment_No ='" + text1.getText() + "'");

                ResultSet rs = statement.executeQuery(query);
                display(rs);
                statement.close();
              }
            } catch (SQLException sqlex) {
              sqlex.printStackTrace();
            }
            setVisible(true);
          }
        });
  }
예제 #15
0
  /** Create the frame. */
  public SotrudnikDialog() {
    setTitle(
        "\u041D\u043E\u0432\u044B\u0439 \u0441\u043E\u0442\u0440\u0443\u0434\u043D\u0438\u043A");
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    setBounds(100, 100, 450, 330);
    contentPane = new JPanel();
    contentPane.setBackground(new Color(255, 204, 255));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JLabel label_familiya = new JLabel("\u0424\u0430\u043C\u0438\u043B\u0438\u044F");
    label_familiya.setBounds(10, 37, 110, 14);
    contentPane.add(label_familiya);

    JLabel label_imya = new JLabel("\u0418\u043C\u044F");
    label_imya.setBounds(10, 62, 110, 14);
    contentPane.add(label_imya);

    JLabel label_otchestvo = new JLabel("\u041E\u0442\u0447\u0435\u0441\u0442\u0432\u043E");
    label_otchestvo.setBounds(10, 87, 110, 14);
    contentPane.add(label_otchestvo);

    textField_otchestvo = new JTextField();
    textField_otchestvo.setBounds(167, 84, 186, 20);
    contentPane.add(textField_otchestvo);
    textField_otchestvo.setColumns(10);

    textField_imya = new JTextField();
    textField_imya.setBounds(167, 58, 186, 20);
    contentPane.add(textField_imya);
    textField_imya.setColumns(10);

    textField_familiya = new JTextField();
    textField_familiya.setBounds(167, 33, 186, 20);
    contentPane.add(textField_familiya);
    textField_familiya.setColumns(10);

    JLabel label_data_priema =
        new JLabel(
            "\u0414\u0430\u0442\u0430 \u043F\u0440\u0438\u0435\u043C\u0430 \u043D\u0430 \u0440\u0430\u0431\u043E\u0442\u0443");
    label_data_priema.setBounds(10, 112, 147, 14);
    contentPane.add(label_data_priema);

    JLabel label_phone = new JLabel("\u0422\u0435\u043B\u0435\u0444\u043E\u043D");
    label_phone.setBounds(10, 137, 134, 14);
    contentPane.add(label_phone);

    JLabel label_doljnost = new JLabel("\u0414\u043E\u043B\u0436\u043D\u043E\u0441\u0442\u044C");
    label_doljnost.setBounds(10, 162, 140, 14);
    contentPane.add(label_doljnost);

    JLabel label_kvalification =
        new JLabel("\u041A\u0432\u0430\u043B\u0438\u0444\u0438\u043A\u0430\u0446\u0438\u044F");
    label_kvalification.setBounds(10, 190, 147, 14);
    contentPane.add(label_kvalification);

    textField_phone = new JTextField();
    textField_phone.setBounds(167, 134, 186, 20);
    contentPane.add(textField_phone);
    textField_phone.setColumns(10);

    textField_date.setBounds(167, 109, 186, 20);
    contentPane.add(textField_date);

    label_id_hidden.setFont(new Font("Tahoma", Font.BOLD, 12));
    label_id_hidden.setBounds(143, 11, 122, 14);
    contentPane.add(label_id_hidden);

    button_insert.setBounds(83, 230, 160, 23);
    contentPane.add(button_insert);

    button_cancel.setBounds(264, 230, 104, 23);
    contentPane.add(button_cancel);

    button_update.setBounds(83, 230, 160, 23);
    contentPane.add(button_update);

    JButton button_plus_doljnost = new JButton("+");
    button_plus_doljnost.addActionListener(
        new ActionListener() {
          @SuppressWarnings("deprecation")
          public void actionPerformed(ActionEvent arg0) {
            DoljnostDialog d = new DoljnostDialog();
            d.setTitle("Добавление должности");
            d.show();
          }
        });
    button_plus_doljnost.setBounds(359, 159, 41, 23);
    contentPane.add(button_plus_doljnost);

    JButton button_plus_kvalification = new JButton("+");
    button_plus_kvalification.addActionListener(
        new ActionListener() {
          @SuppressWarnings("deprecation")
          public void actionPerformed(ActionEvent arg0) {
            KvalificationDialog d = new KvalificationDialog();
            d.setTitle("Добавление квалификации");
            d.show();
          }
        });
    button_plus_kvalification.setBounds(359, 184, 41, 23);
    contentPane.add(button_plus_kvalification);

    JLabel label =
        new JLabel(
            "\u041F\u043E\u043B\u044F, \u043E\u0442\u043C\u0435\u0447\u0435\u043D\u043D\u044B\u0435 ");
    label.setBounds(60, 264, 122, 14);
    contentPane.add(label);

    JLabel label_3 = new JLabel("*");
    label_3.setForeground(Color.RED);
    label_3.setFont(new Font("Tahoma", Font.BOLD, 11));
    label_3.setBounds(186, 264, 12, 14);
    contentPane.add(label_3);

    JLabel label_4 =
        new JLabel(
            "\u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u044B  \u0434\u043B\u044F \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u0438\u044F!");
    label_4.setBounds(197, 264, 203, 14);
    contentPane.add(label_4);

    JLabel label_5 = new JLabel("*");
    label_5.setForeground(Color.RED);
    label_5.setFont(new Font("Tahoma", Font.BOLD, 11));
    label_5.setBounds(356, 37, 12, 14);
    contentPane.add(label_5);

    JLabel label_1 = new JLabel("*");
    label_1.setForeground(Color.RED);
    label_1.setFont(new Font("Tahoma", Font.BOLD, 11));
    label_1.setBounds(356, 62, 12, 14);
    contentPane.add(label_1);

    comboBox_doljnost.setBounds(167, 159, 186, 20);
    contentPane.add(comboBox_doljnost);

    comboBox_kvalification.setBounds(167, 187, 186, 20);
    contentPane.add(comboBox_kvalification);

    // Actions for button "Добавить"
    button_insert.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (!textField_familiya.getText().equals("") && !textField_imya.getText().equals("")) {
              try {
                Sotrudnik s = new Sotrudnik();
                s.setFamiliya(textField_familiya.getText());
                s.setImya(textField_imya.getText());
                s.setOtchestvo(textField_otchestvo.getText());
                s.setData_priema(Date.valueOf(textField_date.getText()));
                s.setPhone(textField_phone.getText());
                Doljnost d = (Doljnost) comboBox_doljnost.getSelectedItem();
                s.setId_doljnosti(d.getId_doljnosti());
                Kvalification k = (Kvalification) comboBox_kvalification.getSelectedItem();
                s.setId_kvalification(k.getId_kvalification());

                DBClass db = new DBClass();
                db.sotrudnikUpsert(s, "INSERT");
                MyFrame.updateList();
                ZakazDialog.updateSotrudnik();
              } catch (SQLException e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(panelException, e.getMessage());
              } catch (ClassNotFoundException ee) {
                ee.printStackTrace();
                JOptionPane.showMessageDialog(panelException, ee.getMessage());
              } finally {
                dispose();
              }
            } else JOptionPane.showMessageDialog(null, "Введите обязательные параметры!");
          }
        });

    // Actions for button "Отмена"
    button_cancel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            dispose();
          }
        });

    // Actions for button "Сохранить изменения"
    button_update.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (!textField_familiya.getText().equals("")
                && !textField_imya.getText().equals("")
                && !textField_date.getText().equals("")) {
              if (textField_date.getText().length() == 10) {
                try {
                  Integer.parseInt((textField_date.getText().substring(0, 3)));
                  Integer.parseInt((textField_date.getText().substring(5, 6)));
                  Integer.parseInt((textField_date.getText().substring(8, 9)));

                  Sotrudnik s = new Sotrudnik();
                  s.setId_sotrudnika(Integer.parseInt(label_id_hidden.getText()));
                  s.setFamiliya(textField_familiya.getText());
                  s.setImya(textField_imya.getText());
                  s.setOtchestvo(textField_otchestvo.getText());
                  s.setPhone(textField_phone.getText());

                  Doljnost d = (Doljnost) comboBox_doljnost.getSelectedItem();
                  s.setId_doljnosti(d.getId_doljnosti());

                  Kvalification k = (Kvalification) comboBox_kvalification.getSelectedItem();
                  s.setId_kvalification(k.getId_kvalification());

                  DBClass db = new DBClass();
                  db.sotrudnikUpsert(s, "UPDATE");
                  MyFrame.updateList();
                  dispose();
                } catch (NumberFormatException e) {
                  JOptionPane.showMessageDialog(panelException, e.getMessage());
                } catch (SQLException e) {
                  // e.printStackTrace();
                  JOptionPane.showMessageDialog(panelException, e.getMessage());
                } catch (ClassNotFoundException ee) {
                  // ee.printStackTrace();
                  JOptionPane.showMessageDialog(panelException, ee.getMessage());
                }
              } else JOptionPane.showMessageDialog(null, "Введите дату в правильном формате!");
            } else JOptionPane.showMessageDialog(null, "Введите обязательные параметры!");
          }
        });
  }
예제 #16
0
  public NewUser() {
    super("Adding New User");
    label1 = new JLabel("Name");
    label2 = new JLabel("Category");
    username = new JLabel("Username");
    password = new JLabel("Password");
    confirm = new JLabel("Re-enter Password");
    pass1 = new JPasswordField();
    pass2 = new JPasswordField();
    txtusername = new JTextField();
    name = new JTextField();
    combo1 = new JComboBox();
    button1 = new JButton("Ok", new ImageIcon("Icon/i16x16/ok.png"));
    button2 = new JButton("Cancel", new ImageIcon("Icon/i16x16/exit.png"));

    panel1 = new JPanel(new GridLayout(6, 2));
    panel1.add(label1);
    panel1.add(name);
    panel1.add(label2);
    panel1.add(combo1);
    panel1.add(username);
    panel1.add(txtusername);
    panel1.add(password);
    panel1.add(pass1);
    panel1.add(confirm);
    panel1.add(pass2);
    panel1.add(button1);
    panel1.add(button2);
    combo1.addItem("Manager");
    combo1.addItem("Booking Clerk");
    combo1.addItem("Supervisor");
    panel2 = new JPanel();
    panel2.add(panel1);
    getContentPane().add(panel2);
    setSize(350, 195);
    setVisible(true);
    setLocation((screen.width - 500) / 2, ((screen.height - 350) / 2));
    setResizable(false);
    name.addKeyListener(
        new KeyAdapter() {
          public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();
            if (!(Character.isLetter(c)
                || (c == KeyEvent.VK_BACK_SPACE)
                || (c == KeyEvent.VK_SPACE)
                || (c == KeyEvent.VK_DELETE))) {

              getToolkit().beep();
              JOptionPane.showMessageDialog(
                  null, "Invalid Character", "ERROR", JOptionPane.DEFAULT_OPTION);
              e.consume();
            }
          }
        });
    txtusername.addKeyListener(
        new KeyAdapter() {
          public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();
            if (!(Character.isLetter(c)
                || (c == KeyEvent.VK_BACK_SPACE)
                || (c == KeyEvent.VK_SPACE)
                || (c == KeyEvent.VK_DELETE))) {

              getToolkit().beep();
              JOptionPane.showMessageDialog(
                  null, "Invalid Character", "ERROR", JOptionPane.DEFAULT_OPTION);
              e.consume();
            }
          }
        });
    button1.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent e) {

            if (name.getText() == null || name.getText().equals("")) {
              JOptionPane.showMessageDialog(
                  null, "Enter name", "ERROR", JOptionPane.DEFAULT_OPTION);
              name.requestFocus();
              return;
            }
            if (txtusername.getText() == null || txtusername.getText().equals("")) {
              JOptionPane.showMessageDialog(
                  null, "Enter username", "ERROR", JOptionPane.DEFAULT_OPTION);
              txtusername.requestFocus();
              return;
            }
            if (pass1.getText() == null || pass1.getText().equals("")) {
              JOptionPane.showMessageDialog(
                  null, "Enter password", "ERROR", JOptionPane.DEFAULT_OPTION);
              pass1.requestFocus();
              return;
            }
            if (pass2.getText() == null || pass2.getText().equals("")) {
              JOptionPane.showMessageDialog(
                  null, "Confirm your password", "ERROR", JOptionPane.DEFAULT_OPTION);
              pass2.requestFocus();
              return;
            }
            if (!pass1.getText().equals(pass2.getText())) {
              JOptionPane.showMessageDialog(
                  null, "passwords do not match.", "ERROR", JOptionPane.DEFAULT_OPTION);
              pass2.requestFocus();
              return;
            }
            try {
              Statement statement = Connect.getConnection().createStatement();
              {
                String temp =
                    "INSERT INTO users (Name,Category,username, password) VALUES ('"
                        + name.getText()
                        + "', '"
                        + combo1.getSelectedItem()
                        + "', '"
                        + txtusername.getText()
                        + "', '"
                        + pass1.getText()
                        + "')";

                int result = statement.executeUpdate(temp);
                JOptionPane.showMessageDialog(
                    null, "User is succesfully added", "SUCCESS", JOptionPane.DEFAULT_OPTION);
                dispose();
              }

            } catch (Exception in) {
              in.printStackTrace();
            }
          }
        });
    button2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        });
  }
예제 #17
0
  public TableModelDemo() {

    try {
      // Load the JDBC driver
      Class.forName("com.mysql.jdbc.Driver");
      Class.forName("oracle.jdbc.driver.OracleDriver");
      System.out.println("Driver loaded");

      // Create a row set
      rowSet = new CachedRowSetImpl();

      // Set RowSet properties
      //      rowSet.setUrl("jdbc:mysql://localhost/javabook");
      rowSet.setUrl("jdbc:oracle:thin:@liang.armstrong.edu:1521:orcl");
      rowSet.setUsername("scott");
      rowSet.setPassword("tiger");

      rowSet.setCommand("select * from StateCapital");

      rowSet.setConcurrency(ResultSet.CONCUR_UPDATABLE);
      rowSet.execute();
      tableModel.setRowSet(rowSet);
      rowSet.addRowSetListener(tableModel);
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    JPanel panel1 = new JPanel();
    panel1.setLayout(new GridLayout(2, 2));
    panel1.add(jbtAddRow);
    panel1.add(jbtAddColumn);
    panel1.add(jbtDeleteRow);
    panel1.add(jbtDeleteColumn);

    JPanel panel2 = new JPanel();
    panel2.add(jbtSave);
    panel2.add(jbtClear);
    panel2.add(jbtRestore);

    JPanel panel3 = new JPanel();
    panel3.setLayout(new BorderLayout(5, 0));
    panel3.add(new JLabel("Selection Mode"), BorderLayout.WEST);
    panel3.add(jcboSelectionMode, BorderLayout.CENTER);

    JPanel panel4 = new JPanel();
    panel4.setLayout(new FlowLayout(FlowLayout.LEFT));
    panel4.add(jchkRowSelectionAllowed);
    panel4.add(jchkColumnSelectionAllowed);

    JPanel panel5 = new JPanel();
    panel5.setLayout(new GridLayout(2, 1));
    panel5.add(panel3);
    panel5.add(panel4);

    JPanel panel6 = new JPanel();
    panel6.setLayout(new BorderLayout());
    panel6.add(panel1, BorderLayout.SOUTH);
    panel6.add(panel2, BorderLayout.CENTER);

    add(panel5, BorderLayout.NORTH);
    add(new JScrollPane(jTable1), BorderLayout.CENTER);
    add(panel6, BorderLayout.SOUTH);

    // Initialize table selection mode
    jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    jbtAddRow.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              rowSet.absolute(2);
              rowSet.moveToInsertRow();
              rowSet.updateString("state", "Georia");
              rowSet.updateString("capital", "Atlanta");
              rowSet.insertRow();
              ((CachedRowSetImpl) rowSet).acceptChanges();
              rowSet.moveToCurrentRow();
            } catch (Exception ex) {
              ex.printStackTrace();
            }

            //        if (jTable1.getSelectedRow() >= 0)
            //          tableModel.insertRow(jTable1.getSelectedRow(),
            //            new java.util.Vector());
            //        else
            //          tableModel.addRow(new java.util.Vector());
          }
        });

    jbtAddColumn.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            //        String name = JOptionPane.showInputDialog("New Column Name");
            //        tableModel.addColumn(name, new java.util.Vector());
          }
        });

    jbtDeleteRow.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (jTable1.getSelectedRow() >= 0) {
              try {
                rowSet.absolute(jTable1.getSelectedRow() + 1);
                rowSet.deleteRow();
                ((CachedRowSetImpl) rowSet).acceptChanges();
              } catch (Exception ex) {
                ex.printStackTrace();
              }
            }
          }
        });

    jbtDeleteColumn.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (jTable1.getSelectedColumn() >= 0) {
              TableColumnModel columnModel = jTable1.getColumnModel();
              TableColumn tableColumn = columnModel.getColumn(jTable1.getSelectedColumn());
              columnModel.removeColumn(tableColumn);
            }
          }
        });

    jbtSave.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              ObjectOutputStream out =
                  new ObjectOutputStream(new FileOutputStream("tablemodel.dat"));
              //          out.writeObject(tableModel.getDataVector());
              out.writeObject(getColumnNames());
              out.close();
            } catch (Exception ex) {
              ex.printStackTrace();
            }
          }
        });

    jbtClear.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            //        tableModel.setRowCount(0);
          }
        });

    jbtRestore.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              ObjectInputStream in = new ObjectInputStream(new FileInputStream("tablemodel.dat"));
              Vector rowData = (Vector) in.readObject();
              Vector columnNames = (Vector) in.readObject();
              //          tableModel.setDataVector(rowData, columnNames);
              in.close();
            } catch (Exception ex) {
              ex.printStackTrace();
            }
          }
        });

    jchkRowSelectionAllowed.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            jTable1.setRowSelectionAllowed(jchkRowSelectionAllowed.isSelected());
          }
        });

    jchkColumnSelectionAllowed.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            jTable1.setColumnSelectionAllowed(jchkColumnSelectionAllowed.isSelected());
          }
        });

    jcboSelectionMode.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String selectedItem = (String) jcboSelectionMode.getSelectedItem();

            if (selectedItem.equals("SINGLE_SELECTION"))
              jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            else if (selectedItem.equals("SINGLE_INTERVAL_SELECTION"))
              jTable1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
            else if (selectedItem.equals("MULTIPLE_INTERVAL_SELECTION"))
              jTable1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
          }
        });
  }
예제 #18
0
  private Container createBorrowPane() {
    // Initialise date combo boxes
    borDay = new JComboBox();
    borMonth = new JComboBox();
    borYear = new JComboBox();
    String[] days = new String[31];
    for (int i = 0; i < 31; i++) days[i] = String.valueOf(i + 1);
    String[] months = {
      "January",
      "February",
      "March",
      "April",
      "May",
      "June",
      "July",
      "August",
      "September",
      "October",
      "November",
      "December"
    };
    String[] years = {
      "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014"
    };
    borDay.setModel(new DefaultComboBoxModel(days));
    borMonth.setModel(new DefaultComboBoxModel(months));
    borYear.setModel(new DefaultComboBoxModel(years));
    Calendar today = Calendar.getInstance();
    borDay.setSelectedIndex(today.get(DAY_OF_MONTH) - 1);
    borMonth.setSelectedIndex(today.get(MONTH));
    borYear.setSelectedIndex(today.get(YEAR) - 2005);

    // Create borrow button
    borrowButton = new JButton(borrowAction);

    // Create text fields
    borISBN = new JTextField(15);
    borCustID = new JTextField(15);

    // Create panel and layout
    JPanel pane = new JPanel();
    pane.setOpaque(false);
    GridBagLayout gb = new GridBagLayout();
    pane.setLayout(gb);
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(1, 5, 1, 5);

    // Fill panel
    c.anchor = GridBagConstraints.EAST;
    addToGridBag(gb, c, pane, new JLabel("ISBN:"), 0, 0, 1, 1);
    addToGridBag(gb, c, pane, new JLabel("Customer ID:"), 0, 1, 1, 1);
    addToGridBag(gb, c, pane, new JLabel("Due Date:"), 0, 2, 1, 1);

    c.anchor = GridBagConstraints.WEST;
    c.fill = GridBagConstraints.HORIZONTAL;
    addToGridBag(gb, c, pane, borISBN, 1, 0, 3, 1);
    addToGridBag(gb, c, pane, borCustID, 1, 1, 3, 1);

    c.fill = GridBagConstraints.NONE;
    addToGridBag(gb, c, pane, borDay, 1, 2, 1, 1);
    addToGridBag(gb, c, pane, borMonth, 2, 2, 1, 1);
    addToGridBag(gb, c, pane, borYear, 3, 2, 1, 1);

    addToGridBag(gb, c, pane, borrowButton, 4, 0, 1, 3);

    // Set up VK_ENTER triggering the borrow button in this panel
    InputMap input = pane.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    input.put(getKeyStroke("ENTER"), "borrowAction");
    pane.getActionMap().put("borrowAction", borrowAction);

    return pane;
  }
  public vehicle() {
    message = new JLabel("VEHICLE  DETAILS");
    mname = new JLabel("Model Name");
    cap = new JLabel("Capacity");
    cc = new JLabel("CC");
    eng = new JLabel("Engine");
    stroke = new JLabel("Stroke");
    bhp = new JLabel("BHP");
    volt = new JLabel("Volts");
    rpm = new JLabel("RPM");
    weight = new JLabel("Weight");
    kg = new JLabel("Kg");
    gear = new JLabel("Gears");
    color = new JLabel("Color");

    jcmname = new JComboBox();

    tfcap = new JTextField(30);
    tfeng = new JTextField(20);
    tfbhp = new JTextField(10);
    tfvolt = new JTextField(20);
    tfrpm = new JTextField(20);
    tfweight = new JTextField(20);
    tfgear = new JTextField(30);

    jccolor = new JComboBox();

    ok = new JButton("OK");
    can = new JButton("CANCEL");

    can.addActionListener(this);
    can.setActionCommand("can");
    ok.addActionListener(this);
    ok.setActionCommand("Ok");

    Container c = getContentPane();

    setSize(800, 600);
    setTitle("Vehicle Details");
    c.setLayout(null);
    setVisible(true);

    c.add(message);
    c.add(mname);
    c.add(cap);
    c.add(cc);
    c.add(eng);
    c.add(stroke);
    c.add(bhp);
    c.add(volt);
    c.add(rpm);
    c.add(weight);
    c.add(kg);
    c.add(gear);
    c.add(color);

    c.add(jcmname);

    c.add(tfcap);
    c.add(tfeng);
    c.add(tfbhp);
    c.add(tfvolt);
    c.add(tfrpm);
    c.add(tfweight);
    c.add(tfgear);

    c.add(jccolor);

    c.add(ok);
    c.add(can);
    c.setBackground(Color.pink);

    message.setBounds(300, 40, 200, 50);
    mname.setBounds(50, 100, 100, 30);
    cap.setBounds(50, 150, 100, 30);
    cc.setBounds(275, 150, 50, 30);
    eng.setBounds(50, 200, 50, 30);
    stroke.setBounds(275, 200, 100, 30);
    bhp.setBounds(50, 250, 100, 30);
    volt.setBounds(50, 300, 100, 30);
    rpm.setBounds(50, 350, 100, 30);
    weight.setBounds(50, 400, 50, 30);
    kg.setBounds(275, 400, 100, 30);
    gear.setBounds(450, 150, 150, 30);
    color.setBounds(450, 200, 100, 30);

    jcmname.setBounds(200, 100, 100, 30);
    jcmname.addItem(" -- Select --");
    jcmname.addItem("Pulsar");
    jcmname.addItem("CT 100");
    jcmname.addItem("Discover DTS-i");
    jcmname.addItem("Wave DTS-i");

    tfcap.setBounds(200, 150, 70, 30);
    tfeng.setBounds(200, 200, 70, 30);
    tfbhp.setBounds(200, 250, 70, 30);
    tfvolt.setBounds(200, 300, 70, 30);
    tfrpm.setBounds(200, 350, 70, 30);
    tfweight.setBounds(200, 400, 70, 30);
    tfgear.setBounds(500, 150, 70, 30);

    jccolor.setBounds(500, 200, 100, 30);
    jccolor.addItem("Black");
    jccolor.addItem("Blue");
    jccolor.addItem("Red");
    jccolor.addItem("Grey");

    ok.setBounds(270, 480, 85, 30);
    can.setBounds(370, 480, 85, 30);
  }
  public emp() {
    setTitle("AMRITA HUMAN RESOURCE MANAGEMENT SYSTEM    (EMPLOYEE DETAIL)");

    getContentPane().add(p, BorderLayout.CENTER);
    getContentPane().add(q, BorderLayout.SOUTH);

    setTitle("Placement Office");

    lname = new JLabel("Name: ");
    lextra = new JLabel("Vacancy(s): ");
    lfield = new JLabel("Field: ");
    lsal = new JLabel("Minimum Expected Salary: ");
    lusr = new JLabel("Login name: ");
    lpwd = new JLabel("Password: "******"5,000");
    cbsal.addItem("10,000");
    cbsal.addItem("15,000");
    cbsal.addItem("20,000");
    cbsal.setBackground(Color.ORANGE);

    it = new JRadioButton("Software Engg.");
    civil = new JRadioButton("Civil Engg.");
    mech = new JRadioButton("Mechanical Engg.");
    ButtonGroup bg2 = new ButtonGroup();
    bg2.add(it);
    bg2.add(civil);
    bg2.add(mech);
    civil.setBackground(Color.ORANGE);

    bSub = new JButton("Submit");
    bRes = new JButton("Reset");

    p.setLayout(new GridLayout(11, 2));
    Blank = new JLabel("");
    Blank1 = new JLabel("");
    Blank2 = new JLabel("");
    Blank3 = new JLabel("");
    Blank4 = new JLabel("");

    p.add(lusr);
    p.add(tusr);

    p.add(lpwd);
    p.add(tpwd);

    p.add(lname);
    p.add(tname);

    p.add(lextra);
    p.add(textra);

    p.add(lfield);
    p.add(it);

    p.add(Blank4);
    p.add(civil);

    p.add(Blank1);
    p.add(mech);

    p.add(lsal);
    p.add(cbsal);

    q.add(bSub);
    q.add(bRes);

    bSub.addActionListener(this);
    bRes.addActionListener(this);
    setVisible(true);
    setBounds(200, 200, 300, 300);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
  }
예제 #21
0
  public void actionPerformed(ActionEvent evt) {
    String arg = evt.getActionCommand();
    if (arg.equals("Query")) { // 用户按下Query按钮
      ResultSet rs = null;
      try {
        String author = (String) authors.getSelectedItem();
        String publisher = (String) publishers.getSelectedItem();
        if (!author.equals("Any") && !publisher.equals("Any")) {
          if (authorPublisherQueryStmt == null) {
            //  根据用户选择的出版社名和作者名查询相关的书名和书价
            String authorPublisherQuery =
                "SELECT Books.Price, Books.Title "
                    + "FROM Books, BooksAuthors, Authors, Publishers "
                    + "WHERE Authors.Author_Id = BooksAuthors.Author_Id AND "
                    + "BooksAuthors.ISBN = Books.ISBN AND "
                    + "Books.Publisher_Id = Publishers.Publisher_Id AND "
                    + "Authors.Name = ? AND "
                    + "Publishers.Name = ?";
            authorPublisherQueryStmt = con.prepareStatement(authorPublisherQuery);
          }

          authorPublisherQueryStmt.setString(1, author);
          authorPublisherQueryStmt.setString(2, publisher);
          rs = authorPublisherQueryStmt.executeQuery();
        } else if (!author.equals("Any") && publisher.equals("Any")) {
          if (authorQueryStmt == null) {
            //  根据用户选择的作者名查询相关的书名和书价
            String authorQuery =
                "SELECT Books.Price, Books.Title "
                    + "FROM Books, BooksAuthors, Authors "
                    + "WHERE Authors.Author_Id = BooksAuthors.Author_Id AND "
                    + "BooksAuthors.ISBN = Books.ISBN AND "
                    + "Authors.Name = ?";
            authorQueryStmt = con.prepareStatement(authorQuery);
          }
          authorQueryStmt.setString(1, author);
          rs = authorQueryStmt.executeQuery();
        } else if (author.equals("Any") && !publisher.equals("Any")) {
          if (publisherQueryStmt == null) {
            //  根据用户选择的出版社名查询相关的书名和书价
            String publisherQuery =
                "SELECT Books.Price, Books.Title "
                    + "FROM Books, Publishers "
                    + "WHERE Books.Publisher_Id = Publishers.Publisher_Id AND "
                    + "Publishers.Name = ?";
            publisherQueryStmt = con.prepareStatement(publisherQuery);
          }
          publisherQueryStmt.setString(1, publisher);
          rs = publisherQueryStmt.executeQuery();
        } else {
          if (allQueryStmt == null) {
            // 若用户未选任何信息,则输出所有的书名和对应的书价
            String allQuery = "SELECT Books.Price, Books.Title FROM Books";
            allQueryStmt = con.prepareStatement(allQuery);
          }
          rs = allQueryStmt.executeQuery();
        }

        result.setText("");
        while (rs.next()) result.append(rs.getString(1) + " | " + rs.getString(2) + "\n");
        rs.close();
      } catch (Exception e) {
        result.setText("Error " + e);
      }
    } else if (arg.equals("Change prices")) { //  用户选择“Change prices”按钮
      String publisher = (String) publishers.getSelectedItem();
      if (publisher.equals("Any")) result.setText("I am sorry, but I cannot do that.");
      else
        try {
          // 根据用户输入的新的书价更新Books表的数据
          String updateStatement =
              "UPDATE Books "
                  + "SET Price = Price + "
                  + priceChange.getText()
                  + " WHERE Books.Publisher_Id = "
                  + "(SELECT Publisher_Id FROM Publishers WHERE Name = '"
                  + publisher
                  + "')";
          int r = stmt.executeUpdate(updateStatement);
          result.setText(r + " records updated.");
        } catch (Exception e) {
          result.setText("Error " + e);
        }
    }
  }
예제 #22
0
  public QueryDBFrame() {
    setTitle("QueryDB");
    setSize(400, 300);
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    getContentPane().setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    authors = new JComboBox();
    authors.setEditable(false);
    authors.addItem("Any");

    publishers = new JComboBox();
    publishers.setEditable(false);
    publishers.addItem("Any");

    result = new JTextArea(4, 50);
    result.setEditable(false);

    priceChange = new JTextField(8);
    priceChange.setText("-5.00");

    try {
      //  连接数据库
      con = getConnection();
      stmt = con.createStatement();

      // 将数据库中的作者名添加到组合框
      String query = "SELECT Name FROM Authors";
      ResultSet rs = stmt.executeQuery(query);
      while (rs.next()) authors.addItem(rs.getString(1));

      //  将出版社名添加到组合框
      query = "SELECT Name FROM Publishers";
      rs = stmt.executeQuery(query);
      while (rs.next()) publishers.addItem(rs.getString(1));
    } catch (Exception e) {
      result.setText("Error " + e);
    }

    gbc.fill = GridBagConstraints.NONE;
    gbc.weightx = 100;
    gbc.weighty = 100;
    add(authors, gbc, 0, 0, 2, 1);

    add(publishers, gbc, 2, 0, 2, 1);

    gbc.fill = GridBagConstraints.NONE;
    JButton queryButton = new JButton("Query");
    queryButton.addActionListener(this);
    add(queryButton, gbc, 0, 1, 1, 1);

    JButton changeButton = new JButton("Change prices");
    changeButton.addActionListener(this);
    add(changeButton, gbc, 2, 1, 1, 1);

    gbc.fill = GridBagConstraints.HORIZONTAL;
    add(priceChange, gbc, 3, 1, 1, 1);

    gbc.fill = GridBagConstraints.BOTH;
    add(result, gbc, 0, 2, 4, 1);
  }
예제 #23
0
  // ambil data dari database untuk tabel
  public void setDataTabel() {
    // combobox jenis
    JComboBox cbJenis = new JComboBox();
    cbJenis.setModel(new DefaultComboBoxModel(dataJenis.toArray()));

    dataProduk = new ArrayList<Produk>();
    try {
      String qry =
          "SELECT * FROM produk,suplier,jenis,stok_produk WHERE produk.id_jenis = jenis.id_jenis AND produk.id_suplier = suplier.id_suplier AND produk.id_produk=stok_produk.id_produk";
      ResultSet rs = stm.executeQuery(qry);
      while (rs.next()) {
        Produk p = new Produk();
        p.setIdProduk(rs.getInt("id_produk"));
        p.setNamaProduk(rs.getString("nama_produk"));
        p.setJenis(rs.getString("nama_jenis"));
        p.setHarga(rs.getInt("harga"));
        p.setStok(rs.getInt("stok"));
        p.setNamaSuplier(rs.getString("nama_suplier"));

        p.setComboJenis(cbJenis);

        dataProduk.add(p);
      }
    } catch (Exception err) {
      err.printStackTrace();
    }

    model = new TableModelProduk(dataProduk);
    tabel.setModel(model);
    tabel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    class EditProdukListener implements TableModelListener {
      public void tableChanged(TableModelEvent tme) {
        int baris = tme.getFirstRow();
        int kolom = tme.getColumn();

        TableModel model = (TableModel) tme.getSource();
        int id = (Integer) model.getValueAt(baris, 0);

        String query = "";
        switch (kolom) {
          case 1:
            String nama = (String) model.getValueAt(baris, kolom);
            query = "UPDATE produk SET nama_produk='" + nama + "' WHERE id_produk=" + id;
            prosesEdit(query);
            break;
          case 2:
            String jenis = (String) model.getValueAt(baris, kolom);
            try {
              query = "select * from jenis where nama_jenis='" + jenis + "'";
              ResultSet rs = stm.executeQuery(query);
              if (rs.next()) {
                int idJenis = rs.getInt("id_jenis");
                query = "UPDATE produk SET id_jenis=" + idJenis + " WHERE id_produk=" + id;
                prosesEdit(query);
              } else {
                setDataTabel();
                JOptionPane.showMessageDialog(null, "gagal,jenis tidak ada");
              }
            } catch (SQLException SQLerr) {
              SQLerr.printStackTrace();
            }
            break;
          case 3:
            int stok = (Integer) model.getValueAt(baris, kolom);
            query = "UPDATE `stok_produk` SET stok=" + stok + " WHERE id_produk=" + id;
            prosesEdit(query);
            break;
          case 4:
            int harga = (Integer) model.getValueAt(baris, kolom);
            query = "UPDATE produk SET harga=" + harga + " WHERE id_produk=" + id;
            prosesEdit(query);
            break;
          case 5:
            String suplier = (String) model.getValueAt(baris, kolom);
            try {
              query = "SELECT * FROM suplier WHERE nama_suplier='" + suplier + "'";
              ResultSet rs = stm.executeQuery(query);
              if (rs.next()) {
                int idSuplier = rs.getInt("id_suplier");
                query = "UPDATE produk SET id_suplier=" + idSuplier + " WHERE id_produk=" + id;
                prosesEdit(query);
              } else {
                setDataTabel();
                JOptionPane.showMessageDialog(null, "gagal,suplier belum terdaftar");
              }
            } catch (SQLException SQLerr) {
              SQLerr.printStackTrace();
            }
            break;
          default:
            break;
        }
      }

      private void prosesEdit(String query) {
        try {
          int hasil = stm.executeUpdate(query);
          if (hasil == 1) {
            setDataTabel();
            JOptionPane.showMessageDialog(null, "edit berhasil");
          } else {
            JOptionPane.showMessageDialog(null, "gagal");
          }
        } catch (SQLException SQLerr) {
          SQLerr.printStackTrace();
        }
      }
    }
    model.addTableModelListener(new EditProdukListener());
  }
  public Design() throws Exception {
    super.setBackground(Color.BLACK);
    this.setTitle("");
    con = getContentPane();
    con.setLayout(null);
    dim = tk.getDefaultToolkit().getScreenSize();
    this.setTitle("Customer Peer Login");

    l1 = new JLabel(new ImageIcon("plain.jpg"));
    l1.setBounds(0, 0, 400, 400);
    con.add(l1);
    l1.setBorder(BorderFactory.createEtchedBorder(5, Color.black, Color.black));

    title = new JLabel("CUSTOMER PEER LOGIN ");
    title.setFont(new Font("Bookman Old Style", Font.ROMAN_BASELINE, 20));
    title.setForeground(Color.red);
    title.setBounds(80, 30, 300, 30);
    l1.add(title);

    l4 = new JLabel("CMACHINE NAME");
    l4.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l4.setForeground(Color.BLUE);
    l4.setBounds(70, 100, 160, 20);
    //	l4.setBorder(BorderFactory.createEtchedBorder(5,Color.green,Color.green));

    l1.add(l4);
    jtf2 = new JTextField();
    jtf2.setBounds(250, 100, 100, 20);
    jtf2.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));

    l1.add(jtf2);

    l2 = new JLabel("CUSER LOGIN");
    l2.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l2.setForeground(Color.blue);
    l2.setBounds(70, 150, 120, 20);
    l1.add(l2);

    jtf1 = new JTextField();
    jtf1.setBounds(250, 150, 100, 20);
    jtf1.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));

    l1.add(jtf1);

    l3 = new JLabel("CPASSWORD");
    l3.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l3.setForeground(Color.blue);
    l3.setBounds(70, 200, 120, 20);
    l1.add(l3);

    jptf1 = new JPasswordField();
    jptf1.setBounds(250, 200, 100, 20);
    jptf1.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));

    l1.add(jptf1);

    JLabel l4 = new JLabel("DAgent");
    l4.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l4.setForeground(Color.blue);
    l4.setBounds(70, 250, 120, 20);
    l1.add(l4);

    box = new JComboBox();
    box.setBounds(250, 250, 100, 20);
    box.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));
    l1.add(box);

    b2 = new JButton("Register");
    b2.setBounds(50, 300, 100, 20);
    l1.add(b2);
    b2.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE));

    b3 = new JButton("Login");
    b3.setBounds(150, 300, 100, 20);
    b3.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE));
    l1.add(b3);

    b1 = new JButton("Cancel");
    b1.setBounds(250, 300, 100, 20);
    b1.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE));

    l1.add(b1);

    b1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent we) {

            dispose();
          }
        });

    try {

      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      conn = DriverManager.getConnection("jdbc:odbc:agent");

    } catch (Exception exp) {

    }

    try {
      Statement satem = conn.createStatement();
      ResultSet rsatem = satem.executeQuery("select * from Dagent");
      while (rsatem.next()) {
        String namem = rsatem.getString("uname");
        box.addItem(namem);
      }

    } catch (Exception expo1) {

    }

    b2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent we) {

            String username = jtf1.getText().trim();
            String password = jptf1.getText().trim();
            String mechine = jtf2.getText().trim();
            String dname = box.getSelectedItem().toString();
            int porte = 0;

            try {
              Statement sate = conn.createStatement();
              ResultSet rsate =
                  sate.executeQuery("select * from Dagent where uname='" + dname + "'");
              if (rsate.next()) {
                servermachine = rsate.getString("umechine");
                porte = rsate.getInt("ulistport");
                System.out.println(servermachine);
              }
              System.out.println(servermachine);

            } catch (Exception exp) {
              exp.printStackTrace();
            }

            try {
              packet p = new packet();
              p.setaction("Creg");
              p.setCuser(username);
              p.setCpass(password);
              p.setCmname(mechine);
              p.setCDpeer(dname);
              Socket soc = new Socket(servermachine, porte);
              ObjectOutputStream out = new ObjectOutputStream(soc.getOutputStream());
              out.writeObject(p);
              ObjectInputStream in = new ObjectInputStream(soc.getInputStream());
              packet rpac = (packet) in.readObject();
              if (rpac.getaction().equals("ok")) {

                JOptionPane.showMessageDialog(null, "Sucessfully Registered");

                jtf2.setText("");
                jtf1.setText("");
                jptf1.setText("");

              } else {

                JOptionPane.showMessageDialog(null, "Already Registered");
                jtf2.setText("");
                jtf1.setText("");
                jptf1.setText("");
              }

            } catch (Exception exp) {
            }
          }
        });

    b3.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent we) {

            String username = jtf1.getText().trim();
            String password = jptf1.getText().trim();
            String mechine = jtf2.getText().trim();
            String Dname = box.getSelectedItem().toString();

            int porte = 0;

            try {
              Statement sate = conn.createStatement();
              ResultSet rsate =
                  sate.executeQuery("select * from Dagent where uname='" + Dname + "'");
              if (rsate.next()) {
                servermachine = rsate.getString("umechine");
                porte = rsate.getInt("ulistport");
                System.out.println(servermachine);
              }
              System.out.println(servermachine);

            } catch (Exception exp) {

            }

            try {

              packet p1 = new packet();
              p1.setaction("clogin");
              p1.setCuser(username);
              p1.setCpass(password);
              p1.setCmname(mechine);
              p1.setCDpeer(Dname);
              Socket soc1 = new Socket(servermachine, porte);
              ObjectOutputStream out1 = new ObjectOutputStream(soc1.getOutputStream());
              out1.writeObject(p1);
              ObjectInputStream in1 = new ObjectInputStream(soc1.getInputStream());
              packet rpac1 = (packet) in1.readObject();
              if (rpac1.getaction().equals("ok")) {
                int port1 = 0;
                try {

                  int portm = rpac1.getCport();
                  System.out.println("XXXXXXX" + portm);
                  //	JOptionPane.showMessageDialog(null,"Sucessfully Started");

                  new Listen(portm);
                  new process(username, portm);
                  dispose();
                } catch (Exception exp) {
                }
              } else {
                JOptionPane.showMessageDialog(
                    null, "Enter valid username and password", "Server reply", 2);
                jtf1.setText("");
                jtf2.setText("");
                jptf1.setText("");
              }

            } catch (Exception exp) {
            }
          }
        });

    setSize(400, 400);
    show();
    setLocation(150, 100);
    setResizable(false);
  }