/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package club.ui;
import club.beans.MemberBean;
import club.data.DataConfig;
import club.data.DataMember;
import club.data.DataTransaction;
import javax.swing.JOptionPane;
/**
*
* @author Quang
*/
public class updateBalance extends javax.swing.JDialog {
/**
* Creates new form updateBalance
*/
public updateBalance(java.awt.Frame parent, boolean modal, int memberID) {
super(parent, modal);
this.memberID = memberID;
this.setLocation(450,200);
initComponents();
init();
}
private void init() {
lbError.setText("");
MemberBean member = DataMember.getMemberByID(memberID);
lbConfirmInfo.setText("User No. " + member.getMemberID() + ": " + member.getFirstName());
lbOldValue.setText(String.format("%1$,.1f", member.getBalance()));
lbNewValue.setText(String.format("%1$,.1f", member.getBalance()));
}
/**
* 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() {
lbTitle = new javax.swing.JLabel();
txtValue = new javax.swing.JTextField();
lbValue = new javax.swing.JLabel();
lbConfirmInfo = new javax.swing.JLabel();
lbBalance1 = new javax.swing.JLabel();
lbOldValue = new javax.swing.JLabel();
lbBalance2 = new javax.swing.JLabel();
lbNewValue = new javax.swing.JLabel();
lbNote = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
btnSubmit = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
lbError = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Update balance");
setResizable(false);
lbTitle.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
lbTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lbTitle.setText("Update Balance");
txtValue.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
txtValueKeyReleased(evt);
}
});
lbValue.setText("Value");
lbConfirmInfo.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
lbConfirmInfo.setText("User No 10: Pham Ngoc Quang");
lbBalance1.setText("Current Balance");
lbOldValue.setText("10,000,000.0");
lbBalance2.setText("New Balance");
lbNewValue.setText("10,000,000.0");
lbNote.setText("Note");
jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
btnSubmit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/club/icon/edit.png"))); // NOI18N
btnSubmit.setText("Submit");
btnSubmit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSubmitActionPerformed(evt);
}
});
btnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/club/icon/cancel.png"))); // NOI18N
btnCancel.setText("Cancel");
btnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCancelActionPerformed(evt);
}
});
lbError.setForeground(new java.awt.Color(255, 0, 0));
lbError.setText("Error Notofications");
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)
.addComponent(lbError, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1)
.addComponent(lbTitle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(btnSubmit, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lbValue)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtValue))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lbNote)
.addComponent(lbConfirmInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(lbBalance1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lbBalance2, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lbOldValue, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lbNewValue, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(lbTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lbValue))
.addGap(7, 7, 7)
.addComponent(lbError)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbConfirmInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbBalance1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lbOldValue))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbBalance2)
.addComponent(lbNewValue))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lbNote)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnSubmit, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
// TODO add your handling code here:
this.dispose();
}//GEN-LAST:event_btnCancelActionPerformed
private void txtValueKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtValueKeyReleased
// TODO add your handling code here:
try {
Double input = Double.parseDouble(txtValue.getText().trim());
Double oldValue = Double.parseDouble(lbOldValue.getText().trim());
Double newValue = oldValue + input;
if (newValue > oldValue) {
lbNewValue.setText(String.format("<html><b><font color='green'>" + "%1$,.1f" + "</font></b></html>", newValue));
} else {
lbNewValue.setText(String.format("<html><i><font color='red'>" + "%1$,.1f" + "</font></i></html>", newValue));
}
lbError.setText("");
} catch (NumberFormatException e) {
lbError.setText("Invalid money value. Double only!");
}
}//GEN-LAST:event_txtValueKeyReleased
private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitActionPerformed
// TODO add your handling code here:
Double input;
try {
input = Double.parseDouble(txtValue.getText().trim());
DataConfig dataConfig = new DataConfig();
if (dataConfig.isRightConfig()) {
int adminID = dataConfig.getCurrentAdminID();
String des = jTextArea1.getText().trim();
DataTransaction dataTrans = new DataTransaction();
if (dataTrans.insertTrans(adminID, memberID, des, input)) {
this.dispose();
} else {
JOptionPane.showMessageDialog(rootPane, "Error !");
}
}
} catch (NumberFormatException e) {
txtValue.requestFocus();
}
}//GEN-LAST:event_btnSubmitActionPerformed
/**
* @param args the command line arguments
*/
int adminID;
int memberID;
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnSubmit;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JLabel lbBalance1;
private javax.swing.JLabel lbBalance2;
private javax.swing.JLabel lbConfirmInfo;
private javax.swing.JLabel lbError;
private javax.swing.JLabel lbNewValue;
private javax.swing.JLabel lbNote;
private javax.swing.JLabel lbOldValue;
private javax.swing.JLabel lbTitle;
private javax.swing.JLabel lbValue;
private javax.swing.JTextField txtValue;
// End of variables declaration//GEN-END:variables
}