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.pss.sale.order.craftDesign.model.ComMscEntity;
import com.steering.pss.sale.order.craftDesign.tool.CraftTool;

public class Msc0Dao {
	/**
	 * 查询冶金规范码信息
	 * 
	 * @param con
	 * @param msc
	 * @return
	 * @throws SQLException
	 */
	public ComMscEntity getMscInfo(Connection con, String msc)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("Msc0Dao.getMscInfo");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, msc);
		ResultSet rs = ps.executeQuery();
		List<ComMscEntity> list = EntityTool.getEntitysByRs(rs,
				ComMscEntity.class);
		rs.close();
		ps.close();
		if (list == null || list.size() != 1) {
			return null;
		} else {
			CraftTool.nullConverNullString(list.get(0));
			return list.get(0);
		}
	}

	/**
	 * 查询Msc0
	 * 
	 * @param con
	 * @param psc
	 * @return
	 * @throws SQLException
	 */
	public String getMsc0(Connection con, String psc) throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("Msc0Dao.getMsc0");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, psc);
		ResultSet rs = ps.executeQuery();
		String msc = "";
		if (rs.next()) {
			msc = rs.getString("MSC");
		}
		rs.close();
		ps.close();
		return msc;
	}

	/**
	 * 新增工艺评审标准号主表索引号
	 * 
	 * @param con
	 * @param designKey
	 * @throws SQLException
	 */
	public void addCraftOrdDesignStd(Connection con, String designKey)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("Msc0Dao.addCraftOrdDesignStd");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 修改工艺评审记录的科室
	 * 
	 * @param con
	 * @param deptCode
	 * @param deptDesc
	 * @param designKey
	 * @throws SQLException
	 */
	public void updateCraftDepement(Connection con, String deptCode,
			String deptDesc, String designKey) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("Msc0Dao.updateCraftDepement");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, deptCode);
		ps.setObject(2, deptDesc);
		ps.setObject(3, designKey);
		ps.executeUpdate();
		ps.close();
	}
}
