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

📄 readermanage.java

📁 简单的书店管理系统,是课设期间教师指导完成的,希望会对大家有帮助!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				del.setEnabled(false);
				query.setEnabled(false);
			}
		});

		del = new ButtonIcon("删除");
		del.setBounds(183, 500, 70, 25);
		del.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				delJudga();
			}
		});

		save = new ButtonIcon("保存");//添加新读者 
		save.setBounds(268, 500, 70, 25);
		save.setEnabled(false);
		save.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					if (AddJudge()) {
						java.sql.Date nowTime= new java.sql.Date(Calendar.getInstance().getTime().getTime());
						MainDAO dao = new MainDAO();
						String str = "insert into duzheziliao values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
						pstmt = dao.getPreparedStatement(str);
						pstmt.setInt(1, Integer.parseInt(tnumber.getText()));
						pstmt.setString(2, tname.getText());
						pstmt.setString(3, csex.getSelectedItem().toString());
						pstmt.setString(4, atddress.getText());
						pstmt.setString(5, tphone.getText());
						pstmt.setString(6, com.getSelectedItem().toString());
						pstmt.setString(8, twnumber.getText());
						pstmt.setString(7, tjnumber.getText());
						pstmt.setString(9, tjsnumber.getText());
						pstmt.setInt(10,0);
						pstmt.setString(11, testate.getText());
						pstmt.setDate(12,nowTime);
						pstmt.setString(13, tremark.getText());
						pstmt.executeUpdate();
						pstmt.close();
						dao.close();
						table.Renovate("select * from duzheziliao");

						xiugai.setEnabled(true);
						add.setEnabled(true);
						del.setEnabled(true);
						save.setEnabled(false);
						query.setEnabled(true);
						JOptionPane.showMessageDialog(table, "添加新读者成功!!!!!!!!");	
					}
				} catch (SQLException e1) {
					showError(e1);
					e1.printStackTrace();
				} finally {

				}
			}
		});

		query = new ButtonIcon("查询");
		query.setBounds(500, 500, 70, 25);
		query.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				try {
					Query();
				} catch (SQLException e) {
					showError(e);
					e.printStackTrace();
				}
			}
		});

		cancel = new ButtonIcon("取消");
		cancel.setBounds(640, 500, 70, 25);
		cancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				atname.setText("");
				atnumber.setText("");
				acsex.setSelectedItem("任何性别");
				acom.setSelectedItem("任何类型");
			}
		});

		close = new ButtonIcon("关闭");
		close.setBounds(353, 500, 70, 25);
		close.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				close();
			}
		});

	}
//设置选中的数据
	void setSelect() {
		tnumber.setText(List.get(0).toString());
		tname.setText(List.get(1).toString());
		csex.setSelectedItem(List.get(2).toString());
		atddress.setText(List.get(3).toString());
		tphone.setText(List.get(4).toString());
		com.setSelectedItem(List.get(5).toString());
		tjnumber.setText(List.get(6).toString());
		twnumber.setText(List.get(7).toString());
		tjsnumber.setText(List.get(8).toString());
		testate.setText(List.get(10).toString());
		ttime.setText(List.get(11).toString());
		tremark.setText(List.get(12).toString());
	}
//清空
	private void clean() {
		tnumber.setText("输入数字编号");
		tnumber.setEnabled(true);
		tnumber.selectAll();
		tname.setText("");
		csex.setSelectedIndex(0);
		atddress.setText("");
		tphone.setText("");
		com.setSelectedIndex(0);
		twnumber.setText("0");
		testate.setText("正常");
		SimpleDateFormat mat = new SimpleDateFormat("yyyy-MM-dd");
		ttime.setText(mat.format(new Date()).toString());
		tremark.setText("");
	}
