/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package club.ui;
import club.beans.ConfigBean;
import club.beans.EventBean;
import club.beans.MemberBean;
import club.data.DataAttendance;
import club.data.DataConfig;
import club.data.DataEvent;
import club.data.DataMember;
import club.data.DataTransaction;
import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
/**
*
* @author Quang
*/
public class AttendanceList extends javax.swing.JDialog {
/**
* Creates new form JoinEvent
*/
public AttendanceList(java.awt.Frame parent, boolean modal,int id) {
super(parent, modal);
initComponents();
eventID = id;
intitContent();
updateListUnjoiner();
updateListJoiner();
}
private void intitContent(){
lbEventID.setText(String.valueOf(eventID));
}
private void updateListUnjoiner(){
DataAttendance data = new DataAttendance();
List<MemberBean> MemberList = data.getUnjoinedMember(eventID);
unjoiners = new Vector();
for (MemberBean bean : MemberList){
unjoiners.add(bean);
}
listUnjoiner.setListData(unjoiners);
}
private void updateListJoiner(){
DataAttendance data = new DataAttendance();
List<MemberBean> MemberList = data.getJoinedMember(eventID);
joiners = new Vector();
for (MemberBean bean : MemberList){
bean.setJoinType(data.getType(eventID, bean.getMemberID()));
joiners.add(bean);
}
listJoiner.setListData(joiners);
}
private void addJoiner(int type){
int[] rows = listUnjoiner.getSelectedIndices();
if (rows.length != 1){
JOptionPane.showMessageDialog(this, "You must select one and only one member from UNJOINERS LIST");
} else{
try{
//lay thong tin fee
DataEvent dataEvent = new DataEvent();
DataMember dataMember = new DataMember();
DataAttendance dataAttendance = new DataAttendance();
DataTransaction dataTransaction = new DataTransaction();
EventBean event = dataEvent.getEventByID(eventID);
//tru tien
DataConfig dataConfig = new DataConfig();
ConfigBean config = dataConfig.readConfigFile();
int admin = config.getAdminID();
MemberBean member = (MemberBean)unjoiners.get(listUnjoiner.getSelectedIndex());
String des = "Pay fee to join event: " + event.getDescription();
Double fee = (type == 0) ? event.getFee() : 0.0;
if (member.getBalance() >= fee || type !=0){
if (dataTransaction.insertTrans(admin, member.getMemberID(), des, 0.0-fee)){
int transID = dataTransaction.getMaxID( member.getMemberID());
dataAttendance.makeAttendance(eventID, member.getMemberID(), type, transID);
JOptionPane.showMessageDialog(this, "Successfully added");
updateListUnjoiner();
updateListJoiner();
} else{
JOptionPane.showMessageDialog(this, "Error make transaction!");
}
} else{
JOptionPane.showMessageDialog(this, "Member's balance doesn't have enough money to payy the fee for this event!");
}
} catch(Exception e){
JOptionPane.showMessageDialog(this, "Error! Exit application");
System.exit(0);
}
}
}
private void removeJoiner(){
int[] rows = listJoiner.getSelectedIndices();
if (rows.length != 1){
JOptionPane.showMessageDialog(this, "You must select one and only one member from JOINERS LIST");
} else{
try{
//lay thong tin fee
DataEvent dataEvent = new DataEvent();
DataMember dataMember = new DataMember();
DataAttendance dataAttendance = new DataAttendance();
DataTransaction dataTransaction = new DataTransaction();
EventBean event = dataEvent.getEventByID(eventID);
//tru tien
DataConfig dataConfig = new DataConfig();
ConfigBean config = dataConfig.readConfigFile();
int admin = config.getAdminID();
MemberBean member = (MemberBean)joiners.get(listJoiner.getSelectedIndex());
String des = "Return fee of event: " + event.getDescription();
int type = member.getJoinType();
Double fee = (type == 0) ? event.getFee() : 0.0;
if (dataAttendance.removeAttendance(eventID, member.getMemberID())){
dataTransaction.insertTrans(admin,member.getMemberID(),des, fee);
joiners.remove(member);
JOptionPane.showMessageDialog(this, "Successfully removed");
updateListUnjoiner();
updateListJoiner();
} else{
JOptionPane.showMessageDialog(this, "Error!");
}
} catch (Exception e){
JOptionPane.showMessageDialog(this, "Error! Exit application");
System.exit(0);
}
}
}
/**
* 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() {
panelJoiners = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
listUnjoiner = new javax.swing.JList();
jScrollPane2 = new javax.swing.JScrollPane();
listJoiner = new javax.swing.JList();
btnAddAsInviter = new javax.swing.JButton();
btnAddAsSpeaker = new javax.swing.JButton();
btnAddAsMember = new javax.swing.JButton();
btnRemove = new javax.swing.JButton();
lbUnjoinersList = new javax.swing.JLabel();
lbJoinersList = new javax.swing.JLabel();
lbClickToAdd = new javax.swing.JLabel();
lbEventNo = new javax.swing.JLabel();
btnClose = new javax.swing.JButton();
lbEventID = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Select members for event");
setResizable(false);
panelJoiners.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
jScrollPane1.setViewportView(listUnjoiner);
jScrollPane2.setViewportView(listJoiner);
btnAddAsInviter.setText("Inviter ->");
btnAddAsInviter.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAddAsInviterActionPerformed(evt);
}
});
btnAddAsSpeaker.setText("Committee ->");
btnAddAsSpeaker.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAddAsSpeakerActionPerformed(evt);
}
});
btnAddAsMember.setText("Member ->");
btnAddAsMember.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAddAsMemberActionPerformed(evt);
}
});
btnRemove.setText("<- Remove");
btnRemove.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnRemoveActionPerformed(evt);
}
});
lbUnjoinersList.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
lbUnjoinersList.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lbUnjoinersList.setText("Members");
lbJoinersList.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
lbJoinersList.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lbJoinersList.setText("JOINERS LIST");
lbClickToAdd.setText("Click to add as");
javax.swing.GroupLayout panelJoinersLayout = new javax.swing.GroupLayout(panelJoiners);
panelJoiners.setLayout(panelJoinersLayout);
panelJoinersLayout.setHorizontalGroup(
panelJoinersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelJoinersLayout.createSequentialGroup()
.addContainerGap()
.addGroup(panelJoinersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelJoinersLayout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(panelJoinersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(btnRemove, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lbClickToAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnAddAsMember, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnAddAsSpeaker, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnAddAsInviter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(lbUnjoinersList, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(panelJoinersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lbJoinersList, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(26, Short.MAX_VALUE))
);
panelJoinersLayout.setVerticalGroup(
panelJoinersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelJoinersLayout.createSequentialGroup()
.addGroup(panelJoinersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelJoinersLayout.createSequentialGroup()
.addContainerGap()
.addGroup(panelJoinersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 367, Short.MAX_VALUE)
.addComponent(jScrollPane1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(panelJoinersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbUnjoinersList)
.addComponent(lbJoinersList)))
.addGroup(panelJoinersLayout.createSequentialGroup()
.addGap(54, 54, 54)
.addComponent(btnRemove)
.addGap(43, 43, 43)
.addComponent(lbClickToAdd)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnAddAsMember)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnAddAsSpeaker)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnAddAsInviter)))
.addContainerGap(32, Short.MAX_VALUE))
);
lbEventNo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
lbEventNo.setText("Event No :");
btnClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/club/icon/cancel.png"))); // NOI18N
btnClose.setText("Close");
btnClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCloseActionPerformed(evt);
}
});
lbEventID.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
lbEventID.setText("1");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnClose, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(panelJoiners, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(lbEventNo)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lbEventID)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbEventNo)
.addComponent(lbEventID))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(panelJoiners, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnClose, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnAddAsMemberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddAsMemberActionPerformed
// TODO add your handling code here:
addJoiner(0);
}//GEN-LAST:event_btnAddAsMemberActionPerformed
private void btnAddAsSpeakerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddAsSpeakerActionPerformed
// TODO add your handling code here:
addJoiner(2);
}//GEN-LAST:event_btnAddAsSpeakerActionPerformed
private void btnAddAsInviterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddAsInviterActionPerformed
// TODO add your handling code here:
addJoiner(1);
}//GEN-LAST:event_btnAddAsInviterActionPerformed
private void btnRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveActionPerformed
// TODO add your handling code here:
removeJoiner();
}//GEN-LAST:event_btnRemoveActionPerformed
private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
// TODO add your handling code here:
this.dispose();
}//GEN-LAST:event_btnCloseActionPerformed
/**
* @param args the command line arguments
*/
int eventID;
Vector unjoiners;
Vector joiners;
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAddAsInviter;
private javax.swing.JButton btnAddAsMember;
private javax.swing.JButton btnAddAsSpeaker;
private javax.swing.JButton btnClose;
private javax.swing.JButton btnRemove;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JLabel lbClickToAdd;
private javax.swing.JLabel lbEventID;
private javax.swing.JLabel lbEventNo;
private javax.swing.JLabel lbJoinersList;
private javax.swing.JLabel lbUnjoinersList;
private javax.swing.JList listJoiner;
private javax.swing.JList listUnjoiner;
private javax.swing.JPanel panelJoiners;
// End of variables declaration//GEN-END:variables
}