/**
 * @(#)file    ContIntBiz.java
 * @(#)author  Kim Myung Ho
 * @(#)version 1.0
 * @(#)date    2014-07-15
 * @(#)since   JDK 1.4.2
 */
package kr.co.udapsoft.ebid.supplier.portal.cont.biz;


import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;

import oracle.toplink.internal.ox.StrBuffer;
import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.base.WAFMessages;
import kr.co.hsnc.common.sql.Row;
import kr.co.hsnc.common.sql.RowSet;
import kr.co.hsnc.common.sql.RowSetImpl;
import kr.co.hsnc.common.sql.WAFSQLException;
import kr.co.hsnc.common.sql.persistent.Persistent;
import kr.co.hsnc.common.sql.persistent.PersistentImpl;
import kr.co.hsnc.common.sql.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;
import kr.co.hsnc.common.sql.util.RowSetUtility;
import kr.co.hsnc.common.util.ValueObject;
import kr.co.udapsoft.common.code.CommCodeManager;
import kr.co.udapsoft.common.sender.MessageSend;
import kr.co.udapsoft.common.util.PDFMaker;
import kr.co.udapsoft.common.util.Crosscert;
import kr.co.udapsoft.ebid.buyer.common.file.FileManager;
import kr.co.udapsoft.ebid.buyer.sycs.user.biz.UserCommon;

import com.udapsoft.modular.web.ibsheet7.IBSheet7Factory;
import com.udapsoft.modular.web.ibsheet7.util.IBSheet7Utils;
import com.udapsoft.waf.common.ui.InitCombo;
import com.udapsoft.waf.common.util.StringUtils;
import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;


public class PurPricesysBiz extends Biz {

	public PurPricesysBiz(HandlerStorage storage) {
		super(storage);
	}

	public void doBiz() throws Exception {
        ValueObject user = new ValueObject();
        ValueObject pricesysInfo = new ValueObject();
		boolean success = false;
		
		if(storage.compareEvent("")){
			
		}else if(storage.compareEvent("FORM_SAVE")){
			PurPricesysSave(super.conn.getConnection(), params);	//표준 미얀동 계약서(미연동_팝업)

			super.storage.setSuccess(true);
			
		}
	}
	
	
	/**
     * 구매_표준미연동계약서 저장
	 * @param connection
	 * @param valueObject
	 * @throws Exception
	 */
	public boolean PurPricesysSave(Connection connection, ValueObject valueObject) throws Exception {

		PreparedStatement pstmt = null;
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("MERGE INTO PRICE_SYS   																										\n");
        	sqlstr.append("USING DUAL   																												\n");
        	sqlstr.append("ON (CONT_MOD_ID = ?)   																										\n");
        	sqlstr.append("WHEN MATCHED THEN   																											\n");
        	sqlstr.append("UPDATE SET   																												\n");
        	sqlstr.append("OBJECT_NM = ?	,																											\n");
        	sqlstr.append("ITEM_NM = ?		,																											\n");
        	sqlstr.append("SYS_REASON = ?	,																											\n");
        	sqlstr.append("REMARK = ?																													\n");
        	sqlstr.append("WHEN NOT MATCHED THEN																										\n");
        	sqlstr.append("INSERT																														\n");
        	sqlstr.append("(PRICE_SYS_ID, PRICE_SYS_YN, OBJECT_NM, ITEM_NM, SYS_REASON, REMARK, CONT_MOD_ID, CORP_REG_NO, CORP_NAME, CONT_NO, MOD_NO)	\n");
        	sqlstr.append("VALUES																														\n");
        	sqlstr.append("(PRICE_SYS_ID_S.NEXTVAL, '01', ?, ?, ?, ?, ?, ?, ?, ?, ?)																	\n");
            
        	
        	pstmt = connection.prepareStatement(sqlstr.toString());
			int paramIdx = 1;
			
			pstmt.setString(paramIdx++, valueObject.get("CONTMODID"));
			pstmt.setString(paramIdx++, valueObject.get("OBJECT_NM"));
			pstmt.setString(paramIdx++, valueObject.get("ITEM_NM"));
			pstmt.setString(paramIdx++, valueObject.get("SYS_REASON"));
			pstmt.setString(paramIdx++, valueObject.get("REMARK"));
			pstmt.setString(paramIdx++, valueObject.get("OBJECT_NM"));
			pstmt.setString(paramIdx++, valueObject.get("ITEM_NM"));
			pstmt.setString(paramIdx++, valueObject.get("SYS_REASON"));
			pstmt.setString(paramIdx++, valueObject.get("REMARK"));
			pstmt.setString(paramIdx++, valueObject.get("CONTMODID"));
			pstmt.setString(paramIdx++, valueObject.get("CORPREGNO"));
			pstmt.setString(paramIdx++, valueObject.get("CORPNAME"));
			pstmt.setString(paramIdx++, valueObject.get("CONTNO"));
			pstmt.setString(paramIdx++, valueObject.get("MODNO"));
            
			pstmt.executeUpdate();
            return true;
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> updUser() : " + e.getMessage());
            WAFLogger.error("SQL : " + sqlstr);
            WAFLogger.error(e);
            throw e;
        }
    }	
	
}