package baseclass;

import p2.pao.Pao;
import p2.pao.PaoServer;
import p2.pao.PaoSet;
import p2.pao.PaoSetRemote;
import p2.util.P2Exception;
import p2.util.P2RowChangeException;

import java.util.ArrayList;

public abstract class PaoSetCust extends PaoSet {

	public PaoSetCust(PaoServer arg0) {
		super(arg0);
	}

	/**
	 * 获取paoset中field栏位的值，将其存入数组并返回
	 * 
	 * @param paoset
	 * @param fieldname
	 * @return
	 * @throws P2Exception
	 */
	public String[] getStrings(PaoSetRemote paoset, String fieldname) throws P2Exception {
		String[] values = new String[paoset.count()];
		int i = 0;
		while (paoset.getPao(i) != null) {
			values[i] = paoset.getPao(i).getString(fieldname);
			i++;
		}
		return values;
	}

	/**
	 * 获取paoset中field栏位的唯一值，将其存入数组并返回
	 * 
	 * @param paoset
	 * @param fieldname
	 * @return
	 * @throws P2Exception
	 */
	public String[] getDistinctString(PaoSetRemote paoset, String fieldname, boolean isselect) throws P2Exception {
		ArrayList<String> list = new ArrayList<String>();
		int i = 0;
		while (paoset.getPao(i) != null) {
			if (isselect) {
				if (paoset.getPao(i).isSelected()) {
					String date = paoset.getPao(i).getString(fieldname);
					if (!list.contains(date)) {
						list.add(date);
					}
				}
			} else {
				String date = paoset.getPao(i).getString(fieldname);
				if (!list.contains(date)) {
					list.add(date);
				}
			}
			i++;
		}
		String[] date = new String[list.size()];
		int n = 0;
		for (String d : list) {
			date[n] = d;
			n++;
		}
		return date;
	}

	@Override
	protected Pao getPaoInstance(PaoSet arg0) throws P2Exception {
		return null;
	}

	/**
	 * 另一用户已将数据更新
	 */
	@Override
	public void logRowUpdatedException(P2RowChangeException p2rowchangeexception) {
		/*if (getSqlLogger().isErrorEnabled()) {
			 getSqlLogger().error(p2rowchangeexception.getMessage(), p2rowchangeexception);
		}*/
	}

}
