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

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

import CoreFS.SA08.CoreXmlSqlParsersFactory;

import com.steering.comm.tools.EntityTool;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignStsTklgLstEntity;

public class CraftStatusDao {
	/**
	 * 新增工艺评审明细
	 * 
	 * @param con
	 * @param designStsList
	 * @throws SQLException
	 */
	public void addCraftOrdDesignStsTklgLst(Connection con,
			CraftOrdDesignStsTklgLstEntity designStsList) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("StatusDao.addCraftOrdDesignStsTklgLst");
		sql = EntityTool.fillSqlByEntity(sql, designStsList);
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 新增明细主记录
	 * 
	 * @param con
	 * @param designKey
	 * @param ordLnPk
	 * @param userName
	 * @throws SQLException
	 */
	public void addCraftOrdDesignStsTklg(Connection con, String designKey,
			String ordLnPk, String userName) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("StatusDao.addCraftOrdDesignStsTklg");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designKey);
		ps.setObject(2, ordLnPk);
		ps.setObject(3, userName);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 修改明细项目
	 * 
	 * @param con
	 * @param designSts
	 *            设计状态
	 * @param designStsRs
	 *            设计状态原因
	 * @param designStsDesc
	 *            结果描述
	 * @param objKey
	 *            设计对象主键
	 * @param designKey
	 *            工艺评审主键
	 * @param lstItem
	 *            评审项
	 * @throws SQLException
	 */
	public void updateCraftOrdDesignStsTklgLst(Connection con, String msc,
			String designSts, String designStsRs, String designStsDesc,
			String objKey, String designKey, String lstItem)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("StatusDao.updateCraftOrdDesignStsTklgLst");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, msc);
		ps.setObject(2, designSts);
		ps.setObject(3, designStsRs);
		ps.setObject(4, designStsDesc);
		ps.setObject(5, objKey);
		ps.setObject(6, designKey);
		ps.setObject(7, lstItem);

		ps.executeUpdate();
		ps.close();
	}
	
	/**
	 * 修改明细项目
	 * 
	 * @param con
	 * @param designSts
	 *            设计状态
	 * @param designStsRs
	 *            设计状态原因
	 * @param designStsDesc
	 *            结果描述
	 * @param objKey
	 *            设计对象主键
	 * @param designKey
	 *            工艺评审主键
	 * @param lstItem
	 *            评审项
	 * @throws SQLException
	 */
	public void updateCraftOrdDesignStsTklgLst2(Connection con, String msc,
			String designSts, String designStsRs, String designStsDesc,
			String objKey, String designKey, String lstItem, String unitCode, String unitDesc)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("StatusDao.updateCraftOrdDesignStsTklgLst2");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, msc);
		ps.setObject(2, designSts);
		ps.setObject(3, designStsRs);
		ps.setObject(4, designStsDesc);
		ps.setObject(5, objKey);
		ps.setObject(6, unitCode);
		ps.setObject(7, unitDesc);
		ps.setObject(8, designKey);
		ps.setObject(9, lstItem);
		

		ps.executeUpdate();
		ps.close();
	}
	
	/**
	 * 修改明细项目
	 * 
	 * @param con
	 * @param designSts
	 *            设计状态
	 * @param designStsRs
	 *            设计状态原因
	 * @param designStsDesc
	 *            结果描述
	 * @param objKey
	 *            设计对象主键
	 * @param designKey
	 *            工艺评审主键
	 * @param lstItem
	 *            评审项
	 * @throws SQLException
	 */
	public void updateCraftOrdDesignStsTklgLst3(Connection con, String msc,
			String designSts, String designStsRs, String designStsDesc,
			String designKey, String lstItem)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("StatusDao.updateCraftOrdDesignStsTklgLst3");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, msc);
		ps.setObject(2, designSts);
		ps.setObject(3, designStsRs);
		ps.setObject(4, designStsDesc);
		ps.setObject(5, designKey);
		ps.setObject(6, lstItem);

		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 修改设计状态（合同行）
	 * 
	 * @param con
	 *            连接字符串
	 * @param designKey
	 *            designKey
	 * @param userName
	 *            操作人
	 * @param designSts
	 *            设计状态 (W:等待;S:通过;F:失败)
	 * @param prdcycMeet
	 *            生产周期满足(W:等待;S:满足;F:不满足)
	 * @throws SQLException
	 */
	public void updateDesignStsTklg(Connection con, String designKey,
			String userName, String designSts, String prdcycMeet)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("StatusDao.updateDesignStsTklg");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, designSts);
		ps.setObject(2, prdcycMeet);
		ps.setObject(3, userName);
		ps.setObject(4, designKey);
		ps.executeUpdate();
		ps.close();

	}
}