//检测添加读者是否存在是否合法 
	boolean AddJudge() {
		MainDAO dao;
		boolean boo = false;
		boolean bool = false;
		boolean bool1 = false;

		char a[] = tnumber.getText().toCharArray();
		for (int i = 0; i < a.length; i++) {
			if (!(Character.isDigit(a[i]))) {
				bool1 = true;
			}
		}

		try {
			dao = new MainDAO();
			boo = dao.Judge("select 读者编号 from duzheziliao", tnumber.getText(),
					"读者编号");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		if (bool1 == true) {
			JOptionPane.showMessageDialog(this, "非法数据!!读者编号只能是数字!!");
		} else if (tnumber.getText().equals("") || tname.getText().equals("")) {
			JOptionPane.showMessageDialog(this, "读者编号和读者姓名不能空,请输入!!");
		} else if (boo) {
			JOptionPane.showMessageDialog(this, "此读者编号已经存在,请重新输入!!");
		} else {
			bool = true;
		}
		return bool;
	}
//删除读者
	void delJudga() {

		if (tnumber.getText().equals("")) {
			JOptionPane.showMessageDialog(this, "没选中任何用户!!!!");
		} else {
			int n = JOptionPane.showConfirmDialog(this, "确认删除此用户??删除后将不可以恢复!!",
					"退出", JOptionPane.YES_NO_OPTION);
			if (n == 0) {
				MainDAO dao;
				try {
					dao = new MainDAO();
					String str;
					str = "delete from duzheziliao where 读者编号="
							+ tnumber.getText();
					dao.del(str);
					table.Renovate("select * from duzheziliao");
				} catch (SQLException e1) {
					showError(e1);
					e1.printStackTrace();
				}
			}
		}
	}
//获取是绝对查询还是模糊查询
	public void itemStateChanged(ItemEvent e) {
		if (e.getItemSelectable() == pt) {
			bl = true;
			atnumber.setEnabled(true);
			atname.setEnabled(false);
			acsex.setEnabled(false);
			acom.setEnabled(false);
		} else {
			bl = false;
			atnumber.setEnabled(false);
			atname.setEnabled(true);
			acsex.setEnabled(true);
			acom.setEnabled(true);
		}

	}
  //模糊查询
	void Query() throws SQLException {
		String sql, type, sex, name = null;
		if (acsex.getSelectedItem().equals("任何性别")) {
			sex = "'%'";
		} else
			sex = "'" + acsex.getSelectedItem().toString() + "'";
		if (acom.getSelectedItem().equals("任何类型")) {
			type = "'%'";
		} else
			type = "'" + acom.getSelectedItem().toString() + "'";

		if (atname.getText().equals("")) {
			name = "'%'";
		} else
			name = "'%" + atname.getText() + "%'";

		if (bl && atnumber.getText().equals("")) {
			JOptionPane.showMessageDialog(this, "绝对查询时,条件不能为空!!!!!!");
		} else if (bl) {
			table.Renovate("select * from duzheziliao where 读者编号="
					+ atnumber.getText());
		} else {
			String s;
			s = " and ";
			table.Renovate("select * from duzheziliao where 读者姓名 LIKE " + name
					+ s + " 读者性别 LIKE " + sex + s + " 读者类别 LIKE " + type);
		}
      getCount();
	}
	
	//如果查询结果集为0的话 设置修改等按钮不可编辑
     private void getCount() {
		
		if(table.getRowCount()==0){
    		xiugai.setEnabled(false);
    		add.setEnabled(false);
    		del.setEnabled(false);
    	}
		else{
			xiugai.setEnabled(true);
    		add.setEnabled(true);
    		del.setEnabled(true);
		}
		
	}
	
	//提示错误信息
	void showError(SQLException e1){
		
		JOptionPane.showMessageDialog(this,"错误!!"+e1.getMessage());
	}

	void add() {
		con.add(icon);
		con.add(scrool);
		con.add(number);
		con.add(tnumber);
		con.add(name);
		con.add(tname);
		con.add(sex);
		con.add(csex);
		con.add(type);
		con.add(com);
		con.add(address);
		con.add(scrool1);
		con.add(phone);
		con.add(tphone);
		con.add(time);
		con.add(ttime);
		con.add(remark);
		con.add(scrool2);
		con.add(testate);
		con.add(estate);
		con.add(jnumber);
		con.add(tjnumber);
		con.add(wnumber);
		con.add(twnumber);
		con.add(jsnumber);
		con.add(tjsnumber);

		con.add(xiugai);
		con.add(add);
		con.add(del);
		con.add(save);
		con.add(close);

		con.add(chaxun);
		con.add(anumber);
		con.add(aname);
		con.add(atnumber);
		con.add(atname);
		con.add(asex);
		con.add(atype);
		con.add(acsex);
		con.add(acom);
		con.add(pt);
		con.add(mh);
		con.add(query);
		con.add(cancel);

		con.validate();
		table.getSelectionModel().setSelectionInterval(0, 0);
	}

}

⌨️ 快捷键说明

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