📄 houseinfo.java~52~
字号:
String ID = new String();
try {
ResultSet rs = db.getResult(sql);
if (rs.first()) {
ID = rs.getString("ID");
}
else {
rs.close();
}
}
catch (Exception e) {
e.printStackTrace();
}
return ID;
}
//根据房主姓名得到房主ID
//与房产坐落类似,住房信息表中住户信息项存储的是房主ID,所以在保存时首先要将房主姓名转化为房主ID
String getOwnerID(String owner) {
String sql = "select * from OwnerInfo where name='" + owner + "'";
String ID = new String();
try {
ResultSet rs = db.getResult(sql);
if (rs.first()) {
ID = rs.getString("ID");
}
else {
CommonDialog.showDialog(CommonDialog.OK, "房产管理系统", "当前住户不存在,请先增加其基本信息!");
rs.close();
return "";
}
}
catch (Exception e) {
e.printStackTrace();
}
return ID;
}
void groupSetEnabled(boolean enabled) {
txtArea.setEnabled(enabled);
txtBuyPrice.setEnabled(enabled);
txtRoomNum.setEnabled(enabled);
txtBuyTime.setEnabled(enabled);
txtHouseName.setEnabled(enabled);
txtYTArea.setEnabled(enabled);
txtOwner.setEnabled(enabled);
cboHouseLocation.setEnabled(enabled);
cboHeading.setEnabled(enabled);
cboUseType.setEnabled(enabled);
}
void btnSetEnabled(boolean add, boolean edit, boolean delete, boolean save) {
btnAdd.setEnabled(add);
btnEdit.setEnabled(edit);
btnDelete.setEnabled(delete);
btnSave.setEnabled(save);
}
void clearData() {
txtArea.setText("");
txtBuyPrice.setText("");
txtRoomNum.setText("");
txtBuyTime.setText("");
txtHouseName.setText("");
txtYTArea.setText("");
txtOwner.setText("");
cboHouseLocation.setSelectedItem(null);
cboHeading.setSelectedItem(null);
cboUseType.setSelectedItem(null);
}
boolean checkData() {
if (cboHouseLocation.getSelectedIndex() < 0) {
CommonDialog.showDialog(CommonDialog.OK, "房产管理系统", "房屋坐落不能为空!");
return false;
}
if (txtHouseName.getText().trim().equals("")) {
CommonDialog.showDialog(CommonDialog.OK, "房产管理系统", "房间号不能为空!");
txtHouseName.setFocusable(true);
return false;
}
return true;
}
void btnSave_actionPerformed(ActionEvent e) {
System.out.println("here");
if (!checkData()) {
return;
}
String sql = new String();
String id = new String();
String locationID = new String();
String name = new String();
String heading = new String();
String roomNum = new String();
String useType = new String();
String buyTime = new String();
String buyPrice = new String();
String area = new String();
String ytArea = new String();
String ownerID = new String();
locationID = getLocationID(cboHouseLocation.getSelectedItem().toString());
if (!txtOwner.getText().equals("")) {
ownerID = getOwnerID(txtOwner.getText());
if (ownerID.equals("")) {
return;
}
}
if (cboHeading.getSelectedIndex() >= 0) {
heading = db.CodeDesConvert("Heading", "",
cboHeading.getSelectedItem().toString(), 0);
}
if (cboUseType.getSelectedIndex() >= 0) {
useType = db.CodeDesConvert("UseType", "",
cboUseType.getSelectedItem().toString(), 0);
}
if (!txtRoomNum.getText().equals("")) {
roomNum = txtRoomNum.getText().trim();
}
if (!txtBuyPrice.getText().equals("")) {
buyPrice = txtBuyPrice.getText().trim();
}
if (!txtArea.getText().equals("")) {
area = txtArea.getText().trim();
}
if (!txtYTArea.getText().equals("")) {
ytArea = txtYTArea.getText().trim();
}
if (operType.equals("add")) {
id = db.getID("HouseInfo","ID");
setCurID(id);
sql = "insert into HouseInfo values('" + id + "','" + locationID + "','" +
txtHouseName.getText() + "','" + heading + "','" + roomNum + "','" +
useType + "','" + txtBuyTime.getText() + "','" + buyPrice +
"','" + area + "','" + ytArea + "','" + ownerID + "')";
}
else if (operType.equals("edit")) {
sql = "update HouseInfo set BuildID='" + locationID + "',";
sql = sql + " Name='" + txtHouseName.getText() + "',";
sql = sql + " Heading='" + heading + "',";
sql = sql + " Number='" + roomNum + "',";
sql = sql + " UseType='" + useType + "',";
sql = sql + " BuyTime='" + txtBuyTime.getText() + "',";
sql = sql + " BuyPrice='" + buyPrice + "',";
sql = sql + " Area='" + area + "',";
sql = sql + " YTArea='" + ytArea + "',";
sql = sql + " OwnerID='" + ownerID + "'";
sql = sql + " where ID='" + curID + "'";
}
if (db.executeSql(sql)) {
CommonDialog.showDialog(CommonDialog.OK, "房产管理系统", "新增住房信息成功!");
groupSetEnabled(false);
btnSetEnabled(true, true, true, false);
setOperType("none");
}
else {
CommonDialog.showDialog(CommonDialog.OK, "房产管理系统", "新增住房信息失败!");
}
}
void btnEdit_actionPerformed(ActionEvent e) {
groupSetEnabled(true);
btnSetEnabled(true, true, true, true);
setOperType("edit");
}
void btnDelete_actionPerformed(ActionEvent e) {
if (!curID.equals("")) {
int ir = CommonDialog.showDialog(3, "房产管理系统", "确定要删除当前记录吗?");
if (ir == 2) {
return;
}
String sql = "delete from HouseInfo where ID='" + curID + "'";
if (db.executeSql(sql)) {
CommonDialog.showDialog(CommonDialog.OK, "房产管理系统", "删除记录成功!");
clearData();
groupSetEnabled(false);
btnSetEnabled(true, false, false, false);
setOperType("none");
}
else {
CommonDialog.showDialog(CommonDialog.OK, "房产管理系统", "删除记录失败,请重试!");
}
}
}
}
class HouseInfo_txtArea_actionAdapter
implements java.awt.event.ActionListener {
HouseInfo adaptee;
HouseInfo_txtArea_actionAdapter(HouseInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.txtArea_actionPerformed(e);
}
}
class HouseInfo_btnExit_actionAdapter
implements java.awt.event.ActionListener {
HouseInfo adaptee;
HouseInfo_btnExit_actionAdapter(HouseInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnExit_actionPerformed(e);
}
}
class HouseInfo_btnAdd_actionAdapter
implements java.awt.event.ActionListener {
HouseInfo adaptee;
HouseInfo_btnAdd_actionAdapter(HouseInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnAdd_actionPerformed(e);
}
}
class HouseInfo_btnSave_actionAdapter
implements java.awt.event.ActionListener {
HouseInfo adaptee;
HouseInfo_btnSave_actionAdapter(HouseInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnSave_actionPerformed(e);
}
}
class HouseInfo_btnEdit_actionAdapter
implements java.awt.event.ActionListener {
HouseInfo adaptee;
HouseInfo_btnEdit_actionAdapter(HouseInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnEdit_actionPerformed(e);
}
}
class HouseInfo_btnDelete_actionAdapter
implements java.awt.event.ActionListener {
HouseInfo adaptee;
HouseInfo_btnDelete_actionAdapter(HouseInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnDelete_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -