📄 currentinfopanel.java
字号:
/**
* @author lulicheng
* @version 1.0
*
*/
package view.panel.exchange;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import view.common.CheckInputUtil;
import view.common.GBC;
import view.frame.MainFrame;
import vo.DutyExchangeVo;
import vo.OperatorVo;
import control.exchange.CurrentInfoPanelListener;
import dao.exchange.DutyExchangeDao;
import dao.exchange.impl.DutyExchangeDaoImpl;
public class CurrentInfoPanel extends JPanel {
// =====面板分割成三个字面板 顶部面板,交班面板,按钮面板=====
JPanel topPanel, exchangePanel, buttonPanel;
// -----topPanel-----
// 上次交班时间字符串,当前交班信息字符串
String curLastDateString, curCurrentDateString;
// 当前交班综合信息,值班时间,lastDateString + "至" + currentDateString
JLabel panelTitle, dutyPeriod, detailedTime;
// -----exchangePanel-----
// 值班收入信息表,换班信息表
JPanel dutyInfoPanel, exchangeInfoPanel;
// 前班结余,现金收入,会员卡收入,营业总额,上交营业额,下拨营业额,当前结余,交班员工
JLabel lastBalance, cashIncome, cardIncome, totalIncome, upTurnover,
downTurnover, currentBalance, operatorOff, operatorOn,
operatorOnId, operatorOnPsw;
// 前班结余文本框,现金收入文本框,会员卡收入文本框,营业总额文本框,
// 上交营业额文本框,下拨营业额文本框,当前结余文本框,交班员工文本框
JTextField lastBalanceField, cashIncomeField, cardIncomeField,
totalIncomeField, upTurnoverField, downTurnoverField,
currentBalanceField, operatorOffField, operatorOnField,
operatorOnIdField;
JPasswordField operatorOnPswField = new JPasswordField(10);
// -----buttonPanel-----
// 按钮打印交班记录,确定交班,取消交班
JButton buttonPrint, buttonOk, buttonCancel;
// 用于外界交互的属性
JDialog matherDioalg;
/**
* 构造函数,初始化组件,并且添加子面板
*/
public CurrentInfoPanel(JDialog dialog) {
this.matherDioalg = dialog;
this.setSize(630, 440);
// this.setBackground(Color.GRAY);
this.setLayout(new BorderLayout());
DutyExchangeDao dao = new DutyExchangeDaoImpl();
initComponent(dao.getCurrentExchangeInfo());
this.add(buildTopPanel(), BorderLayout.NORTH);
this.add(buildExchangePanel());
this.add(buildButtonPanel(dialog), BorderLayout.SOUTH);
}
public JPanel buildTopPanel() {
if (topPanel == null) {
topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
JPanel titlePanel = new JPanel();
titlePanel.add(panelTitle);
JPanel timePanel = new JPanel();
timePanel.setLayout(new FlowLayout());
timePanel.add(dutyPeriod);
timePanel.add(detailedTime);
topPanel.add(titlePanel, BorderLayout.CENTER);
topPanel.add(timePanel, BorderLayout.SOUTH);
}
return topPanel;
}
/**
* 将已经初始化的标签,文本输入框,文本域添加到信息面板,并且设置布局
*
* @return JPanel
*/
public JPanel buildExchangePanel() {
if (exchangePanel == null) {
exchangePanel = new JPanel();
exchangePanel.setBorder(BorderFactory.createTitledBorder("交班信息"));
exchangePanel.setLayout(new BorderLayout());
exchangePanel.add(buildDutyInfoPanel());
exchangePanel.add(buildExchangeInfoPanel(), BorderLayout.SOUTH);
}
return exchangePanel;
}
/**
* 构造dutyInfoPanel,并且添加组件,设置布局
*
* @return JPanel dutyInfoPanel
*/
public JPanel buildDutyInfoPanel() {
if (dutyInfoPanel == null) {
dutyInfoPanel = new JPanel();
dutyInfoPanel.setLayout(new GridBagLayout());
dutyInfoPanel.setBorder(BorderFactory.createTitledBorder("值班收入信息"));
dutyInfoPanel.add(lastBalance, new GBC(0, 0).setInset(5, 15, 5, 15)
.setFill(GBC.WEST));
dutyInfoPanel.add(lastBalanceField, new GBC(1, 0).setInset(5, 15,
5, 15).setWeight(20, 0).setFill(GBC.HORIZONTAL));
dutyInfoPanel.add(cashIncome, new GBC(0, 1).setInset(5, 15, 5, 15)
.setFill(GBC.WEST));
dutyInfoPanel.add(cashIncomeField, new GBC(1, 1).setInset(5, 15, 5,
15).setWeight(5, 0).setFill(GBC.HORIZONTAL));
dutyInfoPanel.add(cardIncome, new GBC(0, 2).setInset(5, 15, 5, 15)
.setFill(GBC.WEST));
dutyInfoPanel.add(cardIncomeField, new GBC(1, 2).setInset(5, 15, 5,
15).setWeight(5, 0).setFill(GBC.HORIZONTAL));
dutyInfoPanel.add(totalIncome, new GBC(0, 3).setInset(5, 15, 5, 15)
.setFill(GBC.WEST));
dutyInfoPanel.add(totalIncomeField, new GBC(1, 3).setInset(5, 15,
5, 15).setWeight(5, 0).setFill(GBC.HORIZONTAL));
dutyInfoPanel.add(upTurnover, new GBC(2, 0).setInset(5, 15, 5, 15)
.setFill(GBC.WEST));
dutyInfoPanel.add(upTurnoverField, new GBC(3, 0).setInset(5, 15, 5,
15).setWeight(5, 0).setFill(GBC.HORIZONTAL));
dutyInfoPanel.add(downTurnover, new GBC(2, 1)
.setInset(5, 15, 5, 15).setFill(GBC.WEST));
dutyInfoPanel.add(downTurnoverField, new GBC(3, 1).setInset(5, 15,
5, 15).setWeight(5, 0).setFill(GBC.HORIZONTAL));
dutyInfoPanel.add(currentBalance, new GBC(2, 3).setInset(5, 15, 5,
15).setFill(GBC.WEST));
dutyInfoPanel.add(currentBalanceField, new GBC(3, 3).setInset(5,
15, 5, 15).setWeight(5, 0).setFill(GBC.HORIZONTAL));
}
return dutyInfoPanel;
}
/**
* 交班信息表,交班员工,接班员工,交班员工密码
*
* @return JPanel exchangeInfoPanel
*/
public JPanel buildExchangeInfoPanel() {
if (exchangeInfoPanel == null) {
exchangeInfoPanel = new JPanel();
exchangeInfoPanel.setBorder(BorderFactory
.createTitledBorder("换班登陆信息"));
exchangeInfoPanel.setLayout(new GridBagLayout());
exchangeInfoPanel.add(operatorOff, new GBC(0, 0).setInset(5, 15, 5,
15).setFill(GBC.WEST));
exchangeInfoPanel.add(operatorOffField, new GBC(1, 0).setInset(5,
15, 5, 15).setWeight(20, 0).setFill(GBC.HORIZONTAL));
exchangeInfoPanel.add(operatorOn, new GBC(2, 0).setInset(5, 15, 5,
15).setFill(GBC.WEST));
exchangeInfoPanel.add(operatorOnField, new GBC(3, 0).setInset(5,
15, 5, 15).setWeight(5, 0).setFill(GBC.HORIZONTAL));
exchangeInfoPanel.add(operatorOnId, new GBC(0, 1).setInset(5, 15,
5, 15).setFill(GBC.WEST));
exchangeInfoPanel.add(operatorOnIdField, new GBC(1, 1).setInset(5,
15, 5, 15).setWeight(5, 0).setFill(GBC.HORIZONTAL));
exchangeInfoPanel.add(operatorOnPsw, new GBC(2, 1).setInset(5, 15,
5, 15).setFill(GBC.WEST));
exchangeInfoPanel.add(operatorOnPswField, new GBC(3, 1).setInset(5,
15, 5, 15).setWeight(5, 0).setFill(GBC.HORIZONTAL));
}
return exchangeInfoPanel;
}
/**
* 构造按钮面板(buttonPanel),并且设置布局
*
* @return JPanel
*/
public JPanel buildButtonPanel(JDialog dialog) {
if (buttonPanel == null) {
buttonPanel = new JPanel();
buttonPanel.add(buildButton("打印交班信息"));
buttonPanel.add(buildButton("确定交班"));
buttonPanel.add(buildButton("取消", dialog));
}
return buttonPanel;
}
/**
* 调用该函数一次,就将构造一个通过参数命名的JButton
*
* @param name
* name of a button
* @return JButton button named 'name'
*/
public JButton buildButton(String name) {
JButton button = new JButton(name);
button.addActionListener(new CurrentInfoPanelListener(this));
return button;
}
/**
* 调用该函数一次,就将构造一个通过参数命名,且需要对上级Dialog进行操作的的JButton
*
* @param name
* name of a button
* @return JButton button named 'name'
*/
public JButton buildButton(String name, JDialog dialog) {
JButton button = new JButton(name);
button.addActionListener(new CurrentInfoPanelListener(this, dialog));
return button;
}
/*
* 初始化无需添加事件处理的组件,包括文本标签,文本输入框
*/
public void initComponent(DutyExchangeVo value) {
initJLabel(value);
initJTextField(value);
}
/**
* 初始化面板中标签属性
*/
public void initJLabel(DutyExchangeVo value) {
panelTitle = new JLabel("当前交班综合信息");
// panelTitle.setFont(new Font(Font.SERIF, Font.PLAIN, 32));
dutyPeriod = new JLabel("值班时间:");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy'-'MM'-'dd HH':'mm");
curLastDateString = value.getPresentTime().substring(0, 16);
curCurrentDateString = sdf.format(new Date());
detailedTime = new JLabel(curLastDateString + " 至 "
+ curCurrentDateString);
lastBalance = new JLabel("前班结余");
cashIncome = new JLabel("现金收入");
cardIncome = new JLabel("会员卡收入");
totalIncome = new JLabel("营业总额");
upTurnover = new JLabel("上交营业额");
downTurnover = new JLabel("下拨营业额");
currentBalance = new JLabel("当前结余");
operatorOff = new JLabel("交班员工");
operatorOn = new JLabel("接班员工");
operatorOnId = new JLabel("接班员工编号");
operatorOnPsw = new JLabel("员工登陆密码");
}
/**
* 初始化文本框,并且给予初始化大小
*/
public void initJTextField(DutyExchangeVo value) {
lastBalanceField = new JTextField(10);
cashIncomeField = new JTextField(10);
cardIncomeField = new JTextField(10);
totalIncomeField = new JTextField(10);
upTurnoverField = new JTextField(10);
downTurnoverField = new JTextField(10);
currentBalanceField = new JTextField(10);
operatorOffField = new JTextField(10);
operatorOnField = new JTextField(10);
operatorOnIdField = new JTextField(10);
lastBalanceField.setText(String.valueOf(value.getLastBalance()));
cashIncomeField.setText(String.valueOf(value.getIncomeCash()));
cardIncomeField.setText(String.valueOf(value.getIncomeCard()));
totalIncomeField.setText(String.valueOf(value.getTatalIncome()));
currentBalanceField.setText(String.valueOf(value.getTatalIncome()
+ value.getLastBalance()));
operatorOffField.setText(MainFrame.getOperatorName());
lastBalanceField.setEditable(false);
cashIncomeField.setEditable(false);
cardIncomeField.setEditable(false);
totalIncomeField.setEditable(false);
currentBalanceField.setEditable(false);
operatorOffField.setEditable(false);
upTurnoverField.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
try {
double lastBala = Double.parseDouble(lastBalanceField
.getText());
double totalInco = Double.parseDouble(totalIncomeField
.getText());
double upTurn = (upTurnoverField.getText() == null ? 0
: (Double.parseDouble(upTurnoverField.getText())));
double downTurn = (downTurnoverField.getText() == null ? 0
: Double.parseDouble(downTurnoverField.getText()));
currentBalanceField.setText(String.valueOf(lastBala
+ totalInco + downTurn - upTurn));
} catch (NumberFormatException e1) {
}
}
});
downTurnoverField.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e) {
try {
double lastBala = Double.parseDouble(lastBalanceField
.getText());
double totalInco = Double.parseDouble(totalIncomeField
.getText());
double upTurn = (upTurnoverField.getText() == null ? 0
: (Double.parseDouble(upTurnoverField.getText())));
double downTurn = (downTurnoverField.getText() == null ? 0
: Double.parseDouble(downTurnoverField.getText()));
currentBalanceField.setText(String.valueOf(lastBala
+ totalInco + downTurn - upTurn));
} catch (NumberFormatException e1) {
}
}
});
}
// 获得当前窗口的输入值,并将它封装在一个Vo中,传递给Dao
public DutyExchangeVo getInputTxtValue() {
double lastBalance = Double.parseDouble(lastBalanceField.getText());
double incomeCash = Double.parseDouble(cashIncomeField.getText());
double incomeCard = Double.parseDouble(cardIncomeField.getText());
double tatalIncome = Double.parseDouble(totalIncomeField.getText());
double turnoverUp = (upTurnoverField.getText().equals("") ? 0 : Double
.parseDouble(upTurnoverField.getText()));
double turnoverDown = (downTurnoverField.getText().equals("") ? 0
: Double.parseDouble(downTurnoverField.getText()));
double currentBalance = tatalIncome + turnoverDown - turnoverUp;
String recLastDateString = curLastDateString.substring(0, 10);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy'-'MM'-'dd");
String recCurrentDateString = sdf.format(new Date());
String operatorOff = operatorOffField.getText();
String operatorOn = operatorOnField.getText();
return new DutyExchangeVo(lastBalance, incomeCash, incomeCard,
tatalIncome, turnoverUp, turnoverDown, currentBalance,
recLastDateString, recCurrentDateString, operatorOff,
operatorOn);
}
/**
* 检查该面板输入的信息是否符合条件,包括编号不含字符,必备条件非空,密码和密码确认匹配
*
* @return
*/
public boolean checkInput() {
if (CheckInputUtil.checkInputIsNull(operatorOffField.getText())) {
JOptionPane.showMessageDialog(null, "交班员工不能为空", "提示信息",
JOptionPane.YES_OPTION);
operatorOffField.requestFocus();
return false;
}
if (CheckInputUtil.checkInputIsNull(operatorOnField.getText())) {
JOptionPane.showMessageDialog(null, "接班员工不能为空", "提示信息",
JOptionPane.YES_OPTION);
operatorOnField.requestFocus();
return false;
}
if (Double.parseDouble(currentBalanceField.getText()) <= 0) {
JOptionPane.showMessageDialog(null, "当前结余不能小于或等于0,请检查上交和下拨的营业额",
"提示信息", JOptionPane.YES_OPTION);
upTurnoverField.requestFocus();
return false;
}
if (CheckInputUtil.checkInputIsNull(String.valueOf(operatorOnPswField
.getPassword()))) {
JOptionPane.showMessageDialog(null, "请输入登陆密码(小于16位)", "提示信息",
JOptionPane.YES_OPTION);
operatorOnPswField.requestFocus();
return false;
}
return true;
}
/**
* 获得登陆员工的信息,并且传递给时间处理,注册
*/
public OperatorVo getOperatorOn() {
int operatorId = Integer.parseInt(operatorOnIdField.getText().trim());
String operatorPsw = String.valueOf(operatorOnPswField.getPassword());
String operatorName = operatorOnField.getText();
return new OperatorVo(operatorId, operatorName, operatorPsw);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -