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 CoreFS.SA08.CoreXmlSqlParsersFactory;
import com.steering.pss.sale.order.model.DesignStdCicEntity;
import com.steering.pss.sale.order.model.DesignStdDicEntity;
import com.steering.pss.sale.order.model.DesignStdEntity;
import com.steering.pss.sale.order.model.DesignStdGicEntity;
import com.steering.pss.sale.order.model.DesignStdPicEntity;
import com.steering.pss.sale.order.model.DesignStdPicSmpEntity;
import com.steering.pss.sale.order.model.DesignStdSicEntity;
import com.steering.pss.sale.order.model.DesignStdWicEntity;
import com.steering.pss.sale.order.model.DesignWaterRatioEntity;
import com.steering.pss.sale.order.model.MscStdWaterEntity;
import com.steering.pss.sale.order.qualityDesign.QualityDesignTool;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.DeliveryStdDaoImp;

/**
 * 交互标准连接数据 类
 * 
 * @author Administrator
 * 
 */
public class IDeliveryStdDao implements DeliveryStdDaoImp {

	public String getQuoteMsc(Connection con, String msc) throws SQLException {
		String mscSeq = "";
		String sql = CoreXmlSqlParsersFactory
				.getSql("IDeliveryStdDao.getQuoteMsc");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, msc);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			mscSeq = rs.getString("MSC_SEQ");
		}
		return mscSeq;
	}

	/**
	 * 查询成分索引号 （扣型，冶金规范码）
	 * 
	 * @param con
	 * @param msc
	 *            冶金规范码
	 * @param modelCode
	 *            扣型
	 * @return
	 * @throws SQLException
	 */
	public List<String> getCic(Connection con, String msc, String modelCode)
			throws SQLException {
		List<String> list = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("IDeliveryStdDao.getChemIndex");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, msc);
		ps.setObject(2, modelCode);
		ps.setObject(3, msc);
		ps.setObject(4, modelCode);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			String cic = rs.getString("CIC");
			list.add(cic);
		}
		return list;
	}

	/**
	 * 查询理化索引号 （扣型，冶金规范码）
	 * 
	 * @param con
	 * @param msc
	 *            冶金规范码
	 * @param modelCode
	 *            扣型
	 * @return
	 * @throws SQLException
	 */
	public List<String> getPic(Connection con, String msc, String modelCode)
			throws SQLException {
		List<String> list = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("IDeliveryStdDao.getPhyIndex");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, msc);
		ps.setObject(2, modelCode);
		ps.setObject(3, msc);
		ps.setObject(4, modelCode);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			String pic = rs.getString("PIC");
			list.add(pic);
		}
		return list;
	}

	/**
	 * 查询公差索引号 （扣型，冶金规范码）
	 * 
	 * @param con
	 * @param msc
	 *            冶金规范码
	 * @param modelCode
	 *            扣型
	 * @return
	 * @throws SQLException
	 */
	public List<String> getSic(Connection con, String msc, String modelCode)
			throws SQLException {
		List<String> list = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("IDeliveryStdDao.getSpecIndex");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, msc);
		ps.setObject(2, modelCode);
		ps.setObject(3, msc);
		ps.setObject(4, modelCode);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			String sic = rs.getString("SIC");
			list.add(sic);
		}
		return list;
	}

	/**
	 * 查询探伤索引号 （扣型，冶金规范码）
	 * 
	 * @param con
	 * @param msc
	 *            冶金规范码
	 * @param modelCode
	 *            扣型
	 * @return
	 * @throws SQLException
	 */
	public List<String> getDic(Connection con, String msc, String modelCode)
			throws SQLException {
		List<String> list = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("IDeliveryStdDao.getDeteIndex");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, msc);
		ps.setObject(2, modelCode);
		ps.setObject(3, msc);
		ps.setObject(4, modelCode);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			String dic = rs.getString("DIC");
			list.add(dic);
		}
		return list;
	}

	/**
	 * 查询水压主表数据 （扣型，冶金规范码）
	 * 
	 * @param con
	 * @param msc
	 *            冶金规范码
	 * @param modelCode
	 *            扣型
	 * @return
	 * @throws SQLException
	 */
	public List<MscStdWaterEntity> getWic(Connection con, String msc,
			String modelCode) throws SQLException {
		List<MscStdWaterEntity> list = new ArrayList<MscStdWaterEntity>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("IDeliveryStdDao.getWaterIndex");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, msc);
		ps.setObject(2, modelCode);
		ps.setObject(3, msc);
		ps.setObject(4, modelCode);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			MscStdWaterEntity water = new MscStdWaterEntity();
			water.setWic(rs.getString("WIC"));
			water.setStdstyle(rs.getString("STDSTYLE"));
			water.setProcessCdoe(rs.getString("PROCESS_CDOE"));
			water.setProcessDesc(rs.getString("PROCESS_DESC"));
			water.setStdCodeNk(rs.getString("STD_CODE_NK"));
			water.setStdNameNk(rs.getString("STD_NAME_NK"));
			water.setMinD(rs.getString("MIN_D"));
			water.setMaxD(rs.getString("MAX_D"));
			water.setMinH(rs.getString("MIN_H"));
			water.setMaxH(rs.getString("MAX_H"));
			water.setSpecJg(rs.getString("SPEC_JG"));
			water.setSpecJgDesc(rs.getString("SPEC_JG_DESC"));
			water.setModelCode(rs.getString("MODEL_CODE"));
			water.setModelDesc(rs.getString("MODEL_DESC"));
			water.setMsc(rs.getString("MSC"));
			water.setProducHead(rs.getString("PRODUC_HEAD"));
			water.setCodeJg(rs.getString("CODE_JG"));
			QualityDesignTool.nullConverNullString(water);
			list.add(water);
		}
		rs.close();
		ps.close();
		return list;
	}

	/**
	 * 查询引用水压标准
	 * 
	 * @param con
	 *            连接字符串
	 * @param stdCode
	 *            标准
	 * @param stdStyle
	 *            标准类别
	 * @return 引用水压标准和引用水压标准类别
	 * @throws SQLException
	 */
	public String[] getQuoteWaterStd(Connection con, String stdCode,
			String stdStyle) throws SQLException {
		String[] str = new String[2];
		String sql = CoreXmlSqlParsersFactory
				.getSql("IDeliveryStdDao.getWaterRatioStd");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, stdCode);
		ps.setObject(2, stdStyle);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			str[0] = rs.getString("STD_CODE");
			str[1] = rs.getString("STD_STYLE");
		} else {
			return null;
		}
		rs.close();
		ps.close();
		return str;
	}

	/**
	 * 查询水压压力等
	 * 
	 * @param con
	 * @param modelCode
	 *            扣型
	 * @param stdCode
	 *            标准
	 * @param steelStyle
	 *            钢级
	 * @param stdStyle
	 *            类别
	 * @return
	 * @throws SQLException
	 */
	public List<DesignWaterRatioEntity> getWaterPress(Connection con,
			String modelCode, String stdCode, String steelStyle, String stdStyle)
			throws SQLException {
		List<DesignWaterRatioEntity> list = new ArrayList<DesignWaterRatioEntity>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("IDeliveryStdDao.getWaterRatioStd");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, modelCode);
		ps.setObject(2, stdCode);
		ps.setObject(3, steelStyle);
		ps.setObject(4, stdStyle);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			DesignWaterRatioEntity entity = new DesignWaterRatioEntity();
			entity.setRatioId(rs.getString("RATIO_ID"));
			entity.setStdCode(rs.getString("STD_CODE"));
			entity.setStdName(rs.getString("STD_NAME"));
			entity.setSizeMinSign(rs.getString("SIZE_MIN_SIGN"));
			entity.setSizeMin(rs.getString("SIZE_MIN"));
			entity.setSizeMaxSign(rs.getString("SIZE_MAX_SIGN"));
			entity.setSizeMax(rs.getString("SIZE_MAX"));
			entity.setRatioStd(rs.getString("RATIO_STD"));
			entity.setRatioReplace(rs.getString("RATIO_REPLACE"));
			entity.setMaxPress(rs.getString("MAX_PRESS"));
			entity.setStdStyle(rs.getString("STD_STYLE"));
			entity.setStdStyleDesc(rs.getString("STD_STYLE_DESC"));
			entity.setModelCode(rs.getString("MODEL_CODE"));
			entity.setModelDesc(rs.getString("MODEL_DESC"));
			entity.setSteelCode(rs.getString("STEELCODE"));
			QualityDesignTool.nullConverNullString(entity);
			list.add(entity);
		}
		return list;
	}

	/**
	 * 查询加工索引号 （扣型，冶金规范码）
	 * 
	 * @param con
	 * @param msc
	 *            冶金规范码
	 * @param modelCode
	 *            扣型
	 * @return
	 * @throws SQLException
	 */
	public List<String> getGic(Connection con, String msc, String modelCode)
			throws SQLException {
		List<String> list = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("IDeliveryStdDao.getGicIndex");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, msc);
		ps.setObject(2, modelCode);
		ps.setObject(3, msc);
		ps.setObject(4, modelCode);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			String gic = rs.getString("GIC");
			list.add(gic);
		}
		return list;
	}

	public void addStandard(Connection con, DesignStdEntity comDesignStd,
			String designKey) throws SQLException {
		if (comDesignStd == null) {
			return;
		}
		String sql = CoreXmlSqlParsersFactory
				.getSql("IDeliveryStdDao.addStand");
		sql = sql.replaceAll("#DESGIN_KEY#", designKey);
		sql = sql.replaceAll("#CIC#", comDesignStd.getCic());
		sql = sql.replaceAll("#PIC#", comDesignStd.getPic());
		sql = sql.replaceAll("#SIC#", comDesignStd.getSic());
		sql = sql.replaceAll("#DIC#", comDesignStd.getDic());
		sql = sql.replaceAll("#WIC#", comDesignStd.getWic());
		sql = sql.replaceAll("#GIC#", comDesignStd.getGic());
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

	public List<DesignStdCicEntity> getChem(Connection con, String cic)
			throws SQLException {
		List<DesignStdCicEntity> list = new ArrayList<DesignStdCicEntity>();
		String sql = CoreXmlSqlParsersFactory.getSql("IDeliveryStdDao.getChem");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, cic);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			DesignStdCicEntity chem = new DesignStdCicEntity();
			chem.setCic(rs.getString("cic"));
			chem.setIndexSeq(rs.getString("index_seq"));
			chem.setChemCode(rs.getString("chem_code"));
			chem.setChemName(rs.getString("chem_name"));
			chem.setChemType(rs.getString("chem_type"));
			chem.setChemFormula(rs.getString("chem_formula"));
			chem.setIscheck(rs.getString("ischeck"));
			chem.setIsjudge(rs.getString("isjudge"));
			chem.setIsquote(rs.getString("isquote"));
			chem.setComplexType(rs.getString("complex_type"));
			chem.setStdminSign(rs.getString("stdmin_sign"));
			chem.setStdmin(rs.getString("stdmin"));
			chem.setStdmaxSign(rs.getString("stdmax_sign"));
			chem.setStdmax(rs.getString("stdmax"));
			chem.setStdtarget(rs.getString("stdtarget"));
			chem.setModelCode(rs.getString("model_code"));
			chem.setModelDesc(rs.getString("model_desc"));
			chem.setStdmemo(rs.getString("stdmemo"));
			chem.setEleCode(rs.getString("ele_code"));
			chem.setEleName(rs.getString("ele_name"));
			chem.setEleMinSign(rs.getString("ele_min_sign"));
			chem.setEleMin(rs.getString("ele_min"));
			chem.setEleMaxSign(rs.getString("ele_max_sign"));
			chem.setEleMax(rs.getString("ele_max"));
			chem.setSizeCode2(rs.getString("size_code2"));
			chem.setSizeName2(rs.getString("size_name2"));
			chem.setSizeMinSign2(rs.getString("size_min_sign2"));
			chem.setSizeMin2(rs.getString("size_min2"));
			chem.setSizeMaxSign2(rs.getString("size_max_sign2"));
			chem.setSizeMax2(rs.getString("size_max2"));
			chem.setSizeCode(rs.getString("size_code"));
			chem.setSizeName(rs.getString("size_name"));
			chem.setSizeMinSign(rs.getString("size_min_sign"));
			chem.setSizeMin(rs.getString("size_min"));
			chem.setSizeMaxSign(rs.getString("size_max_sign"));
			chem.setSizeMax(rs.getString("size_max"));
			chem.setSpecJg(rs.getString("spec_jg"));
			chem.setSpecJgDesc(rs.getString("spec_jg_desc"));
			chem.setRepCode(rs.getString("rep_code"));
			chem.setRepName(rs.getString("rep_name"));
			chem.setRepMinSign(rs.getString("rep_min_sign"));
			chem.setRepMin(rs.getString("rep_min"));
			chem.setRepMaxSign(rs.getString("rep_max_sign"));
			chem.setRepMax(rs.getString("rep_max"));
			chem.setRepVal(rs.getString("rep_val"));
			QualityDesignTool.nullConverNullString(chem);
			list.add(chem);
		}
		rs.close();
		ps.close();
		return list;
	}

	public void saveChem(Connection con, DesignStdCicEntity chem,
			String designKey, String userName) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("IDeliveryStdDao.saveChem");
		sql = sql.replaceAll("#DESGIN_KEY#", chem.getDesginKey());
		sql = sql.replaceAll("#CIC#", chem.getCic());
		sql = sql.replaceAll("#USE_CODE#", chem.getUseCode());
		sql = sql.replaceAll("#USE_DESC#", chem.getUseDesc());
		sql = sql.replaceAll("#SPECL_FL#", chem.getSpeclFl());
		sql = sql.replaceAll("#INDEX_SEQ#", chem.getIndexSeq());
		sql = sql.replaceAll("#CHEM_CODE#", chem.getChemCode());
		sql = sql.replaceAll("#CHEM_NAME#", chem.getChemName());
		sql = sql.replaceAll("#CHEM_TYPE#", chem.getChemType());
		sql = sql.replaceAll("#CHEM_FORMULA#", chem.getChemFormula());
		sql = sql.replaceAll("#ISCHECK#", chem.getIscheck());
		sql = sql.replaceAll("#ISJUDGE#", chem.getIsjudge());
		sql = sql.replaceAll("#ISQUOTE#", chem.getIsquote());
		sql = sql.replaceAll("#COMPLEX_TYPE#", chem.getComplexType());
		sql = sql.replaceAll("#STDMIN_SIGN#", chem.getStdminSign());
		sql = sql.replaceAll("#STDMIN#", chem.getStdmin());
		sql = sql.replaceAll("#STDMAX_SIGN#", chem.getStdmaxSign());
		sql = sql.replaceAll("#STDMAX#", chem.getStdmax());
		sql = sql.replaceAll("#STDTARGET#", chem.getStdtarget());
		sql = sql.replaceAll("#MODEL_CODE#", chem.getModelCode());
		sql = sql.replaceAll("#MODEL_DESC#", chem.getModelDesc());
		sql = sql.replaceAll("#STDMEMO#", chem.getStdmemo());
		sql = sql.replaceAll("#ELE_CODE#", chem.getEleCode());
		sql = sql.replaceAll("#ELE_NAME#", chem.getEleName());
		sql = sql.replaceAll("#ELE_MIN_SIGN#", chem.getEleMinSign());
		sql = sql.replaceAll("#ELE_MIN#", chem.getEleMin());
		sql = sql.replaceAll("#ELE_MAX_SIGN#", chem.getEleMaxSign());
		sql = sql.replaceAll("#ELE_MAX#", chem.getEleMax());
		sql = sql.replaceAll("#SIZE_CODE2#", chem.getSizeCode2());
		sql = sql.replaceAll("#SIZE_NAME2#", chem.getSizeName2());
		sql = sql.replaceAll("#SIZE_MIN_SIGN2#", chem.getSizeMinSign2());
		sql = sql.replaceAll("#SIZE_MIN2#", chem.getSizeMin2());
		sql = sql.replaceAll("#SIZE_MAX_SIGN2#", chem.getSizeMaxSign2());
		sql = sql.replaceAll("#SIZE_MAX2#", chem.getSizeMax2());
		sql = sql.replaceAll("#SIZE_CODE#", chem.getSizeCode());
		sql = sql.replaceAll("#SIZE_NAME#", chem.getSizeName());
		sql = sql.replaceAll("#SIZE_MIN_SIGN#", chem.getSizeMinSign());
		sql = sql.replaceAll("#SIZE_MIN#", chem.getSizeMin());
		sql = sql.replaceAll("#SIZE_MAX_SIGN#", chem.getSizeMaxSign());
		sql = sql.replaceAll("#SIZE_MAX#", chem.getSizeMax());
		sql = sql.replaceAll("#SPEC_JG#", chem.getSpecJg());
		sql = sql.replaceAll("#SPEC_JG_DESC#", chem.getSpecJgDesc());
		sql = sql.replaceAll("#VALIDFLAG#", chem.getValidflag());
		sql = sql.replaceAll("#CREATE_NAME#", userName);
		sql = sql.replaceAll("#REP_CODE#", chem.getRepCode());
		sql = sql.replaceAll("#REP_NAME#", chem.getRepName());
		sql = sql.replaceAll("#REP_MIN_SIGN#", chem.getRepMinSign());
		sql = sql.replaceAll("#REP_MIN#", chem.getRepMin());
		sql = sql.replaceAll("#REP_MAX_SIGN#", chem.getRepMaxSign());
		sql = sql.replaceAll("#REP_MAX#", chem.getRepMax());
		sql = sql.replaceAll("#REP_VAL#", chem.getRepVal());
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();

	}

	public List<DesignStdPicEntity> getPhy(Connection con, String pic)
			throws SQLException {
		List<DesignStdPicEntity> list = new ArrayList<DesignStdPicEntity>();
		String sql = CoreXmlSqlParsersFactory.getSql("IDeliveryStdDao.getPhy");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, pic);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			DesignStdPicEntity phy = new DesignStdPicEntity();
			phy.setPic(rs.getString("pic"));
			phy.setIndexSeq(rs.getString("index_seq"));
			phy.setPhyCodeMax(rs.getString("phy_code_max"));
			phy.setPhyNameMax(rs.getString("phy_name_max"));
			phy.setPhyCodeMin(rs.getString("phy_code_min"));
			phy.setPhyNameMin(rs.getString("phy_name_min"));
			phy.setPhyCode(rs.getString("phy_code"));
			phy.setPhyName(rs.getString("phy_name"));
			phy.setItemCodeF(rs.getString("item_code_f"));
			phy.setItemNameF(rs.getString("item_name_f"));
			phy.setItemCodeW(rs.getString("item_code_w"));
			phy.setItemNameW(rs.getString("item_name_w"));
			phy.setItemCodeS(rs.getString("item_code_s"));
			phy.setItemNameS(rs.getString("item_name_s"));
			phy.setGroupSeq(rs.getString("group_seq"));
			phy.setResultCount(rs.getString("result_count"));
			phy.setIscheck(rs.getString("ischeck"));
			phy.setIsjudge(rs.getString("isjudge"));
			phy.setIsquote(rs.getString("isquote"));
			phy.setPhyType(rs.getString("phy_type"));
			phy.setPhyFormula(rs.getString("phy_formula"));
			phy.setStdminSign(rs.getString("stdmin_sign"));
			phy.setStdmin(rs.getString("stdmin"));
			phy.setStdmaxSign(rs.getString("stdmax_sign"));
			phy.setStdmax(rs.getString("stdmax"));
			phy.setJudgeBasis(rs.getString("judge_basis"));
			phy.setDeliverystate(rs.getString("deliverystate"));
			phy.setModelCode(rs.getString("model_code"));
			phy.setModelDesc(rs.getString("model_desc"));
			phy.setStdmemo(rs.getString("stdmemo"));
			phy.setSizeCode2(rs.getString("size_code2"));
			phy.setSizeName2(rs.getString("size_name2"));
			phy.setSizeMinSign2(rs.getString("size_min_sign2"));
			phy.setSizeMin2(rs.getString("size_min2"));
			phy.setSizeMaxSign2(rs.getString("size_max_sign2"));
			phy.setSizeMax2(rs.getString("size_max2"));
			phy.setSizeCode(rs.getString("size_code"));
			phy.setSizeName(rs.getString("size_name"));
			phy.setSizeMinSign(rs.getString("size_min_sign"));
			phy.setSizeMin(rs.getString("size_min"));
			phy.setSizeMaxSign(rs.getString("size_max_sign"));
			phy.setSizeMax(rs.getString("size_max"));
			phy.setSpecJg(rs.getString("spec_jg"));
			phy.setSpecJgDesc(rs.getString("spec_jg_desc"));
			phy.setAddcondition(rs.getString("addcondition"));
			phy.setAddstdconCode(rs.getString("addstdcon_code"));
			phy.setAddstdMinSign(rs.getString("addstd_min_sign"));
			phy.setAddstdMin(rs.getString("addstd_min"));
			phy.setAddstdMaxSign(rs.getString("addstd_max_sign"));
			phy.setAddstdMax(rs.getString("addstd_max"));
			phy.setAddpercent(rs.getString("addpercent"));
			phy.setStdChoose(rs.getString("STD_CHOOSE"));
			QualityDesignTool.nullConverNullString(phy);
			list.add(phy);
		}
		rs.close();
		ps.close();
		return list;
	}

	public void savePhy(Connection con, DesignStdPicEntity phy,
			String designKey, String userName) throws SQLException {
		if (phy == null) {
			return;
		}
		String sql = CoreXmlSqlParsersFactory.getSql("IDeliveryStdDao.savePhy");
		sql = sql.replaceAll("#DESGIN_KEY#", designKey);
		sql = sql.replaceAll("#PIC#", phy.getPic());
		sql = sql.replaceAll("#INDEX_SEQ#", phy.getIndexSeq());
		sql = sql.replaceAll("#USE_CODE#", phy.getUseCode());
		sql = sql.replaceAll("#USE_DESC#", phy.getUseDesc());
		sql = sql.replaceAll("#SPECL_FL#", phy.getSpeclFl());
		sql = sql.replaceAll("#PHY_CODE_MAX#", phy.getPhyCodeMax());
		sql = sql.replaceAll("#PHY_NAME_MAX#", phy.getPhyNameMax());
		sql = sql.replaceAll("#PHY_CODE_MIN#", phy.getPhyCodeMin());
		sql = sql.replaceAll("#PHY_NAME_MIN#", phy.getPhyNameMin());
		sql = sql.replaceAll("#PHY_CODE#", phy.getPhyCode());
		sql = sql.replaceAll("#PHY_NAME#", phy.getPhyName());
		sql = sql.replaceAll("#ITEM_CODE_F#", phy.getItemCodeF());
		sql = sql.replaceAll("#ITEM_NAME_F#", phy.getItemNameF());
		sql = sql.replaceAll("#ITEM_CODE_W#", phy.getItemCodeW());
		sql = sql.replaceAll("#ITEM_NAME_W#", phy.getItemNameW());
		sql = sql.replaceAll("#ITEM_CODE_S#", phy.getItemCodeS());
		sql = sql.replaceAll("#ITEM_NAME_S#", phy.getItemNameS());
		sql = sql.replaceAll("#GROUP_SEQ#", phy.getGroupSeq());
		sql = sql.replaceAll("#ISCHECK#", phy.getIscheck());
		sql = sql.replaceAll("#ISQUOTE#", phy.getIsquote());
		sql = sql.replaceAll("#RESULT_COUNT#", phy.getResultCount());
		sql = sql.replaceAll("#ISJUDGE#", phy.getIsjudge());
		sql = sql.replaceAll("#PHY_TYPE#", phy.getPhyType());
		sql = sql.replaceAll("#PHY_FORMULA#", phy.getPhyFormula());
		sql = sql.replaceAll("#STDMIN_SIGN#", phy.getStdminSign());
		sql = sql.replaceAll("#STDMIN#", phy.getStdmin());
		sql = sql.replaceAll("#STDMAX_SIGN#", phy.getStdmaxSign());
		sql = sql.replaceAll("#STDMAX#", phy.getStdmax());
		sql = sql.replaceAll("#JUDGE_BASIS#", phy.getJudgeBasis());
		sql = sql.replaceAll("#DELIVERYSTATE#", phy.getDeliverystate());
		sql = sql.replaceAll("#MODEL_CODE#", phy.getModelCode());
		sql = sql.replaceAll("#MODEL_DESC#", phy.getModelDesc());
		sql = sql.replaceAll("#STDMEMO#", phy.getStdmemo());
		sql = sql.replaceAll("#SIZE_CODE#", phy.getSizeCode());
		sql = sql.replaceAll("#SIZE_NAME#", phy.getSizeName());
		sql = sql.replaceAll("#SIZE_MIN_SIGN#", phy.getSizeMinSign());
		sql = sql.replaceAll("#SIZE_MIN#", phy.getSizeMin());
		sql = sql.replaceAll("#SIZE_MAX_SIGN#", phy.getSizeMaxSign());
		sql = sql.replaceAll("#SIZE_MAX#", phy.getSizeMax());
		sql = sql.replaceAll("#SIZE_CODE2#", phy.getSizeCode2());
		sql = sql.replaceAll("#SIZE_NAME2#", phy.getSizeName2());
		sql = sql.replaceAll("#SIZE_MIN_SIGN2#", phy.getSizeMinSign2());
		sql = sql.replaceAll("#SIZE_MIN2#", phy.getSizeMin2());
		sql = sql.replaceAll("#SIZE_MAX_SIGN2#", phy.getSizeMaxSign2());
		sql = sql.replaceAll("#SIZE_MAX2#", phy.getSizeMax2());
		sql = sql.replaceAll("#SPEC_JG#", phy.getSpecJg());
		sql = sql.replaceAll("#SPEC_JG_DESC#", phy.getSpecJgDesc());
		sql = sql.replaceAll("#ADDCONDITION#", phy.getAddcondition());
		sql = sql.replaceAll("#ADDSTDCON_CODE#", phy.getAddstdconCode());
		sql = sql.replaceAll("#ADDSTD_MIN_SIGN#", phy.getAddstdMinSign());
		sql = sql.replaceAll("#ADDSTD_MIN#", phy.getAddstdMin());
		sql = sql.replaceAll("#ADDSTD_MAX_SIGN#", phy.getAddstdMaxSign());
		sql = sql.replaceAll("#ADDSTD_MAX#", phy.getAddstdMax());
		sql = sql.replaceAll("#ADDPERCENT#", phy.getAddpercent());
		sql = sql.replaceAll("#STDMIN_SIGN2#", phy.getStdminSign2());
		sql = sql.replaceAll("#STDMIN2#", phy.getStdmin2());
		sql = sql.replaceAll("#STDMAX_SIGN2#", phy.getStdmaxSign2());
		sql = sql.replaceAll("#STDMAX2#", phy.getStdmax2());
		sql = sql.replaceAll("#STD_CHOOSE#", phy.getStdChoose());
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();

	}

	public DesignStdPicSmpEntity getPicSample(Connection con, String pic,
			String phyCodeMin) throws SQLException {
		DesignStdPicSmpEntity comPicSmp = new DesignStdPicSmpEntity();
		String sql = CoreXmlSqlParsersFactory
				.getSql("IDeliveryStdDao.getPicSample");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, pic);
		ps.setObject(2, phyCodeMin);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			comPicSmp.setPic(rs.getString("pic"));
			comPicSmp.setSic(rs.getString("sic"));
			comPicSmp.setPhyCodeMin(rs.getString("phy_code_min"));
			comPicSmp.setPhyNameMin(rs.getString("phy_name_min"));
			comPicSmp.setStdCode(rs.getString("std_code"));
			comPicSmp.setStdName(rs.getString("std_name"));
			comPicSmp.setLength(rs.getString("length"));
			comPicSmp.setDescLength(rs.getString("desc_length"));
			comPicSmp.setRate(rs.getString("rate"));
			comPicSmp.setDescRate(rs.getString("desc_rate"));
			comPicSmp.setDescCount(rs.getString("desc_count"));
			comPicSmp.setPosition(rs.getString("position"));
			comPicSmp.setDescPosition(rs.getString("desc_position"));
			comPicSmp.setMemo(rs.getString("memo"));
			QualityDesignTool.nullConverNullString(comPicSmp);
		} else {
			return null;
		}
		rs.close();
		ps.close();
		return comPicSmp;
	}

	public void savePicSample(Connection con, DesignStdPicSmpEntity comPicSmp,
			String designKey) throws SQLException {
		if (comPicSmp == null) {
			return;
		}
		String sql = CoreXmlSqlParsersFactory
				.getSql("IDeliveryStdDao.savePicSample");
		sql = sql.replaceAll("#DESGIN_KEY#", designKey);
		sql = sql.replaceAll("#PIC#", comPicSmp.getPic());
		sql = sql.replaceAll("#SIC#", comPicSmp.getSic());
		sql = sql.replaceAll("#PHY_CODE_MIN#", comPicSmp.getPhyCodeMin());
		sql = sql.replaceAll("#PHY_NAME_MIN#", comPicSmp.getPhyNameMin());
		sql = sql.replaceAll("#STD_CODE#", comPicSmp.getStdCode());
		sql = sql.replaceAll("#STD_NAME#", comPicSmp.getStdName());
		sql = sql.replaceAll("#LENGTH#", comPicSmp.getLength());
		sql = sql.replaceAll("#DESC_LENGTH#", comPicSmp.getDescLength());
		sql = sql.replaceAll("#RATE#", comPicSmp.getRate());
		sql = sql.replaceAll("#DESC_RATE#", comPicSmp.getDescRate());
		sql = sql.replaceAll("#DESC_COUNT#", comPicSmp.getDescCount());
		sql = sql.replaceAll("#POSITION#", comPicSmp.getPosition());
		sql = sql.replaceAll("#DESC_POSITION#", comPicSmp.getDescPosition());
		sql = sql.replaceAll("#SAMPLE_COUNT#", comPicSmp.getSampleCount());
		sql = sql.replaceAll("#MEMO#", comPicSmp.getMemo());
		PreparedStatement ps = con.prepareStatement(sql);
		ps.close();

	}

	public List<DesignStdSicEntity> getSpec(Connection con, String sic)
			throws SQLException {
		List<DesignStdSicEntity> list = new ArrayList<DesignStdSicEntity>();
		String sql = CoreXmlSqlParsersFactory.getSql("IDeliveryStdDao.getSic");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, sic);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			DesignStdSicEntity spec = new DesignStdSicEntity();
			spec.setSic(rs.getString("SIC"));
			spec.setIndexSeq(rs.getString("INDEX_SEQ"));
			spec.setBiasCode(rs.getString("BIAS_CODE"));
			spec.setBiasName(rs.getString("BIAS_NAME"));
			spec.setLv(rs.getString("LV"));
			spec.setBiasCodeZ(rs.getString("BIAS_CODE_Z"));
			spec.setBiasNameZ(rs.getString("BIAS_NAME_Z"));
			spec.setZminSign(rs.getString("ZMIN_SIGN"));
			spec.setZmin(rs.getString("ZMIN"));
			spec.setZmaxSign(rs.getString("ZMAX_SIGN"));
			spec.setZmax(rs.getString("ZMAX"));
			spec.setBiasCodeC(rs.getString("BIAS_CODE_C"));
			spec.setBiasNameC(rs.getString("BIAS_NAME_C"));
			spec.setCminSign(rs.getString("CMIN_SIGN"));
			spec.setCmin(rs.getString("CMIN"));
			spec.setCmaxSign(rs.getString("CMAX_SIGN"));
			spec.setCmax(rs.getString("CMAX"));
			spec.setBiasCodeS(rs.getString("BIAS_CODE_S"));
			spec.setBiasNameS(rs.getString("BIAS_NAME_S"));
			spec.setSminSign(rs.getString("SMIN_SIGN"));
			spec.setSmin(rs.getString("SMIN"));
			spec.setSmaxSign(rs.getString("SMAX_SIGN"));
			spec.setSmax(rs.getString("SMAX"));
			spec.setIscheck(rs.getString("ISCHECK"));
			spec.setStdMinVal(rs.getString("STD_MIN_VAL"));
			spec.setStdMaxVal(rs.getString("STD_MAX_VAL"));
			spec.setStdMinIn(rs.getString("STD_MIN_IN"));
			spec.setStdMaxIn(rs.getString("STD_MAX_IN"));
			spec.setStdMinPercent(rs.getString("STD_MIN_PERCENT"));
			spec.setStdMaxPercent(rs.getString("STD_MAX_PERCENT"));
			spec.setStdMinFormula(rs.getString("STD_MIN_FORMULA"));
			spec.setStdMaxFormula(rs.getString("STD_MAX_FORMULA"));
			spec.setStdMinFormulaV(rs.getString("STD_MIN_FORMULA_V"));
			spec.setStdMaxFormulaV(rs.getString("STD_MAX_FORMULA_V"));
			spec.setStdmemo(rs.getString("STDMEMO"));
			QualityDesignTool.nullConverNullString(spec);
			list.add(spec);
		}
		rs.close();
		ps.close();
		return list;
	}

	public void saveSpec(Connection con, DesignStdSicEntity spec,
			String designKey) throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("IDeliveryStdDao.saveSic");
		sql = sql.replaceAll("#BIAS_CODE_C#", spec.getBiasCodeC());
		sql = sql.replaceAll("#BIAS_NAME_C#", spec.getBiasNameC());
		sql = sql.replaceAll("#CMIN_SIGN#", spec.getCminSign());
		sql = sql.replaceAll("#CMIN#", spec.getCmin());
		sql = sql.replaceAll("#CMAX_SIGN#", spec.getCmaxSign());
		sql = sql.replaceAll("#CMAX#", spec.getCmax());
		sql = sql.replaceAll("#BIAS_CODE_S#", spec.getBiasCodeS());
		sql = sql.replaceAll("#BIAS_NAME_S#", spec.getBiasNameS());
		sql = sql.replaceAll("#SMIN_SIGN#", spec.getSminSign());
		sql = sql.replaceAll("#SMIN#", spec.getSmin());
		sql = sql.replaceAll("#SMAX_SIGN#", spec.getSmaxSign());
		sql = sql.replaceAll("#SMAX#", spec.getSmax());
		sql = sql.replaceAll("#ISCHECK#", spec.getIscheck());
		sql = sql.replaceAll("#STD_MIN_VAL#", spec.getStdMinVal());
		sql = sql.replaceAll("#STD_MAX_VAL#", spec.getStdMaxVal());
		sql = sql.replaceAll("#STD_MIN_IN#", spec.getStdMinIn());
		sql = sql.replaceAll("#STD_MAX_IN#", spec.getStdMaxIn());
		sql = sql.replaceAll("#STD_MIN_PERCENT#", spec.getStdMinPercent());
		sql = sql.replaceAll("#STD_MAX_PERCENT#", spec.getStdMaxPercent());
		sql = sql.replaceAll("#STD_MIN_FORMULA#", spec.getStdMinFormula());
		sql = sql.replaceAll("#STD_MAX_FORMULA#", spec.getStdMaxFormula());
		sql = sql.replaceAll("#STD_MIN_FORMULA_V#", spec.getStdMinFormulaV());
		sql = sql.replaceAll("#STD_MAX_FORMULA_V#", spec.getStdMaxFormulaV());
		sql = sql.replaceAll("#STDMEMO#", spec.getStdmemo());
		sql = sql.replaceAll("#DESGIN_KEY#", designKey);
		sql = sql.replaceAll("#SIC#", spec.getSic());
		sql = sql.replaceAll("#USE_CODE#", spec.getUseCode());
		sql = sql.replaceAll("#USE_DESC#", spec.getUseDesc());
		sql = sql.replaceAll("#SPECL_FL#", spec.getSpeclFl());
		sql = sql.replaceAll("#INDEX_SEQ#", spec.getIndexSeq());
		sql = sql.replaceAll("#BIAS_CODE#", spec.getBiasCode());
		sql = sql.replaceAll("#BIAS_NAME#", spec.getBiasName());
		sql = sql.replaceAll("#LV#", spec.getLv());
		sql = sql.replaceAll("#BIAS_CODE_Z#", spec.getBiasCodeZ());
		sql = sql.replaceAll("#BIAS_NAME_Z#", spec.getBiasNameZ());
		sql = sql.replaceAll("#ZMIN_SIGN#", spec.getZminSign());
		sql = sql.replaceAll("#ZMIN#", spec.getZmin());
		sql = sql.replaceAll("#ZMAX_SIGN#", spec.getZmaxSign());
		sql = sql.replaceAll("#ZMAX#", spec.getZmax());
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();

	}

	public List<DesignStdDicEntity> getDetes(Connection con, String dic)
			throws SQLException {
		List<DesignStdDicEntity> list = new ArrayList<DesignStdDicEntity>();
		String sql = CoreXmlSqlParsersFactory.getSql("IDeliveryStdDao.getDic");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, dic);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			DesignStdDicEntity dete = new DesignStdDicEntity();
			dete.setDic(rs.getString("DIC"));
			dete.setXh(rs.getString("XH"));
			dete.setPhyCode(rs.getString("PHY_CODE"));
			dete.setPhyName(rs.getString("PHY_NAME"));
			dete.setPositionCode(rs.getString("POSITION_CODE"));
			dete.setPositionDesc(rs.getString("POSITION_DESC"));
			dete.setStdDesc(rs.getString("STD_DESC"));
			dete.setLvCode(rs.getString("LV_CODE"));
			dete.setGroovePos(rs.getString("GROOVE_POS"));
			dete.setGrooveDir(rs.getString("GROOVE_DIR"));
			dete.setLvDesc(rs.getString("LV_DESC"));
			dete.setCoverage(rs.getString("COVERAGE"));
			dete.setMemo(rs.getString("MEMO"));
			dete.setRate(rs.getString("RATE"));
			dete.setDescRate(rs.getString("DESC_RATE"));
			dete.setDescVal(rs.getString("DESC_VAL"));
			dete.setGroupSeq(rs.getString("GROUP_SEQ"));
			QualityDesignTool.nullConverNullString(dete);
			list.add(dete);
		}
		rs.close();
		ps.close();
		return list;
	}

	public void saveDete(Connection con, DesignStdDicEntity dete,
			String designKey) throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("IDeliveryStdDao.saveDic");
		PreparedStatement ps = con.prepareStatement(sql);
		sql = sql.replaceAll("#LV_CODE#", dete.getLvCode());
		sql = sql.replaceAll("#LV_DESC#", dete.getLvDesc());
		sql = sql.replaceAll("#GROOVE_POS#", dete.getGroovePos());
		sql = sql.replaceAll("#GROOVE_DIR#", dete.getGrooveDir());
		sql = sql.replaceAll("#COVERAGE#", dete.getCoverage());
		sql = sql.replaceAll("#RATE#", dete.getRate());
		sql = sql.replaceAll("#DESC_RATE#", dete.getDescRate());
		sql = sql.replaceAll("#DESC_VAL#", dete.getDescVal());
		sql = sql.replaceAll("#GROUP_SEQ#", dete.getGroupSeq());
		sql = sql.replaceAll("#MEMO#", dete.getMemo());
		sql = sql.replaceAll("#DESGIN_KEY#", designKey);
		sql = sql.replaceAll("#DIC#", dete.getDic());
		sql = sql.replaceAll("#USE_CODE#", dete.getUseCode());
		sql = sql.replaceAll("#USE_DESC#", dete.getUseDesc());
		sql = sql.replaceAll("#SPECL_FL#", dete.getSpeclFl());
		sql = sql.replaceAll("#XH#", dete.getXh());
		sql = sql.replaceAll("#PHY_CODE#", dete.getPhyCode());
		sql = sql.replaceAll("#PHY_NAME#", dete.getPhyName());
		sql = sql.replaceAll("#POSITION_CODE#", dete.getPositionCode());
		sql = sql.replaceAll("#POSITION_DESC#", dete.getPositionDesc());
		sql = sql.replaceAll("#STD_DESC#", dete.getStdDesc());
		ps.executeUpdate();
		ps.close();
	}

	public List<DesignStdWicEntity> getWater(Connection con, String wic)
			throws SQLException {
		List<DesignStdWicEntity> list = new ArrayList<DesignStdWicEntity>();
		String sql = CoreXmlSqlParsersFactory.getSql("IDeliveryStdDao.getWic");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, wic);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			DesignStdWicEntity water = new DesignStdWicEntity();
			water.setWic(rs.getString("WIC"));
			water.setIndexSeq(rs.getString("XH"));
			water.setPressureY(rs.getString("PRESSURE_Y"));
			water.setPressure(rs.getString("PRESSURE"));
			water.setFormula(rs.getString("FORMULA"));
			water.setSaveTime(rs.getString("SAVE_TIME"));
			water.setGetMaxvalue(rs.getString("GET_MAXVALUE"));
			water.setGetMinvalue(rs.getString("GET_MINVALUE"));
			QualityDesignTool.nullConverNullString(water);
			list.add(water);
		}
		rs.close();
		ps.close();
		return list;
	}

	public void saveWater(Connection con, DesignStdWicEntity water,
			String designKey) throws SQLException {
		String sql = CoreXmlSqlParsersFactory.getSql("IDeliveryStdDao.saveWic");
		sql = sql.replaceAll("#DESGIN_KEY#", designKey);
		sql = sql.replaceAll("#WIC#", water.getWic());
		sql = sql.replaceAll("#USE_CODE#", water.getUseCode());
		sql = sql.replaceAll("#USE_DESC#", water.getUseDesc());
		sql = sql.replaceAll("#SPECL_FL#", water.getSpeclFl());
		sql = sql.replaceAll("#INDEX_SEQ#", water.getIndexSeq());
		sql = sql.replaceAll("#PRESSURE_Y#", water.getPressureY());
		sql = sql.replaceAll("#PRESSURE#", water.getPressure());
		sql = sql.replaceAll("#FORMULA#", water.getFormula());
		sql = sql.replaceAll("#SAVE_TIME#", water.getSaveTime());
		sql = sql.replaceAll("#GET_MAXVALUE#", water.getGetMaxvalue());
		sql = sql.replaceAll("#GET_MINVALUE#", water.getGetMinvalue());
		sql = sql.replaceAll("#RATIO_STD#", water.getRatioStd());
		sql = sql.replaceAll("#RATIO_REPLACE#", water.getRatioReplace());
		sql = sql.replaceAll("#MAX_PRESS#", water.getMaxPress());
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();

	}

	public List<DesignStdGicEntity> getProcess(Connection con, String gic)
			throws SQLException {
		List<DesignStdGicEntity> list = new ArrayList<DesignStdGicEntity>();
		String sql = CoreXmlSqlParsersFactory.getSql("IDeliveryStdDao.getGic");
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, gic);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			DesignStdGicEntity process = new DesignStdGicEntity();
			process.setGic(rs.getString("GIC"));
			process.setXh(rs.getString("XH"));
			process.setStationCode(rs.getString("STATION_CODE"));
			process.setStationDesc(rs.getString("STATION_DESC"));
			process.setProcessCdoe(rs.getString("PROCESS_CDOE"));
			process.setProcessDesc(rs.getString("PROCESS_DESC"));
			process.setProcessCdoeC(rs.getString("PROCESS_CDOE_C"));
			process.setProcessDescC(rs.getString("PROCESS_DESC_C"));
			process.setValueText(rs.getString("VALUE_TEXT"));
			process.setValueNum(rs.getString("VALUE_NUM"));
			process.setValueMemo(rs.getString("VALUE_MEMO"));
			process.setGroupSeq(rs.getString("GROUP_SEQ"));
			process.setMemo(rs.getString("MEMO"));
			QualityDesignTool.nullConverNullString(process);
			list.add(process);
		}
		rs.close();
		ps.close();
		return list;
	}

	/**
	 * 保存质量加工标准
	 * 
	 * @param con
	 * @param process
	 * @param designKey
	 * @throws SQLException
	 */
	public void saveProcess(Connection con, DesignStdGicEntity process,
			String designKey) throws SQLException {
		if (process == null) {
			return;
		}
		String sql = CoreXmlSqlParsersFactory.getSql("IDeliveryStdDao.saveGic");
		sql = sql.replaceAll("#DESGIN_KEY#", designKey);
		sql = sql.replaceAll("#GIC#", process.getGic());
		sql = sql.replaceAll("#USE_CODE#", process.getUseCode());
		sql = sql.replaceAll("#USE_DESC#", process.getUseDesc());
		sql = sql.replaceAll("#SPECL_FL#", process.getSpeclFl());
		sql = sql.replaceAll("#XH#", process.getXh());
		sql = sql.replaceAll("#PROCESS_CDOE#", process.getProcessCdoe());
		sql = sql.replaceAll("#PROCESS_DESC#", process.getProcessDesc());
		sql = sql.replaceAll("#PROCESS_CDOE_C#", process.getProcessCdoeC());
		sql = sql.replaceAll("#PROCESS_DESC_C#", process.getProcessCdoeC());
		sql = sql.replaceAll("#STATION_CODE#", process.getStationCode());
		sql = sql.replaceAll("#STATION_DESC#", process.getStationDesc());
		sql = sql.replaceAll("#VALUE_TEXT#", process.getValueText());
		sql = sql.replaceAll("#VALUE_NUM#", process.getValueNum());
		sql = sql.replaceAll("#VALUE_MEMO#", process.getValueMemo());
		sql = sql.replaceAll("#GROUP_SEQ#", process.getGroupSeq());
		sql = sql.replaceAll("#MEMO#", process.getMemo());
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();

	}

}
