/*
* CourseManageInterFrm.java
*
* Created on __DATE__, __TIME__
*/
package com.jakey.view;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import com.jakey.dao.CourseDao;
import com.jakey.model.Course;
import com.jakey.model.Selection;
import com.jakey.util.DbUtil;
import com.jakey.util.StringUtil;
/**
*
* @author __USER__
*/
public class CourseManageInterFrm extends javax.swing.JInternalFrame {
DbUtil dbUtil = new DbUtil();
CourseDao courseDao = new CourseDao();
private int NumSelected;
/** Creates new form CourseManageInterFrm */
public CourseManageInterFrm() {
initComponents();
this.setLocation(200, 50);
this.fillTable(new Course());
}
private void resetValue() {
this.courseIdTxt.setText("");
this.courseNameTxt.setText("");
this.courseTeacherTxt.setText("");
this.courseTimeTxt.setText("");
this.capacityTxt.setText("");
this.numSelectedTxt.setText("");
}
private void fillTable(Course course) {
DefaultTableModel dtm = (DefaultTableModel) courseTable.getModel();
dtm.setRowCount(0);
Connection con = null;
try {
con = dbUtil.getCon();
ResultSet rs = courseDao.courseList(con, course);
while (rs.next()) {
Vector v = new Vector();
v.add(rs.getString("courseId"));
v.add(rs.getString("courseName"));
v.add(rs.getString("courseTime"));
v.add(rs.getString("courseTeacher"));
v.add(rs.getString("capacity"));
v.add(rs.getString("numSelected"));
dtm.addRow(v);
}
} 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();
}
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
s_courseNameTxt = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
s_courseTimeTxt = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
s_courseTeacherTxt = new javax.swing.JTextField();
jb_search = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
courseTable = new javax.swing.JTable();
jPanel2 = new javax.swing.JPanel();
courseIdTxt = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
courseNameTxt = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
courseTimeTxt = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
courseTeacherTxt = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
capacityTxt = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
numSelectedTxt = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
jb_modify = new javax.swing.JButton();
jb_delete = new javax.swing.JButton();
setClosable(true);
setIconifiable(true);
setTitle("\u8bfe\u7a0b\u4fe1\u606f\u4fee\u6539");
jPanel1.setBorder(javax.swing.BorderFactory
.createTitledBorder("\u641c\u7d22\u6761\u4ef6"));
jLabel1.setText("\u8bfe\u7a0b\u540d\u79f0");
jLabel2.setText("\u4efb\u8bfe\u8001\u5e08");
jLabel3.setText("\u4e0a\u8bfe\u65f6\u95f4");
jb_search
.setIcon(new javax.swing.ImageIcon(
"D:\\Workspaces\\MyEclipse 8.5\\CourseSys\\src\\com\\jakey\\view\\image\\search.png")); // NOI18N
jb_search.setText("\u67e5\u8be2");
jb_search.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jb_searchActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout
.setHorizontalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(jLabel1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
s_courseNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
158,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(26, 26, 26)
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(
s_courseTimeTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
149,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(46, 46, 46)
.addComponent(jLabel2)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
s_courseTeacherTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
110,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
50, Short.MAX_VALUE)
.addComponent(jb_search).addGap(94, 94,
94)));
jPanel1Layout
.setVerticalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
s_courseNameTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)
.addComponent(jb_search)
.addComponent(jLabel3)
.addComponent(
s_courseTimeTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(
s_courseTeacherTxt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)));
courseTable.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] {
}, new String[] { "课程编号", "课程名称", "上课时间", "任课老师", "课程容量",
"已选人数" }) {
boolean[] canEdit = new boolean[] { false, false, false, false,
false, false };
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
});
courseTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
courseTableMousePressed(evt);
}
});
jScrollPane1.setViewportView(courseTable);
jPanel2.setBorder(javax.swing.BorderFactory
.createTitledBorder("\u8868\u5355\u64cd\u4f5c"));
courseIdTxt.setEditable(false);
jLabel4.setText("\u8bfe\u7a0b\u7f16\u53f7");
jLabel5.setText("\u8bfe\u7a0b\u540d\u79f0");
jLabel6.setText("\u4e0a\u8bfe\u65f6\u95f4");
jLabel7.setText("\u4efb\u8bfe\u8001\u5e08");
jLabel8.setText("\u8bfe\u7a0b\u5bb9\u91cf");
numSelectedTxt.setEditable(false);
jLabel9.setText(