?? checkout不帶線程.java
字號:
package com.sunshine.checkout;
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import com.sunshine.sunsdk.sql.*; //公共類
import com.sunshine.sunsdk.swing.*;
import com.sunshine.sunsdk.system.*;
import com.sunshine.mainframe.*; //主框架窗口
public class CheckOut
extends JDialog
implements ActionListener, MouseListener {
public JLabel lbA, lbB, lbC, lbD, lbE, lbF, lbG, lbH;
//賬單號,房間,姓名,金額,應(yīng)收,押金,優(yōu)惠,找零
public DefaultTableModel dtm;
public JTable tb;
public JTextField tf1, tf2, tf3, tf;
//實收,支付,備注
private JButton bt1, bt2;
//結(jié)賬,取消
private JScrollPane sp;
private JPanel panelMain,p1,p2;
public String inNo = ""; //入住單號
//構(gòu)造函數(shù)
public CheckOut(JFrame frame) {
super (frame, "收銀結(jié)賬", true);
panelMain = new JPanel(new GridLayout(2, 1, 0, 0)); //主面板為(2,1)表格布局
p1 = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));//上半部分為(4,1)表格布局
p2 = new JPanel(new BorderLayout(15, 0)); //下半部分為邊界布局
buildP1();//構(gòu)造上半面板
buildP2();//構(gòu)造下半面板
panelMain.add(p1);
panelMain.add(p2);
addListener();
this.setContentPane(panelMain);
this.setPreferredSize (new Dimension(640, 450));
this.setMinimumSize (new Dimension(640, 450));
this.setResizable(false); //不允許改變窗口大小
pack();
sunswing.setWindowCenter(this); //窗口屏幕居中
}
//加事件監(jiān)聽
private void addListener() {
tf1.addActionListener(this);
tf2.addActionListener(this);
tf3.addActionListener(this);
bt1.addActionListener(this);
bt2.addActionListener(this);
bt1.addMouseListener(this);
bt2.addMouseListener(this);
}
//構(gòu)造上半面板
private void buildP1() {
JPanel p11,p111,p112,p113,
p12,p121,p122,p123,p124,
p13,p131,p132,p133,
p14,p141,p142,p15;
JLabel lb1,lb2,lb3,lb4,lb5,lb6,lb7,lb8,lb9,lb10,lb11;
p11 = new JPanel(new FlowLayout(FlowLayout.LEFT,5,3)); //放置結(jié)賬單號...一行
p111 = new JPanel(new FlowLayout(FlowLayout.LEFT,0,3)); //放置結(jié)賬單號
p112 = new JPanel(new FlowLayout(FlowLayout.LEFT,0,3)); //放置結(jié)賬房間
p113 = new JPanel(new FlowLayout(FlowLayout.LEFT,0,3)); //放置賓客姓名
p12 = new JPanel(new FlowLayout(FlowLayout.LEFT,10,3));//放置應(yīng)收金額...一行
p121 = new JPanel(new FlowLayout(FlowLayout.LEFT,0,3)); //放置應(yīng)收金額
p122 = new JPanel(new FlowLayout(FlowLayout.LEFT,0,3)); //放置已收押金
p123 = new JPanel(new FlowLayout(FlowLayout.LEFT,0,3)); //放置優(yōu)惠金額
p124 = new JPanel(new FlowLayout(FlowLayout.LEFT,0,3)); //放置消費金額
p13 = new JPanel(new FlowLayout(FlowLayout.LEFT,10,3));//放置實收金額...一行
p131 = new JPanel(new FlowLayout(FlowLayout.LEFT,0,3)); //放置實收金額
p132 = new JPanel(new FlowLayout(FlowLayout.LEFT,0,3)); //放置賓客支付
p133 = new JPanel(new FlowLayout(FlowLayout.LEFT,0,3)); //放置找零
p14 = new JPanel(new FlowLayout(FlowLayout.LEFT,10,3));//放置結(jié)賬備注...一行
p141 = new JPanel(new FlowLayout(FlowLayout.LEFT,0,3)); //放置結(jié)賬備注
p142 = new JPanel(new FlowLayout(FlowLayout.LEFT,33,3)); //放置按鈕
p15 = new JPanel(new GridLayout(3,1,0,5));
lb1 = new JLabel("結(jié)賬單號:");
lb2 = new JLabel(" 結(jié)賬房間:");
lb3 = new JLabel(" 賓客姓名:");
lb4 = new JLabel("消費金額:");
lb5 = new JLabel(" 應(yīng)收金額:");
lb6 = new JLabel(" 已收押金:");
lb7 = new JLabel(" 優(yōu)惠金額:");
lb8 = new JLabel("實收金額:");
lb9 = new JLabel(" 賓客支付:");
lb10 = new JLabel(" 找 零:");
lb11 = new JLabel("結(jié)賬備注:");
lb1.setFont(new Font("宋體",Font.BOLD,15));
lb2.setFont(new Font("宋體",Font.BOLD,15));
lb3.setFont(new Font("宋體",Font.BOLD,15));
lb4.setFont(new Font("宋體",Font.BOLD,15));
lb5.setFont(new Font("宋體",Font.BOLD,15));
lb6.setFont(new Font("宋體",Font.BOLD,15));
lb7.setFont(new Font("宋體",Font.BOLD,15));
lb10.setFont(new Font("宋體",Font.BOLD,15));
lb4.setForeground(Color.blue);
lb5.setForeground(Color.blue);
lb6.setForeground(Color.blue);
lb7.setForeground(Color.blue);
lb10.setForeground(Color.blue);
////////////////////////////////////////////////////////////////////////
lbA = new JLabel("ZD200604210001");
lbB = new JLabel("BD001");
lbC = new JLabel("你好嗎");
lbD = new JLabel("500.00");
lbE = new JLabel("450.00");
lbF = new JLabel("300.00");
lbG = new JLabel("50.00");
lbH = new JLabel("¥0.00");
////////////////////////////////////////////////////////////////////////
lbA.setFont(new Font("宋體",Font.BOLD,15));
lbB.setFont(new Font("宋體",Font.BOLD,15));
lbC.setFont(new Font("宋體",Font.BOLD,15));
lbD.setFont(new Font("宋體",Font.BOLD,15));
lbE.setFont(new Font("宋體",Font.BOLD,15));
lbF.setFont(new Font("宋體",Font.BOLD,15));
lbG.setFont(new Font("宋體",Font.BOLD,15));
lbH.setFont(new Font("宋體",Font.BOLD,15));
lbA.setForeground(Color.blue);
lbB.setForeground(Color.blue);
lbC.setForeground(Color.blue);
lbD.setForeground(Color.blue);
lbE.setForeground(Color.red);
lbF.setForeground(Color.red);
lbG.setForeground(Color.red);
lbH.setForeground(Color.red);
tf1 = new TJMoneyField("0.00",10);
tf2 = new TJMoneyField("0.00",10);
tf3 = new TJTextField(20);
bt1 = new TJButton("pic/u04.gif", " 結(jié) 賬 ", "結(jié)算房費");
bt2 = new TJButton("pic/cancel.gif", " 取 消 ", "取消結(jié)賬");
//第一行
p111.add(lb1);
p111.add(lbA);
p112.add(lb2);
p112.add(lbB);
p113.add(lb3);
p113.add(lbC);
p11.add(p111);
p11.add(p112);
p11.add(p113);
p11.setBorder(BorderFactory.createTitledBorder(""));
//第二行
p121.add(lb4);
p121.add(lbD);
p122.add(lb5);
p122.add(lbE);
p123.add(lb6);
p123.add(lbF);
p124.add(lb7);
p124.add(lbG);
p12.add(p121);
p12.add(p122);
p12.add(p123);
p12.add(p124);
//第三行
p131.add(lb8);
p131.add(tf1);
p132.add(lb9);
p132.add(tf2);
p133.add(lb10);
p133.add(lbH);
p13.add(p131);
p13.add(p132);
p13.add(p133);
//第四行
p141.add(lb11);
p141.add(tf3);
p142.add(bt1);
p142.add(bt2);
p14.add(p141);
p14.add(p142);
p15.add(p12);
p15.add(p13);
p15.add(p14);
p15.setBorder(BorderFactory.createTitledBorder(""));
p1.add(p11);
p1.add(p15);
}
//構(gòu)造下半面板
private void buildP2() {
JPanel p2c;
p2c = new JPanel(new GridLayout(1,1));
tf = new JTextField("結(jié)賬區(qū)內(nèi)房間消費清單");
tf.setEditable(false);
tf.setBorder(new LineBorder(new Color(87,87,47)));
tf.setBackground(new Color(199,183,143));
tf.setHorizontalAlignment(JTextField.CENTER);
dtm = new DefaultTableModel();
tb = new JTable(dtm);
sp = new JScrollPane(tb);
///////////////////////填表格
p2c.add(sp);
p2.add("North",tf);
p2.add(p2c);
p2.setBorder(BorderFactory.createTitledBorder(""));
}
//初始化DTM
public void initDTM() {
sunsql.initDTM(dtm, "select pk,r_type_id,r_no 房間號,price 單價,discount 折扣," +
"dis_price 折扣價,account 消費天數(shù),money 消費金額,in_time 消費時間 from checkout_temp");
tb.removeColumn(tb.getColumn("pk"));
tb.removeColumn(tb.getColumn("r_type_id"));
}
/**=======================================================================**
* [## private boolean isValidity() {} ]: 測試用戶輸入的數(shù)據(jù)是否合法
* 參數(shù) :無
* 返回值 :boolean
* 修飾符 :private
* 功能 :測試用戶輸入的數(shù)據(jù)是否合法
**=======================================================================**
*/
private boolean isValidity() {
double t1 = Double.parseDouble(tf1.getText());//實收金額
double t2 = Double.parseDouble(lbE.getText());//應(yīng)收金額
double t3 = Double.parseDouble(lbH.getText());//找零
if(t1 < t2) {
JOptionPane.showMessageDialog(null, "[ 實收金額 ] 不能小于 [ 應(yīng)收金額 ]",
"提示", JOptionPane.INFORMATION_MESSAGE);
tf1.requestFocus(true);
return false;
}else if(t3 < 0) {
JOptionPane.showMessageDialog(null, "請賓客支付足夠的消費費用",
"提示", JOptionPane.INFORMATION_MESSAGE);
tf2.requestFocus(true);
return false;
}//Endif
return true;
}
//保存結(jié)算數(shù)據(jù)
private void saveCKO() {
long ckPK = sunsql.getPrimaryKey(); //獲得結(jié)算記錄首PK
String chNO = suntools.getNumber(suntools.Number_JS); //獲得結(jié)算單號
String chkTime = Journal.getNowDTime(); //結(jié)算時間
String reMark = tf3.getText(); //備注
int count = tb.getRowCount(); //得到有幾點結(jié)算記錄
String sqlCode[] = new String[count * 3]; //創(chuàng)建SQL語句數(shù)組
String riState = "可供"; //房間狀態(tài)
int flag = Integer.parseInt(sunini.getIniKey("Ck_Habitus"));//結(jié)算后的房間狀態(tài) 0:可供 1:清理
if(flag == 1) {
riState = "臟房";
}//Endif
int sc=0;
for (int i = 0; i < count * 3; i++) {
//向結(jié)算表加數(shù)據(jù)
sqlCode[i] = "insert into checkout(pk,chk_no,in_no,days,money,chk_time,remark) values(" +
(ckPK + sc) + ",'" + chNO + "','" + inNo + "'," + dtm.getValueAt(sc, 6) + "," +
dtm.getValueAt(sc, 7) + ",'" + chkTime + "','" + reMark + "')";
i++;
//更改入住信息表里的記錄狀態(tài)為已結(jié)算
sqlCode[i] = "update livein set statemark='已結(jié)算' where pk='" + dtm.getValueAt(sc, 0) + "'";
i++;
//更改房間狀態(tài)
sqlCode[i] = "update roominfo set state='" + riState + "' where delmark=0 and id='" +
dtm.getValueAt(sc, 2) + "'";
sc++; //DTM指針+1
}//Endfor
flag = sunsql.runTransaction(sqlCode); //執(zhí)行事務(wù)操作
if(flag < sqlCode.length) {
JOptionPane.showMessageDialog(null, "開設(shè)房間操作失敗,請檢查網(wǎng)絡(luò)" +
"連接或聯(lián)系管理員", "提示", JOptionPane.INFORMATION_MESSAGE);
return; //用戶繼續(xù)輸入
}else if(flag == sqlCode.length) {
//如果事務(wù)成功,則更改狀態(tài)圖片
for (int i = 0; i < tb.getRowCount(); i++) {
//更改狀態(tài)圖片
RightTopPanel.setViewListButtonImage(dtm.getValueAt(i, 1) + "",
dtm.getValueAt(i, 2) + "", riState);
}//Endfor
tf1.setText("0.00"); //清空控件
tf2.setText("0.00");
tf3.setText("");
this.setVisible(false); //關(guān)閉窗口
}//Endif
}
/**=======================================================================**
* ActionListener 監(jiān)聽
**=======================================================================**
*/
public void actionPerformed(ActionEvent ae) {
Object o = ae.getSource();
if(o == bt1) {
if(isValidity()) {
saveCKO(); //保存結(jié)算數(shù)據(jù)
}//Endif
}else if(o == bt2) { //取消操作
tf1.setText("0.00"); //所有文本框清零
tf2.setText("0.00");
tf3.setText("");
this.setVisible(false); //關(guān)閉窗口
}//Endif
}
/**=======================================================================**
* MouseListener 監(jiān)聽
**=======================================================================**
*/
public void mouseClicked (MouseEvent me) {
}
public void mousePressed (MouseEvent me) {
}
public void mouseReleased(MouseEvent me) {
}
public void mouseEntered (MouseEvent me) { //鼠標(biāo)移進(jìn)提示
Object o = me.getSource ();
if(o == bt1) {
HotelFrame.lbA.setText (HotelFrame.clue +
"結(jié)算當(dāng)前房間的消費項目 ");
}else if(o == bt2) {
HotelFrame.lbA.setText (HotelFrame.clue +
"取消結(jié)算操作,返回主窗口 ");
}//Endif
}
public void mouseExited (MouseEvent me) {
HotelFrame.lbA.setText (HotelFrame.clue + "請選擇功能項 ... ");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -