Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pop #39

Merged
merged 5 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private void initHomePanel() {
interestService.calculateCurrentInterest();
homePanel.updateCurrentBallance();
homePanel.updateGoal();
homePanel.updateFixBallance();

setContentPane(this.homePanel.$$$getRootComponent$$$());
// 显式刷新
Expand All @@ -118,6 +119,7 @@ private void initSettingsPanel() {
}

private void initFixedAccountPanel() {
fixedAccountPanel.createTable();
fixedAccountPanel.$$$getRootComponent$$$().updateUI();
setContentPane(this.fixedAccountPanel.$$$getRootComponent$$$());
// 显式刷新
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public CurrentAccountPanel() {
});
transferToFixedButton.addActionListener(e -> {
toFixedPop.init();
updatePanel();
});
backHomeButton.addActionListener(e -> {
publisher.publishEvent(new PanelSwitchEvent(this, "home"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</grid>
</children>
</grid>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="e3588" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand All @@ -67,42 +67,53 @@
</component>
<component id="a785e" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Deposit Period"/>
<text value="Deposit Period (mounth)"/>
</properties>
</component>
<component id="2e46d" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Password"/>
</properties>
</component>
<component id="8a5dc" class="javax.swing.JTextField" binding="textField1" default-binding="true">
<component id="58dda" class="javax.swing.JPasswordField" binding="passwordField1" default-binding="true">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="8a5dc" class="javax.swing.JTextField" binding="amountField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="e7a76" class="javax.swing.JComboBox" binding="comboBox1" default-binding="true">
<component id="b0a38" class="javax.swing.JLabel" binding="rateLabel">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model>
<item value="3 months"/>
<item value="6 months"/>
<item value="1 year"/>
<item value="3 years"/>
</model>
<text value="Deposit rate"/>
</properties>
</component>
<component id="58dda" class="javax.swing.JPasswordField" binding="passwordField1" default-binding="true">
<component id="b17b7" class="javax.swing.JTextField" binding="rateField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="6b268" class="javax.swing.JTextField" binding="monthField">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,41 @@
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import com.seg83.childbank.dao.AdminDao;
import com.seg83.childbank.service.CurrentService;
import com.seg83.childbank.gui.component.currentpanel.CurrentAccountPanel;
import com.seg83.childbank.service.DepositService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.*;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
* A JDialog component that facilitates depositing money into fixed account
* It includes fields for entering the amount, the mode and password, and buttons for OK and Cancel actions
*/
@Component
@Slf4j
public class ToFixedPop extends JDialog {

@Autowired
DepositService depositService;

@Autowired
AdminDao adminDao;

private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTextField textField1;
private JComboBox comboBox1;
private JTextField amountField;
private JPasswordField passwordField1;
private JLabel rateLabel;
private JTextField rateField;
private JTextField monthField;

public ToFixedPop() {
setContentPane(contentPane);
Expand Down Expand Up @@ -63,11 +75,67 @@ public void actionPerformed(ActionEvent e) {

private void onOK() {
// add your code here
dispose();
String amount = amountField.getText();
int amountInt;
// ammount should be a integer
try {
amountInt = Integer.parseInt(amount);
} catch (NumberFormatException e) {
// show a dialog
JOptionPane.showMessageDialog(this, "Amount should be an Integer", "Error", JOptionPane.ERROR_MESSAGE);
return;
}

String rate = rateField.getText();
double rateDouble;
try {
rateDouble = Double.parseDouble(rate);
} catch (NumberFormatException e) {
// show a dialog
JOptionPane.showMessageDialog(this, "Amount should be an Double", "Error", JOptionPane.ERROR_MESSAGE);
return;
}

String month = monthField.getText();
int monthInt;
try {
monthInt = Integer.parseInt(amount);
} catch (NumberFormatException e) {
// show a dialog
JOptionPane.showMessageDialog(this, "Amount should be an Integer", "Error", JOptionPane.ERROR_MESSAGE);
return;
}


char[] pass = passwordField1.getPassword();
String password = new String(pass);
log.debug("Amount: {}, Password: {}", amount, password);


// 处理日期
LocalDate today = LocalDate.now();
LocalDate futureDate = today.plusMonths(monthInt);

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

String todayStr = formatter.format(today);
String futureDateStr = formatter.format(futureDate);


String target = (String) adminDao.getAttribute("adminPassword");
boolean check = password.equals(target);
if (!check) {
JOptionPane.showMessageDialog(this, "Password mistake", "Error", JOptionPane.ERROR_MESSAGE);
} else {
depositService.depositFixAccount(amountInt, rateDouble, todayStr, futureDateStr);
dispose();
}
}

private void onCancel() {
// add your code here if necessary


dispose();
}

Expand Down Expand Up @@ -110,29 +178,28 @@ public void init() {
buttonCancel.setText("Cancel");
panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JPanel panel3 = new JPanel();
panel3.setLayout(new GridLayoutManager(3, 2, new Insets(0, 0, 0, 0), -1, -1));
panel3.setLayout(new GridLayoutManager(4, 2, new Insets(0, 0, 0, 0), -1, -1));
contentPane.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
final JLabel label1 = new JLabel();
label1.setText("Deposit Amount");
panel3.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JLabel label2 = new JLabel();
label2.setText("Deposit Period");
panel3.add(label2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
label2.setText("Deposit Period (mounth)");
panel3.add(label2, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JLabel label3 = new JLabel();
label3.setText("Password");
panel3.add(label3, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
textField1 = new JTextField();
panel3.add(textField1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
comboBox1 = new JComboBox();
final DefaultComboBoxModel defaultComboBoxModel1 = new DefaultComboBoxModel();
defaultComboBoxModel1.addElement("3 months");
defaultComboBoxModel1.addElement("6 months");
defaultComboBoxModel1.addElement("1 year");
defaultComboBoxModel1.addElement("3 years");
comboBox1.setModel(defaultComboBoxModel1);
panel3.add(comboBox1, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
panel3.add(label3, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
passwordField1 = new JPasswordField();
panel3.add(passwordField1, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
panel3.add(passwordField1, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
amountField = new JTextField();
panel3.add(amountField, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
rateLabel = new JLabel();
rateLabel.setText("Deposit rate");
panel3.add(rateLabel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
rateField = new JTextField();
panel3.add(rateField, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
monthField = new JTextField();
panel3.add(monthField, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
}

/**
Expand All @@ -141,4 +208,5 @@ public void init() {
public JComponent $$$getRootComponent$$$() {
return contentPane;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
<properties/>
<border type="none" title="Fixed Balance"/>
<children>
<component id="d5387" class="javax.swing.JLabel">
<component id="d5387" class="javax.swing.JLabel" binding="totalLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="$114514"/>
<text value="$114514--"/>
</properties>
</component>
</children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.seg83.childbank.gui.event.PanelSwitchEvent;
import com.seg83.childbank.service.DepositService;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
Expand All @@ -22,39 +24,36 @@
@Slf4j

public class FixedAccountPanel {
@Autowired
DepositService depositService;

@Autowired
private ApplicationEventPublisher publisher;

private JPanel panel1;
private JButton backButton;
private JTable table1;
private JLabel totalLabel;


public FixedAccountPanel() {
$$$setupUI$$$();
createTable();
// $$$setupUI$$$();
backButton.addActionListener(e -> {
log.info("Back Home button clicked");
publisher.publishEvent(new PanelSwitchEvent(this, "home"));
});
}

private void createTable() {
@PostConstruct
public void init() {
setTotalFixedLabel();
}

public void createTable() {
// TODO: use actual data
// Object[][] data = historyService.generateHistoryList();
Object[][] data = new Object[][]{
{1, "2021-12-31", 0.03, 1000},
{2, "2022-12-31", 0.03, 2000},
{3, "2023-12-31", 0.03, 3000},
{4, "2024-12-31", 0.03, 4000},
{5, "2025-12-31", 0.03, 5000},
{6, "2026-12-31", 0.03, 6000},
{7, "2027-12-31", 0.03, 7000},
{8, "2028-12-31", 0.03, 8000},
{9, "2029-12-31", 0.03, 9000},
{10, "2030-12-31", 0.03, 10000},
};

String[] columnNames = {"Id", "ExpireTime", "Rate", "Amount"};
Object[][] data = depositService.generateDepositList();


String[] columnNames = {"Id", "Amount", "Rate", "Effective Date", "Expire Date"};

table1.setModel(new DefaultTableModel(data, columnNames));
table1.setFillsViewportHeight(true);
Expand All @@ -67,9 +66,22 @@ private void createTable() {
// 设置列宽
TableColumnModel columnModel = table1.getColumnModel();
columnModel.getColumn(0).setPreferredWidth(25); // ID 列
columnModel.getColumn(1).setPreferredWidth(200); // DateTime 列
columnModel.getColumn(2).setPreferredWidth(80); // Type 列
columnModel.getColumn(3).setPreferredWidth(80); // Amount 列
columnModel.getColumn(1).setPreferredWidth(80); // Amount 列
columnModel.getColumn(2).setPreferredWidth(80); // Rate 列
columnModel.getColumn(3).setPreferredWidth(200); // Effective Date 列
columnModel.getColumn(4).setPreferredWidth(200); // Expire Date 列
}


public void setTotalFixedLabel() {
totalLabel.setText(String.valueOf(depositService.calculateTotalDeposits()));
}

{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}

/**
Expand All @@ -90,9 +102,9 @@ private void createTable() {
panel3.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
panel2.add(panel3, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
panel3.setBorder(BorderFactory.createTitledBorder(null, "Fixed Balance", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
final JLabel label1 = new JLabel();
label1.setText("$114514");
panel3.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
totalLabel = new JLabel();
totalLabel.setText("$114514--");
panel3.add(totalLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
final JPanel panel4 = new JPanel();
panel4.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
panel2.add(panel4, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<properties/>
<border type="none" title="Fixed Balance"/>
<children>
<component id="7ef9c" class="javax.swing.JLabel">
<component id="7ef9c" class="javax.swing.JLabel" binding="fixedLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
Expand Down
Loading
Loading