⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 systemoperation.java

📁 这是一个简单的图书管理系统,适用于教学中演示,讲解java高级编程语言
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
											+ text1[0][0].getText().trim()
											+ "'");
							if (rs.next()) {
								if (rs.getString("图书状态").trim().equals("借出"))
									JOptionPane.showMessageDialog(
											SystemOperation.this,
											"该书已被借出,暂时无法删除!删除失败!");
								else {
									st
											.executeUpdate("delete from Book where 图书序号 = '"
													+ (text1[0][0].getText()
															.trim() + "'"));
									st.executeUpdate("update Book set 图书序号 = '"
											+ text1[0][0].getText().trim()
											+ "' where 图书序号 = '"
											+ Integer.toString(count) + "'");
									JOptionPane.showMessageDialog(
											SystemOperation.this,
											"该书已成功从列表中删除!");
								}
							} else
								JOptionPane.showMessageDialog(
										SystemOperation.this,
										"该书不在列表中,请检查您的输入是否正确!");
						}
					}
					if (!text1[0][1].getText().trim().equals("")) {
						String s;
						int SelectValue = JOptionPane.showConfirmDialog(
								SystemOperation.this, "是否要删除此图书?删除后将无法恢复",
								"询问", JOptionPane.YES_NO_OPTION);
						if (SelectValue == 1) {
							JOptionPane.showMessageDialog(SystemOperation.this,
									"删除被取消!该书没有删除!");
						} else {
							rs = st
									.executeQuery("select * from Book where 图书编号 ='"
											+ (text1[0][1].getText().trim())
											+ "'");
							if (rs.next()) {
								s = rs.getString("图书序号");
								if (rs.getString("图书状态").trim().equals("借出"))
									JOptionPane.showMessageDialog(
											SystemOperation.this,
											"该书已被借出,暂时无法删除!删除失败!");
								else {
									st
											.executeUpdate("delete from Book where 图书编号 = '"
													+ (text1[0][1].getText() + "'"));
									st.executeUpdate("update Book set 图书序号 = '"
											+ s + "' where 图书序号 = '"
											+ Integer.toString(count) + "'");
									JOptionPane.showMessageDialog(
											SystemOperation.this, "该书已从列表中删除!");
								}

							}

							else
								JOptionPane.showMessageDialog(
										SystemOperation.this,
										"该书不在列表中,请检查您的输入是否正确!");
						}
					}

					con.close();
				} catch (Exception ex) {
					JOptionPane.showMessageDialog(SystemOperation.this,
							"数据库连接错误!\n" + ex);
					ex.printStackTrace();
				}
			}
		}
	}

	private class BookChange implements ActionListener {
		public void actionPerformed(ActionEvent event) {

			boolean b = true;
			combo = (String) comboBox[0].getSelectedItem();
			for (int i = 1; i < text1[0].length - 1; i++) {
				if (text1[0][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 Book where 图书编号='"
							+ (text1[0][1].getText().trim()) + "'");
					if (!rs.next())
						JOptionPane.showMessageDialog(SystemOperation.this,
								"该书不在列表中,请使用插入方法!");
					else {
						SelectValue = JOptionPane.showConfirmDialog(
								SystemOperation.this, "是否要修改此图书?修改后将无法恢复!",
								"询问", JOptionPane.YES_NO_OPTION);
						if (SelectValue == 1) {
							JOptionPane.showMessageDialog(SystemOperation.this,
									"修改被取消,该书没有修改!");
						} else {
							if (rs.getString("图书状态").trim().equals("借出"))
								JOptionPane.showMessageDialog(
										SystemOperation.this,
										"该书已被借出,暂时无法修改!删除修改!");
							else {
								st.executeUpdate("update Book set 图书序号 = "
										+ Integer.parseInt(text1[0][0]
												.getText().trim())
										+ "  ,图书书名 ='"
										+ text1[0][2].getText().trim()
										+ "', 图书作者='"
										+ text1[0][3].getText().trim()
										+ "' ,图书出版社='"
										+ text1[0][4].getText().trim()
										+ "',图书单价='"
										+ Integer.parseInt(text1[0][5]
												.getText().trim())
										+ "' ,图书摘要='"
										+ text1[0][6].getText().trim()
										+ "',图书分类='"
										+ text1[0][7].getText().trim()
										+ "' ,图书状态='" + combo.trim()
										+ "' where 图书编号= '"
										+ text1[0][1].getText().trim() + "'");
								JOptionPane.showMessageDialog(
										SystemOperation.this, "该书的信息已被修改!");
							}
						}
					}
					con.close();
				} catch (Exception ex) {
					JOptionPane.showMessageDialog(SystemOperation.this,
							"数据库连接错误!\n" + ex);
					ex.printStackTrace();
				}
			}
		}
	}

	public void keyPressed(KeyEvent e) {

	}

	private class BookConfirmKey implements KeyListener {
		public void keyReleased(KeyEvent e) {
			if (KeyEvent.getKeyText(e.getKeyCode()).equals("Enter")) {
				new BookConfirm();
			}
			if (e.isShiftDown()) {
				new BookConfirm();
			}
		}

		public void keyTyped(KeyEvent e) {
		}

		public void keyPressed(KeyEvent e) {
		}
	}

	private class BookConfirm implements ActionListener {
		public void actionPerformed(ActionEvent event) {
			if (text1[0][0].getText().trim().equals("")
					& text1[0][1].getText().trim().equals(""))
				JOptionPane.showMessageDialog(SystemOperation.this,
						"请给出图书编号或图书序号!");
			else {
				String[] sd = new String[text1[0].length];

				try {
					Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
					Connection con = DriverManager.getConnection(dbURL, user,
							pw);
					Statement st = con.createStatement();
					ResultSet rs;

					if (!text1[0][1].getText().equals("")) {
						rs = st
								.executeQuery("SELECT * FROM Book WHERE 图书编号 = '"
										+ text1[0][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[0][i].setText(sd[i]);
							}
							comboBox[0].setSelectedItem(sd[sd.length - 1]);

						} else
							JOptionPane.showMessageDialog(SystemOperation.this,
									"没有找到您所找的图书,\n请确认您的输入是否正确!");

					} else if (text1[0][1].getText().trim().equals("")
							& !text1[0][0].getText().trim().equals("")) {
						rs = st.executeQuery("SELECT * FROM Book WHERE 图书序号='"
								+ text1[0][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[0][i].setText(sd[i]);
							}
							comboBox[0].setSelectedItem(sd[sd.length - 1]);

						} else
							JOptionPane.showMessageDialog(SystemOperation.this,
									"没有找到您所找的图书,\n请确认您的输入是否正确!");

					}

					con.close();
				} catch (Exception ex) {
					JOptionPane.showMessageDialog(SystemOperation.this,
							"数据库连接错误!\n" + ex);
					ex.printStackTrace();
				}
			}
		}
	}

	private class ReaderUp 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[7];

				try {
					Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
					Connection con = DriverManager.getConnection(dbURL, user,
							pw);
					Statement st = con.createStatement();
					ResultSet rs;

					if (!text1[1][1].getText().trim().equals("")) {
						int num = 0;

						rs = st
								.executeQuery("SELECT * FROM Reader WHERE 读者识别号='"
										+ text1[1][1].getText().trim() + "'");

						while (rs.next())
							num = (rs.getInt("读者编号"));
						if (num == 1) {
							JOptionPane.showMessageDialog(SystemOperation.this,
									"已经到达第一人,无法再上移!");
							rs = st
									.executeQuery("SELECT * FROM Reader WHERE 读者编号 =1");
							while (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 {
							rs = st
									.executeQuery("SELECT * FROM Reader WHERE 读者编号="
											+ (num - 1));
							while (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 if (text1[1][1].getText().trim().equals("")
							& !text1[1][0].getText().trim().equals("")) {
						int num = Integer
								.parseInt(text1[1][0].getText().trim());
						if (num == 1) {
							JOptionPane.showMessageDialog(SystemOperation.this,
									"已经到达第一人,无法再上移!");
							rs = st
									.executeQuery("SELECT * FROM Reader WHERE 读者编号 =1");
							while (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 {

							rs = st
									.executeQuery("SELECT * FROM Reader WHERE  读者编号 = "
											+ (num - 1));
							while (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]);
						}
					}
					con.close();
				} catch (Exception ex) {
					JOptionPane.showMessageDialog(SystemOperation.this,
							"数据库连接错误!\n" + ex);
					ex.printStackTrace();
				}
			}
		}
	}

	private class ReaderDown 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[7];

				try {
					Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
					Connection con = DriverManager.getConnection(dbURL, user,
							pw);
					Statement st = con.createStatement();
					ResultSet rs;

					if (!text1[1][1].getText().trim().equals("")) {
						int num = 0, count = 0;
						rs = st.executeQuery("SELECT * FROM Reader ");
						while (rs.next())
							count++;

						rs = st
								.executeQuery("SELECT * FROM Reader WHERE 读者识别号='"
										+ text1[1][1].getText().trim() + "'");

						while (rs.next())
							num = (rs.getInt("读者编号"));

						if (num == count) {
							JOptionPane.showMessageDialog(SystemOperation.this,
									"已经到达最后一人,无法再下移!");
							rs = st
									.executeQuery("SELECT * FROM Reader WHERE 读者编号 ="
											+ num);
							while (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 {
							rs = st
									.executeQuery("SELECT * FROM Reader WHERE 读者编号="
											+ (num + 1));
							while (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 if (text1[1][1].getText().trim().equals("")
							& !text1[1][0].getText().trim().equals("")) {
						int num = Integer
								.parseInt(text1[1][0].getText().trim()), count = 0;

						rs = st.executeQuery("SELECT * FROM Reader");

						while (rs.next())
							count++;

						if (num == count) {
							JOptionPane.showMessageDialog(SystemOperation.this,
									"已经到达最后一人,无法再下移!");
							rs = st
									.executeQuery("SELECT * FROM Reader WHERE 读者编号 ="
											+ num);
							while (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 {

							rs = st
									.executeQuery("SELECT * FROM Reader WHERE  读者编号 ="
											+ (num + 1));
							while (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]);
						}
					}
					con.close();
				} catch (Exception ex) {
					JOptionPane.showMessageDialog(SystemOperation.this,
							"数据库连接错误!\n" + ex);
					ex.printStackTrace();
				}
			}
		}
	}

	private class ReaderAdd 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().equals("") | combo.trim().equals(""))
					b = false;
			}
			if (b == false)
				JOptionPane.showMessageDialog(SystemOperation.this,
						"请给出关于此读者的正确的信息!");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -