package imis_mate.common;

import database.DBPoolManager;

import java.util.ArrayList;
import java.util.Hashtable;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

//库存树
import java.sql.SQLException;

public class MaterialChangeTree {
	public MaterialChangeTree() {
		
	}
	public ArrayList getChangeId() {
		ArrayList list = new ArrayList();
		DBPoolManager db = new DBPoolManager();
		db.getConnection();
		
		try {
			String s = null;
			String sql = "SELECT ChangeId FROM(SELECT ChangeId FROM Material_Change_Table order by OutDate DESC)WHERE rownum<=50 order by ChangeId"; //查询物品类型编号的SQL语句
			Statement stmt = db.conn.createStatement(); 
			ResultSet rs = stmt.executeQuery(sql);
			
			Hashtable ht = new Hashtable();
			ht.put("OrganID", "1");
			ht.put("SupOrganID", "0");
			ht.put("OrganName", "物品变更编号");
			list.add(ht);
			int i = 11;
			
			while (rs.next()) {
				Hashtable hash = new Hashtable();
				s = rs.getString("ChangeId");
				s = s.trim();
				
				hash.put("OrganID", String.valueOf(i));
				hash.put("SupOrganID", "1");
				hash.put("OrganName", s);
				
				list.add(hash);
				i++;
			}
			rs.close();
			stmt.close();
		} catch (SQLException ex){
			System.err.print("Get MaterialChangeTree SQLException: " + ex.toString());
			ex.printStackTrace();
		} finally {
			db.freeConnection();
		}
		return list;
	}
}