Package sms3

Source Code of sms3.Schedule

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* Schedule.java
*
* Created on 20 Jun, 2010, 7:58:26 PM
*/
package sms3;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JPopupMenu;
import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import sms.calendar.IDateEditor;
import sms.calendar.JCalendar;
import sms.calendar.JTextFieldDateEditor;

import java.sql.*;
import javax.swing.JOptionPane;

/**
*
* @author sumit
*/
public class Schedule extends javax.swing.JFrame implements ActionListener, PropertyChangeListener {

    private static final long serialVersionUID = -4306412745720670722L;
    protected IDateEditor dateEditor;
    protected JButton calendarButton;
    protected JCalendar jcalendar;
    protected JPopupMenu popup;
    protected boolean isInitialized;
    protected boolean dateSelected;
    protected Date lastSelectedDate;
    private ChangeListener changeListener;
    private Dimension screenSize;
    private Dimension size;
    Connection databaseConnection;
    Statement statement;
    ResultSet names;
    SMSManager smsman;
    JobManager jobman;
    int jobid;
    DatabaseConnection dc = new DatabaseConnection();

    /** Creates new form Schedule */
    /*
    public static void main(String args[])
    {
        Schedule s = new Schedule();
        s.setVisible(true);

    }
*/
    /*
    public Schedule()
    {
       
        initComponents();
        screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        size = this.getSize();
        screenSize.height = screenSize.height / 2;
        screenSize.width = screenSize.width / 2;
        size.height = size.height / 2;
        size.width = size.width / 2;
        int y = screenSize.height - size.height;
        int x = screenSize.width - size.width;
        this.setLocation(x, y);
       
    }
    */
    public Schedule(SMSManager sm, JobManager jm, int job_id) {
        initComponents();
        smsman = sm;
        jobman = jm;
        jobid = job_id;

        /*

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        }

         */
       
        this.setDefaultLookAndFeelDecorated(true);
       
        //System.out.print("\nsched loaded\n");
        screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        size = this.getSize();
        screenSize.height = screenSize.height / 2;
        screenSize.width = screenSize.width / 2;
        size.height = size.height / 2;
        size.width = size.width / 2;
        int y = screenSize.height - size.height;
        int x = screenSize.width - size.width;
        this.setLocation(x, y);
    }

