📄 systemoperation.java
字号:
else {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL, user,
pw);
Statement st = con.createStatement();
ResultSet rs;
String s = "";
rs = st.executeQuery("select * from Reader where 读者识别号 = '"
+ (text1[1][1].getText().trim()) + "'");
if (rs.next())
JOptionPane.showMessageDialog(SystemOperation.this,
"该读者已存在于列表中!");
else {
rs = st.executeQuery("select * from Reader");
int count = 0;
while (rs.next()) {
count++;
}
st
.executeUpdate("insert into Reader(读者编号,读者识别号,读者姓名,读者权限,读者联系方法,读者电话号码,读者电子邮件,借书数目) "
+ "values('"
+ (count + 1)
+ "','"
+ text1[1][1].getText().trim()
+ "','"
+ text1[1][2].getText().trim()
+ "','"
+ combo.trim()
+ "','"
+ text1[1][4].getText().trim()
+ "','"
+ (text1[1][5].getText().trim())
+ "','"
+ text1[1][6].getText().trim()
+ "',0)");
s = text1[1][1].getText().trim().substring(4);
st
.executeUpdate("insert into Administer(帐号,口令,权限级别) values('"
+ text1[1][1].getText().trim()
+ "','"
+ s + "','" + combo.trim() + "')");
st
.executeUpdate("insert into Configuration(记录号,最多可借图书数,最多借书天数) values('"
+ text1[1][1].getText().trim()
+ "','8','40')");
text1[1][0].setText(Integer.toString(count + 1));
JOptionPane.showMessageDialog(SystemOperation.this,
"该读者已被成功插入读者列表中!");
}
con.close();
} catch (Exception ex) {
JOptionPane.showMessageDialog(SystemOperation.this,
"数据库连接错误!\n" + ex);
ex.printStackTrace();
}
}
}
}
private class ReaderDelete implements ActionListener {
public void actionPerformed(ActionEvent event) {
if (text1[1][0].getText().trim().equals("")
& text1[1][1].getText().trim().equals(""))
JOptionPane.showMessageDialog(SystemOperation.this,
"请给出读者编号或读者识别号!");
else {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL, user,
pw);
Statement st = con.createStatement();
ResultSet rs;
String s;
int n = 0;
rs = st.executeQuery("select * from Reader");
if (!text1[1][0].getText().trim().equals("")) {
SelectValue = JOptionPane.showConfirmDialog(
SystemOperation.this, "是否要删除此读者?删除后将无法恢复!",
"询问", JOptionPane.YES_NO_OPTION);
if (SelectValue == 1) {
JOptionPane.showMessageDialog(SystemOperation.this,
"删除被取消,该读者没有删除!");
} else {
rs = st
.executeQuery("select * from Reader where 读者编号= "
+ Integer.parseInt(text1[1][0]
.getText().trim()));
if (rs.next()) {
s = rs.getString("读者识别号");
if (rs.getString("读者权限").trim().equals("管理员"))
JOptionPane.showMessageDialog(
SystemOperation.this,
"管理员无法删除!删除失败!");
else if (rs.getInt("借书数目") > 0)
JOptionPane.showMessageDialog(
SystemOperation.this,
"该读者还有书没还上,无法删除!删除失败!");
else {
st
.executeUpdate("delete from Reader where 读者编号 = "
+ Integer
.parseInt(text1[1][0]
.getText()
.trim()));
st
.executeUpdate("update Reader set 读者编号 = 读者编号-1 where 读者编号 > "
+ Integer
.parseInt(text1[1][0]
.getText()
.trim()));
st
.executeUpdate("delete from Configuration where 记录号 = '"
+ s + "'");
st
.executeUpdate("delete from Administer where 帐号 = '"
+ s + "'");
JOptionPane
.showMessageDialog(
SystemOperation.this,
"该读者已从列表中删除!");
}
} else
JOptionPane.showMessageDialog(
SystemOperation.this, "该读者不在列表中!");
}
} else if (!text1[1][1].getText().trim().equals("")
& text1[1][0].getText().trim().equals("")) {
SelectValue = JOptionPane.showConfirmDialog(
SystemOperation.this, "是否要删除此读者?删除后将无法恢复",
"询问", JOptionPane.YES_NO_OPTION);
if (SelectValue == 1) {
JOptionPane.showMessageDialog(SystemOperation.this,
"删除被取消,该读者没有删除!");
} else {
rs = st
.executeQuery("select * from Reader where 读者识别号='"
+ (text1[1][1].getText().trim())
+ "'");
if (!rs.next())
JOptionPane.showMessageDialog(
SystemOperation.this, "该读者不在列表中!");
else {
rs = st
.executeQuery("select * from Reader where 读者识别号 = '"
+ (text1[1][1].getText().trim() + "'"));
if (rs.next()) {
n = rs.getInt("读者编号");
if (rs.getString("读者权限").trim().equals(
"管理员"))
JOptionPane.showMessageDialog(
SystemOperation.this,
"管理员无法删除!删除失败!");
else if (rs.getInt("借书数目") > 0)
JOptionPane.showMessageDialog(
SystemOperation.this,
"该读者还有书没还上,无法删除!删除失败!");
else {
st
.executeUpdate("delete from Reader where 读者识别号= '"
+ (text1[1][1]
.getText()
.trim() + "'"));
st
.executeUpdate("update Reader set 读者编号 =读者编号-1 where 读者编号 > "
+ n + "");
}
st
.executeUpdate("delete from Configuration where 记录号 = '"
+ text1[1][1].getText()
.trim() + "'");
st
.executeUpdate("delete from Administer where 帐号 = '"
+ text1[1][1].getText()
.trim() + "'");
JOptionPane
.showMessageDialog(
SystemOperation.this,
"该读者已从列表中删除!");
}
}
}
}
con.close();
} catch (Exception ex) {
JOptionPane.showMessageDialog(SystemOperation.this,
"数据库连接错误!\n" + ex);
ex.printStackTrace();
}
}
}
}
private class ReaderChange implements ActionListener {
public void actionPerformed(ActionEvent event) {
boolean b = true;
combo = (String) comboBox[1].getSelectedItem();
for (int i = 1; i < text1[1].length & i != 3; i++) {
if (text1[1][i].getText().trim().equals("")
| combo.trim().equals(""))
b = false;
}
if (b == false)
JOptionPane.showMessageDialog(SystemOperation.this,
"请给出关于此读者的正确的信息!");
else {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL, user,
pw);
Statement st = con.createStatement();
ResultSet rs;
rs = st.executeQuery("select * from Reader where 读者识别号 ='"
+ (text1[1][1].getText().trim()) + "'");
if (rs.next()) {
if (rs.getString("读者权限").trim().equals("管理员"))
JOptionPane.showMessageDialog(SystemOperation.this,
"管理员信息无法修改!修改失败!");
else {
SelectValue = JOptionPane.showConfirmDialog(
SystemOperation.this,
"是否要修改此读者信息?修改后将无法恢复!", "询问",
JOptionPane.YES_NO_OPTION);
if (SelectValue == 1) {
JOptionPane
.showMessageDialog(
SystemOperation.this,
"修改被取消,该读者没有被修改!");
} else {
st.executeUpdate("update Reader set 读者编号 ="
+ Integer.parseInt(text1[1][0]
.getText().trim())
+ " ,读者姓名 ='"
+ text1[1][2].getText().trim()
+ "' ,读者权限='" + combo.trim()
+ "' ,读者联系方法='"
+ text1[1][4].getText().trim()
+ "',读者电话号码='"
+ (text1[1][5].getText().trim())
+ "' ,读者电子邮件='"
+ text1[1][6].getText().trim()
+ "' where 读者识别号= '"
+ (text1[1][1].getText().trim() + "'"));
JOptionPane.showMessageDialog(
SystemOperation.this, "该读者的信息已被修改!");
}
}
} else
JOptionPane.showMessageDialog(SystemOperation.this,
"该读者不在列表中,请使用插入方法!");
con.close();
} catch (Exception ex) {
JOptionPane.showMessageDialog(SystemOperation.this,
"数据库连接错误!" + ex);
ex.printStackTrace();
}
}
}
}
private class ReaderConfirm implements ActionListener {
public void actionPerformed(ActionEvent event) {
if (text1[1][0].getText().trim().equals("")
& text1[1][1].getText().trim().equals(""))
JOptionPane.showMessageDialog(SystemOperation.this,
"请给出读者编号或读着识别号!");
else {
String[] sd = new String[text1[1].length];
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL, user,
pw);
Statement st = con.createStatement();
ResultSet rs;
if (!text1[1][0].getText().trim().equals("")
& text1[1][1].getText().trim().equals("")) {
rs = st
.executeQuery("SELECT * FROM Reader WHERE 读者编号 = "
+ Integer.parseInt(text1[1][0]
.getText().trim()));
if (rs.next()) {
for (int i = 0; i < sd.length; i++)
sd[i] = rs.getString((i + 1));
for (int i = 0; i < sd.length; i++) {
text1[1][i].setText(sd[i]);
}
comboBox[1].setSelectedItem(sd[3]);
} else
JOptionPane.showMessageDialog(SystemOperation.this,
"没有找到您所找的读者,\n请确认您的输入是否正确!");
} else if (!text1[1][1].getText().trim().equals("")) {
rs = st
.executeQuery("SELECT * FROM Reader WHERE 读者识别号 = '"
+ text1[1][1].getText().trim() + "'");
if (rs.next()) {
for (int i = 0; i < sd.length; i++)
sd[i] = rs.getString((i + 1));
for (int i = 0; i < sd.length; i++) {
text1[1][i].setText(sd[i]);
}
comboBox[1].setSelectedItem(sd[3]);
} else
JOptionPane.showMessageDialog(SystemOperation.this,
"没有找到您所找的读者,\n请确认您的输入是否正确!");
}
con.close();
} catch (Exception ex) {
JOptionPane.showMessageDialog(SystemOperation.this,
"数据库连接错误!\n" + ex);
ex.printStackTrace();
}
}
}
}
private class SystemChange implements ActionListener {
public void actionPerformed(ActionEvent event) {
if (text2[1][1].getText().trim().equals("")
| text2[1][2].getText().trim().equals("")
| text2[1][0].getText().trim().equals(""))
JOptionPane.showMessageDialog(SystemOperation.this,
"读者号码,借书本数和借阅时间均不能为空!");
else {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL, user,
pw);
Statement st = con.createStatement();
ResultSet rs;
rs = st
.executeQuery("SELECT * FROM Configuration where 记录号 =\'"
+ text2[1][0].getText().trim() + "\'");
if (rs.next()) {
st.executeUpdate("update Configuration set 最多可借图书数 = '"
+ (text2[1][1].getText().trim())
+ " ' where 记录号 = \'"
+ text2[1][0].getText().trim() + "\'");
st.executeUpdate("update Configuration set 最多借书天数 = '"
+ (text2[1][2].getText().trim())
+ " ' where 记录号 = \'"
+ text2[1][0].getText().trim() + "\'");
JOptionPane.showMessageDialog(SystemOperation.this,
"该读者的信息更改成功!");
con.close();
} else
JOptionPane.showMessageDialog(SystemOperation.this,
"您输入的借阅者证号有误!");
} catch (Exception ex) {
JOptionPane.showMessageDialog(SystemOperation.this,
"数据库连接错误!\n" + ex);
ex.printStackTrace();
}
}
}
}
private class PasswordChange implements ActionListener {
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent event) {
if (password[1].getText().equals("")
| password[2].getText().equals("")
| password[0].getText().equals("")
| text2[2][0].getText().trim().equals(""))
JOptionPane.showMessageDialog(SystemOperation.this,
"读者号码,口令均不能为空!");
else {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL, user,
pw);
Statement st = con.createStatement();
ResultSet rs;
// String sqlStr;
rs = st.executeQuery("SELECT * "
+ "FROM Administer where 帐号=\'"
+ text2[2][0].getText().trim() + "\' and 口令= '"
+ password[0].getText() + "'");
if (rs.next()) {
if (!password[1].getText()
.equals(password[2].getText()))
JOptionPane.showMessageDialog(SystemOperation.this,
"您两次输入的口令不一致!");
else {
st.executeUpdate("update Administer set 口令= '"
+ (new String(password[1].getText()))
+ "' where 帐号=\'"
+ text2[2][0].getText().trim() + "\'");
JOptionPane.showMessageDialog(SystemOperation.this,
"口令更改成功!");
}
} else
JOptionPane.showMessageDialog(SystemOperation.this,
"您输入的借阅者证号或口令有误!");
con.close();
} catch (Exception ex) {
JOptionPane.showMessageDialog(SystemOperation.this,
"数据库连接错误!\n" + ex);
ex.printStackTrace();
}
}
}
}
public static void main(String[] args) {
new SystemOperation().setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -