diff --git a/.classpath b/.classpath index ed47a4eaf4d72df76e4596ccd2df221eee7df083..3e1995fb7933c661bf33e69da7678c5ab6e20e35 100644 --- a/.classpath +++ b/.classpath @@ -7,5 +7,6 @@ + diff --git a/jdbc/mysql-connector-java-8.0.25.jar b/jdbc/mysql-connector-java-8.0.25.jar new file mode 100644 index 0000000000000000000000000000000000000000..3db626b13161067ef7ec71640398ca3b468fdc13 Binary files /dev/null and b/jdbc/mysql-connector-java-8.0.25.jar differ diff --git a/src/MyFirstClass.java b/src/MyFirstClass.java deleted file mode 100644 index 614431d77c740f9f7ad845226f8fb42072ac61d2..0000000000000000000000000000000000000000 --- a/src/MyFirstClass.java +++ /dev/null @@ -1,4 +0,0 @@ - -public class MyFirstClass { - -} diff --git a/src/com/artisan/dao/SchoolClassDao.java b/src/com/artisan/dao/SchoolClassDao.java new file mode 100644 index 0000000000000000000000000000000000000000..9921431ac9758166821b306e94382760f1921c19 --- /dev/null +++ b/src/com/artisan/dao/SchoolClassDao.java @@ -0,0 +1,69 @@ +package com.artisan.dao; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import com.artisan.model.SchoolClass; +import com.artisan.util.StringUtil; +/** + * 班级Dao类 + * @author Administrator + * + */ +public class SchoolClassDao { + + /** + * 班级添加 + * @param con + * @param schoolClass + * @return + * @throws Exception + */ + public int add(Connection con,SchoolClass schoolClass)throws Exception{ + String sql="insert into t_school_class values(null,?,?)"; + PreparedStatement pstmt=con.prepareStatement(sql); + pstmt.setString(1, schoolClass.getClassName()); + System.out.println(schoolClass.getClassName()); + pstmt.setString(2, schoolClass.getCalssDesc()); + return pstmt.executeUpdate(); + } + public ResultSet list(Connection con,SchoolClass schoolClass)throws Exception{ + StringBuffer sb=new StringBuffer("select * from t_school_class"); + if(StringUtil.isNotEmpty(schoolClass.getClassName())){ + sb.append(" and className like '%"+schoolClass.getClassName()+"%'"); + } + PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where")); + return pstmt.executeQuery(); + } + /** + * 删除班级 + * @param con + * @param id + * @return + * @throws Exception + */ + public int delete(Connection con,String id)throws Exception{ + String sql="delete from t_school_class where id=?"; + PreparedStatement pstmt=con.prepareStatement(sql); + pstmt.setString(1, id); + return pstmt.executeUpdate(); + } + + + /** + * 更新班级 + * @param con + * @param schoolClass + * @return + * @throws Exception + */ + public int update(Connection con,SchoolClass schoolClass)throws Exception{ + String sql="update t_school_class set className=?,classDesc=? where id=?"; + PreparedStatement pstmt=con.prepareStatement(sql); + pstmt.setString(1, schoolClass.getClassName()); + pstmt.setString(2, schoolClass.getCalssDesc()); + pstmt.setInt(3, schoolClass.getId()); + return pstmt.executeUpdate(); + } +} diff --git a/src/com/artisan/dao/StudentDao.java b/src/com/artisan/dao/StudentDao.java new file mode 100644 index 0000000000000000000000000000000000000000..8e621eccd5aebb7a001d939f4a812569533f8882 --- /dev/null +++ b/src/com/artisan/dao/StudentDao.java @@ -0,0 +1,99 @@ +package com.artisan.dao; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import com.artisan.model.Student; +import com.artisan.util.StringUtil; +/** + * 学生Dao类 + * @author Administrator + * + */ +public class StudentDao { + /** + * 学生 + * @param con + * @param student + * @return + * @throws Exception + */ + public int add(Connection con,Student student)throws Exception{ + String sql="insert into t_student values(null,?,?,?,?,?,?)"; + PreparedStatement pstmt=con.prepareStatement(sql); + pstmt.setString(1, student.getName()); + pstmt.setString(2, student.getSn()); + pstmt.setString(3, student.getSex()); + + pstmt.setString(4, student.getDept()); + pstmt.setInt(5, student.getClassId()); + pstmt.setString(6, student.getAddress()); + return pstmt.executeUpdate(); + } + /** + * 学生信息查询 + * @param con + * @param student + * @return + * @throws Exception + */ + public ResultSet list(Connection con,Student student)throws Exception{ + StringBuffer sb=new StringBuffer("select * from t_student b,t_school_class bt where b.classId=bt.id"); + if(StringUtil.isNotEmpty(student.getName())){ + sb.append(" and b.name like '%"+student.getName()+"%'"); + } + if(StringUtil.isNotEmpty(student.getSn())){ + sb.append(" and b.sn like '%"+student.getSn()+"%'"); + } + if(student.getClassId()!=null && student.getClassId()!=-1){ + sb.append(" and b.classId="+student.getClassId()); + } + PreparedStatement pstmt=con.prepareStatement(sb.toString()); + return pstmt.executeQuery(); + } + /** + * 学生信息删除 + * @param con + * @param id + * @return + * @throws Exception + */ + public int delete(Connection con,String id)throws Exception{ + String sql="delete from t_student where id=?"; + PreparedStatement pstmt=con.prepareStatement(sql); + pstmt.setString(1, id); + return pstmt.executeUpdate(); + } + /** + * 学生信息修改 + * @param con + * @param student + * @return + * @throws Exception + */ + public int update(Connection con,Student student)throws Exception{ + String sql="update t_student set name=?,sn=?,sex=?,dept=?,address=?,classId=? where id=?"; + PreparedStatement pstmt=con.prepareStatement(sql); + pstmt.setString(1, student.getName()); + pstmt.setString(2, student.getSn()); + pstmt.setString(3, student.getSex()); + pstmt.setString(4, student.getDept()); + pstmt.setString(5, student.getAddress()); + pstmt.setInt(6, student.getClassId()); + pstmt.setInt(7, student.getId()); + return pstmt.executeUpdate(); + } + /** + * 指定班级下是否存在学生 + * @param con + * @param studentTypeId + * @return + * @throws Exception + */ + public boolean existStudentByclassId(Connection con,String classId)throws Exception{ + String sql="select * from t_student where classId=?"; + PreparedStatement pstmt=con.prepareStatement(sql); + pstmt.setString(1, classId); + ResultSet rs=pstmt.executeQuery(); + return rs.next(); + } +} \ No newline at end of file diff --git a/src/com/artisan/dao/UserDao.java b/src/com/artisan/dao/UserDao.java new file mode 100644 index 0000000000000000000000000000000000000000..24d1467e4ed53bf05b641f66f7544f2fbee13ee9 --- /dev/null +++ b/src/com/artisan/dao/UserDao.java @@ -0,0 +1,44 @@ +package com.artisan.dao; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; + +import com.artisan.model.User; + + +/** + * 用户Dao类 + * @author Administrator + * + * + * + */ +public class UserDao { + + + /** + * 登录验证 + * @param con + * @param user + * @return + * @throws Exception + */ + public User login(Connection con,User user)throws Exception{ + User resultUser=null; + String sql="select * from t_user where userName=? and password=?"; + PreparedStatement pstmt=con.prepareStatement(sql); + pstmt.setString(1, user.getUserName()); + pstmt.setString(2, user.getPassword()); + ResultSet rs=pstmt.executeQuery(); + + + if(rs.next()){ + resultUser=new User(); + resultUser.setId(rs.getInt("id")); + resultUser.setUserName(rs.getString("userName")); + resultUser.setPassword(rs.getString("password")); + } + return resultUser; + } +} diff --git a/src/com/artisan/model/SchoolClass.java b/src/com/artisan/model/SchoolClass.java new file mode 100644 index 0000000000000000000000000000000000000000..30f8fe3c81d2873e74b2fd0e053818c97d3cc94c --- /dev/null +++ b/src/com/artisan/model/SchoolClass.java @@ -0,0 +1,64 @@ +package com.artisan.model; + +/** + * 班级实体 + */ +public class SchoolClass { + + private int id; // 编号 + private String className; // 班级名称 + private String calssDesc; // 备注 + public SchoolClass() { + super(); + // TODO Auto-generated constructor stub + } + public SchoolClass(String className, String calssDesc) { + super(); + this.className = className; + this.calssDesc = calssDesc; + } + + public SchoolClass(int id, String className, String calssDesc) { + super(); + this.id = id; + this.className = className; + this.calssDesc = calssDesc; + } + + + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + + + + public String getClassName() { + return className; + } + + + public void setClassName(String className) { + this.className = className; + } + + + public String getCalssDesc() { + return calssDesc; + } + + + public void setCalssDesc(String calssDesc) { + this.calssDesc = calssDesc; + } + + + @Override + public String toString() { + return className; + } + + +} diff --git a/src/com/artisan/model/Student.java b/src/com/artisan/model/Student.java new file mode 100644 index 0000000000000000000000000000000000000000..2f4ef297552d32e63d7471eeae7c2ddda190f7bb --- /dev/null +++ b/src/com/artisan/model/Student.java @@ -0,0 +1,125 @@ +package com.artisan.model; + +/** + * 学生实体 + * @author llq-artisan + * + */ +public class Student { + private int id; // 编号 + private String name; // 姓名 + private String sn; // 学号 + private String sex; // 性别 + private String dept; // 所在院系 + private Integer classId; // 班级Id + private String className; // 班级名称 + private String address; // 家庭住址 + public Student() { + super(); + // TODO Auto-generated constructor stub + } + public Student(String name, String sn, String sex, String dept, Integer calssId, String address) { + super(); + this.name = name; + this.sn = sn; + this.sex = sex; + this.dept = dept; + this.classId = calssId; + this.address = address; + } + public Student(int id, String name, String sn, String sex, String dept, Integer calssId, String address) { + super(); + this.id = id; + this.name = name; + this.sn = sn; + this.sex = sex; + this.dept = dept; + this.classId = calssId; + this.address = address; + } + public Student(String name, String sn, Integer calssId) { + super(); + this.name = name; + this.sn = sn; + this.classId = calssId; + } + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + + + + public String getName() { + return name; + } + + + + public void setName(String name) { + this.name = name; + } + + + + public String getSn() { + return sn; + } + + + + public void setSn(String sn) { + this.sn = sn; + } + + + + public String getSex() { + return sex; + } + + + + public void setSex(String sex) { + this.sex = sex; + } + + + + public String getDept() { + return dept; + } + + public void setDept(String dept) { + this.dept = dept; + } + public Integer getClassId() { + return classId; + } + public void setClassId(Integer classId) { + this.classId = classId; + } + public String getClassName() { + return className; + } + public void setClassName(String className) { + this.className = className; + } + + + + public String getAddress() { + return address; + } + + + + public void setAddress(String address) { + this.address = address; + } + + + +} diff --git a/src/com/artisan/model/User.java b/src/com/artisan/model/User.java new file mode 100644 index 0000000000000000000000000000000000000000..7874b4dbd79ebdb6ba49cd7c1c243e4f59e25ee1 --- /dev/null +++ b/src/com/artisan/model/User.java @@ -0,0 +1,49 @@ +package com.artisan.model; + +/** + * 用户实体 + * @author Administrator + * + */ +public class User { + + private int id; // 编号 + private String userName; // 用户名 + private String password; // 密码 + + + + public User() { + super(); + // TODO Auto-generated constructor stub + } + + public User(String userName, String password) { + super(); + this.userName = userName; + this.password = password; + } + + + + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + public String getUserName() { + return userName; + } + public void setUserName(String userName) { + this.userName = userName; + } + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + + +} diff --git a/src/com/artisan/util/DbUtil.java b/src/com/artisan/util/DbUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..4bd03755a940d92b4c1d6d6fc0748840c7515227 --- /dev/null +++ b/src/com/artisan/util/DbUtil.java @@ -0,0 +1,43 @@ +package com.artisan.util; + + +import java.sql.Connection; +import java.sql.DriverManager; + +/** + * 数据库工具类 + * @author Administrator + * + */ +public class DbUtil { + private String dbUrl="jdbc:mysql://localhost:3306/db_student_swing?useUnicode=true"; // 数据库连接地址 + private String dbUserName="root"; // + private String dbPassword="123456"; // + private String jdbcName="com.mysql.cj.jdbc.Driver"; // 驱动名称 + /** + * 获取数据库连接 + * @return + * @throws Exception + */ + public Connection getCon()throws Exception{ + Class.forName(jdbcName); + Connection con=DriverManager.getConnection(dbUrl, dbUserName, dbPassword); + return con; + } + public void closeCon(Connection con)throws Exception{ + if(con!=null){ + con.close(); + } + } + public static void main(String[] args) { + DbUtil dbUtil=new DbUtil(); + try { + dbUtil.getCon(); + System.out.println("数据库连接成功!"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + System.out.println("数据库连接失败"); + } + } +} diff --git a/src/com/artisan/util/StringUtil.java b/src/com/artisan/util/StringUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..c6b47667ec16075cd6a395db0ea520bfe9d8ba4b --- /dev/null +++ b/src/com/artisan/util/StringUtil.java @@ -0,0 +1,35 @@ +package com.artisan.util; + +/** + * 字符串工具类 + * @author Administrator + * + */ +public class StringUtil { + + /** + * 判断是否是空 + * @param str + * @return + */ + public static boolean isEmpty(String str){ + if(str==null || "".equals(str.trim())){ + return true; + }else{ + return false; + } + } + + /** + * 判断是否不是空 + * @param str + * @return + */ + public static boolean isNotEmpty(String str){ + if(str!=null && !"".equals(str.trim())){ + return true; + }else{ + return false; + } + } +} diff --git a/src/com/artisan/view/ArtisanInterFrm.java b/src/com/artisan/view/ArtisanInterFrm.java new file mode 100644 index 0000000000000000000000000000000000000000..d0e28042baade3707c1e79b04a2cb6e4c1aae66e --- /dev/null +++ b/src/com/artisan/view/ArtisanInterFrm.java @@ -0,0 +1,47 @@ +package com.artisan.view; + +import java.awt.EventQueue; + +import javax.swing.JInternalFrame; +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; +import java.awt.Color; +import javax.swing.JLabel; +import javax.swing.ImageIcon; + +public class ArtisanInterFrm extends JInternalFrame { + + + /** + * Create the frame. + */ + public ArtisanInterFrm() { + //getContentPane().setBackground(Color.RED); + setIconifiable(true); + setClosable(true); + setTitle("关于系统"); + setBounds(100, 100, 450, 300); + + + + JLabel lblNewLabel = new JLabel(""); + lblNewLabel.setIcon(new ImageIcon(ArtisanInterFrm.class.getResource("/images/artisan.png"))); + GroupLayout groupLayout = new GroupLayout(getContentPane()); + groupLayout.setHorizontalGroup( + groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addGap(98) + .addComponent(lblNewLabel) + .addContainerGap(126, Short.MAX_VALUE)) + ); + groupLayout.setVerticalGroup( + groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addGap(48) + .addComponent(lblNewLabel) + .addContainerGap(149, Short.MAX_VALUE)) + ); + getContentPane().setLayout(groupLayout); + + } +} diff --git a/src/com/artisan/view/LogOnFrm.java b/src/com/artisan/view/LogOnFrm.java new file mode 100644 index 0000000000000000000000000000000000000000..8fcca65b06655a62f279556dff5a4bb142ca0ef6 --- /dev/null +++ b/src/com/artisan/view/LogOnFrm.java @@ -0,0 +1,200 @@ +package com.artisan.view; + +import java.awt.EventQueue; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.sql.Connection; + +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JTextField; +import javax.swing.UIManager; +import javax.swing.border.EmptyBorder; + +import com.artisan.dao.UserDao; +import com.artisan.model.User; +import com.artisan.util.DbUtil; +import com.artisan.util.StringUtil; + +public class LogOnFrm extends JFrame { + + private JPanel contentPane; + private JTextField userNameTxt; + private JPasswordField passwordTxt; + + private DbUtil dbUtil=new DbUtil(); + private UserDao userDao=new UserDao(); + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + LogOnFrm frame = new LogOnFrm(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the frame. + */ + public LogOnFrm() { + //改变系统默认字体 + Font font = new Font("Dialog", Font.PLAIN, 12); + java.util.Enumeration keys = UIManager.getDefaults().keys(); + while (keys.hasMoreElements()) { + Object key = keys.nextElement(); + Object value = UIManager.get(key); + if (value instanceof javax.swing.plaf.FontUIResource) { + UIManager.put(key, font); + } + } + + setResizable(false); + setTitle("学生信息管理系统"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 450, 343); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + + JLabel lblNewLabel = new JLabel("学生信息管理系统"); + lblNewLabel.setFont(new Font("宋体", Font.BOLD, 23)); + + + JLabel lblNewLabel_1 = new JLabel("\u7528\u6237\u540D\uFF1A"); + + + JLabel lblNewLabel_2 = new JLabel("\u5BC6 \u7801\uFF1A"); + + + userNameTxt = new JTextField(); + userNameTxt.setColumns(10); + + passwordTxt = new JPasswordField(); + + JButton btnNewButton = new JButton("\u767B\u5F55"); + btnNewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + loginActionPerformed(e); + } + }); + + + JButton btnNewButton_1 = new JButton("\u91CD\u7F6E"); + btnNewButton_1.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + resetValueActionPerformed(e); + } + }); + ; + GroupLayout gl_contentPane = new GroupLayout(contentPane); + gl_contentPane.setHorizontalGroup( + gl_contentPane.createParallelGroup(Alignment.LEADING) + .addGroup(gl_contentPane.createSequentialGroup() + .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) + .addGroup(gl_contentPane.createSequentialGroup() + .addGap(111) + .addComponent(lblNewLabel)) + .addGroup(gl_contentPane.createSequentialGroup() + .addGap(101) + .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) + .addComponent(lblNewLabel_1) + .addComponent(lblNewLabel_2) + .addComponent(btnNewButton)) + .addGap(32) + .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) + .addComponent(btnNewButton_1) + .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false) + .addComponent(passwordTxt) + .addComponent(userNameTxt, GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE))))) + .addContainerGap(111, Short.MAX_VALUE)) + ); + gl_contentPane.setVerticalGroup( + gl_contentPane.createParallelGroup(Alignment.LEADING) + .addGroup(gl_contentPane.createSequentialGroup() + .addGap(30) + .addComponent(lblNewLabel) + .addGap(26) + .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) + .addGroup(gl_contentPane.createSequentialGroup() + .addComponent(lblNewLabel_1) + .addGap(29) + .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) + .addComponent(lblNewLabel_2) + .addComponent(passwordTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) + .addComponent(userNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGap(36) + .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) + .addComponent(btnNewButton) + .addComponent(btnNewButton_1)) + .addContainerGap(60, Short.MAX_VALUE)) + ); + contentPane.setLayout(gl_contentPane); + + // 设置JFrame居中显示 + this.setLocationRelativeTo(null); + } + + /** + * 登录事件处理 + * @param e + */ + private void loginActionPerformed(ActionEvent evt) { + String userName=this.userNameTxt.getText(); + String password=new String(this.passwordTxt.getPassword()); + if(StringUtil.isEmpty(userName)){ + JOptionPane.showMessageDialog(null, "用户名不能为空!"); + return; + } + if(StringUtil.isEmpty(password)){ + JOptionPane.showMessageDialog(null, "密码不能为空!"); + return; + } + User user=new User(userName,password); + Connection con=null; + try { + con=dbUtil.getCon(); + User currentUser=userDao.login(con, user); + if(currentUser!=null){ + dispose(); + new MainFrm().setVisible(true); + }else{ + JOptionPane.showMessageDialog(null, "用户名或者密码错误!"); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }finally{ + try { + dbUtil.closeCon(con); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + /** + * 重置事件处理 + * @param e + */ + private void resetValueActionPerformed(ActionEvent evt) { + this.userNameTxt.setText(""); + this.passwordTxt.setText(""); + } +} diff --git a/src/com/artisan/view/MainFrm.java b/src/com/artisan/view/MainFrm.java new file mode 100644 index 0000000000000000000000000000000000000000..569ad4982c1e7a0e19e49311185d7e747d14f48e --- /dev/null +++ b/src/com/artisan/view/MainFrm.java @@ -0,0 +1,118 @@ +package com.artisan.view; + +import java.awt.BorderLayout; +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import javax.swing.JMenuBar; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.ImageIcon; +import javax.swing.JDesktopPane; +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +public class MainFrm extends JFrame { + + private JPanel contentPane; + private JDesktopPane table =null; + + + + + /** + * Create the frame. + */ + public MainFrm() { + setTitle("学生信息管理系统"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 450, 300); + + JMenuBar menuBar = new JMenuBar(); + setJMenuBar(menuBar); + + JMenu mnNewMenu = new JMenu("\u57FA\u672C\u6570\u636E\u7EF4\u62A4"); + + menuBar.add(mnNewMenu); + + JMenu mnNewMenu_1 = new JMenu("班级信息管理"); +; + mnNewMenu.add(mnNewMenu_1); + + JMenuItem menuItem = new JMenuItem("班级信息添加"); + menuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + SchoolClassAddInterFrm bookTypeAddInterFrm=new SchoolClassAddInterFrm(); + bookTypeAddInterFrm.setVisible(true); + table.add(bookTypeAddInterFrm); + } + }); + + mnNewMenu_1.add(menuItem); + + JMenuItem menuItem_1 = new JMenuItem("班级信息调整"); + menuItem_1.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + SchoolClassManageInterFrm bookTypeManageInterFrm=new SchoolClassManageInterFrm(); + bookTypeManageInterFrm.setVisible(true); + table.add(bookTypeManageInterFrm); + } + }); + + mnNewMenu_1.add(menuItem_1); + + JMenu mnNewMenu_2 = new JMenu("学生信息管理"); + + mnNewMenu.add(mnNewMenu_2); + + JMenuItem menuItem_2 = new JMenuItem("学生信息添加"); + menuItem_2.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + StudentAddInterFrm bookAddInterFrm=new StudentAddInterFrm(); + bookAddInterFrm.setVisible(true); + table.add(bookAddInterFrm); + } + }); + + + + mnNewMenu_2.add(menuItem_2); + + JMenuItem menuItem_3 = new JMenuItem("学生信息调整"); + menuItem_3.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + StudentManageInterFrm bookManageInterFrm=new StudentManageInterFrm(); + bookManageInterFrm.setVisible(true); + table.add(bookManageInterFrm); + } + }); + + mnNewMenu_2.add(menuItem_3); + + JMenuItem menuItem_4 = new JMenuItem("\u5B89\u5168\u9000\u51FA"); + menuItem_4.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int result=JOptionPane.showConfirmDialog(null, "是否退出系统"); + if(result==0){ + dispose(); + } + } + }); + + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + contentPane.setLayout(new BorderLayout(0, 0)); + + table = new JDesktopPane(); + contentPane.add(table, BorderLayout.CENTER); + + // 设置JFrame最大化 + this.setExtendedState(JFrame.MAXIMIZED_BOTH); + } +} diff --git a/src/com/artisan/view/SchoolClassAddInterFrm.java b/src/com/artisan/view/SchoolClassAddInterFrm.java new file mode 100644 index 0000000000000000000000000000000000000000..c2a0b06491ada46d3ad521e93d667ebb73607a1d --- /dev/null +++ b/src/com/artisan/view/SchoolClassAddInterFrm.java @@ -0,0 +1,162 @@ +package com.artisan.view; + +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.sql.Connection; + +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JInternalFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.LayoutStyle.ComponentPlacement; +import javax.swing.border.LineBorder; + +import com.artisan.dao.SchoolClassDao; +import com.artisan.model.SchoolClass; +import com.artisan.util.DbUtil; +import com.artisan.util.StringUtil; + +public class SchoolClassAddInterFrm extends JInternalFrame { + + private JTextField classNameTxt; + private JTextArea classDescTxt; + + private DbUtil dbUtil=new DbUtil(); + private SchoolClassDao schoolClassDao=new SchoolClassDao(); + + + /** + * Create the frame. + */ + public SchoolClassAddInterFrm() { + setClosable(true); + setIconifiable(true); + setTitle("添加班级信息界面"); + setBounds(100, 100, 450, 300); + + JLabel lblNewLabel = new JLabel("班级信息名称"); + + JLabel lblNewLabel_1 = new JLabel("班级信息描述"); + + classNameTxt = new JTextField(); + classNameTxt.setColumns(10); + + classDescTxt = new JTextArea(); + classDescTxt.setLineWrap(true); + classDescTxt.setWrapStyleWord(true); + JButton btnNewButton = new JButton("\u6DFB\u52A0"); + btnNewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + bookTypeAddActionPerformed(e); + } + }); + btnNewButton.setIcon(new ImageIcon(SchoolClassAddInterFrm.class.getResource("/images/add.png"))); + + JButton btnNewButton_1 = new JButton("\u91CD\u7F6E"); + btnNewButton_1.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + resetValueActionPerformed(e); + } + }); + btnNewButton_1.setIcon(new ImageIcon(SchoolClassAddInterFrm.class.getResource("/images/reset.png"))); + GroupLayout groupLayout = new GroupLayout(getContentPane()); + groupLayout.setHorizontalGroup( + groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addGap(86) + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addComponent(lblNewLabel) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(classNameTxt, GroupLayout.PREFERRED_SIZE, 185, GroupLayout.PREFERRED_SIZE)) + .addGroup(groupLayout.createSequentialGroup() + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) + .addComponent(lblNewLabel_1) + .addComponent(btnNewButton)) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) + .addComponent(btnNewButton_1) + .addComponent(classDescTxt)))) + .addContainerGap(69, GroupLayout.PREFERRED_SIZE)) + ); + groupLayout.setVerticalGroup( + groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addGap(56) + .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) + .addComponent(lblNewLabel) + .addComponent(classNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGap(29) + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) + .addComponent(lblNewLabel_1) + .addComponent(classDescTxt, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(ComponentPlacement.RELATED, 29, Short.MAX_VALUE) + .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) + .addComponent(btnNewButton) + .addComponent(btnNewButton_1)) + .addGap(28)) + ); + getContentPane().setLayout(groupLayout); + + // 设置文本域边框 + classDescTxt.setBorder(new LineBorder(new java.awt.Color(127,157,185), 1, false)); + + } + + /** + * 班级信息添加事件处理 + * @param e + */ + private void bookTypeAddActionPerformed(ActionEvent evt) { + String className=this.classNameTxt.getText(); + String classDesc=this.classDescTxt.getText(); + if(StringUtil.isEmpty(className)){ + JOptionPane.showMessageDialog(null, "班级信息名称不能为空!"); + return; + } + SchoolClass schoolClass=new SchoolClass(className,classDesc); + Connection con=null; + try{ + con=dbUtil.getCon(); + int n=schoolClassDao.add(con, schoolClass); + if(n==1){ + JOptionPane.showMessageDialog(null, "班级信息添加成功!"); + resetValue(); + }else{ + JOptionPane.showMessageDialog(null, "班级信息添加失败!"); + } + }catch(Exception e){ + e.printStackTrace(); + JOptionPane.showMessageDialog(null, "班级信息添加失败!"); + }finally{ + try { + dbUtil.closeCon(con); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + /** + * 重置事件处理 + * @param evt + */ + private void resetValueActionPerformed(ActionEvent evt) { + this.resetValue(); + } + + /** + * 重置表单 + */ + private void resetValue(){ + this.classNameTxt.setText(""); + this.classDescTxt.setText(""); + } +} diff --git a/src/com/artisan/view/SchoolClassManageInterFrm.java b/src/com/artisan/view/SchoolClassManageInterFrm.java new file mode 100644 index 0000000000000000000000000000000000000000..6668a5d5314ad840787363d9127001220d935577 --- /dev/null +++ b/src/com/artisan/view/SchoolClassManageInterFrm.java @@ -0,0 +1,359 @@ +package com.artisan.view; + +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.sql.Connection; +import java.sql.ResultSet; +import java.util.Vector; + +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JInternalFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.LayoutStyle.ComponentPlacement; +import javax.swing.border.LineBorder; +import javax.swing.border.TitledBorder; +import javax.swing.table.DefaultTableModel; + +import com.artisan.dao.StudentDao; +import com.artisan.dao.SchoolClassDao; +import com.artisan.model.SchoolClass; +import com.artisan.util.DbUtil; +import com.artisan.util.StringUtil; + +public class SchoolClassManageInterFrm extends JInternalFrame { + private JTable schoolClassTable; + private JTextArea classDescTxt ; + + private DbUtil dbUtil=new DbUtil(); + private SchoolClassDao schoolClassDao=new SchoolClassDao(); + private StudentDao studentDao=new StudentDao(); + private JTextField s_classNameTxt; + private JTextField idTxt; + private JTextField classNameTxt; + + + + + + + /** + * Create the frame. + */ + public SchoolClassManageInterFrm() { + setClosable(true); + setIconifiable(true); + setTitle("班级信息管理界面"); + setBounds(100, 100, 507, 481); + + JScrollPane scrollPane = new JScrollPane(); + + JLabel label = new JLabel("班级信息名称"); + + s_classNameTxt = new JTextField(); + s_classNameTxt.setColumns(10); + + JButton button = new JButton("\u67E5\u8BE2"); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + schoolClassSearchActionPerformed(e); + } + }); + button.setIcon(new ImageIcon(SchoolClassManageInterFrm.class.getResource("/images/search.png"))); + + JPanel panel = new JPanel(); + panel.setBorder(new TitledBorder(null, "\u8868\u5355\u64CD\u4F5C", TitledBorder.LEADING, TitledBorder.TOP, null, null)); + GroupLayout groupLayout = new GroupLayout(getContentPane()); + groupLayout.setHorizontalGroup( + groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addGap(42) + .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING) + .addComponent(panel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE) + .addGroup(Alignment.LEADING, groupLayout.createSequentialGroup() + .addComponent(label) + .addGap(18) + .addComponent(s_classNameTxt, GroupLayout.PREFERRED_SIZE, 133, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(button)) + .addComponent(scrollPane, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE)) + .addGap(48)) + ); + groupLayout.setVerticalGroup( + groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addGap(33) + .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) + .addComponent(label) + .addComponent(s_classNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(button)) + .addGap(39) + .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(panel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addContainerGap(25, Short.MAX_VALUE)) + ); + + JLabel lblNewLabel = new JLabel("\u7F16\u53F7\uFF1A"); + + idTxt = new JTextField(); + idTxt.setEditable(false); + idTxt.setColumns(10); + + JLabel label_1 = new JLabel("班级信息名称"); + + classNameTxt = new JTextField(); + classNameTxt.setColumns(10); + + JLabel lblNewLabel_1 = new JLabel("\u63CF\u8FF0\uFF1A"); + + classDescTxt = new JTextArea(); + classDescTxt.setLineWrap(true); + classDescTxt.setWrapStyleWord(true); + JButton btnNewButton = new JButton("\u4FEE\u6539"); + btnNewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + schoolClassUpdateActionEvent(e); + } + }); + btnNewButton.setIcon(new ImageIcon(SchoolClassManageInterFrm.class.getResource("/images/modify.png"))); + + JButton btnNewButton_1 = new JButton("\u5220\u9664"); + btnNewButton_1.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + schoolClassDeleteActionEvent(e); + } + }); + btnNewButton_1.setIcon(new ImageIcon(SchoolClassManageInterFrm.class.getResource("/images/delete.png"))); + GroupLayout gl_panel = new GroupLayout(panel); + gl_panel.setHorizontalGroup( + gl_panel.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel.createSequentialGroup() + .addContainerGap() + .addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false) + .addGroup(gl_panel.createSequentialGroup() + .addComponent(lblNewLabel) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(idTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGap(31) + .addComponent(label_1) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(classNameTxt, GroupLayout.PREFERRED_SIZE, 105, GroupLayout.PREFERRED_SIZE)) + .addGroup(gl_panel.createSequentialGroup() + .addComponent(lblNewLabel_1) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(classDescTxt)) + .addGroup(gl_panel.createSequentialGroup() + .addComponent(btnNewButton) + .addGap(26) + .addComponent(btnNewButton_1))) + .addContainerGap(37, Short.MAX_VALUE)) + ); + gl_panel.setVerticalGroup( + gl_panel.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel.createSequentialGroup() + .addContainerGap() + .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE) + .addComponent(lblNewLabel) + .addComponent(idTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(label_1) + .addComponent(classNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGap(18) + .addGroup(gl_panel.createParallelGroup(Alignment.LEADING) + .addComponent(lblNewLabel_1) + .addComponent(classDescTxt, GroupLayout.PREFERRED_SIZE, 60, GroupLayout.PREFERRED_SIZE)) + .addGap(18) + .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE) + .addComponent(btnNewButton) + .addComponent(btnNewButton_1)) + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + panel.setLayout(gl_panel); + + schoolClassTable = new JTable(); + schoolClassTable.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + schoolClassTableMousePressed(e); + } + }); + schoolClassTable.setModel(new DefaultTableModel( + new Object[][] { + }, + new String[] { + "\u7F16\u53F7", "班级信息名称", "班级信息描述" + } + ) { + boolean[] columnEditables = new boolean[] { + false, false, false + }; + public boolean isCellEditable(int row, int column) { + return columnEditables[column]; + } + }); + schoolClassTable.getColumnModel().getColumn(1).setPreferredWidth(110); + schoolClassTable.getColumnModel().getColumn(2).setPreferredWidth(123); + scrollPane.setViewportView(schoolClassTable); + getContentPane().setLayout(groupLayout); + + this.fillTable(new SchoolClass()); + + // 设置文本域边框 + classDescTxt.setBorder(new LineBorder(new java.awt.Color(127,157,185), 1, false)); + } + + /** + * 班级信息删除事件处理 + * @param e + */ + private void schoolClassDeleteActionEvent(ActionEvent evt) { + String id=idTxt.getText(); + if(StringUtil.isEmpty(id)){ + JOptionPane.showMessageDialog(null, "请选择要删除的记录"); + return; + } + int n=JOptionPane.showConfirmDialog(null, "确定要删除该记录吗?"); + if(n==0){ + Connection con=null; + try{ + con=dbUtil.getCon(); + boolean flag=studentDao.existStudentByclassId(con, id); + if(flag){ + JOptionPane.showMessageDialog(null, "当前班级信息下有图书,不能删除"); + return; + } + int deleteNum=schoolClassDao.delete(con, id); + if(deleteNum==1){ + JOptionPane.showMessageDialog(null, "删除成功"); + this.resetValue(); + this.fillTable(new SchoolClass()); + }else{ + JOptionPane.showMessageDialog(null, "删除失败"); + } + }catch(Exception e){ + e.printStackTrace(); + JOptionPane.showMessageDialog(null, "删除失败"); + }finally{ + try { + dbUtil.closeCon(con); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + + /** + * 班级信息修改事件处理 + * @param evt + */ + private void schoolClassUpdateActionEvent(ActionEvent evt) { + String id=idTxt.getText(); + String className=classNameTxt.getText(); + String classDesc=classDescTxt.getText(); + if(StringUtil.isEmpty(id)){ + JOptionPane.showMessageDialog(null, "请选择要修改的记录"); + return; + } + if(StringUtil.isEmpty(className)){ + JOptionPane.showMessageDialog(null, "班级信息名称不能为空"); + return; + } + SchoolClass bookType=new SchoolClass(Integer.parseInt(id),className,classDesc); + Connection con=null; + try{ + con=dbUtil.getCon(); + int modifyNum=schoolClassDao.update(con, bookType); + if(modifyNum==1){ + JOptionPane.showMessageDialog(null, "修改成功"); + this.resetValue(); + this.fillTable(new SchoolClass()); + }else{ + JOptionPane.showMessageDialog(null, "修改失败"); + } + }catch(Exception e){ + e.printStackTrace(); + JOptionPane.showMessageDialog(null, "修改失败"); + }finally{ + try { + dbUtil.closeCon(con); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + /** + * 表格行点击事件处理 + * @param e + */ + private void schoolClassTableMousePressed(MouseEvent evt) { + int row=schoolClassTable.getSelectedRow(); + idTxt.setText((String)schoolClassTable.getValueAt(row, 0)); + classNameTxt.setText((String)schoolClassTable.getValueAt(row, 1)); + classDescTxt.setText((String)schoolClassTable.getValueAt(row, 2)); + } + + /** + * 班级信息搜索事件处理 + * @param evt + */ + private void schoolClassSearchActionPerformed(ActionEvent evt) { + String s_className=this.s_classNameTxt.getText(); + SchoolClass schoolClass=new SchoolClass(); + schoolClass.setClassName(s_className); + this.fillTable(schoolClass); + } + + /** + * 初始化表格 + * @param schoolClass + */ + private void fillTable(SchoolClass schoolClass){ + DefaultTableModel dtm=(DefaultTableModel) schoolClassTable.getModel(); + dtm.setRowCount(0); // 设置成0行 + Connection con=null; + try{ + con=dbUtil.getCon(); + ResultSet rs=schoolClassDao.list(con, schoolClass); + while(rs.next()){ + Vector v=new Vector(); + v.add(rs.getString("id")); + v.add(rs.getString("className")); + v.add(rs.getString("classDesc")); + dtm.addRow(v); + } + }catch(Exception e){ + e.printStackTrace(); + }finally{ + try { + dbUtil.closeCon(con); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + /** + * 重置表单 + */ + private void resetValue(){ + this.idTxt.setText(""); + this.classNameTxt.setText(""); + this.classDescTxt.setText(""); + } +} diff --git a/src/com/artisan/view/StudentAddInterFrm.java b/src/com/artisan/view/StudentAddInterFrm.java new file mode 100644 index 0000000000000000000000000000000000000000..a74a87812e319c982da1cd3438185f861f62eb42 --- /dev/null +++ b/src/com/artisan/view/StudentAddInterFrm.java @@ -0,0 +1,286 @@ +package com.artisan.view; + +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.sql.Connection; +import java.sql.ResultSet; + +import javax.swing.ButtonGroup; +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JInternalFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JRadioButton; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.LayoutStyle.ComponentPlacement; +import javax.swing.border.LineBorder; + +import com.artisan.dao.StudentDao; +import com.artisan.dao.SchoolClassDao; +import com.artisan.model.Student; +import com.artisan.model.SchoolClass; +import com.artisan.util.DbUtil; +import com.artisan.util.StringUtil; + +public class StudentAddInterFrm extends JInternalFrame { + private JTextField studentTxt; + private JTextField snTxt; + private final ButtonGroup buttonGroup = new ButtonGroup(); + private JTextField deptTxt; + private JComboBox schoolClassJcb; + private JTextArea addressTxt; + private JRadioButton manJrb; + private JRadioButton femaleJrb; + + private DbUtil dbUtil=new DbUtil(); + private SchoolClassDao schoolClassDao=new SchoolClassDao(); + private StudentDao studentDao=new StudentDao(); + + + + /** + * Create the frame. + */ + public StudentAddInterFrm() { + setClosable(true); + setIconifiable(true); + setTitle("添加学生信息"); + setBounds(100, 100, 450, 467); + + JLabel label = new JLabel("学生姓名"); + + studentTxt = new JTextField(); + studentTxt.setColumns(10); + + JLabel label_1 = new JLabel("学生学号"); + + snTxt = new JTextField(); + snTxt.setColumns(10); + + JLabel label_2 = new JLabel("学生性别"); + + manJrb = new JRadioButton("\u7537"); + buttonGroup.add(manJrb); + manJrb.setSelected(true); + + femaleJrb = new JRadioButton("\u5973"); + buttonGroup.add(femaleJrb); + + JLabel label_3 = new JLabel("所在院系"); + + deptTxt = new JTextField(); + deptTxt.setColumns(10); + + JLabel label_4 = new JLabel("家庭住址"); + + addressTxt = new JTextArea(); + + JLabel label_5 = new JLabel("所在班级"); + + schoolClassJcb = new JComboBox(); + + JButton button = new JButton("\u6DFB\u52A0"); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + bookAddActionPerformed(e); + } + }); + button.setIcon(new ImageIcon(StudentAddInterFrm.class.getResource("/images/add.png"))); + + JButton button_1 = new JButton("\u91CD\u7F6E"); + button_1.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + resetValueActionPerformed(e); + } + }); + button_1.setIcon(new ImageIcon(StudentAddInterFrm.class.getResource("/images/reset.png"))); + GroupLayout groupLayout = new GroupLayout(getContentPane()); + groupLayout.setHorizontalGroup( + groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addGap(42) + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addComponent(button) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(button_1) + .addGap(232)) + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) + .addComponent(label_5) + .addGroup(groupLayout.createSequentialGroup() + .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING) + .addComponent(label_4) + .addComponent(label_2) + .addComponent(label)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false) + .addComponent(studentTxt, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE) + .addGroup(groupLayout.createSequentialGroup() + .addComponent(manJrb) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(femaleJrb)) + .addComponent(schoolClassJcb, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(35) + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false) + .addGroup(groupLayout.createSequentialGroup() + .addComponent(label_1) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(snTxt, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)) + .addGroup(groupLayout.createSequentialGroup() + .addComponent(label_3) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(deptTxt)))) + .addComponent(addressTxt)) + .addContainerGap(44, Short.MAX_VALUE))))) + ); + groupLayout.setVerticalGroup( + groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addGap(42) + .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) + .addComponent(label) + .addComponent(studentTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(label_1) + .addComponent(snTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGap(29) + .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) + .addComponent(label_2) + .addComponent(manJrb) + .addComponent(femaleJrb) + .addComponent(label_3) + .addComponent(deptTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGap(33) + .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) + .addComponent(label_5) + .addComponent(schoolClassJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGap(30) + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) + .addComponent(label_4) + .addComponent(addressTxt, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(ComponentPlacement.RELATED, 37, Short.MAX_VALUE) + .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) + .addComponent(button) + .addComponent(button_1)) + .addGap(42)) + ); + getContentPane().setLayout(groupLayout); + + // 设置文本域边框 + addressTxt.setBorder(new LineBorder(new java.awt.Color(127,157,185), 1, false)); + + + fillBookType(); + } + + /** + * 重置事件处理 + * @param e + */ + private void resetValueActionPerformed(ActionEvent e) { + this.resetValue(); + } + + /** + * 学生添加事件处理 + * @param e + */ + private void bookAddActionPerformed(ActionEvent evt) { + String bookName=this.studentTxt.getText(); + String author=this.snTxt.getText(); + String price=this.deptTxt.getText(); + String bookDesc=this.addressTxt.getText(); + + if(StringUtil.isEmpty(bookName)){ + JOptionPane.showMessageDialog(null, "学生姓名不能为空!"); + return; + } + + if(StringUtil.isEmpty(author)){ + JOptionPane.showMessageDialog(null, "学生学号不能为空!"); + return; + } + + if(StringUtil.isEmpty(price)){ + JOptionPane.showMessageDialog(null, "学生学院不能为空!"); + return; + } + + String sex=""; + if(manJrb.isSelected()){ + sex="男"; + }else if(femaleJrb.isSelected()){ + sex="女"; + } + + SchoolClass bookType=(SchoolClass) schoolClassJcb.getSelectedItem(); + int bookTypeId=bookType.getId(); + + Student book=new Student(bookName,author, sex, price , bookTypeId, bookDesc); + + Connection con=null; + try{ + con=dbUtil.getCon(); + int addNum=studentDao.add(con, book); + if(addNum==1){ + JOptionPane.showMessageDialog(null, "学生添加成功!"); + resetValue(); + }else{ + JOptionPane.showMessageDialog(null, "学生添加失败!"); + } + }catch(Exception e){ + e.printStackTrace(); + JOptionPane.showMessageDialog(null, "学生添加失败!"); + }finally{ + try { + dbUtil.closeCon(con); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + /** + * 重置表单 + */ + private void resetValue(){ + this.studentTxt.setText(""); + this.snTxt.setText(""); + this.deptTxt.setText(""); + this.manJrb.setSelected(true); + this.addressTxt.setText(""); + if(this.schoolClassJcb.getItemCount()>0){ + this.schoolClassJcb.setSelectedIndex(0); + } + } + + /** + * 初始化学生类别下拉框 + */ + private void fillBookType(){ + Connection con=null; + SchoolClass bookType=null; + try{ + con=dbUtil.getCon(); + ResultSet rs=schoolClassDao.list(con, new SchoolClass()); + while(rs.next()){ + bookType=new SchoolClass(); + bookType.setId(rs.getInt("id")); + bookType.setClassName(rs.getString("className")); + this.schoolClassJcb.addItem(bookType); + } + }catch(Exception e){ + e.printStackTrace(); + }finally{ + + } + } +} diff --git a/src/com/artisan/view/StudentManageInterFrm.java b/src/com/artisan/view/StudentManageInterFrm.java new file mode 100644 index 0000000000000000000000000000000000000000..3a7e9bb5883bcadbb2b282373e11ec8f1ed4378c --- /dev/null +++ b/src/com/artisan/view/StudentManageInterFrm.java @@ -0,0 +1,556 @@ +package com.artisan.view; + +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.sql.Connection; +import java.sql.ResultSet; +import java.util.Vector; + +import javax.swing.ButtonGroup; +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JInternalFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.LayoutStyle.ComponentPlacement; +import javax.swing.border.LineBorder; +import javax.swing.border.TitledBorder; +import javax.swing.table.DefaultTableModel; + +import com.artisan.dao.StudentDao; +import com.artisan.dao.SchoolClassDao; +import com.artisan.model.Student; +import com.artisan.model.SchoolClass; +import com.artisan.util.DbUtil; +import com.artisan.util.StringUtil; + +public class StudentManageInterFrm extends JInternalFrame { + private JTable studentTable; + private JTextField s_nameTxt; + private JTextField s_snTxt; + private JComboBox s_schoolClassJcb; + private JRadioButton manJrb ; + private JRadioButton femaleJrb ; + private JTextArea addressTxt; + private JComboBox schoolClassJcb ; + + private DbUtil dbUtil=new DbUtil(); + private SchoolClassDao schoolClassDao=new SchoolClassDao(); + private StudentDao studentDao=new StudentDao(); + private JTextField idTxt; + private JTextField nameTxt; + private final ButtonGroup buttonGroup = new ButtonGroup(); + private JTextField deptTxt; + private JTextField snTxt; + + + /** + * Create the frame. + */ + public StudentManageInterFrm() { + setClosable(true); + setIconifiable(true); + setTitle("学生信息管理主界面"); + setBounds(100, 100, 677, 487); + + JScrollPane scrollPane = new JScrollPane(); + + JPanel panel = new JPanel(); + panel.setBorder(new TitledBorder(null, "\u641C\u7D22\u6761\u4EF6", TitledBorder.LEADING, TitledBorder.TOP, null, null)); + + JPanel panel_1 = new JPanel(); + panel_1.setBorder(new TitledBorder(null, "\u8868\u5355\u64CD\u4F5C", TitledBorder.LEADING, TitledBorder.TOP, null, null)); + GroupLayout groupLayout = new GroupLayout(getContentPane()); + groupLayout.setHorizontalGroup( + groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addContainerGap() + .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING) + .addComponent(panel_1, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(Alignment.LEADING, groupLayout.createParallelGroup(Alignment.LEADING, false) + .addComponent(panel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(scrollPane))) + .addContainerGap(66, Short.MAX_VALUE)) + ); + groupLayout.setVerticalGroup( + groupLayout.createParallelGroup(Alignment.LEADING) + .addGroup(groupLayout.createSequentialGroup() + .addGap(28) + .addComponent(panel, GroupLayout.PREFERRED_SIZE, 65, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(panel_1, GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE) + .addContainerGap()) + ); + + JLabel lblNewLabel = new JLabel("\u7F16\u53F7\uFF1A"); + + idTxt = new JTextField(); + idTxt.setEditable(false); + idTxt.setColumns(10); + + JLabel lblNewLabel_1 = new JLabel("学生姓名"); + + nameTxt = new JTextField(); + nameTxt.setColumns(10); + + JLabel label_3 = new JLabel("学生性别"); + + manJrb = new JRadioButton("\u7537"); + buttonGroup.add(manJrb); + manJrb.setSelected(true); + + femaleJrb = new JRadioButton("\u5973"); + buttonGroup.add(femaleJrb); + + JLabel label_4 = new JLabel("所在学院"); + + deptTxt = new JTextField(); + deptTxt.setColumns(10); + + JLabel lblNewLabel_2 = new JLabel("学生学号"); + + snTxt = new JTextField(); + snTxt.setColumns(10); + + JLabel label_5 = new JLabel("所属班级"); + + schoolClassJcb = new JComboBox(); + + JLabel label_6 = new JLabel("家庭住址"); + + addressTxt = new JTextArea(); + + JButton button_1 = new JButton("\u4FEE\u6539"); + button_1.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + studentUpdateActionPerformed(evt); + } + }); + button_1.setIcon(new ImageIcon(StudentManageInterFrm.class.getResource("/images/modify.png"))); + + JButton button_2 = new JButton("\u5220\u9664"); + button_2.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + studentDeleteActionPerformed(evt); + } + }); + button_2.setIcon(new ImageIcon(StudentManageInterFrm.class.getResource("/images/delete.png"))); + GroupLayout gl_panel_1 = new GroupLayout(panel_1); + gl_panel_1.setHorizontalGroup( + gl_panel_1.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(19) + .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_1.createSequentialGroup() + .addComponent(button_1) + .addGap(18) + .addComponent(button_2) + .addGap(386)) + .addGroup(gl_panel_1.createSequentialGroup() + .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_1.createSequentialGroup() + .addComponent(label_6) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(addressTxt)) + .addGroup(gl_panel_1.createSequentialGroup() + .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false) + .addGroup(gl_panel_1.createSequentialGroup() + .addComponent(label_4) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(deptTxt)) + .addGroup(gl_panel_1.createSequentialGroup() + .addComponent(lblNewLabel) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(idTxt, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE))) + .addGap(26) + .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false) + .addGroup(gl_panel_1.createSequentialGroup() + .addComponent(lblNewLabel_1) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(nameTxt, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE)) + .addGroup(gl_panel_1.createSequentialGroup() + .addComponent(lblNewLabel_2) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(snTxt))) + .addGap(26) + .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING, false) + .addGroup(gl_panel_1.createSequentialGroup() + .addComponent(label_3) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(manJrb) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(femaleJrb)) + .addGroup(gl_panel_1.createSequentialGroup() + .addComponent(label_5) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(schoolClassJcb, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))) + .addContainerGap(86, Short.MAX_VALUE)))) + ); + gl_panel_1.setVerticalGroup( + gl_panel_1.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel_1.createSequentialGroup() + .addGap(21) + .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE) + .addComponent(lblNewLabel) + .addComponent(idTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(lblNewLabel_1) + .addComponent(nameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(label_3) + .addComponent(manJrb) + .addComponent(femaleJrb)) + .addGap(18) + .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE) + .addComponent(label_4) + .addComponent(deptTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(lblNewLabel_2) + .addComponent(snTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(label_5) + .addComponent(schoolClassJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGap(18) + .addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING) + .addComponent(label_6) + .addComponent(addressTxt, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(ComponentPlacement.RELATED, 20, Short.MAX_VALUE) + .addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE) + .addComponent(button_1) + .addComponent(button_2))) + ); + panel_1.setLayout(gl_panel_1); + + JLabel label = new JLabel("学生姓名"); + + s_nameTxt = new JTextField(); + s_nameTxt.setColumns(10); + + JLabel label_1 = new JLabel("学生编号"); + + s_snTxt = new JTextField(); + s_snTxt.setColumns(10); + + JLabel label_2 = new JLabel("所属班级"); + + s_schoolClassJcb = new JComboBox(); + + JButton button = new JButton("\u67E5\u8BE2"); + button.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + bookSearchActionPerformed(e); + } + }); + button.setIcon(new ImageIcon(StudentManageInterFrm.class.getResource("/images/search.png"))); + GroupLayout gl_panel = new GroupLayout(panel); + gl_panel.setHorizontalGroup( + gl_panel.createParallelGroup(Alignment.LEADING) + .addGroup(gl_panel.createSequentialGroup() + .addGap(19) + .addComponent(label) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(s_nameTxt, GroupLayout.PREFERRED_SIZE, 77, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(label_1) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(s_snTxt, GroupLayout.PREFERRED_SIZE, 74, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(ComponentPlacement.UNRELATED) + .addComponent(label_2) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(s_schoolClassJcb, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE) + .addGap(18) + .addComponent(button) + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + gl_panel.setVerticalGroup( + gl_panel.createParallelGroup(Alignment.TRAILING) + .addGroup(gl_panel.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE) + .addComponent(label) + .addComponent(s_nameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(label_1) + .addComponent(s_snTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(label_2) + .addComponent(s_schoolClassJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(button)) + .addGap(16)) + ); + panel.setLayout(gl_panel); + + studentTable = new JTable(); + studentTable.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent met) { + studentTableMousePressed(met); + } + }); + scrollPane.setViewportView(studentTable); + studentTable.setModel(new DefaultTableModel( + new Object[][] { + }, + new String[] { + "\u7F16\u53F7", "学生姓名", "学生学号", "学生性别", "所属院系", "家庭住址", "所属班级" + } + ) { + boolean[] columnEditables = new boolean[] { + false, false, false, false, false, false, false + }; + public boolean isCellEditable(int row, int column) { + return columnEditables[column]; + } + }); + studentTable.getColumnModel().getColumn(5).setPreferredWidth(119); + getContentPane().setLayout(groupLayout); + + // 设置文本域边框 + addressTxt.setBorder(new LineBorder(new java.awt.Color(127,157,185), 1, false)); + + + this.fillBookType("search"); + this.fillBookType("modify"); + this.fillTable(new Student()); + } + + /** + * 学生信息删除事件处理 + * @param evt + */ + private void studentDeleteActionPerformed(ActionEvent evt) { + String id=idTxt.getText(); + if(StringUtil.isEmpty(id)){ + JOptionPane.showMessageDialog(null, "请选择要删除的记录"); + return; + } + int n=JOptionPane.showConfirmDialog(null, "确定要删除该记录吗?"); + if(n==0){ + Connection con=null; + try{ + con=dbUtil.getCon(); + int deleteNum=studentDao.delete(con, id); + if(deleteNum==1){ + JOptionPane.showMessageDialog(null, "删除成功"); + this.resetValue(); + this.fillTable(new Student()); + }else{ + JOptionPane.showMessageDialog(null, "删除失败"); + } + }catch(Exception e){ + e.printStackTrace(); + JOptionPane.showMessageDialog(null, "删除失败"); + }finally{ + try { + dbUtil.closeCon(con); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + + /** + * 学生信息修改事件处理 + * @param evt + */ + private void studentUpdateActionPerformed(ActionEvent evt) { + String id=this.idTxt.getText(); + if(StringUtil.isEmpty(id)){ + JOptionPane.showMessageDialog(null, "请选择要修改的记录"); + return; + } + + String sname=this.nameTxt.getText(); + String sn=this.snTxt.getText(); + String dept=this.deptTxt.getText(); + String address=this.addressTxt.getText(); + + if(StringUtil.isEmpty(sname)){ + JOptionPane.showMessageDialog(null, "学生信息名称不能为空!"); + return; + } + + if(StringUtil.isEmpty(sn)){ + JOptionPane.showMessageDialog(null, "学生信息作者不能为空!"); + return; + } + + if(StringUtil.isEmpty(dept)){ + JOptionPane.showMessageDialog(null, "学生信息价格不能为空!"); + return; + } + + String sex=""; + if(manJrb.isSelected()){ + sex="男"; + }else if(femaleJrb.isSelected()){ + sex="女"; + } + + SchoolClass schoolClassTmp=(SchoolClass) schoolClassJcb.getSelectedItem(); + int scId=schoolClassTmp.getId(); + + Student book=new Student(Integer.parseInt(id), sname, sn, sex, dept, scId, address); + + Connection con=null; + try{ + con=dbUtil.getCon(); + int addNum=studentDao.update(con, book); + if(addNum==1){ + JOptionPane.showMessageDialog(null, "学生信息修改成功!"); + resetValue(); + this.fillTable(new Student()); + }else{ + JOptionPane.showMessageDialog(null, "学生信息修改失败!"); + } + }catch(Exception e){ + e.printStackTrace(); + JOptionPane.showMessageDialog(null, "学生信息修改失败!"); + }finally{ + try { + dbUtil.closeCon(con); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + /** + * 重置表单 + */ + private void resetValue(){ + this.idTxt.setText(""); + this.nameTxt.setText(""); + this.snTxt.setText(""); + this.deptTxt.setText(""); + this.manJrb.setSelected(true); + this.addressTxt.setText(""); + if(this.schoolClassJcb.getItemCount()>0){ + this.schoolClassJcb.setSelectedIndex(0); + } + } + + /** + * 表格行点击事件处理 + * @param met + */ + private void studentTableMousePressed(MouseEvent met) { + int row=this.studentTable.getSelectedRow(); + this.idTxt.setText((String)studentTable.getValueAt(row, 0)); + this.nameTxt.setText((String)studentTable.getValueAt(row, 1)); + this.snTxt.setText((String)studentTable.getValueAt(row, 2)); + String sex=(String)studentTable.getValueAt(row, 3); + if("男".equals(sex)){ + this.manJrb.setSelected(true); + }else if("女".equals(sex)){ + this.femaleJrb.setSelected(true); + } + this.deptTxt.setText(studentTable.getValueAt(row, 4)+""); + this.addressTxt.setText((String)studentTable.getValueAt(row, 5)); + String className=(String)this.studentTable.getValueAt(row, 6); + int n=this.schoolClassJcb.getItemCount(); + for(int i=0;i + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file