Пример #1
0
  public void acessaTecladoNumerico(
      JFormattedTextField campoAtual, JFormattedTextField proximoCampo) {

    if (Inicio.isMobile()) {
      campoAtual.setBackground(new Color(255, 255, 190));
      TelaTecladoNumerico tela = new TelaTecladoNumerico(null, true, campoAtual, proximoCampo);
      tela.setVisible(true);
    }
  }
Пример #2
0
  public NewTaskFrame() throws SQLException {

    this.setModal(true);
    this.setTitle("Create Task"); // title of frame
    this.setSize(400, 350);
    this.setLayout(new BorderLayout()); // layout of frame

    JLabel task_id = new JLabel("ID:");
    JLabel task_name = new JLabel("Name:");
    JLabel task_desc = new JLabel("Description:");

    JLabel priority = new JLabel("Level of Priority:");
    JLabel duedate = new JLabel("Due Date (yyyy-mm-dd)");
    JLabel numberofdays = new JLabel("Number of days required:");
    JLabel skills_required = new JLabel("Skills Required:");

    Object[] id_possibilities = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
    StringBuffer generated_name = new StringBuffer("t");

    for (int i = 0; i < 6; ++i) {
      generated_name.append(
          id_possibilities[new java.util.Random().nextInt(id_possibilities.length)]);
    }

    task_idfield = new JTextField(generated_name.toString());
    taskname_field = new JTextField();
    taskdesc_field = new JTextArea();

    priority_checkbox = new JCheckBox("High", false);
    numberofdays_field = new JTextField();

    format = new SimpleDateFormat("dd-MM-yyyy"); // set format
    duedate_field = new JFormattedTextField(format);

    // set the duedatefield to tomorrow (since minimum task length = 1)
    java.util.Calendar cal = java.util.Calendar.getInstance();
    cal.setTime(new Date()); // get current date
    cal.add(Calendar.DAY_OF_MONTH, 1); // add 1 to current date
    Date date = cal.getTime(); // get this date
    duedate_field.setValue(date); // set this date to the field

    // panel to hold labels and text fields
    JPanel labeltextpanel = new JPanel();
    labeltextpanel.setLayout(new GridLayout(7, 2));
    labeltextpanel.add(task_id);
    labeltextpanel.add(task_idfield);
    labeltextpanel.add(task_name);
    labeltextpanel.add(taskname_field);
    labeltextpanel.add(task_desc);
    labeltextpanel.add(taskdesc_field);
    labeltextpanel.add(priority);
    labeltextpanel.add(priority_checkbox);
    labeltextpanel.add(numberofdays);
    labeltextpanel.add(numberofdays_field);
    labeltextpanel.add(duedate);
    labeltextpanel.add(duedate_field);
    labeltextpanel.add(skills_required);

    this.getSkills();

    // main panel for frame including its layout
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(labeltextpanel, BorderLayout.CENTER);

    // buttons
    clear_button = new JButton("Clear");
    submit_button = new JButton("Submit");

    // add listeners to buttons
    clear_button.addActionListener(this);
    submit_button.addActionListener(this);

    // create panel for buttons and add buttons
    JPanel buttonpanel = new JPanel();
    buttonpanel.setLayout(new FlowLayout());
    buttonpanel.add(clear_button);
    buttonpanel.add(submit_button);

    JPanel checkbox_panel = new JPanel();
    checkbox_panel.setLayout(new FlowLayout());

    for (int i = 0; i < skill_list.size(); i++) {
      checkbox_panel.add(skill_list.get(i)); // make this panel flowlayout
    }

    scrollpane = new JScrollPane(checkbox_panel);
    scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(mainPanel, BorderLayout.CENTER);
    panel.add(scrollpane, BorderLayout.SOUTH);
    // add the main panel to main frame

    add(panel, BorderLayout.CENTER);
    add(buttonpanel, BorderLayout.SOUTH);

    this.setVisible(true);
  }
