今天给大家提供一个由今天给大家提供一个由Java swing实现的酒店管理系统,数据库采用sqlserver,我会贴上部分代码,完整的代码请看文章最下方下载,下面看代码:
1.主框架代码:
package 主框架窗口; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSplitPane; import javax.swing.JToolBar; import javax.swing.border.LineBorder; import javax.swing.table.DefaultTableModel; import com.sunshine.sunsdk.system.suntools; import sunsdk.sql.Journal; import sunsdk.sql.sunsql; import sunsdk.swing.TJButton; import 关于我们.About; import 团体开单.Team; import 客户管理.Customer; import 客房预定.Engage; import 宾客结账.CheckOut; import 散客开单.Individual; import 系统设置.Setup; import 网络设置.NetSetup; import 菜单事件窗口.ApartBill; import 菜单事件窗口.Change; import 菜单事件窗口.GoOn; import 菜单事件窗口.Record; import 菜单事件窗口.UniteBill; import 营业查询.Query; //加入公共类库 //加入模块类库 //散客开单 //团体开单 //宾客结帐 //预订房间 //营业查询 //客户管理 //网络设置 //系统设置 //关于我们 //下拉菜单中的功能库 public class HotelFrame extends JFrame implements ActionListener, MouseListener, Runnable { //用户名,权限 public static String userid, puil; public static JLabel lbA, lbB; public static String clue = " 提 示 : "; public static String face = " 当前操作界面 : "; //声名与菜单相关的类 private JMenuBar mb; private JMenu m1, m2, m3, m4; private JMenuItem mi11, mi12, mi13, mi14, mi15, mi16, mi17, mi18, mi19, mi21, mi22, mi23, mi24, mi25, mi31, mi32, mi33, mi34, mi35, mi36; //工具栏 private JToolBar tb; private JButton bt1, bt2, bt3, bt4, bt5, bt6, bt7, bt8, bt9, btA; //分割面板 private JSplitPane spaneMain, spaneLeft, spaneRight; //模块接口 private JPanel panelMain, bott, jp2, jp3, jp4; private LeftTopPanel jp1; //主窗口左边面板 //功能提示 private String toolTip[] = { "零散宾客入住登记 ", "团体入住登记 ", "关于本软件的支持信息 ", "宾客退房结算 ", "为宾客预订房间 ", "查询营业情况 ", "为酒店固定客户设置参数 ", "设置系统的网络连接方式 ", "设置系统参数 ", "返回Windows " }; //功能模块 /*#######################################################################*/ Individual idv = new Individual(this); //散客开单 Team tm = new Team(this); //团体开单 CheckOut co = new CheckOut(this); //宾客结帐 Engage eg = new Engage(this); //客房预定 Query qr = new Query(this); //营业查询 Customer ct = new Customer(this); //客户管理 NetSetup ns = new NetSetup(this); //网络设置 Setup st = new Setup(this); //系统设置 About ab = new About(this); //关于我们 GoOn go = new GoOn(this); //宾客续住 Change cg = new Change(this); //更换房间 // Remind rm = new Remind(this); //电子提醒 UniteBill ub = new UniteBill(this); //合并帐单 ApartBill ap = new ApartBill(this); //拆分帐单 Record rc = new Record(this); //系统日志 /*#######################################################################*/ //构造函数 public HotelFrame (String us, String pu) { super ("阳光酒店管理系统 - ★★版"); userid = us; //获得操作员名称 puil = pu; //获得操作员权限 panelMain = new JPanel (new BorderLayout()); //主面板 //制作菜单 buildMenuBar (); //制作工具栏 buildToolBar (); //制作分割面板 buildSpaneMain (); //制作窗口底端信息框 buildBott (); //加入组件到主面板 panelMain.add ("North", tb); //加入工具栏 panelMain.add ("South", bott); //加入窗口底端信息框 panelMain.add ("Center", spaneMain); //加入分割面板 //加入菜单栏 this.setJMenuBar (mb); //加事件监听 addListener (); this.addWindowListener (new WindowAdapter () { public void windowClosing (WindowEvent we) { quit (); }//End windowClosing }); this.setContentPane (panelMain); this.setBounds (2, 2, 1020, 740); this.setDefaultCloseOperation (JFrame.DO_NOTHING_ON_CLOSE); this.setMinimumSize (new Dimension (1020, 740)); //设置窗口最小尺寸 this.setVisible (true); (new Thread(this)).start(); //启动房间状态检查线程 } //制作菜单 private void buildMenuBar () { //实例菜单栏 mb = new JMenuBar (); //实例菜单 m1 = new JMenu ("来宾登记 (B)"); m2 = new JMenu ("收银结算 (S)"); m3 = new JMenu ("系统维护 (W)"); //实例菜单项 mi11 = new JMenuItem ("散客开单 (G)"); mi12 = new JMenuItem ("团体开单 (M)"); mi13 = new JMenuItem ("宾客续住 (Z)"); mi14 = new JMenuItem ("更换房间 (A)"); mi15 = new JMenuItem ("修改登记 (J)"); mi16 = new JMenuItem ("房间状态 (Z)"); mi17 = new JMenuItem ("预订管理 (T)"); mi18 = new JMenuItem ("电子提醒 (L)"); mi19 = new JMenuItem ("退出系统 (X)"); mi21 = new JMenuItem ("宾客结帐 (J)"); mi22 = new JMenuItem ("合并帐单 (E)"); mi23 = new JMenuItem ("折分帐单 (F)"); mi24 = new JMenuItem ("宾客消费明细查询"); mi25 = new JMenuItem ("宾客退单明细查询"); mi31 = new JMenuItem ("网络设置 (N)"); mi32 = new JMenuItem ("系统设置 (X)"); mi33 = new JMenuItem ("系统日志 (Z)"); mi34 = new JMenuItem ("数据备份 (R)"); mi35 = new JMenuItem ("软件帮助 (H)"); mi36 = new JMenuItem ("关于我们 (A)"); /////////////////////////////////////////// mi16.setEnabled(false);//未开发完毕的功能 mi18.setEnabled(false); mi34.setEnabled(false); //////////////////////////////////////////// //组织菜单 m1.add (mi11); //来宾登记 m1.add (mi12); m1.add (mi13); m1.add (mi14); m1.add (mi15); m1.add (mi16); m1.addSeparator(); m1.add (mi17); m1.add (mi18); m1.addSeparator(); m1.add (mi19); m2.add (mi21); //收银结算 m2.add (mi22); m2.add (mi23); //m2.addSeparator(); //m2.add (mi24); //宾客消费明细 //m2.add (mi25); m3.add (mi31); //系统维护 m3.add (mi32); m3.add (mi33); m3.addSeparator(); m3.add (mi34); m3.addSeparator(); m3.add (mi35); m3.add (mi36); mb.add (m1); //加入菜单栏 mb.add (m2); mb.add (m3); } //制作工具栏 private void buildToolBar () { tb = new JToolBar(); //制作按键 bt1 = new TJButton ("pic/ToolBar/m01.gif", " 散客开单 ", "零散宾客入住登记", true); bt2 = new TJButton ("pic/ToolBar/m02.gif", " 团体开单 ", "团体入住登记", true); bt3 = new TJButton ("pic/ToolBar/m03.gif", " 关于我们 ", "软件信息", true); bt4 = new TJButton ("pic/ToolBar/m04.gif", " 宾客结帐 ", "宾客退房结算", true); bt5 = new TJButton ("pic/ToolBar/m05.gif", " 客房预订 ", "为宾客预定房间", true); bt6 = new TJButton ("pic/ToolBar/m06.gif", " 营业查询 ", "查询营业情况", true); bt7 = new TJButton ("pic/ToolBar/m07.gif", " 客户管理 ", "为酒店固定客户设置", true); bt8 = new TJButton ("pic/ToolBar/m08.gif", " 网络设置 ", "设置连接方式", true); bt9 = new TJButton ("pic/ToolBar/m09.gif", " 系统设置 ", "设置系统参数", true); btA = new TJButton ("pic/ToolBar/m10.gif", " 退出系统 ", "返回Windows", true); //把按键加入工具栏 tb.addSeparator (); tb.add (bt1); tb.add (bt2); tb.addSeparator (); tb.add (bt4); tb.add (bt5); tb.add (bt6); tb.addSeparator (); tb.add (bt7); tb.add (bt8); tb.add (bt9); tb.addSeparator (); tb.add (bt3); tb.addSeparator (); tb.add (btA); //设置工具栏不可浮动 tb.setFloatable(false); } //制作主面板 private void buildSpaneMain () { jp1 = new LeftTopPanel (); //这四个面板为功能接口////////////// jp2 = new LeftBottPanel(); //左下面板 快速通道 jp3 = new RightTopPanel(); /////////////////////////////// jp4 = new RightBottPanel(); //右下面板 消费信息表 //声名分割面板 spaneLeft = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, jp1, jp2); spaneRight = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, jp3, jp4); spaneMain = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, spaneLeft, spaneRight); //设置面板最小尺寸 jp1.setMinimumSize(new Dimension (157, 450)); jp2.setMinimumSize(new Dimension (157, 94)); jp3.setMinimumSize(new Dimension (875, 300)); jp4.setMinimumSize(new Dimension (875, 94)); spaneRight.setMinimumSize(new Dimension (875, 565)); //设置分割条是否有伸缩键 spaneMain.setOneTouchExpandable (true); spaneRight.setOneTouchExpandable(true); //设置各面板的初起尺寸 spaneMain.setDividerLocation (160); spaneLeft.setDividerLocation (450); spaneRight.setDividerLocation(450); //设置分隔条宽度 spaneMain.setDividerSize (10); spaneLeft.setDividerSize (23); spaneRight.setDividerSize(23); } //制作bott栏 private void buildBott () { JLabel lb1, lb2; lb1 = new JLabel(" 阳 光 酒 店 管 理 系 统 "); lb2 = new JLabel(" 当前操作员 : " + userid + " "); lbA = new JLabel(clue + "请选择功能项 ... "); lbB = new JLabel(face + "阳 光 酒 店 管 理 系 统 - ★★ 版 "); //加外框线 lbA.setBorder(new LineBorder(new Color(87, 87, 47))); lbB.setBorder(new LineBorder(new Color(87, 87, 47))); lb1.setBorder(new LineBorder(new Color(87, 87, 47))); lb2.setBorder(new LineBorder(new Color(87, 87, 47))); bott = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 2)); bott.add (lb1); bott.add (lbA); bott.add (lbB); bott.add (lb2); } //加事件监听 private void addListener () { mi11.addActionListener (this); //来宾登记 mi12.addActionListener (this); mi13.addActionListener (this); mi14.addActionListener (this); mi15.addActionListener (this); mi16.addActionListener (this); mi17.addActionListener (this); mi18.addActionListener (this); mi19.addActionListener (this); mi21.addActionListener (this); //收银结算 mi22.addActionListener (this); mi23.addActionListener (this); mi24.addActionListener (this); mi25.addActionListener (this); mi31.addActionListener (this); //系统维护 mi32.addActionListener (this); mi33.addActionListener (this); mi34.addActionListener (this); mi35.addActionListener (this); mi36.addActionListener (this); bt1.addActionListener (this); //按键加动作监听 bt2.addActionListener (this); bt3.addActionListener (this); bt4.addActionListener (this); bt5.addActionListener (this); bt6.addActionListener (this); bt7.addActionListener (this); bt8.addActionListener (this); bt9.addActionListener (this); btA.addActionListener (this); bt1.addMouseListener (this); //按键加鼠标监听 bt2.addMouseListener (this); bt3.addMouseListener (this); bt4.addMouseListener (this); bt5.addMouseListener (this); bt6.addMouseListener (this); bt7.addMouseListener (this); bt8.addMouseListener (this); bt9.addMouseListener (this); btA.addMouseListener (this); } /**=======================================================================** * [## private void quit () {} ]: 系统退出 * 参数 :无 * 返回值 :无 * 修饰符 :private * 功能 :关闭系统函数,仅类内使用 **=======================================================================** */ private void quit () { int flag = 0; String msg = "您 现 在 要 关 闭 系 统 吗 ?"; flag = JOptionPane.showConfirmDialog (null, msg, "提示", JOptionPane.YES_NO_OPTION); if(flag == JOptionPane.YES_OPTION) { Journal.writeJournalInfo(userid, "退出本系统", Journal.TYPE_LG);//记录操作日志 this.setVisible (false); System.exit (0); }//End if(flag == JOptionPane.YES_OPTION) return; } //刷新左房间信息栏数据 private void initLeftData() { jp1.title1.setText(""); //刷房间信息 for (int i = 0; i < 8; i++) { jp1.lt[i].setText(""); }//Endfor jp1.initRoomstate(); //刷新房间总状态 } //传数据给散客开单窗口 private boolean initIDV() { try { //从房间信息表里获得当前房间的状态和房间类型编号 ResultSet rs = sunsql.executeQuery("select state,r_type_id from roominfo " + "where delmark=0 and id='" + LeftTopPanel.title1.getText() + "'"); if(!rs.next()) { //如果无结果集,提示用户刷新房间数据 if(LeftTopPanel.title1.getText().length() == 0) { JOptionPane.showMessageDialog(null,"请选定房间后,再为宾客开设房间", "提示", JOptionPane.INFORMATION_MESSAGE); }else { JOptionPane.showMessageDialog(null, "[ " + LeftTopPanel.title1.getText() + " ] 房间信息已更改,请刷新房间信息,再为宾客开设房间", "提示", JOptionPane.INFORMATION_MESSAGE); } return false; }else { if(!rs.getString(1).equals("可供")) { //只有状态是可供房间,才能为宾客开设 JOptionPane.showMessageDialog(null, "请选择空房间,再为宾客开设房间", "提示", JOptionPane.INFORMATION_MESSAGE); return false; }//Endif //传房间号到开单窗口 Individual.lbA.setText(LeftTopPanel.title1.getText()); //传房间类型到开单窗口 Individual.lbB.setText(LeftTopPanel.title0.getText().substring(0, LeftTopPanel.title0.getText().length()-2)); //传房间单价到开单窗口 Individual.lbC.setText(LeftTopPanel.lt[1].getText()); //房间类型编号 String clRoom = rs.getString(2); //获得此类型房间是否可以开设钟点房 rs = sunsql.executeQuery("select cl_room from roomtype where " + "delmark=0 and id='" + clRoom + "'"); rs.next(); if(rs.getString(1).equals("N")) { //不能开设,则开单窗口的钟点选项不可用 Individual.chk1.setSelected(false); //取消选中状态 Individual.chk1.setEnabled(false); //设置不可用 }else { Individual.chk1.setEnabled(true); //可用 }//Endif //传宾客类型数据给开单窗口 rs = sunsql.executeQuery("select distinct c_type from customertype where " + "delmark = 0 and pk!=0"); int ct = sunsql.recCount(rs); String cType[] = new String[ct]; for (int i = 0; i < ct; i++) { rs.next(); cType[i] = rs.getString(1); }//Endfor Individual.cb2.removeAllItems(); for (int i = 0; i < ct; i++) { Individual.cb2.addItem(cType[i]); }//Endfor Individual.cb2.setSelectedItem("普通宾客"); //初始化开单房间表---------临时表 sunsql.executeUpdate("delete from roomnum"); //清空临时表 sunsql.executeUpdate("insert into roomnum(roomid) values('" + LeftTopPanel.title1.getText() + "')"); //加入当前房间信息 //初始化开单窗口的开单房间表 sunsql.initDTM(Individual.dtm2,"select roomid 房间编号 from roomnum"); //初始化追加房间表---------当前类型的除当前房间的所有可供房间 sunsql.executeUpdate("update roominfo set indimark=0"); //刷新所有房间的开单状态 sunsql.executeUpdate("update roominfo set indimark=1 where id='" + LeftTopPanel.title1.getText() + "'"); //设置当前房间为开单状态 //初始化开单窗口的可供房间表 sunsql.initDTM(Individual.dtm1,"select a.id 房间编号1 from roominfo " + "a,(select id from roomtype where r_type='" + Individual.lbB.getText() + "') b where a.delmark=0 and a.indimark=0 and a.state='可供' and a.r_type_id=b.id"); }//Endif } catch (Exception ex) { System.out.println ("HotelFrame.initIDV(): false"); }//End try return true; } //传数据给团体开单窗口 private boolean initTeam() { try { //初始化开单房间表---------临时表 sunsql.executeUpdate("delete from roomnums"); //清空临时表 //初始化开单窗口的开单房间表 Team.initDTM2(); //初始化追加房间表---------当前类型的除当前房间的所有可供房间 sunsql.executeUpdate("update roominfo set indimark=0"); //刷新所有房间的开单状态 //传房间类型数据给团体开单窗口 ResultSet rs = sunsql.executeQuery("select r_type from roomtype where delmark=0"); int ct = sunsql.recCount(rs); String type[] = new String[ct]; //传宾客房型数据给团体开单窗口 for (int i = 0; i < ct; i++) { rs.next(); type[i] = rs.getString(1); }//Endfor Team.cb.removeAllItems(); for (int i = 0; i < ct; i++) { Team.cb.addItem(type[i]); }//Endfor //传宾客类型数据给团体开单窗口 rs = sunsql.executeQuery("select distinct c_type from customertype where " + "delmark = 0 and pk!=0"); ct = sunsql.recCount(rs); for (int i = 0; i < ct; i++) { rs.next(); type[i] = rs.getString(1); }//Endfor Team.cb2.removeAllItems(); for (int i = 0; i < ct; i++) { Team.cb2.addItem(type[i]); }//Endfor Team.cb2.setSelectedItem("普通宾客"); } catch (Exception ex) { System.out.println ("HotelFrame.initTeam(): false"); }//Endtry return true; } //传数据给结算窗口 private boolean initCKO() { try { ResultSet rs = sunsql.executeQuery("select state,r_type_id from roominfo " + "where delmark=0 and id='" + LeftTopPanel.title1.getText() + "'"); if(!rs.next()) { //如果无结果集,提示用户刷新房间数据 if(LeftTopPanel.title1.getText().length() == 0) { JOptionPane.showMessageDialog(null,"请选定宾客入住的房间后,再为宾客结算费用", "提示", JOptionPane.INFORMATION_MESSAGE); }else { JOptionPane.showMessageDialog(null, "[ " + LeftTopPanel.title1.getText() + " ] 房间信息已更改,请刷新房间信息,再为宾客开设房间", "提示", JOptionPane.INFORMATION_MESSAGE); }//Endif return false; }else { //只有状态是占用或钟点房间,才能为宾客结算 if(!rs.getString(1).equals("占用") && !rs.getString(1).equals("钟点")) { JOptionPane.showMessageDialog(null, "请选择宾客正在消费的房间进行结算费用操作", "提示", JOptionPane.INFORMATION_MESSAGE); return false; }//Endif //传结算单号给结算窗口 co.lbA.setText(suntools.getNumber(suntools.Number_JS)); //传结算房间给结算窗口 co.lbB.setText(jp1.title1.getText()); //传结算宾客名称给结算窗口 co.lbC.setText(jp1.lt[0].getText()); //传押金给结算窗口 co.lbF.setText(jp1.lt[6].getText()); //清空结算中间表 sunsql.executeUpdate("delete from checkout_temp"); //获得主房间号 rs = sunsql.executeQuery("select main_room,in_no from livein where " + "delmark=0 and r_no='" + co.lbB.getText() + "' and statemark='正在消费'"); if(!rs.next()) { JOptionPane.showMessageDialog(null, "操作失败,请检查网络情况", "提示", JOptionPane.INFORMATION_MESSAGE); return false; }//Endif String mainRoom = rs.getString(1); //取出主房间号 co.inNo = rs.getString(2); //传入住单号为结算窗口 //获得主房间状态,看是普通住宿还是钟点房 rs = sunsql.executeQuery("select state from roominfo where delmark=0 and id='" + mainRoom + "'"); rs.next(); int mrState = 0; //主房间状态 0:普通入住 1:钟点房 if(rs.getString(1).equals("钟点")) { mrState = 1; }//Endif DefaultTableModel ckoDTM = new DefaultTableModel(); //主房间下的所有房间信息 sunsql.initDTM(ckoDTM, "select pk,r_no,r_type_id,c_type_id,in_time,foregift from " + "livein where delmark=0 and main_room='" + mainRoom + "'"); double total = 0; //消费总金额 double shsh = 0; //实收金额 double youh = 0; //优惠金额 for (int i = 0; i < ckoDTM.getRowCount(); i++) { //取出当前房间的标准单价 rs = sunsql.executeQuery("select price,cl_price from roomtype where delmark=0 and id='" + ckoDTM.getValueAt(i, 2) + "'"); rs.next(); double rprice = 0; double days = 0; if(mrState == 0) { rprice = rs.getDouble(1); //普通入住单价 //获得入住天数 days = suntools.getConsumeFactor(ckoDTM.getValueAt(i, 4) + "", Journal.getNowDTime()); }else { rprice = rs.getDouble(2); //钟点房单价 days = suntools.getClockFactor(ckoDTM.getValueAt(i, 4) + "", Journal.getNowDTime()); }//Endif double rd = rprice * days; //当前房间的消费总金额 total = total + rd; //累加总消费 rs = sunsql.executeQuery("select discount from customertype where delmark=0 and " + "id='" + ckoDTM.getValueAt(i, 3) + "' and dis_attr='" + ckoDTM.getValueAt(i, 2) + "'"); rs.next(); //取出宾客享受的折扣 int dst = rs.getInt(1); double ddr = rd * dst/10; //当前房间的打折后价格 shsh = shsh + ddr; //应收金额累加 youh = youh + rd - ddr; //优惠金额累加 //向结算中间表加入数据 sunsql.executeUpdate("insert into checkout_temp(pk,r_type_id,r_no,price," + "discount,dis_price,account,money,in_time) values(" + ckoDTM.getValueAt(i, 0) + ",'" + ckoDTM.getValueAt(i, 2) + "','" + ckoDTM.getValueAt(i, 1) + "'," + rprice + "," + dst + "," + rprice * dst / 10 + "," + days + "," + ddr + ",'" + ckoDTM.getValueAt(i, 4) + "')"); } //传消费金额给结算窗口 co.lbD.setText(total + ""); //传应收金额给结算窗口 co.lbE.setText(shsh + ""); //传实收金额 co.tf1.setText(shsh + ""); //传优惠金额给结算窗口 co.lbG.setText(youh + ""); //传找零金额给结算窗口 co.lbH.setText(Double.parseDouble(co.lbF.getText()) - shsh + ""); //刷新结算中间表数据 co.initDTM(); co.tf2.requestFocus(true); //给宾客支付焦点 }//Endif } catch (Exception ex) { JOptionPane.showMessageDialog(null, "操作失败,请检查网络情况", "提示", JOptionPane.INFORMATION_MESSAGE); ex.printStackTrace(); System.out.println ("HotelFrame.initCKO(): false"); return false; }//End try return true; } /**=======================================================================** * ActionListener 监听 **=======================================================================** */ public void actionPerformed (ActionEvent ae) { Object o = ae.getSource (); if(o == bt1 || o ==mi11) {//============================================ lbB.setText(face + "散 客 开 单 -"); if(initIDV()) { //传数据给散客开单窗口 idv.show(); //散客开单 initLeftData(); //刷新左房间信息栏数据 }//Endif }else if(o == bt2 || o == mi12) {//===================================== lbB.setText(face + "团 体 开 单 -"); if(initTeam()) { //传宾客类型数据给团体开单窗口 tm.show(); //团体开单 initLeftData(); //刷新左房间信息栏数据 }//Endif }else if(o == bt3 || o == mi36) {//===================================== lbB.setText(face + "关 于 我 们 -"); ab.show(); //关于我们 }else if(o == bt4 || o == mi21) {//===================================== lbB.setText(face + "宾 客 结 帐 -"); if(initCKO()) { //传数据给结算窗口 co.show(); //宾客结帐 initLeftData(); //刷新左房间信息栏数据 }//Endif }else if(o == bt5 || o == mi17) {//===================================== lbB.setText(face + "客 房 预 订 -"); eg.show(); //客房预订 initLeftData(); //刷新左房间信息栏数据 }else if(o == bt6) {//================================================== lbB.setText(face + "营 业 查 询 -"); qr.show(); //营业查询 }else if(o == bt7) {//================================================== if(puil.equals("普通操作员")) { //客户管理 String msg = "对不起,您的权限不能进入 [ 客户管理 ] 页面,请用管理员ID登录 ..."; JOptionPane.showMessageDialog(null, msg, "提示", JOptionPane.INFORMATION_MESSAGE); return; } lbB.setText(face + "客 户 管 理 -"); ct.show(); }else if(o == bt8 || o == mi31) {//===================================== if(puil.equals("普通操作员")) { //网络设置 String msg = "对不起,您的权限不能进入 [ 网络设置 ] 页面,请用管理员ID登录 ..."; JOptionPane.showMessageDialog(null, msg, "提示", JOptionPane.INFORMATION_MESSAGE); return; } lbB.setText(face + "网 络 设 置 -"); ns.show(); }else if(o == bt9 || o == mi32) {//===================================== if(puil.equals("普通操作员")) { //系统设置 String msg = "对不起,您的权限不能进入 [ 网络设置 ] 页面,请用管理员ID登录 ..."; JOptionPane.showMessageDialog(null, msg, "提示", JOptionPane.INFORMATION_MESSAGE); return; } lbB.setText(face + "系 统 设 置 -"); st.buildDTM12(""); //刷新房间信息表的房间状态 st.show(); initLeftData(); //刷新左房间信息栏数据 }else if(o == btA || o == mi19) {//===================================== quit (); //退出系统 }else if(o == mi13) {//================================================= lbB.setText(face + "宾 客 续 住 -"); go.show(); //宾客续住 }else if(o == mi14) {//================================================= lbB.setText(face + "更 换 房 间 -"); cg.show(); //更换房间 }else if(o == mi15) {//================================================= lbB.setText(face + "修 改 登 记 -"); idv.show(); //修改登记-------还要修改 }else if(o == mi16) {//================================================= //房间状态 }else if(o == mi18) {//================================================= //电子提醒 }else if(o == mi22) {//================================================= lbB.setText(face + "合 并 帐 单 -"); ub.show(); //合并帐单 }else if(o == mi23) {//================================================= lbB.setText(face + "折 分 帐 单 -"); ap.show(); //折分帐单 }else if(o == mi33) {//================================================= lbB.setText(face + "系 统 日 志 -"); rc.initDTM(); //刷新日志列表 rc.show(); //系统日志 }else if(o == mi34) {//================================================= //数据备份 }else if(o == mi35) {//================================================= //软件帮助 } lbB.setText(face + "阳 光 酒 店 管 理 系 统 - ★★ 版 "); } /**=======================================================================** * MouseListener 监听 **=======================================================================** */ public void mouseClicked (MouseEvent me) { } public void mousePressed (MouseEvent me) { } public void mouseReleased(MouseEvent me) { } public void mouseEntered (MouseEvent me) { //鼠标移进提示 Object o = me.getSource (); if(o == bt1) { lbA.setText (clue + toolTip[0]); }else if(o == bt2) { lbA.setText (clue + toolTip[1]); }else if(o == bt3) { lbA.setText (clue + toolTip[2]); }else if(o == bt4) { lbA.setText (clue + toolTip[3]); }else if(o == bt5) { lbA.setText (clue + toolTip[4]); }else if(o == bt6) { lbA.setText (clue + toolTip[5]); }else if(o == bt7) { lbA.setText (clue + toolTip[6]); }else if(o == bt8) { lbA.setText (clue + toolTip[7]); }else if(o == bt9) { lbA.setText (clue + toolTip[8]); }else if(o == btA) { lbA.setText (clue + toolTip[9]); } } public void mouseExited (MouseEvent me) { lbA.setText (clue + "请选择功能项 ... "); } /**=======================================================================** * [## public void run() {} ]: * 参数 :无 * 返回值 :无 * 修饰符 :public * 功能 :结算后检查房间状态线程 **=======================================================================** */ public void run() { try { Statement ste1 = null; Connection conn1 = null; if(sunini.getIniKey ("Default_Link").equals ("1")) { //JDBC连接方式 String user1 = sunini.getIniKey ("UserID"); String pwd1 = sunini.getIniKey ("Password"); String ip1 = sunini.getIniKey ("IP"); String acc1 = sunini.getIniKey ("Access"); String dbf1 = sunini.getIniKey ("DBFname"); String url1 = "jdbc:microsoft:sqlserver://" + ip1 + ":" + acc1 + ";" + "databasename=" + dbf1; //注册驱动 DriverManager.registerDriver (new com.microsoft.jdbc.sqlserver.SQLServerDriver()); //获得一个连接 conn1 = DriverManager.getConnection (url1, user1, pwd1); } else { //注册驱动 //JDBCODBC连接方式 DriverManager.registerDriver (new sun.jdbc.odbc.JdbcOdbcDriver()); //获得一个连接 conn1 = DriverManager.getConnection ("jdbc:odbc:" + sunini.getIniKey("LinkName")); } //建立高级载体 ste1 = conn1.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); while( true ) { ste1.executeUpdate("update roominfo set statetime=statetime-1 where statetime>0"); ste1.executeUpdate("update roominfo set state='可供' where statetime=0 and state='脏房'"); Thread.sleep(30000); }//End while } catch (Exception ex) { JOptionPane.showMessageDialog (null, "数据库连接失败...", "错误", JOptionPane.ERROR_MESSAGE); System.exit(0); //ex.printStackTrace(); }//End try } /* public static void main (String sd[]) { sunswing.setWindowStyle (sunini.getIniKey ("Sys_style").charAt (0)); new HotelFrame ("gujun", "管理员"); }*/ }
2.系统设置:
/** *############################################################################## * * [ 项目名 ] : 阳光酒店管理系统 * [ 公司名 ] : 清华IT * [ 模块名 ] : 系统设置模块 * [ 文件名 ] : Setup.java * [ 相关文件 ] : * [ 文件实现功能] : 组织系统设置窗口 * [ 作者 ] : 董丰 * [ 版本 ] : 1.1 * ---------------------------------------------------------------------------- * [ 备注 ] : * ---------------------------------------------------------------------------- * [ 修改记录 ] : * * [ 日 期 ] [版本] [修改人] [修改内容] * 2006/04/19 1.0 董丰 创建 * 2006/04/22 1.1 顾俊 实现数据保存 * ##-------------------------------------------------------------------------- * 版权所有(c) 2006-2007, SunshineSOFT Corporation * --------------------------------------------------------------------------## * * [ 函数说明 ] : 看类内各函数开头 * * [ 遗留问题 ] : * *############################################################################## */ package com.sunshine.setup; import javax.swing.*; 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.system.*; import com.sunshine.sunsdk.swing.*; import com.sunshine.mainframe.HotelFrame; //加载主窗口 public class Setup extends JDialog implements ActionListener, MouseListener { private JLabel top,bott; private JTabbedPane tp; private JPanel panelMain; //=========房间项目设置 private JTable tb11, tb12; private DefaultTableModel dtm11, dtm12; //房间类型列表//房间信息列表 private JScrollPane sp11,sp12; private JComboBox cb11,cb12; //房间类型,可供/清理状态 private JButton bt11, bt12, bt13, bt14, bt15, bt16, bt17, bt18, bt19, bt20; //添加, 修改,删除LX,折扣,单个,批量添加,删除,修改FJ,保存,筛选 private JTextField tf11; //=========客户类型设置 private JTable tb21,tb22; private DefaultTableModel dtm21,dtm22; //客户类型列表,房间费打折列表 private JScrollPane sp21,sp22; private JButton bt21, bt22, bt23, bt24; //添加, 修改,删除LX,房费打折 //=========操作员设置 private JTable tb31; private DefaultTableModel dtm31; //操作员列表 private JScrollPane sp31; private JComboBox cb31;//用户名 private JPasswordField tf31, tf32, tf33; //原密码,新密码,确认密码 private JRadioButton rb31, rb32, rb33, rb34, rb35; //新用户登记, 修改密码,删除用户,普通用户,管理员 private JButton bt31, bt32, bt33; // 登记, 修改, 删除 //=========计费设置 private JTextField tf41, tf42, tf43, tf44, tf45, tf46, tf47; private JCheckBox ck; private JButton bt41, bt42; //提示信息 String msg0 = "您确定要删除在表格中选中的资料条目吗?"; String msg1 = "请在相应的表格中选定条目,再点删除键 ..."; //日志信息 String journal; //INI文件中的键名 String ini[] = { "[SOFTINFO]", "UserName", "CompName", "[CONFIG]", "Soft_First", "Default_Link" , "Default_Page", "Sys_style", "[NUMBER]", "LodgName", "LodgNumber", "EngaName", "EngaNumber", "ChouName", "ChouNumber", "[HABITUS]", "Ck_Habitus", "Ck_Minute", "[PARTTIME]", "In_Room", "Out_Room1", "Out_Room2", "InsuDay", "ClockRoom1", "ClockRoom2", "InsuHour1", "InsuHour2", "[JDBC]", "DBFname", "UserID", "Password", "IP", "Access", "[ODBC]", "LinkName" }; //实例化功能模块 //========================================================================// AddRoomType art = new AddRoomType (this); //添加房间类型 ModiRoomType mrt = new ModiRoomType(this); //添加房间类型 AddCustomerType act = new AddCustomerType(this); //添加客户类型 ModiCustomerType mct = new ModiCustomerType(this); //添加客户类型 Discount dis = new Discount(this); //折扣设置 AddRoomInfo ari = new AddRoomInfo(this); //单个添加房间 AddRoomInfos aris = new AddRoomInfos(this); //批量添加房间 ModiRoomInfo mri = new ModiRoomInfo(this); //修改房间信息 //========================================================================// /**=======================================================================** * [## public Setup(JFrame frame) {} ]: 构造函数 * 参数 :JDialog对象表示本对话框的父窗口 * 返回值 :无 * 修饰符 :public * 功能 :组建系统设置模块 **=======================================================================** */ public Setup(JFrame frame) { super (frame, "系统设置", true); top = new JLabel(); //假空格 panelMain = new JPanel(new BorderLayout(0,10)); tab(); //制作系统设置项目标签面板 addListener(); //加入事件监听 panelMain.add("North",top); panelMain.add("Center",tp); this.setContentPane(panelMain); this.setPreferredSize (new Dimension (718,508)); this.setMinimumSize (new Dimension (718,508)); this.setResizable(false); //不允许改变窗口大小 pack(); sunswing.setWindowCenter(this); //窗口屏幕居中 } /**=======================================================================** * [## private void addListener() {} ]: 加事件监听 * 参数 :无 * 返回值 :无 * 修饰符 :private * 功能 :加事件监听 **=======================================================================** */ private void addListener() { bt11.addActionListener(this); //加动作监听 bt12.addActionListener(this); bt13.addActionListener(this); bt14.addActionListener(this); bt15.addActionListener(this); bt16.addActionListener(this); bt17.addActionListener(this); bt18.addActionListener(this); bt19.addActionListener(this); bt20.addActionListener(this); bt21.addActionListener(this); bt22.addActionListener(this); bt23.addActionListener(this); bt24.addActionListener(this); bt31.addActionListener(this); bt32.addActionListener(this); bt33.addActionListener(this); bt41.addActionListener(this); bt42.addActionListener(this); rb31.addActionListener(this); //操作员作操范围监听 rb32.addActionListener(this); rb33.addActionListener(this); tf41.addActionListener(this); //计费设置文本框加监听 tf42.addActionListener(this); tf43.addActionListener(this); tf44.addActionListener(this); tf45.addActionListener(this); tf46.addActionListener(this); bt11.addMouseListener(this); //加鼠标监听 bt12.addMouseListener(this); bt13.addMouseListener(this); bt14.addMouseListener(this); bt15.addMouseListener(this); bt16.addMouseListener(this); bt17.addMouseListener(this); bt18.addMouseListener(this); bt19.addMouseListener(this); bt20.addMouseListener(this); bt21.addMouseListener(this); bt22.addMouseListener(this); bt23.addMouseListener(this); bt24.addMouseListener(this); bt31.addMouseListener(this); bt32.addMouseListener(this); bt33.addMouseListener(this); bt41.addMouseListener(this); bt42.addMouseListener(this); } /**=======================================================================** * [## private void tab() {} ]: 制作系统设置项目标签面板 * 参数 :无 * 返回值 :无 * 修饰符 :private * 功能 :制作系统设置项目标签面板 **=======================================================================** */ private void tab() { JPanel jp1,jp2,jp3,jp4; ///////////////////////////////////////////////-------模块面板接口 jp1 = fangjian(); //房间项目设置 jp2 = kehu(); //客户类型设置 jp3 = caozuo(); //操作员设置 jp4 = jiFei(); //计费设置 ////////////////////////////////////////////////////////////////// tp = new JTabbedPane(); tp.addTab("房间项目设置", new ImageIcon("pic/u01.gif"), jp1); tp.addTab("客户类型设置", new ImageIcon("pic/u02.gif"), jp2); tp.addTab("操作员设置", new ImageIcon("pic/u03.gif"), jp3); tp.addTab("计费设置", new ImageIcon("pic/u04.gif"), jp4); } /**=======================================================================** * [## private JPanel fangjian() {} ]: * 参数 :无 * 返回值 :JPanel * 修饰符 :private * 功能 :房间项目设置 **=======================================================================** */ private JPanel fangjian() { dtm11 = new DefaultTableModel(); tb11 = new JTable(dtm11); sp11 = new JScrollPane(tb11); dtm12 = new DefaultTableModel(); tb12 = new JTable(dtm12); sp12 = new JScrollPane(tb12); JPanel pfangjian,pTop,pBott,pTn,pTc,pBn,pBc,pTcc,pTcs,pBcc,pBcs; pfangjian = new JPanel(new GridLayout(2,1,0,5)); pTop = new JPanel(new BorderLayout()); pBott = new JPanel(new BorderLayout()); pTn = new JPanel(); //放置保存按钮等... pTc = new JPanel(new BorderLayout()); //放置房间类型列表及四个按钮 pBn = new JPanel(new FlowLayout(FlowLayout.LEFT,10,0));//放置下拉列表 pBc = new JPanel(new BorderLayout()); //放置房间信息列表及四个按钮 pTcc = new JPanel(new GridLayout(1,1));//放置房间类型列表 pTcs = new JPanel(new FlowLayout(FlowLayout.CENTER,20,5));//放置四个按钮 pBcc = new JPanel(new GridLayout(1,1));//放置房间信息列表 pBcs = new JPanel(new FlowLayout(FlowLayout.CENTER,20,5));//放置四个按钮 //保存按钮等 ... JLabel lb1,lb2,lb3; lb1 = new JLabel("结帐后房间状态变为: "); lb2 = new JLabel(" 结帐后"); lb3 = new JLabel("分钟后变为可供状态 "); tf11 = new TJTextField(sunini.getIniKey(ini[17]),5); //根据INI文件给初值 tf11.setHorizontalAlignment(JTextField.RIGHT); cb12 = new JComboBox(); cb12.addItem(" 可供状态 "); cb12.addItem(" 清理状态 "); //根据INI文件给初值 cb12.setSelectedIndex(Integer.parseInt(sunini.getIniKey(ini[16]))); bt19 = new TJButton ("pic/save.gif", " 保 存 ", "保存设置"); pTn.add(lb1); pTn.add(cb12); pTn.add(lb2); pTn.add(tf11); pTn.add(lb3); pTn.add(bt19); pTn.setBorder(BorderFactory.createTitledBorder("")); //房间类型列表及四个按钮 bt11 = new TJButton ("pic/new.gif", "添加类型", "添加房间类型"); bt12 = new TJButton ("pic/modi0.gif", "修改类型", "修改房间类型"); bt13 = new TJButton ("pic/del.gif", "删除类型", "删除房间类型"); bt14 = new TJButton ("pic/modi3.gif", "房费打折", "设置房间费折扣"); pTcc.add(sp11); pTcs.add(bt11); pTcs.add(bt12); pTcs.add(bt13); pTcs.add(bt14); pTc.add(pTcc); pTc.add("South",pTcs); pTc.setBorder(BorderFactory.createTitledBorder("房间类型")); //完成上半部分 pTop.add("North",pTn); pTop.add(pTc); //下拉列表 JLabel lb0 = new JLabel("按包厢类型过滤: "); cb11 = new JComboBox(); bt20 = new TJButton ("pic/choose1.gif", "筛 选", "筛选房间信息"); bt20.setBorderPainted(false); bt20.setFocusPainted(false); pBn.add(lb0); pBn.add(cb11); pBn.add(bt20); buildDTM11(); //初始化房间类型列表和下拉列表的值 buildDTM12(""); //初始化房间号列表 //房间信息列表及四个按钮 bt15 = new TJButton ("pic/new.gif", "单个添加", "添加单个房间信息"); bt16 = new TJButton ("pic/book.gif", "批量添加", "批量添加房间信息"); bt17 = new TJButton ("pic/del.gif", "删除房间", "删除某个房间信息"); bt18 = new TJButton ("pic/modi0.gif", "修改房间", "修改某个房间信息"); pBcc.add(sp12); pBcs.add(bt15); pBcs.add(bt16); pBcs.add(bt17); pBcs.add(bt18); pBc.add(pBcc); pBc.add("South",pBcs); pBc.setBorder ( BorderFactory.createTitledBorder ("房间信息") ); //完成下半部分 pBott.add("North",pBn); pBott.add(pBc); //组合 pfangjian.add(pTop); pfangjian.add(pBott); return pfangjian; } // /**=======================================================================** * [## private void buildDTM11() {} ]: * 参数 :无 * 返回值 :无 * 修饰符 :private * 功能 :房间类型列表和ComboBox **=======================================================================** */ private void buildDTM11() { String sqlCode2 = "select pk,sysmark,id,foregift,r_type 房间类型," + "price 预设单价,cl_price " + "'钟点价格/小时'" + ",bed 床位数量,cl_room "+ "'能否按钟点计费(Y/N)' from roomtype where delmark = 0"; sunsql.initDTM(dtm11,sqlCode2); tb11.removeColumn(tb11.getColumn("pk")); tb11.removeColumn(tb11.getColumn("sysmark")); tb11.removeColumn(tb11.getColumn("foregift")); tb11.removeColumn(tb11.getColumn("id")); String sqlCode1 = "select r_type from roomtype where delmark = 0"; sunsql.initJComboBox(cb11,sqlCode1); cb11.addItem("显示全部房间信息"); cb11.setSelectedIndex(cb11.getItemCount() - 1); //设置显示全部 } /**=======================================================================** * [## private void buildDTM12(String rType) {} ]: * 参数 :String rType为刷新参数 * 返回值 :无 * 修饰符 :private * 功能 :房间信息表 **=======================================================================** */ public void buildDTM12(String rType) { String sqlCode = "select a.pk,a.r_type_id,a.id 房间号,b.r_type 房间类型," + "a.state 房间状态,a.location 所在区域,a.r_tel 房间电话 from roominfo as a," + "roomtype as b where a.r_type_id = b.id and a.delmark = 0 " + rType; sunsql.initDTM(dtm12,sqlCode); tb12.removeColumn(tb12.getColumn("pk")); tb12.removeColumn(tb12.getColumn("r_type_id")); } /**=======================================================================** * [## private JPanel kehu() {} ]: * 参数 :无 * 返回值 :无 * 修饰符 :private * 功能 :客户类型设置 **=======================================================================** */ private JPanel kehu() { dtm21 = new DefaultTableModel(); tb21 = new JTable(dtm21); sp21 = new JScrollPane(tb21); dtm22 = new DefaultTableModel(); tb22 = new JTable(dtm22); sp22 = new JScrollPane(tb22); JPanel pkehu,p1,p2,p1b,p2b; p1 = new JPanel(new BorderLayout());//客户类型面板 p2 = new JPanel(new BorderLayout());//房间费打折面板 p1b = new JPanel(new FlowLayout(FlowLayout.CENTER,30,5));//客户类型按钮面板 p2b = new JPanel(); //房间费打折按钮面板 buildDTM21(); //初始化客户类型表 bt21 = new TJButton ("pic/new.gif", "添加类型", "添加客户类型"); bt22 = new TJButton ("pic/modi0.gif", "修改类型", "修改客户类型"); bt23 = new TJButton ("pic/del.gif", "删除类型", "删除客户类型"); p1b.add(bt21); p1b.add(bt22); p1b.add(bt23); p1.add(sp21); p1.add("South",p1b); p1.setBorder ( BorderFactory.createTitledBorder ("客户类型") ); buildDTM22(); //初始化房间打折表 bt24 = new TJButton ("pic/modi3.gif", " 房间费打折 ", "设置房间费折扣"); p2b.add(bt24); p2.add(sp22); p2.add("South",p2b); p2.setBorder ( BorderFactory.createTitledBorder ("房间费打折") ); pkehu = new JPanel(new GridLayout(2,1,0,10)); pkehu.add(p1); pkehu.add(p2); return pkehu; } /**=======================================================================** * [## private JPanel caozuo() {} ]: * 参数 :无 * 返回值 :JPanel * 修饰符 :private * 功能 :操作员设置 **=======================================================================** */ private JPanel caozuo() { JPanel panelMain,panelMain1,panelTop,panelBott1,panelBott2; dtm31 = new DefaultTableModel(); tb31 = new JTable(dtm31); sp31 = new JScrollPane(tb31); panelMain = new JPanel(new GridLayout(2,1,0,5)); panelMain1 = new JPanel (new BorderLayout (0,3)); //下半面板 panelTop = new JPanel(new GridLayout(1,1)); //操作员列表面板 panelBott1 = new JPanel(new GridLayout (1, 2));//详细信息,操作范围,操作权限面板 panelBott2 = new JPanel(new FlowLayout (FlowLayout.CENTER,20,5));//按钮面板 bt31 = new TJButton ("pic/new.gif", " 登 记 ", "保存当前用户信息", false); bt32 = new TJButton ("pic/key.gif", " 修 改 ", "修改密码", false); bt33 = new TJButton ("pic/del.gif", " 删 除 ", "删除当前用户", false); bt32.setEnabled(false); bt33.setEnabled(false); panelBott2.add (bt31); panelBott2.add (bt32); panelBott2.add (bt33); //制作并加入Top_Left面板 panelBott1.add (bottLeft()); //制作并加入Top_Right面板 panelBott1.add (bottRight()); panelMain1.add ("Center", panelBott1); panelMain1.add ("South", panelBott2); buildDTM31(); //初始化操作员信息表 panelTop.add(sp31); panelTop.setBorder(BorderFactory.createTitledBorder("操作员列表")); panelMain.add(panelTop); panelMain.add(panelMain1); return panelMain; } /**=======================================================================** * [## private JPanel topLeft () {} ]: 制作Top_Left面板 * 参数 :无 * 返回值 :JPanel表示组织好的面板 * 修饰符 :private * 功能 :组建对话框的用户名和密码面板 **=======================================================================** */ private JPanel bottLeft () { JLabel lb1, lb2, lb3, lb4; JPanel tl, jp1, jp2; lb1 = new JLabel ("用 户 名: "); lb2 = new JLabel ("原 密 码: "); lb3 = new JLabel ("新 密 码: "); lb4 = new JLabel ("确认密码: "); tf31 = new TJPasswordField (17); tf32 = new TJPasswordField (17); tf33 = new TJPasswordField (17); tl = new JPanel (); jp1 = new JPanel (new GridLayout (4, 1, 0, 18)); jp2 = new JPanel (new GridLayout (4, 1, 0, 9)); //初始化用户名下拉框 cb31 = new JComboBox (); cb31.setEditable (true); tf31.setEditable (false); //加入组件 jp1.add (lb1); jp1.add (lb2); jp1.add (lb3); jp1.add (lb4); jp2.add (cb31); jp2.add (tf31); jp2.add (tf32); jp2.add (tf33); tl.add (jp1); tl.add (jp2); tl.setBorder (BorderFactory.createTitledBorder (" 详细信息 ")); return tl; } /**=======================================================================** * [## private JPanel topRight () {} ]: 制作Top_Right面板 * 参数 :无 * 返回值 :JPanel表示组织好的面板 * 修饰符 :private * 功能 :组建对话框操作面板 **=======================================================================** */ private JPanel bottRight () { JPanel tr, jp1, jp2; ButtonGroup bg1,bg2; rb31 = new JRadioButton ("新用户登记", true); rb32 = new JRadioButton ("修改密码"); rb33 = new JRadioButton ("删除用户"); rb34 = new JRadioButton ("普通操作员", true); rb35 = new JRadioButton ("管 理 员"); bg1 = new ButtonGroup (); bg2 = new ButtonGroup (); tr = new JPanel (new GridLayout (2, 1)); jp1 = new JPanel (); jp2 = new JPanel (); //加单选组 操作范围 bg1.add (rb31); bg1.add (rb32); bg1.add (rb33); //加单选组 操作权限 bg2.add (rb34); bg2.add (rb35); jp1.add (rb31); jp1.add (rb32); jp1.add (rb33); jp2.add (rb34); jp2.add (rb35); jp1.setBorder (BorderFactory.createTitledBorder (" 操作范围 ")); jp2.setBorder (BorderFactory.createTitledBorder (" 操作权限 ")); tr.add (jp1); tr.add (jp2); return tr; } /**=======================================================================** * [## private void buildDTM21() {} ]: * 参数 :无 * 返回值 :无 * 修饰符 :private * 功能 :初始化客户类型列表 **=======================================================================** */ private void buildDTM21() { String sqlCode = "select pk,id 客户类型编号,id,c_type 客户类型,discount " + "打折比率 from customertype where delmark = 0 and dis_attr = '购物折扣' and id!='SYSMARK'"; sunsql.initDTM(dtm21,sqlCode); tb21.removeColumn(tb21.getColumn("pk")); tb21.removeColumn(tb21.getColumn("id")); } /**=======================================================================** * [## private void buildDTM22() {} ]: * 参数 :无 * 返回值 :无 * 修饰符 :private * 功能 :初始化房间打折费列表 **=======================================================================** */ private void buildDTM22() { String sqlCode = "select pk,sysmark,id,foregift,r_type 房间类型,price 预设单价 from roomtype where delmark = 0"; sunsql.initDTM(dtm22,sqlCode); tb22.removeColumn(tb22.getColumn("pk")); tb22.removeColumn(tb22.getColumn("id")); tb22.removeColumn(tb22.getColumn("sysmark")); tb22.removeColumn(tb22.getColumn("foregift")); } /**=======================================================================** * [## private void buildDTM31() {} ]: * 参数 :无 * 返回值 :无 * 修饰符 :private * 功能 :初始化操作员列表 **=======================================================================** */ private void buildDTM31() { String sqlCode = "select pk,userid 用户登录ID,puis 用户权限 from pwd where delmark = 0"; sunsql.initDTM(dtm31,sqlCode); tb31.removeColumn(tb31.getColumn("pk")); sunsql.initJComboBox (cb31, "select userid from pwd where delmark=0"); } /**=======================================================================** * [## private JPanel jiFei() {} ]: * 参数 :无 * 返回值 :JPanel * 修饰符 :private * 功能 :计费设置 **=======================================================================** */ private JPanel jiFei() { JLabel lb1, lb2, lb3, lb4, lb5, lb6, lb7, lb8, lb9, lb10, lb11, lb12, lb13, lb14, lb15, lb16; //定义各方位面板 JPanel panelJF, jfTop, jfLeft, jfRight, jfBott; JPanel jp1, jp2, jp3, jp4, jp5, jp6, jp7, jp8, jp9; //定义标签 lb1 = new JLabel(" 客人开房时间在"); lb2 = new JLabel("点之后按新的一天开始计费"); lb3 = new JLabel(" 客人退房时间在"); lb4 = new JLabel("点之后计价天数自动追加半天"); lb5 = new JLabel(" 客人退房时间在"); lb6 = new JLabel("点之后计价天数自动追加一天"); lb7 = new JLabel(" 开房后"); lb8 = new JLabel("分钟开始计费"); lb9 = new JLabel(" 最少按"); lb10 = new JLabel("小时计费,小于这个时间的按此时间计费"); lb11 = new JLabel(" 若不足一小时但超过"); lb12 = new JLabel("分钟的部分按1小时计费"); lb13 = new JLabel(" 不足上面分钟数但超过"); lb14 = new JLabel("分钟的部分按半小时计费"); lb15 = new JLabel("注:此设置仅限于标准计费的钟点房! "); lb16 = new JLabel(" "); lb15.setForeground(new Color(255, 138, 0)); //初始化计时计费设置 tf41 = new TJTextField(sunini.getIniKey("In_Room"), 5); tf42 = new TJTextField(sunini.getIniKey("Out_Room1"), 5); tf43 = new TJTextField(sunini.getIniKey("Out_Room2"), 5); tf44 = new TJTextField(sunini.getIniKey("ClockRoom1"), 5); tf45 = new TJTextField(sunini.getIniKey("ClockRoom2"), 5); tf46 = new TJTextField(sunini.getIniKey("InsuHour1"), 5); tf47 = new TJTextField(sunini.getIniKey("InsuHour2"), 5); //设置文本框右对齐 tf41.setHorizontalAlignment(JTextField.RIGHT); tf42.setHorizontalAlignment(JTextField.RIGHT); tf43.setHorizontalAlignment(JTextField.RIGHT); tf44.setHorizontalAlignment(JTextField.RIGHT); tf45.setHorizontalAlignment(JTextField.RIGHT); tf46.setHorizontalAlignment(JTextField.RIGHT); tf47.setHorizontalAlignment(JTextField.RIGHT); //不足一天是否按一天计价 ck = new JCheckBox("入住时间不足一天的按一天计费"); if(sunini.getIniKey("InsuDay").equals("1")) { ck.setSelected(true); } bt41 = new TJButton ("pic/save.gif", " 保 存 ", "保存当前设置"); bt42 = new TJButton ("pic/exit.gif", " 返 回 ", "返回主窗口"); panelJF = new JPanel(new BorderLayout()); //计费主面板 jfTop = new JPanel(new GridLayout(2, 1)); //放左右面板 jfLeft = new JPanel(new GridLayout(4, 1)); //计费左面板 jfRight = new JPanel(new GridLayout(5, 1)); //计费右面板 jfBott = new JPanel(new FlowLayout(FlowLayout.RIGHT, 40, 4));//按键面板 jp1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); //左边的面板用到的 jp2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); jp3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); jp4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); jp5 = new JPanel(new FlowLayout(FlowLayout.LEFT)); //右边的面板用到的 jp6 = new JPanel(new FlowLayout(FlowLayout.LEFT)); jp7 = new JPanel(new FlowLayout(FlowLayout.LEFT)); jp8 = new JPanel(new FlowLayout(FlowLayout.LEFT)); jp9 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); //制作左边面板 jp1.add(lb1); jp1.add(tf41); jp1.add(lb2); jp2.add(lb3); jp2.add(tf42); jp2.add(lb4); jp3.add(lb5); jp3.add(tf43); jp3.add(lb6); jp4.add(lb16); //假空格 jp4.add(ck); jfLeft.add(jp1); jfLeft.add(jp2); jfLeft.add(jp3); jfLeft.add(jp4); //制作右边面板 jp5.add(lb7); jp5.add(tf44); jp5.add(lb8); jp6.add(lb9); jp6.add(tf45); jp6.add(lb10); jp7.add(lb11); jp7.add(tf46); jp7.add(lb12); jp8.add(lb13); jp8.add(tf47); jp8.add(lb14); jp9.add(lb15); jfRight.add(jp5); jfRight.add(jp6); jfRight.add(jp7); jfRight.add(jp8); jfRight.add(jp9); //组织两个表到一起 jfTop.add(jfLeft); jfTop.add(jfRight); //组织按键面板 jfBott.add(bt41); jfBott.add(bt42); //加入主面板 panelJF.add("Center", jfTop); panelJF.add("South", jfBott); jfLeft.setBorder(BorderFactory.createTitledBorder("普通房间标准计费")); jfRight.setBorder ( BorderFactory.createTitledBorder ("钟点房标准计费") ); return panelJF; } /**=======================================================================** * [## private boolean initMrt() {} ]: * 参数 :无 * 返回值 :boolean * 修饰符 :private * 功能 :传数据给修改房间类型窗口 **=======================================================================** */ private boolean initMrt() { int row = tb11.getSelectedRow(); if(row == -1) { JOptionPane.showMessageDialog(null, "请在上面类型表中指定房间类型," + "才能执行修改操作", "提示", JOptionPane.INFORMATION_MESSAGE); return false; } ModiRoomType.tf0.setText(dtm11.getValueAt(row,2) + ""); //类型编号 ModiRoomType.tf1.setText(dtm11.getValueAt(row,4) + ""); //类型名称 ModiRoomType.tf2.setText(dtm11.getValueAt(row,7) + ""); //床位数量 ModiRoomType.tf3.setText(dtm11.getValueAt(row,5) + ""); //预设单价 ModiRoomType.tf4.setText(dtm11.getValueAt(row,3) + ""); //预设押金 ModiRoomType.tf5.setText(dtm11.getValueAt(row,6) + ""); //钟点计费 String cl_room = dtm11.getValueAt(row, 8) + ""; if(cl_room.equals("Y")) { ModiRoomType.chk.setSelected(true); //允许提供钟点服务 } else { ModiRoomType.chk.setSelected(false); //不允许提供钟点服务 ModiRoomType.tf5.setEnabled(false); //设置钟点计费不可用 } return true; } /**=======================================================================** * [## private boolean initMri() {} ]: * 参数 :无 * 返回值 :boolean * 修饰符 :private * 功能 :传数据给修改房间信息窗口 **=======================================================================** */ private boolean initMri() { int row = tb12.getSelectedRow(); if(row == -1) { JOptionPane.showMessageDialog(null, "请在上面房间信息表中指定房间号," + "才能执行修改操作", "提示", JOptionPane.INFORMATION_MESSAGE); return false; } ModiRoomInfo.tf1.setText(dtm12.getValueAt(row, 2) + ""); //房间编号 ModiRoomInfo.tf2.setText(dtm12.getValueAt(row, 5) + ""); //所在区域 ModiRoomInfo.tf3.setText(dtm12.getValueAt(row, 6) + ""); //房间电话 ModiRoomInfo.pk = dtm12.getValueAt(row, 0) + ""; //获得当前行的PK try { ResultSet rs = sunsql.executeQuery("select r_type from roomtype " + "where delmark=0 and id='" + dtm12.getValueAt(row,1) + "'"); rs.next(); ModiRoomInfo.cb1.setSelectedItem(rs.getString(1)); //房间类型 } catch (Exception ex) { System.out.println ("ModiRoomInfo.initMri(): Modi false"); }//End try return true; } /**=======================================================================** * [## private boolean initMct() {} ]: * 参数 :无 * 返回值 :boolean * 修饰符 :private * 功能 :传数据给修改客户类型窗口 **=======================================================================** */ private boolean initMct() { int row = tb21.getSelectedRow(); if(row == -1) { JOptionPane.showMessageDialog(null, "请在上面类型表中指定客户类型," + "才能执行修改操作", "提示", JOptionPane.INFORMATION_MESSAGE); return false; } ModiCustomerType.tf1.setText(dtm21.getValueAt(row,1) + ""); //客户类型编号 ModiCustomerType.tf2.setText(dtm21.getValueAt(row,3) + ""); //客户类型名称 ModiCustomerType.tf3.setText(dtm21.getValueAt(row,4) + ""); //客户类型折扣 ModiCustomerType.pk = dtm21.getValueAt(row, 0) + ""; //获得当前行的PK return true; } /**=======================================================================** * [## private boolean initDis(JTable dtb, DefaultTableModel ddtm) {} ]: * 参数 :JTable 与 DefaultTableModel 为项目与折扣中的表 * 返回值 :boolean * 修饰符 :private * 功能 :传数据给打折设置窗口 **=======================================================================** */ private boolean initDis(JTable dtb, DefaultTableModel ddtm) { int row = dtb.getSelectedRow(); if(row == -1) { JOptionPane.showMessageDialog(null, "请在相应列表中指定房间类型," + "才能进行打折设置操作", "提示", JOptionPane.INFORMATION_MESSAGE); return false; } try { Discount.rt = ddtm.getValueAt(row, 2) + ""; //获得房间编号 ResultSet rs = sunsql.executeQuery("select discount from customertype " + "where id='SYSMARK' and dis_attr='" + ddtm.getValueAt(row, 2) + "'"); rs.next(); int temp = rs.getInt(1); if(temp == 10){ Discount.cb1.setSelectedIndex(1); //普通宾客不打折选项 Discount.tf1.setEnabled(false); }else { Discount.cb1.setSelectedIndex(0); //普通宾客打折选项 Discount.tf1.setEnabled(true); }//Endif Discount.tf1.setText(temp + ""); //普通宾客的折扣 } catch (Exception ex) { } Discount.lb1.setText(ddtm.getValueAt(row, 4) + ""); //房间类型名称 Discount.lb2.setText(ddtm.getValueAt(row, 5) + ""); //房间价格 //初始化表格的DTM sunsql.initDTM(Discount.dtm, "select c_type 客户等级,discount 享受折扣, " + "dis_price 折扣价格 from customertype where delmark=0 and dis_attr='" + ddtm.getValueAt(row, 2) + "' and id!='SYSMARK'"); //初始化会员等级ComboBox sunsql.initJComboBox(Discount.cb2, "select c_type from customertype where " + "delmark=0 and id!='SYSMARK' and dis_attr='" + ddtm.getValueAt(row, 2) + "'"); return true; } /**=======================================================================** * [## private boolean delInfo (String tName, DefaultTableModel delDtm, int dr[], String m) {} ]: * 参数 :Sring tName 表示要执行删除的表名 * DTM delDtm 表示相关联的DTM * int dr[] 要被执行删除的行数 * String m 提示信息 * 返回值 :boolean * 修饰符 :private * 功能 :房间类型、房间信息和客户类型的删操作 **=======================================================================** */ private boolean delInfo (String tName, DefaultTableModel delDtm, int dr[], String m) { int rowCount = dr.length; int r =0; //DTM行指针 if(tName.equals ("roomtype")) { //如果删除房间类型,则删除与房间类型相关的房间信息与客户折扣设置 rowCount = rowCount * 3; }//Endif if(rowCount > 0) { //判断选择记录数 int isDel = JOptionPane.showConfirmDialog (null, m, "提示", JOptionPane.YES_NO_OPTION); if(isDel == JOptionPane.YES_OPTION) { String sqlCode[] = new String[rowCount]; //生成SQL语句 for (int i = 0; i < rowCount; i++) { sqlCode[i] = "update " + tName +" set delmark=1 where pk=" + delDtm.getValueAt(dr[r], 0) + " and id='" + delDtm.getValueAt(dr[r],2) + "'"; if(tName.equals ("roomtype")) { //如果删除房间类型,则同时删除相关房间信息 i++; sqlCode[i] = "update roominfo set delmark=1 where id='sunhotel' or r_type_id='" + delDtm.getValueAt(dr[r],2) + "'"; i++; sqlCode[i] = "update customertype set delmark=1 where id='sunhotel' or dis_attr='" + delDtm.getValueAt(dr[r],2) + "'"; } r++; //DTM行指针加1 }//Endfor //以事务模式执行SQL语句组, 确保操作正确, 返回值为成功执行SQL语句的条数 isDel = sunsql.runTransaction(sqlCode); if(isDel != rowCount) { //如果成功执行的条数 = 数组长度,则表示更新成功 String mm = "在执行第 [ " + (isDel + 1) + " ] 条记录的删除操作时出错,数据有可能被其它终端修改\n或者是网络不通畅 ..."; JOptionPane.showMessageDialog(null, mm, "错误",JOptionPane.ERROR_MESSAGE); //更新失败,返回false return false; }//Endif return true; //更新成功,返回true }//Endif } else //如果没有选中记录,则提示一下 JOptionPane.showMessageDialog(null, msg1, "提示",JOptionPane.INFORMATION_MESSAGE); return false; } /**=======================================================================** * [## private void umAdd () {} ]: 添加操作 * 参数 :无 * 返回值 :无 * 修饰符 :private * 功能 :添加新的用户ID **=======================================================================** */ private void umAdd () { String pwd1 = String.valueOf(tf32.getPassword()); String pwd2 = String.valueOf(tf33.getPassword()); String pu = "普通操作员"; //用户权限 if(!pwd1.equals (pwd2)) { //两次密码不相等 JOptionPane.showMessageDialog (null, "输入错误,[ 新密码 ] 与 [ 确认密码 ] " + "不正确,请重新输入 ...", "错误",JOptionPane.ERROR_MESSAGE); return; }//Endif String umName = cb31.getEditor ().getItem () + "";//获得用户名 try { ResultSet rs = sunsql.executeQuery ("select userid from pwd where delmark=0 " + "and userid='" + umName + "'"); int isID = sunsql.recCount(rs); if(isID > 0){ //当前要加入的用户名是否存在 JOptionPane.showMessageDialog (null, "管理员ID [ " + umName + " ] 已存在," + "请重新输入 ...", "错误",JOptionPane.ERROR_MESSAGE); return; }//Endif if(rb35.isSelected()) //获得是否是管理员权限 pu = "管理员"; long pk = sunsql.getPrimaryKey();//从服务获得主键 //记入数据库 isID = sunsql.executeUpdate("insert into pwd(pk,userid,pwd,puis) values(" + pk + ",'" + umName + "','" + pwd1 + "','" + pu + "')"); if(isID == 0) { JOptionPane.showMessageDialog (null, "添加操作失败,请检查网络连接是否正常 " + "...", "错误",JOptionPane.ERROR_MESSAGE); return; } tf32.setText(""); //清空密码 tf33.setText(""); } catch (Exception ex) { System.out.println ("UserID.umAdd(): Add new ID error."); }//End try } /**=======================================================================** * [## private void umUpdate (int type) {} ]: 更新删除操作 * 参数 :int 变量表示操作类型 0:表示修改密码 1:表示删除记录 * 返回值 :无 * 修饰符 :private * 功能 :修改密码和删除用户ID **=======================================================================** */ private void umUpdate (int type) { String umName = cb31.getSelectedItem() + ""; //获得用户名 String pwd0; String pwd1 = String.valueOf (tf32.getPassword ()); String pwd2 = String.valueOf (tf33.getPassword ()); int isID = 0; //用户是否存在 if(!pwd1.equals (pwd2)) { //两次密码不相等 JOptionPane.showMessageDialog (null, "输入错误,[ 新密码 ] 与 [ 确认密码 ] " + "不正确,请重新输入 ...", "错误",JOptionPane.ERROR_MESSAGE); return; }//Endif if(type == 0) pwd0 = String.valueOf (tf31.getPassword ());//取修改操作的密码 else pwd0 = String.valueOf (tf32.getPassword ());//取删除操作的密码 try { ResultSet rs = sunsql.executeQuery ("select pwd from pwd where delmark=0 and " + "userid='" + umName + "'"); rs.next(); if(!pwd0.equals(rs.getString(1))){ //判断原密码是否正确 JOptionPane.showMessageDialog (null, "管理员ID [ " + umName + " ] 的 [ 原" + "密码 ] 不正确,请重新输入 ...", "错误",JOptionPane.ERROR_MESSAGE); return; }//Endif if(type == 0) { //执行修改密码操作 isID = sunsql.executeUpdate("update pwd set pwd='" + pwd1 + "' where " + "delmark=0 and userid='" + umName + "'"); }else { //执行删除操作 isID = sunsql.executeUpdate("update pwd set delmark=1 where userid='" + umName + "'"); }//Endif } catch (Exception ex) { }//End try if(isID == 0) { //判断操作是否成功 JOptionPane.showMessageDialog (null, "执行操作失败,请检查网络连接是否正常 ...", "错误",JOptionPane.ERROR_MESSAGE); } tf31.setText(""); //清空密码 tf32.setText(""); tf33.setText(""); return; } //检查计费设置是否合法 private boolean isValidity() { if(!suntools.isNum(tf41.getText(), 1, 6, 9)) { JOptionPane.showMessageDialog(null, "[ 计费参数 1 ] 只能是数字,且范围在 6-9 之间", "提示", JOptionPane.INFORMATION_MESSAGE); tf41.requestFocus(true); return false; }else if(!suntools.isNum(tf42.getText(), 2, 11, 13)) { JOptionPane.showMessageDialog(null, "[ 计费参数 2 ] 只能是数字,且范围在 11-13 之间", "提示", JOptionPane.INFORMATION_MESSAGE); tf42.requestFocus(true); return false; }else if(!suntools.isNum(tf43.getText(), 2, 17, 19)) { JOptionPane.showMessageDialog(null, "[ 计费参数 3 ] 只能是数字,且范围在 17-19 之间", "提示", JOptionPane.INFORMATION_MESSAGE); tf43.requestFocus(true); return false; }else if(!suntools.isNum(tf44.getText(), 1, 0, 5)) { JOptionPane.showMessageDialog(null, "[ 钟点计费参数 1 ] 只能是数字,且范围在 0-5 之间", "提示", JOptionPane.INFORMATION_MESSAGE); tf44.requestFocus(true); return false; }else if(!suntools.isNum(tf45.getText(), 1, 1, 5)) { JOptionPane.showMessageDialog(null, "[ 钟点计费参数 2 ] 只能是数字,且范围在 1-5 之间", "提示", JOptionPane.INFORMATION_MESSAGE); tf45.requestFocus(true); return false; }else if(!suntools.isNum(tf46.getText(), 2, 20, 40)) { JOptionPane.showMessageDialog(null, "[ 钟点计费参数 3 ] 只能是数字,且范围在 20-40 之间", "提示", JOptionPane.INFORMATION_MESSAGE); tf46.requestFocus(true); return false; }else if(!suntools.isNum(tf47.getText(), 2, 5, 15)) { JOptionPane.showMessageDialog(null, "[ 钟点计费参数 4 ] 只能是数字,且范围在 5-15 之间", "提示", JOptionPane.INFORMATION_MESSAGE); tf47.requestFocus(true); return false; }//endif return true; } /**=======================================================================** * [## private boolean isState(int aRow[]) {} ]: * 参数 :int aRom[] 表示要执行删除操作的行号 * 返回值 :boolean * 修饰符 :private * 功能 :检查房间的状态是否可以删除 **=======================================================================** */ private boolean isState(int aRow[]) { int ar = aRow.length; ResultSet rs = null; String aState = ""; try { for (int i = 0; i < ar; i++) { rs = sunsql.executeQuery("select state from roominfo where " + "delmark=0 and pk='" + dtm12.getValueAt(aRow[i], 0) + "'"); rs.next(); aState = rs.getString(1); if(aState.equals("占用")) { JOptionPane.showMessageDialog(null, "[ " + dtm12.getValueAt(aRow[i], 2) + " ] 房间正处于占用状态,无法执行删除操作,系统取消了所有删除操作", "提示", JOptionPane.INFORMATION_MESSAGE); return false; }else if(aState.equals("钟点")) { JOptionPane.showMessageDialog(null, "[ " + dtm12.getValueAt(aRow[i], 2) + " ] 房间正处于钟点房状态,无法执行删除操作,系统取消了所有删除操作", "提示", JOptionPane.INFORMATION_MESSAGE); return false; }else if(aState.equals("预订")) { JOptionPane.showMessageDialog(null, "[ " + dtm12.getValueAt(aRow[i], 2) + " ] 房间正处于预订状态,无法执行删除操作,系统取消了所有删除操作", "提示", JOptionPane.INFORMATION_MESSAGE); return false; }//Endif }//Endif } catch (Exception ex) { ex.printStackTrace(); System.out.println ("Setup.isState(): false"); }//End try return true; } /**=======================================================================** * ActionListener 监听 **=======================================================================** */ public void actionPerformed(ActionEvent ae) { Object o = ae.getSource(); if(o == bt11) {//======================================================= art.show(true); //添加房间类型 buildDTM11(); //刷新表数据 buildDTM12(""); //刷新表数据 buildDTM22(); //刷新表数据 }else if(o == bt12) {//================================================= if(initMrt()) { //传数据给窗口 mrt.show(true); //修改房间类型 buildDTM11(); //刷新表数据 buildDTM12(""); //刷新表数据 buildDTM22(); //刷新表数据 }//Endif }else if(o == bt13) {//================================================= int rRow[] = tb11.getSelectedRows(); //删除房间类型 int sysmark; for (int i = 0; i < rRow.length; i++) { //获得得记录的属性标志,并转成整型 sysmark = Integer.parseInt(dtm11.getValueAt(rRow[i], 1) + ""); if(sysmark == 1) { JOptionPane.showMessageDialog(null, "[ " + dtm11.getValueAt(rRow[i], 4) + " ] 类型为系统级设置,不允许被删除,系统终止了删除操作 ...", "提示", JOptionPane.INFORMATION_MESSAGE); return; //不执行删除返回窗口 }//Endif }//Endfor String msg = "注意,删除 [ 房间类型 ] 操作会将与 [ 房间类型 ] 相关" + "的所有 [ 房间信息 ] 一并删除。\n您确定要删除在表格中选中的类型条目吗?"; if(delInfo ("roomtype", dtm11, rRow, msg)) { //执行删除操作 buildDTM11(); //刷新类型表数据 buildDTM12(""); //刷新房间表数据 buildDTM22(); //刷新类型表数据 journal = "执行了删除房间类型的操作--删除数量:" + rRow.length; Journal.writeJournalInfo(HotelFrame.userid, journal, Journal.TYPE_RT);//记录操作日志 }//Endif }else if(o == bt14) {//================================================= if(initDis(tb11, dtm11)) { //房间费打折 dis.show(true); }//Endif }else if(o == bt15) {//================================================= sunsql.initJComboBox(AddRoomInfo.cb1, "select r_type from roomtype where delmark = 0"); ari.show(true); //单个添加房间信息 buildDTM12(""); //刷新表数据 }else if(o == bt16) {//================================================= sunsql.initJComboBox(AddRoomInfos.cb, "select r_type from roomtype where delmark = 0"); aris.show(true); //批量添加房间信息 buildDTM12(""); //刷新表数据 }else if(o == bt18) {//================================================= sunsql.initJComboBox(ModiRoomInfo.cb1, "select r_type from roomtype where delmark = 0"); if(initMri()) { //传数据给窗口 mri.show(true); //修改房间信息 buildDTM12(""); //刷新表数据 }//Endif }else if(o == bt17) {//================================================= int rRow[] = tb12.getSelectedRows(); //删除房间信息 if(isState(rRow)) { //判断房间的状态是否可以删除 if(delInfo ("roominfo", dtm12, rRow, msg0)) { //执行删除操作 buildDTM12(""); //刷新房间表数据 journal = "执行了删除房间信息的操作--删除数量:" + rRow.length; Journal.writeJournalInfo(HotelFrame.userid, journal, Journal.TYPE_RI);//记录操作日志 }//Endif } }else if(o == bt19) {//================================================= if(!suntools.isNum(tf11.getText(),2 ,5 ,30)) { //保存退房后房间状态 JOptionPane.showMessageDialog(null, "结算后更改房间状态的时间框只能为数字,且范围在 5 - 30 之间", "提示", JOptionPane.INFORMATION_MESSAGE); tf11.requestFocus(true); return; } sunini.setIniKey(ini[16], cb12.getSelectedIndex() + ""); //将设置保存至缓冲区 sunini.setIniKey(ini[17], tf11.getText()); sunini.saveIni(ini); //将缓冲区的设置保存至INI文件 }else if(o == bt20) {//================================================= int cbIndex = cb11.getSelectedIndex(); //筛选信息 if(cbIndex == cb11.getItemCount() - 1) { //显示全部房间 buildDTM12(""); //刷新房间表数据 }else { String rt = "and a.r_type_id = '" + dtm11.getValueAt(cbIndex, 2) + "'"; buildDTM12(rt); //根据指定房间类型刷新表数据 }//Endif }else if(o == bt21) {//================================================= act.show(true); //添加客户类型 buildDTM21(); }else if(o == bt22) {//================================================= if(initMct()) { //传数据给窗口 mct.show(true); //修改客户类型 buildDTM21(); //刷新表数据 }//Endif }else if(o == bt23) {//================================================= int rRow[] = tb21.getSelectedRows(); //删除客户类型 if(delInfo ("customertype", dtm21, rRow, msg0)) { //执行删除操作 buildDTM21(); //刷新房间表数据 journal = "执行了删除客户类型的操作--删除数量:" + rRow.length; Journal.writeJournalInfo(HotelFrame.userid, journal, Journal.TYPE_US);//记录操作日志 }//Endif }else if(o == bt24) {//================================================= if(initDis(tb22, dtm22)) { //房间费打折 dis.show(true); }//Endif }else if(o == bt31) {//===================================//登记操作员信息 if(String.valueOf(tf32.getPassword()).length() == 0) { JOptionPane.showMessageDialog(null, " [ 新密码 ] 不能为空", "提示", JOptionPane.INFORMATION_MESSAGE); return; }else if(String.valueOf(tf33.getPassword()).length() == 0) { JOptionPane.showMessageDialog(null, " [ 确认密码 ] 不能为空", "提示", JOptionPane.INFORMATION_MESSAGE); return; }//Endif umAdd (); //执行添加操作 buildDTM31(); //刷新表数据 journal = "添加了新的操作员信息-- [ " + cb31.getEditor ().getItem () + " ]"; Journal.writeJournalInfo(HotelFrame.userid, journal, Journal.TYPE_CZ);//记录操作日志 }else if(o == bt32) {//==================================//修改操作员信息 if(String.valueOf(tf31.getPassword()).length() == 0) { JOptionPane.showMessageDialog(null, " [ 新密码 ] 不能为空", "提示", JOptionPane.INFORMATION_MESSAGE); return; }else if(String.valueOf(tf32.getPassword()).length() == 0) { JOptionPane.showMessageDialog(null, " [ 新密码 ] 不能为空", "提示", JOptionPane.INFORMATION_MESSAGE); return; }else if(String.valueOf(tf33.getPassword()).length() == 0) { JOptionPane.showMessageDialog(null, " [ 确认密码 ] 不能为空", "提示", JOptionPane.INFORMATION_MESSAGE); return; }//Endif umUpdate (0); //执行修改密码操作 journal = "修改了操作员 [ " + cb31.getEditor ().getItem () + " ] 的设置"; Journal.writeJournalInfo(HotelFrame.userid, journal, Journal.TYPE_CZ);//记录操作日志 }else if(o == bt33) {//=================================================//删除操作员信息 if(String.valueOf(tf32.getPassword()).length() == 0) { JOptionPane.showMessageDialog(null, " [ 新密码 ] 不能为空", "提示", JOptionPane.INFORMATION_MESSAGE); return; }else if(String.valueOf(tf33.getPassword()).length() == 0) { JOptionPane.showMessageDialog(null, " [ 确认密码 ] 不能为空", "提示", JOptionPane.INFORMATION_MESSAGE); return; }//Endif int wi = JOptionPane.showConfirmDialog(null,"您确认要删除当前的用户ID吗?", "提示", JOptionPane.YES_NO_OPTION); if(wi == JOptionPane.YES_OPTION) { umUpdate (1); //执行删除用户ID操作 buildDTM31(); //刷新表数据 journal = "删除了操作员 [ " + cb31.getEditor ().getItem () + " ] 的设置"; Journal.writeJournalInfo(HotelFrame.userid, journal, Journal.TYPE_CZ);//记录操作日志 }//Endif }else if(o == bt41) {//================================================= if(isValidity()) { int saveJf = JOptionPane.showConfirmDialog(null, "您 确 实 要 保 存 " + "当 前 的 计 费 设 置 吗 ?","保存设置",JOptionPane.YES_NO_OPTION); if(saveJf == JOptionPane.YES_OPTION) { //保存计费设置 sunini.setIniKey("In_Room", tf41.getText()); //将设置保存至缓冲区 sunini.setIniKey("Out_Room1", tf42.getText()); sunini.setIniKey("Out_Room2", tf43.getText()); sunini.setIniKey("ClockRoom1", tf44.getText()); sunini.setIniKey("ClockRoom2", tf45.getText()); sunini.setIniKey("InsuHour1", tf46.getText()); sunini.setIniKey("InsuHour2", tf47.getText()); if(ck.isSelected()) { //不足一天按一天收费 sunini.setIniKey("InsuDay","1"); }else { sunini.setIniKey("InsuDay","0"); }//Endif sunini.saveIni(ini); //将缓冲区的设置保存至INI文件 journal = "修改了系统的计费设置"; Journal.writeJournalInfo(HotelFrame.userid, journal, Journal.TYPE_JF);//记录操作日志 }//Endif }//Endif }else if(o == bt42) {//================================================= this.setVisible(false); //返回主窗口 }else if(o == tf41) { tf42.requestFocus(true); }else if(o == tf42) { tf43.requestFocus(true); }else if(o == tf43) { tf44.requestFocus(true); }else if(o == tf44) { tf45.requestFocus(true); }else if(o == tf45) { tf46.requestFocus(true); }else if(o == tf46) { tf47.requestFocus(true); }else if(o == rb31) {//================================================= bt31.setEnabled (true); //操作范围--添加新操作员 bt32.setEnabled (false); bt33.setEnabled (false); rb34.setEnabled (true); rb35.setEnabled (true); tf31.setEditable(false); tf32.setEditable(true); tf33.setEditable(true); cb31.setEditable (true); }else if(o == rb32) { //操作范围--操作员修改密码 bt31.setEnabled (false); bt32.setEnabled (true); bt33.setEnabled (false); rb34.setEnabled (false); rb35.setEnabled (false); tf31.setEditable(true); tf32.setEditable(true); tf33.setEditable(true); cb31.setEditable (false); }else if(o == rb33) { //操作范围--删除操作员 bt31.setEnabled (false); bt32.setEnabled (false); bt33.setEnabled (true); rb34.setEnabled (false); rb35.setEnabled (false); tf31.setEditable(false); tf32.setEditable(true); tf33.setEditable(true); cb31.setEditable (false); }//Endif }//End actionPerformed /**=======================================================================** * MouseListener 监听 **=======================================================================** */ public void mouseClicked (MouseEvent me) { } public void mousePressed (MouseEvent me) { } public void mouseReleased(MouseEvent me) { } public void mouseEntered (MouseEvent me) { //鼠标移进提示 Object o = me.getSource (); if(o == bt11) { HotelFrame.lbA.setText (HotelFrame.clue + "添加新的房间类型 "); }else if(o == bt12) { HotelFrame.lbA.setText (HotelFrame.clue + "修改指定的房间类型 "); }else if(o == bt13) { HotelFrame.lbA.setText (HotelFrame.clue + "删除指定的房间类型 "); }else if(o == bt14) { HotelFrame.lbA.setText (HotelFrame.clue + "设置指定房间类型的消费折扣 "); }else if(o == bt15) { HotelFrame.lbA.setText (HotelFrame.clue + "为指定的房间类型添加新的客房 "); }else if(o == bt16) { HotelFrame.lbA.setText (HotelFrame.clue + "为指定的房间类型一次添加多个新客房 "); }else if(o == bt17) { HotelFrame.lbA.setText (HotelFrame.clue + "修改指定客房信息设置 "); }else if(o == bt18) { HotelFrame.lbA.setText (HotelFrame.clue + "删除指定的客房 "); }else if(o == bt19) { HotelFrame.lbA.setText (HotelFrame.clue + "保存房间退房后的状态 "); }else if(o == bt20) { HotelFrame.lbA.setText (HotelFrame.clue + "以左边指定的类型显示房间信息 "); } if(o == bt21) { HotelFrame.lbA.setText (HotelFrame.clue + "添加新的客户类型 "); }else if(o == bt22) { HotelFrame.lbA.setText (HotelFrame.clue + "修改指定的客户资料 "); }else if(o == bt23) { HotelFrame.lbA.setText (HotelFrame.clue + "删除指定的客户资料 "); }else if(o == bt24) { HotelFrame.lbA.setText (HotelFrame.clue + "设置指定房间类型的消费折扣 "); }else if(o == bt31) { HotelFrame.lbA.setText (HotelFrame.clue + "添加新的操作员 "); }else if(o == bt32) { HotelFrame.lbA.setText (HotelFrame.clue + "修改指定的操作员密码 "); }else if(o == bt33) { HotelFrame.lbA.setText (HotelFrame.clue + "删除指定的操作员 "); }else if(o == bt41) { HotelFrame.lbA.setText (HotelFrame.clue + "保存当前的计费设置至INI配置文件 "); }else if(o == bt42) { HotelFrame.lbA.setText (HotelFrame.clue + "返回主窗口 "); } } public void mouseExited (MouseEvent me) { HotelFrame.lbA.setText (HotelFrame.clue + "请选择功能项 ... "); } }
3.登录窗口:
/** *############################################################################## * * [ 项目名 ] : 阳光酒店管理系统 * [ 公司名 ] : 清华IT * [ 模块名 ] : 系统登陆窗口 * [ 文件名 ] : Login.java * [ 相关文件 ] : * [ 文件实现功能] : 系统登陆窗口 * [ 作者 ] : 顾俊 * [ 版本 ] : 1.1 * ---------------------------------------------------------------------------- * [ 备注 ] : * ---------------------------------------------------------------------------- * [ 修改记录 ] : * * [ 日 期 ] [版本] [修改人] [修改内容] * 2006/04/02 1.0 顾俊 创建 * 2006/04/06 1.1 顾俊 增加注释 * 2006/04/19 1.2 顾俊 自动记录登录日志 * ##-------------------------------------------------------------------------- * 版权所有(c) 2006-2007, SunshineSOFT Corporation * --------------------------------------------------------------------------## * * [ 函数说明 ] : * * [## public Login() {} ]: * 功能: 构造函数 组建登录窗口 * * [## private void buildCenter() {} ]: * 功能: 组建用户名密码面板,仅类内使用 * * [## private void quit() {} ]: * 功能: 关闭系统函数,仅类内使用 * * [## private void dengLu() {} ]: * 功能: 密码验证通过,进入主操作界面,仅类内使用 * * [ 遗留问题 ] : * *############################################################################## */ //package com.sunshine.login; import javax.swing.*; import javax.swing.border.*; 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 Login extends JFrame implements ActionListener, KeyListener, ItemListener, FocusListener { JLabel top, bott; JComboBox cb; JPasswordField pf; JButton bt1, bt2; JPanel panelMain, panelInfo; String clue = " 提 示 : "; int flag = 0; //登记次数记数器 /**=======================================================================** * [## public Login() {} ]: 构造函数 * 参数 :无 * 返回值 :无 * 修饰符 :public * 功能 :组建登录窗口 **=======================================================================** */ public Login() { super("系 统 登 录"); top = new JLabel (new ImageIcon("pic/login_top.gif")); bott = new JLabel(); panelMain = new JPanel(new BorderLayout(10, 10)); bott.setBorder(new LineBorder (new Color(184, 173, 151))); buildCenter(); panelMain.add("North", top); panelMain.add("South", bott); panelMain.add(panelInfo); //加事件监听 bt1.addActionListener(this); bt2.addActionListener(this); bt1.addFocusListener (this); bt2.addFocusListener (this); bt1.addKeyListener (this); bt2.addKeyListener (this); cb.addItemListener (this); cb.addFocusListener(this); pf.addFocusListener(this); cb.addKeyListener (this); pf.addKeyListener (this); //加窗口监听 new WindowAdapter适配器类 this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { quit(); }//End windowClosing }); this.setContentPane(panelMain); //设置窗口面板 this.setSize(350, 235); this.setResizable (false); //设置窗口不可放大缩小 this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); sunswing.setWindowCenter(this); this.setVisible(true); pf.requestFocus(true); //设置焦点给密码框 } /**=======================================================================** * [## private void buildCenter() {} ]: 制作用户名密码面板 * 参数 :无 * 返回值 :无 * 修饰符 :private * 功能 :组建用户名密码面板,仅类内使用 **=======================================================================** */ private void buildCenter() { JLabel lb1, lb2; JPanel pa1, pa2, pa3; lb1 = new JLabel("用 户 名 :"); lb2 = new JLabel("登录密码 :"); cb = new JComboBox(); pf = new TJPasswordField (15); bt1 = new TJButton ("pic/key.gif", "登 录", "登录系统"); bt2 = new TJButton ("pic/exit.gif", "退 出", "关闭系统"); sunsql.initJComboBox (cb, "select userid from pwd where delmark=0"); //定义面板为无部局 panelInfo = new JPanel(null); //加入组件 panelInfo.add(lb1); panelInfo.add(lb2); panelInfo.add(cb); panelInfo.add(pf); panelInfo.add(bt1); panelInfo.add(bt2); lb1.setBounds(50,14,60,20); lb2.setBounds(50,48,60,20); bt1.setBounds(68,77,86,28); bt2.setBounds(186,77,86,28); cb.setBounds (115,12,168,23); pf.setBounds (115,46,170,23); //设定边框线 panelInfo.setBorder(BorderFactory.createTitledBorder("")); } /**=======================================================================** * [## private void quit() {} ]: 系统退出 * 参数 :无 * 返回值 :无 * 修饰符 :private * 功能 :关闭系统函数,仅类内使用 **=======================================================================** */ private void quit() { int flag = 0; String msg = "您 现 在 要 关 闭 系 统 吗 ?"; flag = JOptionPane.showConfirmDialog(null, msg, "提示", JOptionPane.YES_NO_OPTION); if(flag == JOptionPane.YES_OPTION) { this.setVisible(false); System.exit(0); }//End if(flag == JOptionPane.YES_OPTION) return; } /**=======================================================================** * [## private void dengLu() {} ]: 系统登录 * 参数 :无 * 返回值 :无 * 修饰符 :private * 功能 :密码验证通过,进入主操作界面,仅类内使用 **=======================================================================** */ private void dengLu() { String user = cb.getSelectedItem() + ""; String pwd = String.valueOf(pf.getPassword()); String code = "select pwd,puis from pwd where delmark=0 and userid='" + user + "'"; ResultSet rs = sunsql.executeQuery (code); try { if(rs.next()) { //用户名存在 if(pwd.equals(rs.getString(1))) { bott.setText(clue + "登录成功,正在进入系统 ..."); String puis = rs.getString(2); //获得操作员权限 boolean flag = Journal.writeJournalInfo(user, "登录本系统", Journal.TYPE_LG); if(flag) { //记录日志 new com.sunshine.mainframe.HotelFrame(user, puis); //进入主程序窗口(用户名, 权限) this.setVisible(false); }else { String msg = "写日志错误,请与系统管理员联系 ..."; JOptionPane.showMessageDialog(null, msg, "错误", JOptionPane.ERROR_MESSAGE); System.exit(0); } } else { bott.setText(clue + "用户 [ " + user + " ] 的密码不正确,请重新输入 ..."); flag++; if(flag == 3) { //三次密码验证 JOptionPane.showMessageDialog(null, "您不是本系统的管理员,系统关闭 ...", "警告", JOptionPane.ERROR_MESSAGE); System.exit(0); }//End if(flag == 3) return; }//End if(pwd.equals(rs.getString(1))) } else { bott.setText(clue + "用户ID [ " + user + " ] 不存在 ..."); }//End if(rs.next()) } catch (Exception ex) { ex.printStackTrace(); }//End try } /**=======================================================================** * ActionListener 监听 **=======================================================================** */ public void actionPerformed (ActionEvent ae) { //动作监听 if(ae.getSource() == bt1) { //登录按键 dengLu(); } else { quit(); }//End if(ae.getSource() == bt1) } /**=======================================================================** * ItemListener 监听 **=======================================================================** */ public void itemStateChanged (ItemEvent ie) { pf.requestFocus(true); } /**=======================================================================** * KeyListener 监听 **=======================================================================** */ public void keyPressed (KeyEvent ke) { //键盘按下监听 int key = ke.getKeyCode(); if(key == KeyEvent.VK_ENTER) { if(ke.getSource() == cb) pf.requestFocus(true); //将焦点从用户名给密码 if(pf.getPassword().length > 0) dengLu(); //按Enter键登录系统 } else if(key == KeyEvent.VK_ESCAPE) { //按ESC键退出系统 quit(); }//End if } public void keyReleased (KeyEvent ke) { //键盘释放监听 } public void keyTyped (KeyEvent ke) { //按键型监听 } /**=======================================================================** * FocusListener 监听 **=======================================================================** */ public void focusGained (FocusEvent fe) { //焦点监听 if(fe.getSource() == cb) //窗口最下方的功能提示 bott.setText(clue + "请选择操作员名称 ..."); else if(fe.getSource() == pf) bott.setText(clue + "请输入登录密码 ..."); else if(fe.getSource() == bt1) bott.setText(clue + "登录系统 ..."); else if(fe.getSource() == bt2) bott.setText(clue + "退出系统 ..."); } public void focusLost (FocusEvent fe) { //失去焦点监听 } /**=======================================================================** * [## public static void main(String sd[]) {} ]: 主函数 * 参数 :String sd[] * 返回值 :无 * 修饰符 :public static * 功能 :程序入口 **=======================================================================** */ public static void main(String sd[]) { sunswing.setWindowStyle(sunini.getIniKey("Sys_style").charAt(0)); new FStartWindow ("pic/Login.gif", new Frame(), 1200); new Login(); } }
获取地址:Java swing实现酒店管理系统
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。