package com.steering.pss.sale.order.qualityDesign.Dao.idao;

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 com.steering.comm.tools.SqlBuilder;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.MscBLDaoImp;

import CoreFS.SA08.CoreXmlSqlParsersFactory;

/**
 * 备料码bean类
 * 
 * @author Administrator
 * 
 */
public class IMscBLDao implements MscBLDaoImp {
	/**
	 * 查询备料码
	 * 
	 * @param con
	 *            连接字符串
	 * @param msc
	 *            冶金规范码
	 * @param steelCode
	 *            钢级
	 * @param dimater
	 *            外径
	 * @param height
	 *            壁厚
	 * @return List<String>
	 * @throws SQLException
	 */
	public List<String[]> getCodeBLByDAndH(Connection con, String msc,
			String steelCode, String dimater, String height, String modelCode)
			throws SQLException {
		List<String[]> codeBLs = new ArrayList<String[]>();
		SqlBuilder b = new SqlBuilder("IMscBLDao.getCodeBLByDAndH");
		b.Fill(new String[]{msc, dimater, height, modelCode});
		PreparedStatement ps = con.prepareStatement(b.toString());
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			String[] codeBL = new String[2];
			codeBL[0] = rs.getString("CODE_JG");
			codeBL[1] = rs.getString("GROUP_NUM");
			codeBLs.add(codeBL);
		}
		rs.close();
		ps.close();
		return codeBLs;
	}

	/**
	 * 查询备料码
	 * 
	 * @param con
	 *            连接字符串
	 * @param msc
	 *            冶金规范码
	 * @param steelCode
	 *            钢级
	 * @param specCode
	 *            产品规格
	 * @return List<String>
	 * @throws SQLException
	 */
	public List<String[]> getCodeBLBySpecCode(Connection con, String msc,
			String steelCode, String specCode, String modelCode) throws SQLException {
		List<String[]> codeBLs = new ArrayList<String[]>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("IMscBLDao.getCodeBLBySpecCode");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, msc);
		ps.setObject(2, specCode);
		ps.setObject(3, modelCode);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			String[] codeBL = new String[2];
			codeBL[0] = rs.getString("CODE_JG");
			codeBL[1] = rs.getString("GROUP_NUM");
			codeBLs.add(codeBL);
		}
		rs.close();
		ps.close();
		return codeBLs;
	}

	/**
	 * 保存备料码
	 * 
	 * @param con
	 *            连接字符串
	 * @param designKey
	 *            designKey
	 * @param codeJG
	 *            备料码
	 * @param groupNum
	 *            分组序号
	 * @throws SQLException
	 */
	public void saveBL(Connection con, String designKey, String codeJG,
			String groupNum, String designKeyBl) throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("IMscBLDao.saveBL");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.setObject(2, groupNum);
		ps.setObject(3, codeJG);
		ps.setObject(4, designKeyBl);
		ps.executeUpdate();
		ps.close();
	}
}
