/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package club.ui;
import club.data.DataTransaction;
import club.ulti.Validator;
import java.util.ArrayList;
import java.util.Date;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.TableModel;
/**
*
* @author tuan2
*/
public class Transaction extends javax.swing.JDialog {
private String key;
private String value;
private String adm="admin";
private String mem="member";
private String eve="event";
private DataTransaction dt;
/**
* Creates new form Transaction
* value contain ID
* key=adm for Admin table.
* key=eve for Event table.
* key=mem for Member table.
*/
public Transaction(java.awt.Frame parent, boolean modal,String key,String value) {
super(parent, modal);
initComponents();
this.passTransacionTable();
jBDelete.setVisible(false);
try{
this.key=key;
this.value=value;
if(key.equals("adm")){
jtAdmin.setText(value);
jCAdmin.setSelectedIndex(0);
}
if(key.equals("eve")){
jtEvent.setText(value);
}
if(key.equals("mem")){
jtMember.setText(value);
jCMember.setSelectedIndex(0);
}
}catch(Exception ex){
ex.printStackTrace();
}
this.passTransacionTable();
}
/**
* 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.
*/
public void passTransacionTable(){
try{
dt=new DataTransaction();
if(jtMember.getText().isEmpty()==false){
dt.setFilter(jCMember.getSelectedIndex(), jtMember.getText(), "member");
}
if(jtAdmin.getText().isEmpty()==false){
dt.setFilter(jCAdmin.getSelectedIndex(), jtAdmin.getText(), "admin");
}
if(jtEvent.getText().isEmpty()==false){
dt.setFilter(0, jtEvent.getText(), "event");
}
java.util.Date begin=jDateBegin.getDate();
java.util.Date end=jDateEnd.getDate();
if(begin!=null){
if(end!=null){
dt.fillDateBetween(begin, end);
}else{
dt.fillDateBegin(begin);
}
}else{
if(end!=null){
dt.fillDateEnd(end);
}
}
}catch(Exception ex){
ex.printStackTrace();
}
//jTTransaction=new JTable();
jTTransaction.setModel(dt.filterAllTransaction());
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane2 = new javax.swing.JScrollPane();
jTTransaction = new javax.swing.JTable();
jLabel1 = new javax.swing.JLabel();
jtMember = new javax.swing.JTextField();
jtAdmin = new javax.swing.JTextField();
jCMember = new javax.swing.JComboBox();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jtEvent = new javax.swing.JTextField();
jCAdmin = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
jDateBegin = new com.toedter.calendar.JDateChooser();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jDateEnd = new com.toedter.calendar.JDateChooser();
jBgetMemberID = new javax.swing.JButton();
jBgetAdminID = new javax.swing.JButton();
jBgetEventID = new javax.swing.JButton();
jBDelete = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Transactions");
setResizable(false);
jTTransaction.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane2.setViewportView(jTTransaction);
jLabel1.setText("Member ");
jCMember.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ID", "Name", "Nickname"}));
jCMember.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCMemberActionPerformed(evt);
}
});
jLabel2.setText("Admin");
jLabel3.setText("Event ID");
jCAdmin.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ID", "Name", "Account"}));
jButton1.setText("Search");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel4.setText("Begin Date");
jLabel5.setText("End Date");
jBgetMemberID.setText("Get MemberID");
jBgetAdminID.setText("Get AdminID");
jBgetEventID.setText("Get EventID");
jBDelete.setBackground(new java.awt.Color(255, 0, 51));
jBDelete.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jBDelete.setForeground(new java.awt.Color(255, 0, 0));
jBDelete.setText("Delete");
jBDelete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBDeleteActionPerformed(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)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jtMember)
.addComponent(jtAdmin, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
.addComponent(jtEvent))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jCAdmin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jCMember, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jBgetMemberID, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jBgetAdminID, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel5)))
.addComponent(jBgetEventID))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jBDelete)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(jDateBegin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jDateEnd, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 583, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDateBegin, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jtMember, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jCMember, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(jBgetMemberID)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jtAdmin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(jCAdmin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jBgetAdminID))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jtEvent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jBgetEventID)
.addComponent(jBDelete)))
.addComponent(jLabel5)
.addComponent(jDateEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jCMemberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCMemberActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jCMemberActionPerformed
private ArrayList valiadteForm(){
ArrayList errors = new ArrayList();
if (!jtMember.getText().trim().equals("") && jCMember.getSelectedIndex() == 0){
try {
int member = Integer.parseInt(jtMember.getText().trim());
}
catch(Exception e){
errors.add("Member ID must be an integer value");
}
}
if (!jtAdmin.getText().trim().equals("") && jCAdmin.getSelectedIndex() == 0){
try {
int admin = Integer.parseInt(jtAdmin.getText().trim());
}
catch(Exception e){
errors.add("Admin Id must be an integer value");
}
}
if (!jtEvent.getText().trim().equals("")){
try {
int event = Integer.parseInt(jtEvent.getText().trim());
}
catch(Exception e){
errors.add("Event ID must be an integer value");
}
}
return errors;
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
if (valiadteForm().size() == 0){
this.passTransacionTable();
} else{
Validator.showErrors(valiadteForm());
}
}//GEN-LAST:event_jButton1ActionPerformed
private void jBDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBDeleteActionPerformed
// TODO add your handling code here:
int selectedRow = jTTransaction.getSelectedRow();
if (selectedRow == -1) {
JOptionPane.showMessageDialog(rootPane, "You must chose one Transaction first!", "Error!", JOptionPane.ERROR_MESSAGE);
} else
{
int id = (int) jTTransaction.getModel().getValueAt(selectedRow, 0);
double money=(double)jTTransaction.getModel().getValueAt(selectedRow, 5);
boolean isPossibleToDelete = dt.checkTransaction(id);
if (isPossibleToDelete == false)
{
JOptionPane.showMessageDialog(rootPane, "Delete Attendance of Member first", "Error!", JOptionPane.ERROR_MESSAGE);
} else
{
try {
dt.deleteTransaction(id,money);
this.passTransacionTable();
} catch (Exception ex) {
Logger.getLogger(MembershipDialog.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}//GEN-LAST:event_jBDeleteActionPerformed
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jBDelete;
private javax.swing.JButton jBgetAdminID;
private javax.swing.JButton jBgetEventID;
private javax.swing.JButton jBgetMemberID;
private javax.swing.JButton jButton1;
private javax.swing.JComboBox jCAdmin;
private javax.swing.JComboBox jCMember;
private com.toedter.calendar.JDateChooser jDateBegin;
private com.toedter.calendar.JDateChooser jDateEnd;
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.JScrollPane jScrollPane2;
private javax.swing.JTable jTTransaction;
private javax.swing.JTextField jtAdmin;
private javax.swing.JTextField jtEvent;
private javax.swing.JTextField jtMember;
// End of variables declaration//GEN-END:variables
}