package com.steering.pss.sale.order.craftDesign.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignMscBiltCEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignMscBiltCPlEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignMscBiltEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignMscBiltPlEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignMscGzGgEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignMscGzGgPlEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignMscPlEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignMscPlGxPrlEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignMscPlGzEntity;

import CoreFS.SA08.CoreXmlSqlParsersFactory;

public class StandardDao {
	/**
	 * 验证钢种
	 * 
	 * @param con
	 * @param gradeInfo
	 * @return
	 * @throws SQLException
	 */
	public int checkDesignGrade(Connection con,
			CraftOrdDesignMscPlGzEntity gradeInfo) throws SQLException {
		int count = 0;
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftStandardDao.checkDesignGrade");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, gradeInfo.getDesginKey());
		ps.setObject(2, gradeInfo.getMscPline());
		ps.setObject(3, gradeInfo.getGradecode());
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			count = rs.getInt("COUNT");
		}
		rs.close();
		ps.close();
		return count;
	}

	/**
	 * 验证轧管规格
	 * 
	 * @param con
	 * @param rollSpecs
	 * @return
	 * @throws SQLException
	 */
	public int checkRollSpec(Connection con,
			CraftOrdDesignMscGzGgEntity rollSpecs) throws SQLException {
		int count = 0;
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftStandardDao.checkRollSpec");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, rollSpecs.getDesginKey());
		ps.setObject(2, rollSpecs.getMscPline());
		ps.setObject(3, rollSpecs.getSpecCode());
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			count = rs.getInt("COUNT");
		}
		rs.close();
		ps.close();
		return count;
	}

	/**
	 * 验证锻造规格
	 * 
	 * @param con
	 * @param billSpec
	 * @return
	 * @throws SQLException
	 */
	public int checkBillSpec(Connection con,
			CraftOrdDesignMscBiltEntity billSpec) throws SQLException {
		int count = 0;
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftStandardDao.checkBillSpec");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, billSpec.getDesginKey());
		ps.setObject(2, billSpec.getMscPline());
		ps.setObject(3, billSpec.getSpecCode());
		ps.setObject(4, billSpec.getBSpecCode());
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			count = rs.getInt("COUNT");
		}
		rs.close();
		ps.close();
		return count;
	}

	/**
	 * 验证铸造规格
	 * 
	 * @param con
	 * @param billCSpec
	 * @return
	 * @throws SQLException
	 */
	public int checkBillCSpec(Connection con,
			CraftOrdDesignMscBiltCEntity billCSpec) throws SQLException {
		int count = 0;
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftStandardDao.checkBillCSpec");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, billCSpec.getDesginKey());
		ps.setObject(2, billCSpec.getMscPline());
		ps.setObject(3, billCSpec.getCSpecCode());
		ps.setObject(4, billCSpec.getSpecCode() + billCSpec.getBSpecCode()
				+ billCSpec.getCSpecCode());
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			count = rs.getInt("COUNT");
		}
		rs.close();
		ps.close();
		return count;
	}

	/**
	 * 验证制程产线
	 * 
	 * @param con
	 * @param zcLine
	 * @return
	 * @throws SQLException
	 */
	public int checkZCline(Connection con, CraftOrdDesignMscPlGxPrlEntity zcLine)
			throws SQLException {
		int count = 0;
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftStandardDao.checkZCline");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, zcLine.getDesginKey());
		ps.setObject(2, zcLine.getMscPline());
		ps.setObject(3, zcLine.getBacklogSeq());
		ps.setObject(4, zcLine.getProcessCode());
		ps.setObject(5, zcLine.getPlineCode());
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			count = rs.getInt("COUNT");
		}
		rs.close();
		ps.close();
		return count;
	}

	/**
	 * 验证轧管产线
	 * 
	 * @param con
	 * @param rollLine
	 * @return
	 * @throws SQLException
	 */
	public int checkRollLine(Connection con,
			CraftOrdDesignMscGzGgPlEntity rollLine) throws SQLException {
		int count = 0;
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftStandardDao.checkRollLine");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, rollLine.getDesginKey());
		ps.setObject(2, rollLine.getMscPline());
		ps.setObject(3, rollLine.getSpecCode());
		ps.setObject(4, rollLine.getPlineCode());
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			count = rs.getInt("COUNT");
		}
		rs.close();
		ps.close();
		return count;
	}

	/**
	 * 验证锻造产线
	 * 
	 * @param con
	 * @param billLine
	 * @return
	 * @throws SQLException
	 */
	public int checkBillLine(Connection con,
			CraftOrdDesignMscBiltPlEntity billLine) throws SQLException {
		int count = 0;
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftStandardDao.checkBillLine");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, billLine.getDesginKey());
		ps.setObject(2, billLine.getMscPline());
		ps.setObject(3, billLine.getBSpecCode());
		ps.setObject(4, billLine.getPlineCode());
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			count = rs.getInt("COUNT");
		}
		rs.close();
		ps.close();
		return count;
	}

	/**
	 * 验证铸造产线
	 * 
	 * @param con
	 * @param billLine
	 * @return
	 * @throws SQLException
	 */
	public int checkBillCLine(Connection con,
			CraftOrdDesignMscBiltCPlEntity billLine) throws SQLException {
		int count = 0;
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftStandardDao.checkBillCLine");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, billLine.getDesginKey());
		ps.setObject(2, billLine.getMscPline());
		ps.setObject(3, billLine.getCSpecCode());
		ps.setObject(4, billLine.getPlineCode());
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			count = rs.getInt("COUNT");
		}
		rs.close();
		ps.close();
		return count;
	}

	/**
	 * 验证制程
	 * 
	 * @param con
	 * @param proDuc
	 * @return
	 * @throws SQLException
	 */
	public int checkProduc(Connection con, CraftOrdDesignMscPlEntity proDuc)
			throws SQLException {
		int count = 0;
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftStandardDao.checkProduc");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, proDuc.getDesginKey());
		ps.setObject(2, proDuc.getMscPline());
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			count = rs.getInt("COUNT");
		}
		rs.close();
		ps.close();
		return count;
	}

}
