package com.steering.pss.qcm;

import CoreFS.SA06.CoreReturnObject;
import java.util.ArrayList;
import com.steering.comm.db.DBCommon;
import CoreFS.SA08.CoreXmlSqlParsersFactory;


public class CoreStandardSpray extends DBCommon {
	
	
	
	/**
	 * 获取喷标主表序号最大值
	 * @param name
	 * @return
	 */
	public CoreReturnObject GetMaxIndexSeq() {
		return this.getDataBySqlID("CoreStandardSpray.GetMaxIndexSeq");
	}
	
	
	/**
	 * 获取喷标从表序号最大值
	 * @param name
	 * @return
	 */
	public CoreReturnObject GetMaxIndexSeqC() {
		return this.getDataBySqlID("CoreStandardSpray.GetMaxIndexSeqC");
	}
	
	/**
	 * 获取接箍料限制规格代码和描述
	 * 
	 * @return
	 */
	public CoreReturnObject GetJG() {
		return this.getDataBySqlID("CoreStandardSpray.GetJG");
	}
	
	/**
	 * 获取限制规格1、2代码和描述
	 * 
	 * @return
	 */
	public CoreReturnObject GetSizeCode() {
		return this.getDataBySqlID("CoreStandardSpray.GetSizeCode");
	}
	
	/**
	 * 根据冶金规范码获取喷标主表记录
	 * @author Administrator
	 */
	public CoreReturnObject getLineList(String pscCode) {
		Object[] params = new Object[] { pscCode };
		return this.getDataBySqlID("CoreStandardSpray.GetSpray", params);
	}
	
	/**
	 * 获取从表记录
	 * @author Administrator
	 */
	public CoreReturnObject GetSprayC(String pscCode) {
		Object[] params = new Object[] { pscCode };
		return this.getDataBySqlID("CoreStandardSpray.GetSprayC", params);
	}
	
	
	/**
	 * 获取冶金规范码
	 * @return
	 */
	public CoreReturnObject GetMSC() {
		return this.getDataBySqlID("CoreStandardSpray.GetMSC");
	}
	
	/**
	 * 保存
	 * @param spbAddParams
	 * @param spbUpdateParams
	 * @param spbSupplementAddParams
	 * @param spbSupplementUpdateParams
	 * @return
	 */
	public CoreReturnObject doSave(ArrayList<ArrayList<Object>> spbAddParams,
			ArrayList<ArrayList<Object>> spbUpdateParams,
			ArrayList<ArrayList<Object>> spbSupplementAddParams,
			ArrayList<ArrayList<Object>> spbSupplementUpdateParams) {

		CoreReturnObject spbCro = new CoreReturnObject();

		String spbAddSql = CoreXmlSqlParsersFactory.getSql("CoreStandardSpray.ADD");

		String spbUpdateSql = CoreXmlSqlParsersFactory
				.getSql("CoreStandardSpray.MODIFY");

		String spbSupplementAddSql = CoreXmlSqlParsersFactory
				.getSql("CoreStandardSpray.ADDC");

		String spbSupplementUpdateSql = CoreXmlSqlParsersFactory
				.getSql("CoreStandardSpray.MODIFYC");

		ArrayList<Object> spbSqlList = new ArrayList<Object>();
		ArrayList<Object[]> spbParmList = new ArrayList<Object[]>();

		// 构建主表addsql语句和参数。

		if (spbAddParams.size() > 0) {
			for (int i = 0; i < spbAddParams.size(); i++) {
				spbSqlList.add(spbAddSql);
				spbParmList.add(spbAddParams.get(i).toArray());
			}
		}

		// 构建主表修改sql语句和参数。

		if (spbUpdateParams.size() > 0) {
			for (int j = 0; j < spbUpdateParams.size(); j++) {
				spbSqlList.add(spbUpdateSql);
				spbParmList.add(spbUpdateParams.get(j).toArray());
			}
		}
		// 构建从表新增sql语句和参数。

		if (spbSupplementAddParams.size() > 0) {
			for (int k = 0; k < spbSupplementAddParams.size(); k++) {
				spbSqlList.add(spbSupplementAddSql);
				spbParmList.add(spbSupplementAddParams.get(k).toArray());
			}
		}

		// 构建从表修改sql语句和参数。
		if (spbSupplementUpdateParams.size() > 0) {
			for (int g = 0; g < spbSupplementUpdateParams.size(); g++) {
				spbSqlList.add(spbSupplementUpdateSql);
				spbParmList.add(spbSupplementUpdateParams.get(g).toArray());
			}
		}

		try {
			spbCro = this.getDao("TgDao").ExcuteTransction(spbSqlList,
					spbParmList);
		} catch (Exception e) {
			spbCro = spbCro.SetErrInfo(e.getMessage());
		}

		return spbCro;

	}

	/**
	 * 删除或恢复
	 */
	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("CoreStandardSpray.DELETE");
				params.add(new Object[] { operator,
						plineCodes.get(i).toString() });
			} else {
				sqlIDList.add("CoreStandardSpray.RESUME");
				params.add(new Object[] { plineCodes.get(i).toString() });
			}
		}
		return this.setDataById(sqlIDList, params);
	}
	
	
	/**
	 * 从表删除或恢复
	 */
	public CoreReturnObject deleteLineInfoC(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("CoreStandardSpray.DELETEC");
				params.add(new Object[] { operator,
						plineCodes.get(i).toString() });
			} else {
				sqlIDList.add("CoreStandardSpray.RESUMEC");
				params.add(new Object[] { plineCodes.get(i).toString() });
			}
		}
		return this.setDataById(sqlIDList, params);
	}


}
