📄 op_homework.java
字号:
package grad.util.homework;import java.util.*;import java.sql.*;import grad.util.DataBase;public class op_homework { public op_homework() { } /** * 查看指定课程所发布的全部作业 * @param sourseid * @return */ public ArrayList getAllHomeworkPub(String sourseid){ Connection conn=null; Statement st=null; ResultSet rs=null; String sql ="select * from t_homework where course_code='"+sourseid+"' and type=1"; ArrayList al=new ArrayList(); try{ DataBase ds = new DataBase(); conn = ds.conn; st = conn.createStatement(); rs = st.executeQuery(sql); while (rs.next()) { homework cs=new homework(); cs.setid(rs.getInt(1)); cs.settitle(rs.getString(2)); cs.setlink(rs.getString(3)); cs.setdate(rs.getString(4)); cs.settype(rs.getString(5)); cs.setcourse_code(rs.getString(6)); cs.setuser_id(rs.getString(7)); al.add(cs); } return al; }catch(Exception e){System.out.println(e.getMessage());return null;} } /** * 查询指定课程作业 全部学生提交的作业 * @param sourseid * @return */public ArrayList getAllHomeworkCommit(String sourseid){ Connection conn=null; Statement st=null; ResultSet rs=null; String sql ="select * from t_homework where course_code='"+sourseid+"' and type=2 order by user_id desc"; ArrayList al=new ArrayList(); try{ DataBase ds = new DataBase(); conn = ds.conn; st = conn.createStatement(); rs = st.executeQuery(sql); while (rs.next()) { homework cs=new homework(); cs.setid(rs.getInt(1)); cs.settitle(rs.getString(2)); cs.setlink(rs.getString(3)); cs.setdate(rs.getString(4)); cs.settype(rs.getString(5)); cs.setcourse_code(rs.getString(6)); cs.setuser_id(rs.getString(7)); cs.setstatus(rs.getString(8)); al.add(cs); } return al; }catch(Exception e){System.out.println(e.getMessage());return null;} } /** * 查询学生为某门课程提交的全部作业答案 * @param sourseid * @param stuentid * @return */public ArrayList getAllHomeworkCommitBystu(String sourseid,String stuentid){ Connection conn=null; Statement st=null; ResultSet rs=null; String sql ="select * from t_homework where course_code='"+sourseid+"' and type=2 and user_id='"+stuentid+"'"; ArrayList al=new ArrayList(); try{ DataBase ds = new DataBase(); conn = ds.conn; st = conn.createStatement(); rs = st.executeQuery(sql); while (rs.next()) { homework cs=new homework(); cs.setid(rs.getInt(1)); cs.settitle(rs.getString(2)); cs.setlink(rs.getString(3)); cs.setdate(rs.getString(4)); cs.settype(rs.getString(5)); cs.setcourse_code(rs.getString(6)); cs.setuser_id(rs.getString(7)); cs.setstatus(rs.getString(8)); al.add(cs); } return al; }catch(Exception e){System.out.println(e.getMessage());return null;} } /** * 添加作业 老师发布的作业 或者学生为作业提交的答案 * @param rs */ public void addHomework(homework rs) { Connection conn=null; Statement st=null; String sql="insert into t_homework(title,link,date,type,course_code,user_id)values("+ " '"+rs.gettitle()+"',"+ " '"+rs.getlink()+"',"+ " getdate(),"+ " '"+rs.gettype()+"',"+ " '"+rs.getcourse_code()+"',"+ " '"+rs.getuser_id()+"')"; System.out.println(sql); try{ DataBase ds = new DataBase(); conn = ds.conn; st = conn.createStatement(); st.executeUpdate(sql); }catch(Exception e){System.out.println(e.getMessage());return ;} } /** * 老师删除已发布作业 * @param id */ public void delHomeWork(String id) { Connection conn=null; Statement st=null; String sql="delete from t_homework where id='"+id+"'"; System.out.println(sql); try{ DataBase ds = new DataBase(); conn = ds.conn; st = conn.createStatement(); st.executeUpdate(sql); }catch(Exception e){System.out.println(e.getMessage());return ;} } /** * 学生提交答案 当老师阅览过后 置状态位为2 * @param id */ public static void updateHomeWorkSta(String id) { Connection conn=null; Statement st=null; String sql="update t_homework set status='2' where id='"+id+"'"; System.out.println(sql); try{ DataBase ds = new DataBase(); conn = ds.conn; st = conn.createStatement(); st.executeUpdate(sql); }catch(Exception e){System.out.println(e.getMessage());return ;} }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -