package net.ihypo.work;

import java.sql.ResultSet;
import java.sql.SQLException;

import net.ihypo.db.DbDriver;

import com.mysql.jdbc.Statement;

public class Work {
	private int id;
	private String title;
	private int userId = 0;
	private String data;
	//rank：1=重要且紧急 2=不重要但紧急 3=重要不紧急 4=不重要不紧急
	private int rank;
	private boolean finash;
	
	public Work(int id) throws ClassNotFoundException, SQLException{
		this.id = id;
		Statement statement = (Statement) new DbDriver().getConnection().createStatement();
		ResultSet set = statement.executeQuery("select * from works where work_id = " + id + ";");
		if(set.next()){
			this.title = set.getString("work_title");
			this.userId = set.getInt("work_user_id");
			this.data = null;
			this.rank = set.getInt("work_rank");
			this.finash = set.getBoolean("work_finash");
		}
	}
	
	public Work(int id,String title,int userId,String data,int rank){
		this.id = id;
		this.title = title;
		this.userId = userId;
		this.data = data;
		this.rank = rank;
		this.finash = false;
	}

	public int getId() {
		return id;
	}

	public String getTitle() {
		return title;
	}
	
	public void setTitle(String title){
		this.title = title;
	}

	public int getUserId() {
		return userId;
	}

	public String getData() {
		return data;
	}
	
	public int getRank() {
		return rank;
	}
	
	public void setRank(int rank){
		this.rank = rank;
	}
	
	public boolean isFinash() {
		return finash;
	}
	
	public void finash(){
		this.finash = true;
	}
	
	public void unFinash(){
		this.finash = false;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Work other = (Work) obj;
		if (id != other.id)
			return false;
		return true;
	}
	public void update() throws ClassNotFoundException, SQLException{
		Statement statement = (Statement) new DbDriver().getConnection().createStatement();
		statement.execute("update works set work_title = '" + title + "',work_user_id = "
				 + userId + ",work_rank = " + rank + ", work_finash = " + finash + " where work_id = " + id + ";");
	}
	
	public void drop() throws ClassNotFoundException, SQLException{
		Statement statement = (Statement) new DbDriver().getConnection().createStatement();
		statement.execute("delete from works where work_id = " + id + ";");
	}
}

@@ -334,16 +334,42 @@
 finash;%0A
+%09private int workGroupId;%0A
 %09%0A%09publi
@@ -840,16 +840,67 @@
 nash%22);%0A
+%09%09%09this.workGroupId = set.getInt(%22work_group_id%22);%0A
 %09%09%7D%0A%09%7D%0A%09
@@ -956,32 +956,48 @@
 ng data,int rank
+,int workGroupId
 )%7B%0A%09%09this.id = i
@@ -1104,24 +1104,58 @@
 sh = false;%0A
+%09%09this.workGroupId = workGroupId;%0A
 %09%7D%0A%0A%09public 
@@ -1640,24 +1640,162 @@
 = false;%0A%09%7D%0A
+%09%0A%09public int getGroupId()%7B%0A%09%09return this.workGroupId;%0A%09%7D%0A%09%0A%09public void setGroupId(int workGroupId)%7B%0A%09%09this.workGroupId = workGroupId;%0A%09%7D
 %0A%09@Override%0A
@@ -2477,16 +2477,52 @@
 finash +
+ %22,work_group_id = %22 + workGroupId +
  %22 where
@@ -2532,32 +2532,33 @@
 rk_id = %22 + id +
+ 
  %22;%22);%0A%09%7D%0A%09%0A%09pub

update class work,add the workGroupId