📄 tipwizardframe.java
字号:
values[1] = leftTable.getValueAt(i, 2)
.toString();// 获得商品编号
values[2] = leftTable.getValueAt(i, 5)
.toString();// 获得商品数量
values[3] = leftTable.getValueAt(i, 7)
.toString();// 获得商品消费金额
dao.iOrderItem(values);// 持久化到数据库
}
JOptionPane.showMessageDialog(null, rightTable
.getValueAt(selectedRow, 1)
+ " 结账完成!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);// 弹出结账完成提示
rightTableModel.removeRow(selectedRow);// 从“开台列表”中取消开台
leftTableValueV.removeAllElements();// 清空“签单列表”
leftTableModel.setDataVector(leftTableValueV,
leftTableColumnV);// 刷新“签单列表”
realWagesTextField.setText("0.00");// 清空“实收金额”文本框
changeTextField.setText("0.00");// 清空“找零金额”文本框
menuOfDeskV.remove(selectedRow);// 从“签单列表”集合中移除已结账的签单列表
}
}
}
}
});
checkOutButton.setMargin(new Insets(2, 14, 2, 14));
checkOutButton.setText("结 账");
final GridBagConstraints gridBagConstraints_10 = new GridBagConstraints();
gridBagConstraints_10.anchor = GridBagConstraints.EAST;
gridBagConstraints_10.gridwidth = 2;
gridBagConstraints_10.insets = new Insets(10, 0, 0, 0);
gridBagConstraints_10.gridy = 2;
gridBagConstraints_10.gridx = 2;
checkOutPanel.add(checkOutButton, gridBagConstraints_10);
final JLabel changeLabel = new JLabel();
changeLabel.setFont(new Font("", Font.BOLD, 16));
changeLabel.setText("找零金额:");
final GridBagConstraints gridBagConstraints_11 = new GridBagConstraints();
gridBagConstraints_11.insets = new Insets(10, 10, 0, 0);
gridBagConstraints_11.gridy = 3;
gridBagConstraints_11.gridx = 1;
checkOutPanel.add(changeLabel, gridBagConstraints_11);
changeTextField = new JTextField();
changeTextField.setHorizontalAlignment(SwingConstants.RIGHT);
changeTextField.setText("0.00");
changeTextField.setForeground(new Color(255, 0, 255));
changeTextField.setFont(new Font("", Font.BOLD, 15));
changeTextField.setEditable(false);
changeTextField.setColumns(7);
final GridBagConstraints gridBagConstraints_12 = new GridBagConstraints();
gridBagConstraints_12.insets = new Insets(10, 0, 0, 0);
gridBagConstraints_12.gridy = 3;
gridBagConstraints_12.gridx = 2;
checkOutPanel.add(changeTextField, gridBagConstraints_12);
final JLabel changeUnitLabel = new JLabel();
changeUnitLabel.setForeground(new Color(255, 0, 255));
changeUnitLabel.setFont(new Font("", Font.BOLD, 15));
changeUnitLabel.setText(" 元");
final GridBagConstraints gridBagConstraints_16 = new GridBagConstraints();
gridBagConstraints_16.insets = new Insets(10, 0, 0, 0);
gridBagConstraints_16.gridy = 3;
gridBagConstraints_16.gridx = 3;
checkOutPanel.add(changeUnitLabel, gridBagConstraints_16);
final JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1, 0));
bottomPanel.add(buttonPanel, BorderLayout.EAST);
final JPanel aButtonPanel = new JPanel();
aButtonPanel.setBorder(new TitledBorder(null, "",
TitledBorder.DEFAULT_JUSTIFICATION,
TitledBorder.DEFAULT_POSITION, null, null));
aButtonPanel.setLayout(new GridLayout(0, 1));
buttonPanel.add(aButtonPanel);
final JButton aTopButton = new MButton();
aTopButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
MenuDialog menuDialog = new MenuDialog();
menuDialog.setLocation((screenSize.width - menuDialog
.getWidth()) / 2, (screenSize.height - menuDialog
.getHeight()) / 2);
menuDialog.setVisible(true);
}
});
URL menuUrl = this.getClass().getResource("/img/menu.jpg");
ImageIcon menuIcon = new ImageIcon(menuUrl);
aTopButton.setIcon(menuIcon);
aButtonPanel.add(aTopButton);
final JButton aCenterButton = new MButton();
aCenterButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
SortDialog sortDialog = new SortDialog();
sortDialog.setLocation((screenSize.width - sortDialog
.getWidth()) / 2, (screenSize.height - sortDialog
.getHeight()) / 2);
sortDialog.setVisible(true);
}
});
URL sortUrl = this.getClass().getResource("/img/sort.jpg");
ImageIcon sortIcon = new ImageIcon(sortUrl);
aCenterButton.setIcon(sortIcon);
aButtonPanel.add(aCenterButton);
final JButton aBottomButton = new MButton();
aBottomButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
DeskNumDialog deskNumDialog = new DeskNumDialog(rightTable);
deskNumDialog.setLocation((screenSize.width - deskNumDialog
.getWidth()) / 2, (screenSize.height - deskNumDialog
.getHeight()) / 2);
deskNumDialog.setVisible(true);
initNumComboBox();
}
});
URL deskUrl = this.getClass().getResource("/img/desk.jpg");
ImageIcon deskIcon = new ImageIcon(deskUrl);
aBottomButton.setIcon(deskIcon);
aButtonPanel.add(aBottomButton);
final JPanel dButtonPanel = new JPanel();
dButtonPanel.setPreferredSize(new Dimension(0, 0));
dButtonPanel.setBorder(new TitledBorder(null, "",
TitledBorder.DEFAULT_JUSTIFICATION,
TitledBorder.DEFAULT_POSITION, null, null));
dButtonPanel.setLayout(new GridLayout(0, 1));
buttonPanel.add(dButtonPanel);
final JButton dTopButton = new MButton();
dTopButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DayDialog dayDialog = new DayDialog();
dayDialog.setVisible(true);
}
});
URL dayUrl = this.getClass().getResource("/img/day.png");
ImageIcon dayIcon = new ImageIcon(dayUrl);
dTopButton.setIcon(dayIcon);
dButtonPanel.add(dTopButton);
final JButton dCenterButton = new MButton();
dCenterButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MonthDialog monthDialog = new MonthDialog();
monthDialog.setVisible(true);
}
});
URL monthUrl = this.getClass().getResource("/img/month.png");
ImageIcon monthIcon = new ImageIcon(monthUrl);
dCenterButton.setIcon(monthIcon);
dButtonPanel.add(dCenterButton);
final JButton dBottomButton = new MButton();
dBottomButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
YearDialog yearDialog = new YearDialog();
yearDialog.setVisible(true);
}
});
URL yearUrl = this.getClass().getResource("/img/year.png");
ImageIcon yearIcon = new ImageIcon(yearUrl);
dBottomButton.setIcon(yearIcon);
dButtonPanel.add(dBottomButton);
final JPanel cButtonPanel = new JPanel();
cButtonPanel.setBorder(new TitledBorder(null, "",
TitledBorder.DEFAULT_JUSTIFICATION,
TitledBorder.DEFAULT_POSITION, null, null));
cButtonPanel.setLayout(new GridLayout(0, 1));
buttonPanel.add(cButtonPanel);
final JButton cTopButton = new MButton();
cTopButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
UpdatePasswordDialog upDialog = new UpdatePasswordDialog();
upDialog.setLocation(
(screenSize.width - upDialog.getWidth()) / 2,
(screenSize.height - upDialog.getHeight()) / 2);
upDialog.setUser(user);
upDialog.setVisible(true);
}
});
URL passwordUrl = this.getClass().getResource("/img/password.jpg");
ImageIcon passwordIcon = new ImageIcon(passwordUrl);
cTopButton.setIcon(passwordIcon);
cButtonPanel.add(cTopButton);
final JButton cCenterButton = new MButton();
cCenterButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
UserManagerDialog umDialog = new UserManagerDialog();
umDialog.setLocation(
(screenSize.width - umDialog.getWidth()) / 2,
(screenSize.height - umDialog.getHeight()) / 2);
umDialog.setVisible(true);
}
});
URL userUrl = this.getClass().getResource("/img/user.jpg");
ImageIcon userIcon = new ImageIcon(userUrl);
cCenterButton.setIcon(userIcon);
cButtonPanel.add(cCenterButton);
final JButton cBottomButton = new MButton();
cBottomButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
URL exitUrl = this.getClass().getResource("/img/exit.jpg");
ImageIcon exitIcon = new ImageIcon(exitUrl);
cBottomButton.setIcon(exitIcon);
cButtonPanel.add(cBottomButton);
if (user == null) {
numComboBox.setEnabled(false);
numRadioButton.setEnabled(false);
codeRadioButton.setEnabled(false);
codeTextField.setEnabled(false);
amountTextField.setEnabled(false);
addButton.setEnabled(false);
subButton.setEnabled(false);
delButton.setEnabled(false);
realWagesTextField.setEnabled(false);
checkOutButton.setEnabled(false);
aTopButton.setEnabled(false);
aCenterButton.setEnabled(false);
aBottomButton.setEnabled(false);
cTopButton.setEnabled(false);
dTopButton.setEnabled(false);
dCenterButton.setEnabled(false);
dBottomButton.setEnabled(false);
}
}
private void makeOutAnInvoice() {
String deskNum = numComboBox.getSelectedItem().toString();// 获得台号
String menuName = nameTextField.getText();// 获得商品名称
String menuAmount = amountTextField.getText();// 获得数量
// 验证
if (deskNum.equals("请选择")) {// 验证是否已经选择台号
JOptionPane.showMessageDialog(null, "请选择台号!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (menuName.length() == 0) {// 验证是否已经确定商品
JOptionPane.showMessageDialog(null, "请录入商品名称!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
if (!Validate.execute("[1-9]{1}([0-9]{0,1})", menuAmount)) {// 验证数量是否有效,数量必须在1-99之间
String info[] = new String[] { "您输入的数量错误!", "数量必须在1-99之间!" };
JOptionPane.showMessageDialog(null, info, "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
// 处理开台信息
int rightSelectedRow = rightTable.getSelectedRow();// 获得被选中的台号
int leftRowCount = 0;// 默认点菜数量为0
if (rightSelectedRow == -1) {// 没有被选中的台号,即新开台
rightSelectedRow = rightTable.getRowCount();// 被选中的台号为新开的台
Vector deskV = new Vector();// 创建一个代表新开台的向量对象
deskV.add(rightSelectedRow + 1);// 添加开台序号
deskV.add(deskNum);// 添加开台号
deskV.add(Today.getTime());// 添加开台时间
rightTableModel.addRow(deskV);// 将开台信息添加到“开台列表”中
rightTable.setRowSelectionInterval(rightSelectedRow);// 选中新开的台
menuOfDeskV.add(new Vector());// 添加一个对应的签单列表
} else { // 选中的台号已经开台,即添加菜品
leftRowCount = leftTable.getRowCount();// 获得已点菜的数量
}
// 处理点菜信息
Vector vector = dao.sMenuByNameAndState(menuName, "销售");// 获得被点菜品
int amount = Integer.valueOf(menuAmount);// 将菜品数量转为int型
int unitPrice = Integer.valueOf(vector.get(5).toString()); // 将菜品单价转为int型
int money = unitPrice * amount;// 计算菜品消费额
Vector<Object> menuV = new Vector<Object>();
menuV.add("NEW");// 添加新点菜标记
menuV.add(leftRowCount + 1);// 添加点菜序号
menuV.add(vector.get(0));// 添加菜品编号
menuV.add(menuName);// 添加菜品名称
menuV.add(vector.get(4));// 添加菜品单位
menuV.add(amount);// 添加菜品数量
menuV.add(unitPrice);// 添加菜品单价
menuV.add(money);// 添加菜品消费额
leftTableModel.addRow(menuV);// 将点菜信息添加到“签单列表”中
leftTable.setRowSelectionInterval(leftRowCount);// 将新点菜设置为选中行
menuOfDeskV.get(rightSelectedRow).add(menuV);// 将新点菜信息添加到对应的签单列表
//
codeTextField.setText(null);
nameTextField.setText(null);
unitTextField.setText(null);
amountTextField.setText("1");
}
private String getNum() {
String maxNum = dao.sOrderFormOfMaxId();
String date = Today.getDateOfNum();
if (maxNum == null) {
maxNum = date + "001";
} else {
if (maxNum.subSequence(0, 8).equals(date)) {
maxNum = maxNum.substring(8);
int nextNum = Integer.valueOf(maxNum) + 1;
if (nextNum < 10)
maxNum = date + "00" + nextNum;
else if (nextNum < 100)
maxNum = date + "0" + nextNum;
else
maxNum = date + nextNum;
} else {
maxNum = date + "001";
}
}
return maxNum;
}
private void initNumComboBox() {
numComboBox.removeAllItems();
numComboBox.addItem("请选择");
Vector allSortV = dao.sDesk();
for (int i = 0; i < allSortV.size(); i++) {
Vector sortV = (Vector) allSortV.get(i);
numComboBox.addItem(sortV.get(1));
}
}
private void a(JLabel dClueOnLabel) {
Calendar now;
int hour;
int minute;
int second;
while (true) {
now = Calendar.getInstance();
hour = now.get(Calendar.HOUR_OF_DAY);
minute = now.get(Calendar.MINUTE);
second = now.get(Calendar.SECOND);
dClueOnLabel.setText(hour + ":" + minute + ":" + second);
}
}
class Time extends Thread {// 创建内部类
public void run() {// 重构父类的方法
while (true) {
Date date = new Date();// 创建日期对象
timeLabel.setText(date.toString().substring(11, 19));// 获取当前时间,并显示到时间标签中
try {
Thread.sleep(1000);// 令线程休眠1秒
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -