📄 setup.java
字号:
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -