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 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); }
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); } }
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); } } }
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); }