package com.gs.stu.view;
import com.gs.stu.bean.Course;
import com.gs.stu.bean.SelectCourse;
import com.gs.stu.bean.SelectCourseView;
import com.gs.stu.file.PrintScoreExcelTable;
import com.gs.stu.service.TeacherService;
import com.gs.stu.service.impl.TeacherServiceImpl;
import com.gs.stu.util.FrameUtil;
import com.gs.stu.util.checkUtil;
import java.io.File;
import java.util.List;
import java.util.Vector;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
/**
*
* @author yhy
*/
public class TeaScoreFrame extends javax.swing.JInternalFrame {
TeacherService teaservice = new TeacherServiceImpl();
/** Creates new form TeaScoreFrame */
public TeaScoreFrame() {
initComponents();
//初始化课程编号组合框
List<Course> list = teaservice.findCourseByTeacher(SelectiveMainFrame.teacher.getTid());
for(Course course:list){
this.cbCid.addItem(course.getId());
}
}
/** 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
cbCid = new javax.swing.JComboBox();
btnSearch = new javax.swing.JButton();
btnOutSorce = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
scoreTable = new javax.swing.JTable();
jLabel2 = new javax.swing.JLabel();
txtId = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
txtSorce = new javax.swing.JTextField();
btnSave = new javax.swing.JButton();
setClosable(true);
setTitle("教师-成绩管理");
addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
formInternalFrameClosed(evt);
}
public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
}
});
jLabel1.setText("课程编号:");
btnSearch.setText("搜索");
btnSearch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSearchActionPerformed(evt);
}
});
btnOutSorce.setText("导出成绩");
btnOutSorce.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOutSorceActionPerformed(evt);
}
});
scoreTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"学号", "姓名", "课程名", "成绩"
}
) {
boolean[] canEdit = new boolean [] {
false, false, false, true
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
scoreTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
scoreTableMouseClicked(evt);
}
});
jScrollPane1.setViewportView(scoreTable);
jLabel2.setText("学号:");
txtId.setEditable(false);
jLabel3.setText("成绩:");
btnSave.setText("保存");
btnSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSaveActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(cbCid, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnSearch)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 180, Short.MAX_VALUE)
.addComponent(btnOutSorce))))
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel3)
.addGap(29, 29, 29)
.addComponent(txtSorce, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(29, 29, 29)
.addComponent(btnSave)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(cbCid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnOutSorce)
.addComponent(btnSearch))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 366, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(txtSorce, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSave))
.addContainerGap(26, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {
int cid = (Integer)this.cbCid.getSelectedItem();
List<SelectCourseView> list = teaservice.findCourseScoreByCid(cid);
showOnTable(list);
}
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String id=this.txtId.getText().trim();
String sorce=this.txtSorce.getText().trim();
String biao="^[0-9]{8}$";
String biao1="^[0-9]{1,3}$";
if(id.equals("")==true)
{
JOptionPane.showMessageDialog(this, "学号不能为空");
this.txtId.requestFocus();
return;
}
if(sorce.equals("")==true)
{
JOptionPane.showMessageDialog(this, "成绩不能为空");
this.txtSorce.requestFocus();
return;
}
boolean b1=checkUtil.checkData(biao,this.txtId.getText());
if(b1==false)
{
JOptionPane.showMessageDialog(this, "学号必须8位纯数字");
return;
}
boolean b2=checkUtil.checkData(biao1,this.txtSorce.getText());
if(b2==false)
{
JOptionPane.showMessageDialog(this, "分数必须为1到3位纯数字");
return;
}
SelectCourse sc=new SelectCourse();
sc.setSid(Integer.parseInt(id));
int cid = (Integer)this.cbCid.getSelectedItem();
sc.setCid(cid);
sc.setScore(Integer.parseInt(this.txtSorce.getText()));
boolean b=teaservice.updateScore(sc);
if(b==true)
{
JOptionPane.showMessageDialog(this, "分数录入成功");
btnSearchActionPerformed(evt);
return;
}
else
{
JOptionPane.showMessageDialog(this, "分数录入失败");
return;
}
}
private void scoreTableMouseClicked(java.awt.event.MouseEvent evt) {
int row =this.scoreTable.getSelectedRow();
int id=(Integer)this.scoreTable.getValueAt(row,0);
this.txtId.setText(id+"");
}
private void formInternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
FrameUtil.framemap.remove("teascoreframe");
}
private void btnOutSorceActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser savefile = new JFileChooser();//文件选择对话框
FileFilter filter = new FileNameExtensionFilter("Excel文件(*.xls)", "*.xls");
savefile.addChoosableFileFilter(filter);//添加过滤器
savefile.setFileFilter(filter);
int flag = savefile.showSaveDialog(this);//打开文件选选择对话框
File file = null;
if (flag == JFileChooser.APPROVE_OPTION) {
//如果点击了保存按钮
file = savefile.getSelectedFile();
System.out.println("文件名:" + file.getAbsolutePath());
//JTable获取数据,输出到文件
PrintScoreExcelTable.printScoreContent(scoreTable, file);
JOptionPane.showMessageDialog(this, "导出成功");
}
}
private void showOnTable( List<SelectCourseView> list){
DefaultTableModel dtm = (DefaultTableModel) this.scoreTable.getModel();
while (dtm.getRowCount() > 0) {
dtm.removeRow(0);
}
for(SelectCourseView selectcourse:list){
Vector row = new Vector();
row.add(selectcourse.getSid());
row.add(selectcourse.getSname());
row.add(selectcourse.getCoursename());
row.add(selectcourse.getScore());
dtm.addRow(row);
}
}
// Variables declaration - do not modify
private javax.swing.JButton btnOutSorce;
private javax.swing.JButton btnSave;
private javax.swing.JButton btnSearch;
private javax.swing.JComboBox cbCid;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable scoreTable;
private javax.swing.JTextField txtId;
private javax.swing.JTextField txtSorce;
// End of variables declaration
}
import com.gs.stu.bean.Course;
import com.gs.stu.bean.SelectCourse;
import com.gs.stu.bean.SelectCourseView;
import com.gs.stu.file.PrintScoreExcelTable;
import com.gs.stu.service.TeacherService;
import com.gs.stu.service.impl.TeacherServiceImpl;
import com.gs.stu.util.FrameUtil;
import com.gs.stu.util.checkUtil;
import java.io.File;
import java.util.List;
import java.util.Vector;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
/**
*
* @author yhy
*/
public class TeaScoreFrame extends javax.swing.JInternalFrame {
TeacherService teaservice = new TeacherServiceImpl();
/** Creates new form TeaScoreFrame */
public TeaScoreFrame() {
initComponents();
//初始化课程编号组合框
List<Course> list = teaservice.findCourseByTeacher(SelectiveMainFrame.teacher.getTid());
for(Course course:list){
this.cbCid.addItem(course.getId());
}
}
/** 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
cbCid = new javax.swing.JComboBox();
btnSearch = new javax.swing.JButton();
btnOutSorce = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
scoreTable = new javax.swing.JTable();
jLabel2 = new javax.swing.JLabel();
txtId = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
txtSorce = new javax.swing.JTextField();
btnSave = new javax.swing.JButton();
setClosable(true);
setTitle("教师-成绩管理");
addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
formInternalFrameClosed(evt);
}
public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
}
});
jLabel1.setText("课程编号:");
btnSearch.setText("搜索");
btnSearch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSearchActionPerformed(evt);
}
});
btnOutSorce.setText("导出成绩");
btnOutSorce.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOutSorceActionPerformed(evt);
}
});
scoreTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"学号", "姓名", "课程名", "成绩"
}
) {
boolean[] canEdit = new boolean [] {
false, false, false, true
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
scoreTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
scoreTableMouseClicked(evt);
}
});
jScrollPane1.setViewportView(scoreTable);
jLabel2.setText("学号:");
txtId.setEditable(false);
jLabel3.setText("成绩:");
btnSave.setText("保存");
btnSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSaveActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(cbCid, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnSearch)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 180, Short.MAX_VALUE)
.addComponent(btnOutSorce))))
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel3)
.addGap(29, 29, 29)
.addComponent(txtSorce, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(29, 29, 29)
.addComponent(btnSave)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(cbCid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnOutSorce)
.addComponent(btnSearch))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 366, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(txtSorce, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSave))
.addContainerGap(26, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {
int cid = (Integer)this.cbCid.getSelectedItem();
List<SelectCourseView> list = teaservice.findCourseScoreByCid(cid);
showOnTable(list);
}
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String id=this.txtId.getText().trim();
String sorce=this.txtSorce.getText().trim();
String biao="^[0-9]{8}$";
String biao1="^[0-9]{1,3}$";
if(id.equals("")==true)
{
JOptionPane.showMessageDialog(this, "学号不能为空");
this.txtId.requestFocus();
return;
}
if(sorce.equals("")==true)
{
JOptionPane.showMessageDialog(this, "成绩不能为空");
this.txtSorce.requestFocus();
return;
}
boolean b1=checkUtil.checkData(biao,this.txtId.getText());
if(b1==false)
{
JOptionPane.showMessageDialog(this, "学号必须8位纯数字");
return;
}
boolean b2=checkUtil.checkData(biao1,this.txtSorce.getText());
if(b2==false)
{
JOptionPane.showMessageDialog(this, "分数必须为1到3位纯数字");
return;
}
SelectCourse sc=new SelectCourse();
sc.setSid(Integer.parseInt(id));
int cid = (Integer)this.cbCid.getSelectedItem();
sc.setCid(cid);
sc.setScore(Integer.parseInt(this.txtSorce.getText()));
boolean b=teaservice.updateScore(sc);
if(b==true)
{
JOptionPane.showMessageDialog(this, "分数录入成功");
btnSearchActionPerformed(evt);
return;
}
else
{
JOptionPane.showMessageDialog(this, "分数录入失败");
return;
}
}
private void scoreTableMouseClicked(java.awt.event.MouseEvent evt) {
int row =this.scoreTable.getSelectedRow();
int id=(Integer)this.scoreTable.getValueAt(row,0);
this.txtId.setText(id+"");
}
private void formInternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
FrameUtil.framemap.remove("teascoreframe");
}
private void btnOutSorceActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser savefile = new JFileChooser();//文件选择对话框
FileFilter filter = new FileNameExtensionFilter("Excel文件(*.xls)", "*.xls");
savefile.addChoosableFileFilter(filter);//添加过滤器
savefile.setFileFilter(filter);
int flag = savefile.showSaveDialog(this);//打开文件选选择对话框
File file = null;
if (flag == JFileChooser.APPROVE_OPTION) {
//如果点击了保存按钮
file = savefile.getSelectedFile();
System.out.println("文件名:" + file.getAbsolutePath());
//JTable获取数据,输出到文件
PrintScoreExcelTable.printScoreContent(scoreTable, file);
JOptionPane.showMessageDialog(this, "导出成功");
}
}
private void showOnTable( List<SelectCourseView> list){
DefaultTableModel dtm = (DefaultTableModel) this.scoreTable.getModel();
while (dtm.getRowCount() > 0) {
dtm.removeRow(0);
}
for(SelectCourseView selectcourse:list){
Vector row = new Vector();
row.add(selectcourse.getSid());
row.add(selectcourse.getSname());
row.add(selectcourse.getCoursename());
row.add(selectcourse.getScore());
dtm.addRow(row);
}
}
// Variables declaration - do not modify
private javax.swing.JButton btnOutSorce;
private javax.swing.JButton btnSave;
private javax.swing.JButton btnSearch;
private javax.swing.JComboBox cbCid;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable scoreTable;
private javax.swing.JTextField txtId;
private javax.swing.JTextField txtSorce;
// End of variables declaration
}