Пример #3
0
  public void actionPerformed(ActionEvent event) {

    // if clear button is pressed, clear all fields
    if (event.getSource() == clear_button) {
      // erase all fields

      taskname_field.setText("");
      taskdesc_field.setText("");

      priority_checkbox.setSelected(false);
      numberofdays_field.setText("");
      // isallocatedcheckbox.setSelected(false);
      duedate_field.setText("");
    }

    // if submit button is pressed, save all data onto database
    if (event.getSource() == submit_button) {
      try {
        {
          Calendar calendar = Calendar.getInstance();
          calendar.setTime(new Date()); // set to current date
          calendar.add(
              Calendar.DAY_OF_MONTH,
              Integer.parseInt(this.numberofdays_field.getText())
                  - 1); // add days required... then:
          // ^ subtract one day, because if task is created today and allocated tomorrow for one
          // day,
          // then it should be done by end of day tomorrow
          Date date = calendar.getTime(); // (see next *1) use this date to be the earliest
          // because of expected task duration

          /*This is a constraint
           * the date and the length of days that user expected to take
           * if not feasible then the program will say so
           * */
          // method compares the current date and the date that was entered by the user
          if (this.task_idfield.getText().length() != 7 // check chars
              || this.taskname_field.getText().length() > 50 // check chars
              || this.taskdesc_field.getText().length() > 50
              || ((Date) this.duedate_field.getValue()).compareTo(date)
                  < 0 // check that the date is possible (see last *1)
              || this.numberofdays_field.getText().length() > 2
              || this.numberofdays_field.getText().length() == 0 // check number of digits
              || Integer.parseInt(this.numberofdays_field.getText())
                  < 1) // check number of days required for task
          {
            JOptionPane.showMessageDialog(
                this,
                "Task ID has to be 7 chars; "
                    + "\n"
                    + "Description <= 50 chars; "
                    + "\n"
                    + "Because the expected duration of the task is "
                    + Integer.parseInt(this.numberofdays_field.getText())
                    + " days, the due date cannot be earlier than: "
                    + new StringBuffer(new SimpleDateFormat("dd/MM/yyyy").format(date)).toString()
                    + "; "
                    + "\n"
                    + "Task duration must be 2 digit number maximum and must be an integer greater than 0");
          } else

          // check if taskid_field is equals to any of the fields on the database

          if (task_idfield.equals("")) {
            JOptionPane.showMessageDialog(
                this, "Please insert an identification number for a task");

          } else // add constraint and tell customer to enter 7 values
          if (taskname_field.equals("")) {
            JOptionPane.showMessageDialog(this, "Please insert a name to identity the task");

          } else {

            // get all inputs from user inputs and store in variables
            taskid_input = task_idfield.getText();
            taskname_input = taskname_field.getText();
            taskdesc_input = taskdesc_field.getText();

            if (priority_checkbox.isSelected()) {
              priority_input = 1;
            } else {
              priority_input = 0;
            }

            // create and store date from user input
            date = (Date) duedate_field.getValue();

            // store number of days input from user
            numberofdays_input = Integer.parseInt(numberofdays_field.getText());

            // 	String[] column_names = { "Task ID", "Task Name", "Task Description", "Task
            // Priority", "Due Date", "Number of Days", "Is Allocated" , "Unallocateable" };

            task = new Object[8];
            task[0] = taskid_input;
            task[1] = taskname_input;
            task[2] = taskdesc_input;
            task[3] = priority_input;
            task[4] = date;
            task[5] = numberofdays_input;
            task[6] = 0;
            task[7] = 0;

            try {
              //
              SqlConnection.connect();

              SqlConnection.ps =
                  SqlConnection.connection.prepareStatement(
                      "INSERT  INTO TASK VALUES (?,?,?,?,?,?,?,?)");

              SqlConnection.ps.setString(1, taskid_input);
              SqlConnection.ps.setString(2, taskname_input);
              SqlConnection.ps.setString(3, taskdesc_input);
              SqlConnection.ps.setInt(4, priority_input);
              SqlConnection.ps.setDate(5, new java.sql.Date(date.getTime()));
              SqlConnection.ps.setInt(6, numberofdays_input);
              SqlConnection.ps.setInt(7, 0);
              SqlConnection.ps.setInt(8, 0);

              SqlConnection.ps.executeUpdate();

              // now enter skills into TASK SKILL database
              for (int i = 0; i < skill_list.size(); i++) {
                if (skill_list.get(i).isSelected()) {
                  String skillid = skill_list.get(i).getText();
                  SqlConnection.statement.executeUpdate(
                      "INSERT INTO TASKSKILL VALUES ('" + taskid_input + "', '" + skillid + "')");
                }
              }

              SqlConnection.ps.close();
            } catch (SQLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
            // SqlConnection.ps.close();
            SqlConnection.closeConnection();
            this.setVisible(false);
          }
        }

      } catch (Exception exc) {
        JOptionPane.showMessageDialog(
            this,
            "Check your inputs:"
                + "\n"
                + "Priority has to be a 1-digit number;"
                + "\n"
                + "Date has to be in the format dd/MM/yyyy;"
                + "\n"
                + "Task length has to be 2-digit number");
        System.out.println(exc);
      }
    }
    // display dialog box asking task manager if they want to quit,
    // if task manager does not want to quit, go back to adding more tasks
    // if customer quits, close the dialog box and the frame

    // now close the window after saving
  }
Пример #4
0
  public MakeReservation() {
    new BorderLayout();

    standardRoom.setMnemonic(KeyEvent.VK_K);
    standardRoom.setActionCommand("Standard Room");
    standardRoom.setSelected(true);

    familyRoom.setMnemonic(KeyEvent.VK_F);
    familyRoom.setActionCommand("Family Room");

    suiteRoom.setMnemonic(KeyEvent.VK_S);
    suiteRoom.setActionCommand("Suite");

    // Add Booking Button
    ImageIcon bookRoomIcon = createImageIcon("images/book.png");
    bookRoom = new JButton("Book Room", bookRoomIcon);
    bookRoom.setVerticalTextPosition(AbstractButton.BOTTOM);
    bookRoom.setHorizontalTextPosition(AbstractButton.CENTER);
    bookRoom.setMnemonic(KeyEvent.VK_M);
    bookRoom.addActionListener(this);
    bookRoom.setActionCommand("book");

    // Group the radio buttons.
    group.add(standardRoom);
    group.add(familyRoom);
    group.add(suiteRoom);

    // Create the labels.
    nameLabel = new JLabel("Name: ");
    amountroomsLabel = new JLabel("How many rooms? ");
    checkoutdateLabel = new JLabel("Check-Out Date: ");
    checkindateLabel = new JLabel("Check-In Date: ");

    // Create the text fields and set them up.
    nameField = new JFormattedTextField();
    nameField.setColumns(10);

    amountroomsField = new JFormattedTextField(new Integer(1));
    amountroomsField.setValue(new Integer(1));
    amountroomsField.setColumns(10);

    // java.util.Date dt_checkin = new java.util.Date();
    LocalDate today = LocalDate.now();
    // java.text.SimpleDateFormat sdf_checkin = new java.text.SimpleDateFormat("MM/dd/yyyy");
    currentDate_checkin = today.toString();
    checkindateField = new JFormattedTextField(currentDate_checkin);
    checkindateField.setColumns(10);

    // java.util.Date dt_checkout = new java.util.Date();
    LocalDate tomorrow = today.plus(1, ChronoUnit.DAYS);
    // java.text.SimpleDateFormat sdf_checkout = new java.text.SimpleDateFormat("MM/dd/yyyy");
    currentDate_checkout = tomorrow.toString();
    checkoutdateField = new JFormattedTextField(currentDate_checkout);
    checkoutdateField.setColumns(10);

    // Tell accessibility tools about label/textfield pairs.
    nameLabel.setLabelFor(nameField);
    amountroomsLabel.setLabelFor(amountroomsField);
    checkoutdateLabel.setLabelFor(checkoutdateField);
    checkindateLabel.setLabelFor(checkindateField);

    // Lay out the labels in a panel.
    JPanel labelPane1 = new JPanel(new GridLayout(0, 1));

    labelPane1.add(amountroomsLabel);

    JPanel labelPane3 = new JPanel(new GridLayout(0, 1));
    labelPane3.add(checkindateLabel);

    JPanel labelPane2 = new JPanel(new GridLayout(0, 1));
    labelPane2.add(checkoutdateLabel);

    JPanel labelPane4 = new JPanel(new GridLayout(0, 1));
    labelPane4.add(nameLabel);

    // Layout the text fields in a panel.
    JPanel fieldPane1 = new JPanel(new GridLayout(0, 1));
    fieldPane1.add(amountroomsField);

    JPanel fieldPane3 = new JPanel(new GridLayout(0, 1));
    fieldPane3.add(checkindateField);

    JPanel fieldPane2 = new JPanel(new GridLayout(0, 1));
    fieldPane2.add(checkoutdateField);

    JPanel fieldPane4 = new JPanel(new GridLayout(0, 1));
    fieldPane4.add(nameField);

    // Put the radio buttons in a column in a panel.
    JPanel radioPanel = new JPanel(new GridLayout(0, 1));
    radioPanel.add(standardRoom);
    radioPanel.add(familyRoom);
    radioPanel.add(suiteRoom);

    // Put the panels in this panel, labels on left,
    // text fields on right.
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
    add(labelPane1, BorderLayout.LINE_START);
    add(fieldPane1, BorderLayout.LINE_END);
    add(labelPane3, BorderLayout.LINE_START);
    add(fieldPane3, BorderLayout.LINE_END);
    add(labelPane2, BorderLayout.LINE_START);
    add(fieldPane2, BorderLayout.LINE_END);
    add(labelPane4, BorderLayout.LINE_START);
    add(fieldPane4, BorderLayout.LINE_END);

    add(radioPanel, BorderLayout.LINE_END);
    add(bookRoom);
  }
Пример #5
0
  public void bookRoom() {
    try {
      int code = 0;
      Connection con =
          DriverManager.getConnection(
              "jdbc:mysql://67.20.111.85:3306/jeehtove_caliking?relaxAutoCommit=false",
              "jeehtove_ck",
              "Z_^PBBZT+kcy");
      Statement stmt_insert = con.createStatement();
      Statement stmt_tableRange = con.createStatement();
      Statement stmt_checkrooms = con.createStatement();
      Statement stmt_checkrooms_2 = con.createStatement();

      String insert = null;
      int flag = 0;

      String room_type;
      if (standardRoom.isSelected()) {
        room_type = "Standard";
        code = 1;
      } else if (familyRoom.isSelected()) {
        room_type = "Family";
        code = 2;
      } else {
        room_type = "Suite";
        code = 3;
      }

      // Converting string from checkin and checkout dates so that they can access the correct table
      String currentDate_checkin_getText = checkindateField.getText();
      String currentDate_checkin_rest = currentDate_checkin_getText.substring(5);
      String currentDate_checkin_replace = currentDate_checkin_rest.replace("-", "_");
      String currentDate_checkin_year = currentDate_checkin.substring(0, 4);
      String currentDate_checkin_final =
          currentDate_checkin_year + "_" + currentDate_checkin_replace;

      String currentDate_checkout_getText = checkoutdateField.getText();
      String currentDate_checkout_rest = currentDate_checkout_getText.substring(5);
      String currentDate_checkout_replace = currentDate_checkout_rest.replace("-", "_");
      String currentDate_checkout_year = currentDate_checkout.substring(0, 4);
      String currentDate_checkout_final =
          currentDate_checkout_year + "_" + currentDate_checkout_replace;

      // MySQL Statement to select tables from schema that are in between checkin and checkout range
      String tableRange =
          "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='jeehtove_caliking' AND TABLE_NAME BETWEEN 'rooms_"
              + currentDate_checkin_final
              + "' AND 'rooms_"
              + currentDate_checkout_final
              + "';";
      ResultSet tb_Range = stmt_tableRange.executeQuery(tableRange);

      System.out.println(tableRange);
      List tb_range_list = new ArrayList();

      while (tb_Range.next()) {
        String tb_range_date = tb_Range.getString("table_name");
        tb_range_list.add(tb_range_date);
        // String current_table = tb_Range.getString("table_name");
        // System.out.println(tb_range_list.add(tb_Range.getString("table_name")));
      }

      stmt_tableRange.close();

      for (int x = 0; x < tb_range_list.size(); x++) {
        String query_checkrooms =
            "SELECT * FROM "
                + tb_range_list.get(x)
                + " WHERE type = '"
                + code
                + "' AND booked = '0' LIMIT 1;";
        // System.out.println(query_checkrooms);
        ResultSet checkrooms = stmt_checkrooms.executeQuery(query_checkrooms);
        while (checkrooms.next()) {
          String getroomnumber = checkrooms.getString("room");
          insert =
              "INSERT INTO `reservations` VALUES ('"
                  + getroomnumber
                  + "', '"
                  + checkindateField.getText()
                  + "', '"
                  + checkoutdateField.getText()
                  + "',  '"
                  + room_type
                  + "',  '"
                  + nameField.getText()
                  + "');";
          String bookroom =
              "UPDATE `"
                  + tb_range_list.get(x)
                  + "` SET booked = '1' WHERE room = '"
                  + getroomnumber
                  + "';";
          // System.out.println(insert);
          int cr = stmt_checkrooms_2.executeUpdate(bookroom);
          flag = 1;
          System.out.println("Room Booked!");
        }
      }

      if (flag == 1) {
        int rs = stmt_insert.executeUpdate(insert);
      } else {
        System.out.println("All " + room_type + " rooms are booked for the time requested.");
      }

      /*String query_checkrooms = "SELECT * FROM rooms_" + currentDate_checkin_final + " WHERE type = '" + code + "' AND booked = '0';";
      System.out.println(query_checkrooms);
      Statement stmt_checkrooms = con.createStatement();
      ResultSet checkrooms = stmt_checkrooms.executeQuery(query_checkrooms);*/

      /*if (checkrooms.next()){
      		String getroomnumber = checkrooms.getString("room");
      		String insert = "INSERT INTO `reservations` VALUES ('" + getroomnumber + "', '" +  checkindateField.getText() + "', '" +  checkoutdateField.getText() + "',  '" + room_type + "',  '" + nameField.getText() + "');";
      		String bookroom = "UPDATE `rooms_" + currentDate_checkin_final + "` SET booked = '1' WHERE room = '" + getroomnumber + "';";
      //System.out.println(insert);
      	int rs=stmt_insert.executeUpdate(insert);
      	int cr=stmt_checkrooms.executeUpdate(bookroom);
      	con.commit();
      	System.out.println("Room Booked!");
      	}*/

      // else System.out.println("All " + room_type + " rooms are booked for the time requested.");
      System.out.println("Complete.");
    } catch (Exception e) {
      System.out.println(e);
    }
  }
Пример #6
0
  public void actionPerformed(ActionEvent a) {

    int code = 0;
    String roomtypeCompare_arr = null;
    String roomtypeCompare_dep = null;
    if ("book".equals(a.getActionCommand())) {
      try {
        Class.forName("com.mysql.jdbc.Driver");

        // Database connection information. Please note that when porting the code, you must have
        // the jdbc Driver installed where the code is running.
        Connection con =
            DriverManager.getConnection(
                "jdbc:mysql://67.20.111.85:3306/jeehtove_caliking?relaxAutoCommit=true",
                "jeehtove_ck",
                "Z_^PBBZT+kcy");

        // The SELECT query
        String query_arr =
            "SELECT * from reservations WHERE checkin BETWEEN '"
                + checkindateField.getText()
                + "' AND '"
                + checkoutdateField.getText()
                + "'";
        String query_dep =
            "SELECT * from reservations WHERE checkout BETWEEN '"
                + checkindateField.getText()
                + "' AND '"
                + checkoutdateField.getText()
                + "'";

        Statement stmt_arr = con.createStatement();
        Statement stmt_dep = con.createStatement();
        Statement stmt_insert = con.createStatement();
        ResultSet result_arr = stmt_arr.executeQuery(query_arr);
        ResultSet result_dep = stmt_dep.executeQuery(query_dep);

        // Get room type from radio buttons
        String room_type;
        if (standardRoom.isSelected()) {
          room_type = "Standard";
          code = 1;
        } else if (familyRoom.isSelected()) {
          room_type = "Family";
          code = 2;
        } else {
          room_type = "Suite";
          code = 3;
        }

        bookRoom();
        // ResultSet rs=stmt.executeQuery("select * from emp");
        /*if (!result_arr.next() && !result_dep.next()){

        	bookRoom();

        	//Query Prep for checking for open rooms
        	/*String query_checkrooms = "SELECT * FROM makereservation_rooms WHERE type = '" + code + "' AND booked = '0';";
        	Statement stmt_checkrooms = con.createStatement();
        	ResultSet checkrooms = stmt_checkrooms.executeQuery(query_checkrooms);

        	if (checkrooms.next()){
        	String getroomnumber = checkrooms.getString("room");
        	String insert = "INSERT INTO `reservations` VALUES ('" + getroomnumber + "', '" +  checkindateField.getText() + "', '" +  checkoutdateField.getText() + "',  '" + room_type + "',  '" + nameField.getText() + "');";
        	String bookroom = "UPDATE `makereservation_rooms` SET booked = '1' WHERE room = '" + getroomnumber + "';";
        	//System.out.println(insert);
        	int rs=stmt_insert.executeUpdate(insert);
        	int cr=stmt_checkrooms.executeUpdate(bookroom);
        	con.commit();
        	System.out.println("Room Booked!");
        }

        	else System.out.println("All " + room_type + " rooms are booked for the time requested.");
        }

        else {
        	if (result_arr.next()){
        		roomtypeCompare_arr = result_arr.getString("type");
        		System.out.println("(arrival) Does " + roomtypeCompare_arr + " equal " + room_type + "?");
        		if (roomtypeCompare_arr.equals(room_type)){
        			String  checkindateDB_arr = result_arr.getString("checkin");
        			String  checkoutdateDB_arr = result_arr.getString("checkout");
        			System.out.println("There is a room booked on " +  checkindateDB_arr + " that checks out on " +  checkoutdateDB_arr + ". Please select another date.");
        		}

        		else {

        			System.out.println("Room Booked!");
        		}
        	}
        }
        	//System.out.println(query_dep);
        	if (result_dep.next()){
        		roomtypeCompare_dep = result_dep.getString("type");
        		System.out.println("(departure) Does " + roomtypeCompare_dep + " equal " + room_type + "?");
        		if (roomtypeCompare_dep.equals(room_type)){
        			String  checkindateDB_dep = result_dep.getString("checkin");
        			String  checkoutdateDB_dep = result_dep.getString("checkout");
        			System.out.println("There is a room booked on " +  checkindateDB_dep + " that checks out on " +  checkoutdateDB_dep + ". Please select another date.");
        		}

        		else {
        			System.out.println("Room Booked!");
        		}
        	}*/
        con.close();

      } catch (Exception e) {
        System.out.println(e);
      }
    }
  }