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 java.util.List;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.SqlBuilder;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignMscPlEntity;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignMscPlGzEntity;
import com.steering.pss.sale.order.craftDesign.tool.CraftTool;

public class CraftInnerDao {
	/**
	 * 查询制程
	 * 
	 * @param con
	 * @param designKey
	 * @return
	 * @throws SQLException
	 */
	public List<CraftOrdDesignMscPlEntity> getProDuc(Connection con,
			String designKey) throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("CraftInnerDao.getProDuc");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ResultSet rs = ps.executeQuery();
		List<CraftOrdDesignMscPlEntity> list = EntityTool.getEntitysByRs(rs,
				CraftOrdDesignMscPlEntity.class);
		rs.close();
		ps.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (CraftOrdDesignMscPlEntity craftOrdDesignMscPlEntity : list) {
				CraftTool.nullConverNullString(craftOrdDesignMscPlEntity);
			}
			return list;
		}
	}

	public void deleteChem(Connection con, String designKey)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftInnerDao.deleteChem");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.executeUpdate();
		ps.close();
	}

	public void deletePhy(Connection con, String designKey) throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("CraftInnerDao.deletePhy");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.executeUpdate();
		ps.close();
	}

	public void deletePhySmp(Connection con, String designKey)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftInnerDao.deletePhySmp");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.setObject(2, designKey);
		ps.executeUpdate();
		ps.close();
	}

	public void deleteDete(Connection con, String designKey)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftInnerDao.deleteDete");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.executeUpdate();
		ps.close();
	}

	public void deleteSpec(Connection con, String designKey)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftInnerDao.deleteSpec");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.executeUpdate();
		ps.close();
	}

	public void deleteWater(Connection con, String designKey)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftInnerDao.deleteWater");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.executeUpdate();
		ps.close();
	}

	public void deleteProcess(Connection con, String designKey)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("CraftInnerDao.deleteProcess");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.executeUpdate();
		ps.close();
	}
	
	/**
	 * 更新工艺评审工序
	 * @param con
	 * @param designKey
	 * @param mscPline
	 * @throws SQLException
	 */
	public void updateCraftPrc(Connection con, String designKey, String mscPline) throws SQLException{
		SqlBuilder b = new SqlBuilder("CraftInnerDao.updateCraftPrc");
		b.Fill(new String[]{ designKey, mscPline });
		
		PreparedStatement ps = con.prepareStatement(b.toString());
		ps.executeUpdate();
		ps.close();
	}
}
