Package sms3

Source Code of sms3.Schedule1

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

/*
* Schedule1.java
*
* Created on 19 Sep, 2010, 5:34:46 PM
*/

package sms3;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.beans.PropertyChangeEvent;
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
*/
public class Schedule1 extends javax.swing.JInternalFrame {

    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 Schedule1 */
    public Schedule1(SMSManager sm, JobManager jm, int job_id) {
        initComponents();
        smsman = sm;
        jobman = jm;
        jobid = job_id;
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        }
        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);
    }

    /** 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() {

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

        setClosable(true);
        setIconifiable(true);

        jLabel8.setFont(new java.awt.Font("Times New Roman", 0, 13));
        jLabel8.setText("Status :");

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

        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

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

        jLabel1.setFont(new java.awt.Font("Times New Roman", 0, 13));
        jLabel1.setText("Schedule Name :");

        jLabel6.setText("MM");

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 13));
        jLabel2.setText("Schedule Start Date :");

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

        jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 13));
        jLabel3.setText("Schedule Start Time :");

        jLabel5.setFont(new java.awt.Font("Times New Roman", 0, 13));
        jLabel5.setText("Repeat Type :");

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

        jLabel7.setFont(new java.awt.Font("Times New Roman", 0, 13));
        jLabel7.setText("Description :");

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

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

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

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 417, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel7)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addGap(62, 62, 62)
                            .addComponent(scheduleName))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel5)
                                .addComponent(jLabel2)
                                .addComponent(jLabel3))
                            .addGap(38, 38, 38)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(enabled)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .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))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(repeatType, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(hour, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(minute, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(butAdd, javax.swing.GroupLayout.Alignment.LEADING))))))
                .addGap(91, 91, 91))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 334, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .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)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 89, Short.MAX_VALUE)
                        .addComponent(jLabel8))
                    .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.RELATED)
                        .addComponent(enabled)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(startDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(butDate))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(hour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(minute, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(repeatType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(butAdd)
                .addContainerGap())
        );

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

    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", jcalendar);
        jcalendar.getDayChooser().addPropertyChangeListener("day",jcalendar);
        // 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 - 25, y - 100);
    }//GEN-LAST:event_butDateActionPerformed

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

    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;
                    break;
                }
            }
            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 (schedule_name,status,sdate,stime,repeat_type,job_id,description)values ('" + scheduleName.getText() + "'," + enabled.isSelected() + "','" + startDate.getText() + "','" + time + "','" + repeatType.getSelectedItem().toString() + "','" + 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);

        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, e);
        }
    }//GEN-LAST:event_butAddActionPerformed

    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 {

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


    // 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

}
TOP

Related Classes of sms3.Schedule1

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.