package com.steering.pss.qcm;

import java.sql.SQLException;
import java.util.ArrayList;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;

import com.steering.comm.db.DBCommon;


/**
 * 工序点与工艺参数对应管理类
 * 
 * @author WQ 2014/10/16
 * @version v1.0
 * @modify
 */
public class CoreProcessProparameters extends DBCommon {

	/**
	 * 绑定工序点下拉列表
	 */
	public CoreReturnObject GetType() {
		return this.getDataBySqlID("CoreProcessProparameters.PROCESS");
	}
	
	/**
	 * 绑定工序点下拉列表
	 */
	public CoreReturnObject CoreBandProcess() {
		return this.getDataBySqlID("CoreProcessProparameters.PROCESS");
	}

	/**
	 * 绑定工艺参数下拉列表
	 */
	public CoreReturnObject CoreBandProcessParameters() {
		return this.getDataBySqlID("CoreProcessProparameters.PROCESSPARAMETERS");
	}

	/**
	 * 工序点与工艺参数对应管理查询
	 * 
	 * @param includeDeleted
	 *            是否包含已删除数据
	 * @param name
	 *            扣型描述
	 * @return CoreReturnObject 必须返回CoreReturnObject
	 */
	public CoreReturnObject getLineList(Boolean includeDeleted, String name) {
		String deletedFlag = includeDeleted ? "0" : "";
		Object[] params = new Object[] { deletedFlag, name };
		return this.getDataBySqlID("CoreProcessProparameters.QUERY", params);
	}

	/**
	 * 工序点与工艺参数对应管理新增
	 * 
	 * @param parm
	 *            参数
	 * @return CoreReturnObject 必须返回CoreReturnObject
	 */
	public CoreReturnObject doAdd(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory
				.getSql("CoreProcessProparameters.ADD");
		try {
			cro = this.getDao("TgDao").ExcuteNonQuery(strSql, parm.toArray());
		} catch (SQLException e) {
			cro = cro.SetErrInfo(e.getMessage());
		}
		return cro;
	}

	/**
	 * 工序点与工艺参数对应管理修改
	 * 
	 * @param parm
	 *            参数
	 * @return CoreReturnObject 必须返回CoreReturnObject
	 */
	public CoreReturnObject doModify(ArrayList<Object> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		String strSql = CoreXmlSqlParsersFactory
				.getSql("CoreProcessProparameters.MODIFY");
		try {
			cro = this.getDao("TgDao").ExcuteNonQuery(strSql, parm.toArray());
		} catch (SQLException e) {
			cro = cro.SetErrInfo(e.getMessage());
		}
		return cro;
	}

	/**
	 * 工序点与工艺参数对应管理删除或恢复
	 * 
	 * @param plineCodes
	 *            产线代码集合
	 * @param operator
	 *            操作人
	 * @param isDelete
	 *            true删除 false恢复
	 * @return CoreReturnObject 必须返回CoreReturnObject
	 */
	public CoreReturnObject deleteLineInfo(ArrayList<Object> plineCodes,
			String operator, Boolean isDelete) {
		ArrayList<String> sqlIDList = new ArrayList<String>();
		ArrayList<Object[]> params = new ArrayList<Object[]>();
		for (int i = 0; i < plineCodes.size(); i++) {
			if (isDelete) {
				sqlIDList.add("CoreProcessProparameters.DELETE");
				params.add(new Object[] { operator,
						plineCodes.get(i).toString() });
			} else {
				sqlIDList.add("CoreProcessProparameters.RESUME");
				params.add(new Object[] { plineCodes.get(i).toString() });
			}
		}
		return this.setDataById(sqlIDList, params);
	}
}