    public void init() {
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        repeatType = new javax.swing.JComboBox();
        scheduleName = new javax.swing.JTextField();
        enabled = new javax.swing.JCheckBox();
        startDate = new javax.swing.JTextField();
        butDate = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        hour = new javax.swing.JComboBox();
        minute = new javax.swing.JComboBox();
        butAdd = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        description = new javax.swing.JTextArea();
        jLabel8 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Schedule");
        setName("Schedule"); // NOI18N
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
        });

        jLabel1.setText("Schedule Name :");

        jLabel2.setText("Date :");

        jLabel3.setText("Time :");

        jLabel5.setText("Repeat Type :");

        repeatType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Once", "Daily", "Weekly", "Yearly", "Monthly" }));
        repeatType.setName("repeatType"); // NOI18N
        repeatType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                repeatTypeActionPerformed(evt);
            }
        });

        scheduleName.setName("scheduleName"); // NOI18N

        enabled.setText("Enabled");
        enabled.setName("enabled"); // NOI18N
        enabled.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enabledActionPerformed(evt);
            }
        });

        startDate.setName("startDate"); // NOI18N

        butDate.setText("...");
        butDate.setName("butDate"); // NOI18N
        butDate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butDateActionPerformed(evt);
            }
        });

        jLabel4.setText("HH");

        jLabel6.setText("MM");

        hour.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" }));

        minute.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59" }));

        butAdd.setText("Add Schedule");
        butAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butAddActionPerformed(evt);
            }
        });

        jLabel7.setText("Description :");

        description.setColumns(20);
        description.setRows(5);
        jScrollPane1.setViewportView(description);

        jLabel8.setText("Status :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel2)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel3)
                                            .addGap(51, 51, 51))
                                        .addComponent(jLabel1))
                                    .addComponent(jLabel8))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(enabled)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(hour, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(minute, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
                                    .addComponent(scheduleName, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(startDate, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(butDate, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(repeatType, 0, 183, Short.MAX_VALUE))))
                        .addContainerGap())))
            .addGroup(layout.createSequentialGroup()
                .addGap(89, 89, 89)
                .addComponent(butAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(99, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(scheduleName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(enabled)
                            .addComponent(jLabel8))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(butDate)
                    .addComponent(jLabel2)
                    .addComponent(startDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(hour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(minute, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(11, 11, 11)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(jLabel5))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(repeatType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(26, 26, 26)
                .addComponent(butAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        getAccessibleContext().setAccessibleParent(this);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void repeatTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_repeatTypeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_repeatTypeActionPerformed

    private void butDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butDateActionPerformed

        jcalendar = new JCalendar();
        this.dateEditor = dateEditor;
        if (this.dateEditor == null) {
            this.dateEditor = new JTextFieldDateEditor();
        }
        this.dateEditor.addPropertyChangeListener("date", this);
        jcalendar.getDayChooser().addPropertyChangeListener("day", this);
        // always fire"day" property even if the user selects
        // the already selected day again
        jcalendar.getDayChooser().setAlwaysFireDayProperty(true);

        popup = new JPopupMenu() {

            private static final long serialVersionUID = -6078272560337577761L;

            @Override
            public void setVisible(boolean b) {
                Boolean isCanceled = (Boolean) getClientProperty("JPopupMenu.firePopupMenuCanceled");
                if (b || (!b && dateSelected) || ((isCanceled != null) && !b && isCanceled.booleanValue())) {
                    super.setVisible(b);
                }
            }
        };

        changeListener = new ChangeListener() {

            boolean hasListened = false;

            public void stateChanged(ChangeEvent e) {
                if (hasListened) {
                    hasListened = false;
                    return;
                }
                if (popup.isVisible()) {
                    MenuElement[] me = MenuSelectionManager.defaultManager().getSelectedPath();
                    MenuElement[] newMe = new MenuElement[me.length + 1];
                    newMe[0] = popup;
                    for (int i = 0; i < me.length; i++) {
                        newMe[i + 1] = me[i];
                    }
                    hasListened = true;
                    MenuSelectionManager.defaultManager().setSelectedPath(newMe);
                }
            }
        };

        int x = butDate.getWidth() - (int) popup.getPreferredSize().getWidth();
        int y = butDate.getY() + butDate.getHeight();

        popup.setLightWeightPopupEnabled(true);
        popup.add(jcalendar);
        popup.show(butDate, x - 28, y - 185);

    }//GEN-LAST:event_butDateActionPerformed

    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_formMouseClicked

    private void butAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butAddActionPerformed

        try {
            Connection con = dc.database_connection_main();

            statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            String q = "SELECT schedule_name from schedule;";
            int flag = 0;
            ResultSet rs = statement.executeQuery(q);
            while (rs.next()) {
                if (rs.getString("schedule_name").equals(scheduleName.getText())) {
                    flag = 1;
                    rs.close();
                    break;
                }
            }

            q="SELECT max(schedule_id) from schedule";
            rs=statement.executeQuery(q);
            rs.next();
            int MAXID = Integer.parseInt(rs.getString(1));
            MAXID++;
            rs.close();
            //statement.close();
            //con.close();
                       
            if (flag == 0) {
                con = dc.database_connection_main();
                statement = con.createStatement();

                int index = hour.getSelectedIndex();
                String h = hour.getItemAt(index).toString();
                index = minute.getSelectedIndex();
                String m = minute.getItemAt(index).toString();
                String time = h + ":" + m;
                //String query = "insert into schedule values
                // ('" + scheduleName.getText() + "'," + enabled.isSelected() + "','" + startDate.getText() + "','" + time + "','" + repeatType.getSelectedItem().toString() + "','" + jobid + "','" + description.getText() + "');";

                String strEnabled = Boolean.toString(enabled.isSelected());
               
                int intEnabled;
                if(strEnabled.equals("true"))
                    intEnabled = 1;
                else
                    intEnabled = 0;
               
                String query = "insert into schedule values (" + MAXID + ",'"+
                        scheduleName.getText() + "','" + startDate.getText() + "','" + time + "','" +repeatType.getSelectedItem().toString() +
                        "'," + intEnabled + "," + jobid + ",'" + description.getText() + "')" ;

                statement.executeUpdate(query);
                con.close();
                JOptionPane.showMessageDialog(this, "Schedule added successfully");
               
                //jobman.addjob(jobid);
                this.dispose();
                //jobman.setVisible(true);
               

            } else {
                JOptionPane.showMessageDialog(this, "Schedule name already exists.");
            }
        } catch (SQLException e) {
            //JOptionPane.showMessageDialog(this, e.getErrorCode());
            JOptionPane.showMessageDialog(this, e.getMessage());

        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage());
        }

    }//GEN-LAST:event_butAddActionPerformed

    private void enabledActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enabledActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_enabledActionPerformed
    public void propertyChange(PropertyChangeEvent evt) {

        String date = "";
        date = String.valueOf(jcalendar.getCalendar().getTime().getDate());
        date = date + "-" + String.valueOf(jcalendar.getCalendar().getTime().getMonth() + 1);
        date = date + "-" + String.valueOf(jcalendar.getCalendar().getTime().getYear() + 1900);

        if (evt.getPropertyName().equals("day")) {
            if (popup.isVisible()) {
                dateSelected = true;
                popup.setVisible(false);
                startDate.setText(date);
                dateSelected = false;
            }
        } else if (evt.getPropertyName().equals("date")) {
            System.out.print("sss");
            if (evt.getSource() == dateEditor) {
                firePropertyChange("date", evt.getOldValue(), evt.getNewValue());
            } else {
               
            }
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton butAdd;
    private javax.swing.JButton butDate;
    private javax.swing.JTextArea description;
    private javax.swing.JCheckBox enabled;
    private javax.swing.JComboBox hour;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox minute;
    private javax.swing.JComboBox repeatType;
    private javax.swing.JTextField scheduleName;
    private javax.swing.JTextField startDate;
    // End of variables declaration//GEN-END:variables

    public void actionPerformed(ActionEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
TOP

Related Classes of sms3.Schedule

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.