package org.manager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.entity.*;
import org.util.ConnectionManager;
/**
 * 文件
 * @说明 
 * @author fei.teng
 * @version 1.0
 * @since
 */
public class NoteManager {
	/**
	 *  删除 一个文件
	 * @param noteid
	 * @return
	 */
	public static boolean delNote(int noteid) {
		boolean isOk = false;
		String sql = "delete from t_note where id=?";
		Connection conn = ConnectionManager.getConnection();
		if (null != conn) {
			PreparedStatement ps = null;
			try {
				ps = conn.prepareStatement(sql);
				ps.setInt(1, noteid);
				if (ps.executeUpdate() > 0) {
					isOk = true;
				}
			} catch (SQLException e) {
				e.printStackTrace();
			} finally {
				ConnectionManager.close(ps);
				ConnectionManager.close(conn);
			}
		}
		return isOk;
	}
	/**
	 * 增加文件
	 * @param note
	 * @return
	 */
	public static boolean addNote(Note note) {
		boolean isOk = false;
		String sql = "insert into t_note(title,context,newpass,userid,encode_type) values(?,?,?,?,?)";
		String sqls = "insert into t_note(title,context,userid,encode_type) values(?,?,?,?)";
		Connection conn = ConnectionManager.getConnection();
		if (null != conn) {
			PreparedStatement ps = null;
			try {
				if (note.getNewpass() != null && !"".equals(note.getNewpass())) {
					ps = conn.prepareStatement(sql);
					ps = conn.prepareStatement(sql);
					ps.setString(1, note.getTitle());
					ps.setString(2, note.getContext());
					ps.setString(3, note.getNewpass());
					ps.setInt(4, note.getUserid());
					ps.setInt(5, note.getEncode_type());
				} else {
					ps = conn.prepareStatement(sqls);
					ps.setString(1, note.getTitle());
					ps.setString(2, note.getContext());
					ps.setInt(3, note.getUserid());
					ps.setInt(4, note.getEncode_type());
				}
				if (ps.executeUpdate() > 0) {
					isOk = true;
				}
			} catch (SQLException e) {
				e.printStackTrace();
			} finally {
				ConnectionManager.close(ps);
				ConnectionManager.close(conn);
			}
		}
		return isOk;
	}
	/**
	 * 得到某个用户的文件
	 * @param userid
	 * @return
	 */
	public static List<Note> getNoteList(int userid) {
		List<Note> list = new ArrayList<Note>();
		String sql = "select * from t_note where userid=?";
		Connection conn = ConnectionManager.getConnection();
		Note note = null;
		if (null != conn) {
			PreparedStatement ps = null;
			ResultSet rs = null;
			try {
				ps = conn.prepareStatement(sql);
				ps.setInt(1, userid);
				rs = ps.executeQuery();
				while (rs.next()) {
					note = new Note();
					note.setId(rs.getInt("id"));
					note.setContext(rs.getString("context"));
					note.setCreate_time(rs.getString("create_time"));
					note.setEncode_type(rs.getInt("encode_type"));
					note.setNewpass(rs.getString("newpass"));
					note.setTitle(rs.getString("title"));
					note.setUserid(rs.getInt("userid"));
					list.add(note);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			} finally {
				ConnectionManager.close(rs);
				ConnectionManager.close(ps);
				ConnectionManager.close(conn);
			}
		}
		return list;
	}
	/**
	 * 根据编号获得一个文件
	 * @param noteid
	 * @return
	 */
	public static Note getNoteById(int noteid) {
		String sql = "select * from t_note where id=?";
		Connection conn = ConnectionManager.getConnection();
		Note note = null;
		if (null != conn) {
			PreparedStatement ps = null;
			ResultSet rs = null;
			try {
				ps = conn.prepareStatement(sql);
				ps.setInt(1, noteid);
				rs = ps.executeQuery();
				if (rs.next()) {
					note = new Note();
					note.setId(rs.getInt("id"));
					note.setContext(rs.getString("context"));
					note.setCreate_time(rs.getString("create_time"));
					note.setEncode_type(rs.getInt("encode_type"));
					note.setNewpass(rs.getString("newpass"));
					note.setTitle(rs.getString("title"));
					note.setUserid(rs.getInt("userid"));
				}
			} catch (SQLException e) {
				e.printStackTrace();
			} finally {
				ConnectionManager.close(rs);
				ConnectionManager.close(ps);
				ConnectionManager.close(conn);
			}
		}
		return note;
	}
}
最近下载更多
                
                微信网友_6906962132258816     LV7
                2024年5月15日
            
            
        
                except I     LV2
                2023年11月5日
            
            
        
                yymmdm     LV6
                2022年8月10日
            
            
        
                微信网友_5855482984206336     LV1
                2022年3月3日
            
            
        
                llyytt     LV1
                2021年11月22日
            
            
        
                阿基诺     LV1
                2021年11月22日
            
            
        
                rain112     LV31
                2021年5月17日
            
            
        
                2ujkook     LV1
                2021年3月19日
            
            
        
                尹恒yingying     LV18
                2021年3月17日
            
            
        
                lili-yu     LV1
                2021年3月10日
            
            
        
最近浏览更多
                
                微信网友_6906962132258816     LV7
                2024年5月15日
            
            
        
                微信网友_6761206459944960    
                2024年1月5日
            
            
                    暂无贡献等级
            
        
                WBelong     LV8
                2023年12月19日
            
            
        
                uni-code_0123     LV1
                2023年11月29日
            
            
        
                except I     LV2
                2023年11月5日
            
            
        
                asadda     LV2
                2023年6月27日
            
            
        
                1358849392     LV21
                2023年5月31日
            
            
        
                139465     LV12
                2023年3月29日
            
            
        
                pfilwy     LV1
                2023年2月18日
            
            
        
                wwfl02     LV3
                2022年12月16日
            
            
        
                
                
                