/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* SentMessageReport.java
*
* Created on 19 Aug, 2010, 12:31:51 PM
*/
package sms3;
import java.awt.Dimension;
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.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import sms.calendar.IDateEditor;
import sms.calendar.JCalendar;
import sms.calendar.JTextFieldDateEditor;
/**
*
* @author
*/
public class SentMessageReport extends javax.swing.JInternalFrame implements ActionListener, PropertyChangeListener{
/** Creates new form SentMessageReport */
SMSManager smsman;
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;
protected int flagFrom;
public SentMessageReport(SMSManager sm) {
smsman = sm;
initComponents();
}
/** 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();
from_date = new javax.swing.JTextField();
cmdFromDate = new javax.swing.JButton();
cmdToDate = new javax.swing.JButton();
to_date = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
type = new javax.swing.JComboBox();
jLabel4 = new javax.swing.JLabel();
message_type = new javax.swing.JComboBox();
jSeparator1 = new javax.swing.JSeparator();
roll_no_text = new javax.swing.JLabel();
roll_no = new javax.swing.JTextField();
jSeparator2 = new javax.swing.JSeparator();
cell_no = new javax.swing.JTextField();
cell_no_text = new javax.swing.JLabel();
jSeparator3 = new javax.swing.JSeparator();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
user_name = new javax.swing.JComboBox();
view_report = new javax.swing.JButton();
jLabel11 = new javax.swing.JLabel();
report_type = new javax.swing.JComboBox();
roll_no_check = new javax.swing.JCheckBox();
cell_no_check = new javax.swing.JCheckBox();
setClosable(true);
setIconifiable(true);
setTitle("Sent Message Report");
jLabel1.setText("From Date :");
cmdFromDate.setText("...");
cmdFromDate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdFromDateActionPerformed(evt);
}
});
cmdToDate.setText("...");
cmdToDate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdToDateActionPerformed(evt);
}
});
jLabel2.setText("To Date :");
jLabel3.setText("Type :");
type.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "Job", "From Remort Website", "Quick Message", "Keyword" }));
jLabel4.setText("Message Type :");
message_type.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "Sent", "Failed" }));
roll_no_text.setText("Roll No. :");
roll_no_text.setEnabled(false);
roll_no.setEnabled(false);
cell_no.setEnabled(false);
cell_no_text.setText("Cell No. :");
cell_no_text.setEnabled(false);
jLabel9.setText("For Specific Remort User :");
jLabel10.setText("User Name :");
user_name.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All" }));
view_report.setText("View Report");
view_report.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
view_reportActionPerformed(evt);
}
});
jLabel11.setText("Report Type :");
report_type.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "View", "CSV File" }));
roll_no_check.setText("For Specific Roll No.");
roll_no_check.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
roll_no_checkItemStateChanged(evt);
}
});
cell_no_check.setText("For Specific Cell No.");
cell_no_check.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cell_no_checkItemStateChanged(evt);
}
});
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.TRAILING)
.addComponent(jSeparator3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
.addComponent(roll_no_check, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cell_no_check, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(3, 3, 3)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 322, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(roll_no_text)
.addGap(27, 27, 27)
.addComponent(roll_no, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(cell_no_text)
.addGap(27, 27, 27)
.addComponent(cell_no, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel9, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel1)
.addComponent(jLabel4)
.addComponent(jLabel3))
.addGap(72, 72, 72)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(message_type, 0, 139, Short.MAX_VALUE)
.addComponent(type, 0, 139, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(to_date, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
.addComponent(from_date, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cmdToDate, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmdFromDate, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(38, 38, 38))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel10)
.addGap(18, 18, 18)
.addComponent(user_name, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel11)
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(view_report, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(report_type, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(from_date, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmdFromDate)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmdToDate)
.addComponent(to_date, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addGap(15, 15, 15)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(message_type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(roll_no_check)
.addGap(7, 7, 7)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(roll_no, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(roll_no_text))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(7, 7, 7)
.addComponent(cell_no_check)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cell_no_text)
.addComponent(cell_no, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(user_name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(report_type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11))
.addGap(34, 34, 34)
.addComponent(view_report, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(48, 48, 48))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void view_reportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_view_reportActionPerformed
// TODO add your handling code here:
String query = "";
String rollno = "";
String cellno = "";
String mtype = "";
String msgtype = "";
String user = "";
int message_status = 0;
int flag_quickmessage = 0, flag_smtp = 0, flag_keyword = 0, flag_job = 0;
int priority = 1;
if (roll_no_check.isSelected()) {
rollno = roll_no.getText();
}
if (cell_no_check.isSelected()) {
cellno = cell_no.getText();
}
//for job or smtp or keyword or quick message
int i = type.getSelectedIndex();
switch (i) {
case 0:
break;
case 1:
flag_job = 1;
priority = 1;
break;
case 2:
flag_smtp = 1;
priority = 2;
break;
case 3:
flag_quickmessage = 1;
priority = 3;
break;
case 4:
flag_keyword = 1;
priority = 4;
break;
}
//for message type
int j = message_type.getSelectedIndex();
if (j == 0) {
} else if (j == 1) {
message_status = 1;
} else if (j == 2) {
message_status = 2;
}
//for user
int k = user_name.getSelectedIndex();
if (k == 0) {
} else {
user = user_name.getItemAt(k).toString();
}
if (roll_no_check.isSelected()) {
query = "SELECT * from queue where roll_no='" + rollno + "'";
if (flag_job == 1) {
query = query + " and priority=" + priority + "";
}
if (flag_keyword == 1) {
query = query + " and job_id=0 and priority=" + priority + "";
}
if (flag_quickmessage == 1) {
query = query + " and job_id=0 and priority=" + priority + "";
}
if (flag_smtp == 1) {
query = query + " and job_id=0 priority=" + priority + "";
}
if (message_status == 0) {
} else if (message_status == 1) {
query = query + " and status=" + message_status + "";
} else if (message_status == 2) {
query = query + " and status=" + message_status + "";
}
if (user.equals("")) {
} else {
query = query + " and user=" + user + ";";
}
} else {
query = "SELECT * from queue";
if (flag_job == 1) {
query = query + "where priority=" + priority + "";
}
if (flag_keyword == 1) {
query = query + "where job_id=0 and priority=" + priority + "";
}
if (flag_quickmessage == 1) {
query = query + "where job_id=0 and priority=" + priority + "";
}
if (flag_smtp == 1) {
query = query + "where job_id=0 priority=" + priority + "";
}
if (message_status == 0) {
} else if (message_status == 1) {
query = query + " and status=" + message_status + "";
} else if (message_status == 2) {
query = query + " and status=" + message_status + "";
}
if (user.equals("")) {
} else {
query = query + " and user=" + user + ";";
}
}
if (from_date.getText().equals("") || to_date.getText().equals("")) {
} else {
}
int index = report_type.getSelectedIndex();
if (index == 0) {
ViewReport vr = new ViewReport(smsman, query,0);
smsman.addframe(vr);
vr.setVisible(true);
this.setVisible(false);
} else if (index == 1) {
MakeCSV mk = new MakeCSV(query);
}
}//GEN-LAST:event_view_reportActionPerformed
private void cell_no_checkItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cell_no_checkItemStateChanged
// TODO add your handling code here:
if (cell_no_check.isSelected()) {
cell_no.setEnabled(true);
cell_no_text.setEnabled(true);
} else {
cell_no.setEnabled(true);
cell_no_text.setEnabled(true);
}
}//GEN-LAST:event_cell_no_checkItemStateChanged
private void roll_no_checkItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_roll_no_checkItemStateChanged
// TODO add your handling code here:
if (roll_no_check.isSelected()) {
roll_no.setEnabled(true);
roll_no_text.setEnabled(true);
} else {
roll_no.setEnabled(true);
roll_no_text.setEnabled(true);
}
}//GEN-LAST:event_roll_no_checkItemStateChanged
private void cmdFromDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdFromDateActionPerformed
flagFrom=1;
jcalendar = new JCalendar();
//this.dateEditor = dateEditor;
//this.dateEditor=(IDateEditor) startDate;
if (this.dateEditor == null) {
this.dateEditor = new JTextFieldDateEditor();
}
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 = cmdFromDate.getWidth() - (int) popup.getPreferredSize().getWidth();
int y = cmdFromDate.getY() + cmdFromDate.getHeight();
popup.setLightWeightPopupEnabled(true);
popup.add(jcalendar);
popup.show(cmdFromDate, x - 25, y - 100);
}//GEN-LAST:event_cmdFromDateActionPerformed
private void cmdToDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdToDateActionPerformed
flagFrom=0;
jcalendar = new JCalendar();
//this.dateEditor = dateEditor;
//this.dateEditor=(IDateEditor) startDate;
if (this.dateEditor == null) {
this.dateEditor = new JTextFieldDateEditor();
}
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 = cmdToDate.getWidth() - (int) popup.getPreferredSize().getWidth();
int y = cmdToDate.getY() + cmdToDate.getHeight();
popup.setLightWeightPopupEnabled(true);
popup.add(jcalendar);
popup.show(cmdToDate, x - 25, y - 100);
}//GEN-LAST:event_cmdToDateActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField cell_no;
private javax.swing.JCheckBox cell_no_check;
private javax.swing.JLabel cell_no_text;
private javax.swing.JButton cmdFromDate;
private javax.swing.JButton cmdToDate;
private javax.swing.JTextField from_date;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel9;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JSeparator jSeparator3;
private javax.swing.JComboBox message_type;
private javax.swing.JComboBox report_type;
private javax.swing.JTextField roll_no;
private javax.swing.JCheckBox roll_no_check;
private javax.swing.JLabel roll_no_text;
private javax.swing.JTextField to_date;
private javax.swing.JComboBox type;
private javax.swing.JComboBox user_name;
private javax.swing.JButton view_report;
// End of variables declaration//GEN-END:variables
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
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);
if(flagFrom==1)
from_date.setText(date);
else
to_date.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 {
// setDate((Date) evt.getNewValue());
}
}
}
}