/**
 * @(#)file    BidIngBiz.java
 * @(#)author  Son Hyung Min 
 * @(#)version 1.0
 * @(#)date    2014-06-23
 * @(#)since   JDK 1.4.2
 */
package kr.co.udapsoft.ebid.buyer.bid.purchase.biz;



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

import oracle.toplink.internal.ox.StrBuffer;
import kr.co.hsnc.common.base.WAFLogger;
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.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.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

   
public class BidCommonBiz extends Biz {

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

	public void doBiz() throws Exception {

	}
	
	FileManager FileManager = new FileManager();
	
	/**
     * SP_REG_PSR_STATUS 프로시져 호출
	 * @param rightID
	 * @return
	 */
	public void SP_REG_PSR_STATUS(String Vi_activity_cd, String videmanded_id, String acct_id, String demanded_date){
		CallableStatement cs 	= null;
		String pssql			= "";
	
		pssql = "{call SP_REG_PSR_STATUS('',?,'3','',?,0,'',?,?,'',?,?)}";
		try {
			cs = super.conn.getConnection().prepareCall(pssql);
			cs.setString(1, Vi_activity_cd);
			cs.setString(2, videmanded_id);
			cs.setString(3, acct_id);
			cs.setString(4, demanded_date);
		    cs.registerOutParameter(5, java.sql.Types.VARCHAR);
		    cs.registerOutParameter(6, java.sql.Types.VARCHAR);
		    cs.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void SP_REG_PSR_STATUS(String Vi_activity_cd, String videmanded_id, String acct_id){
		CallableStatement cs 	= null;
		String pssql			= "";
	
		pssql = "{call SP_REG_PSR_STATUS('',?,'3','',?,0,'',?,SYSDATE,'',?,?)}";
		try {
			cs = super.conn.getConnection().prepareCall(pssql);
			cs.setString(1, Vi_activity_cd);
			cs.setString(2, videmanded_id);
			cs.setString(3, acct_id);
		    cs.registerOutParameter(4, java.sql.Types.VARCHAR);
		    cs.registerOutParameter(5, java.sql.Types.VARCHAR);
		    cs.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		}
    }
	
	public ValueObject getfilelist(String filegb,String id,String returnid){
		ValueObject vo = new ValueObject();
		RowSet rowSet = FileManager.getFileList(filegb, id);
		String str="";
	        for(int i=0;i<rowSet.size();i++){
	        	Row row=rowSet.getRow(i);
	        	str += (i+1)+" : "+row.get("FILE_NAME")+" ("+ row.get("FILE_SIZE")+")";
	        	if(i+1!=rowSet.size()){
	        		str +="</br>"; 
	        	}
	        }
	        vo.set(returnid, str);
		return vo;
	}
	
	   /**
	  * 			결제중인지 확인 합니다.
	  */
	 public String getDupCnt1(String signClassCd, String key_col1, String key_col2) {
	 	
	 	Search search = new SearchImpl(); 
	 	RowSet rowSet = new RowSetImpl();
	 	StringBuffer sqlstr = new StringBuffer();
	 	String rtnStr = "";
	 	try {
	 		sqlstr.append(" SELECT  COUNT(*) AS CNT                                                                   	\n");
	 		sqlstr.append(" FROM    SIGN001T                                                                     	\n");
	 		sqlstr.append("	WHERE SIGN_CLASS_CD = '"+signClassCd+"'												\n");
	 		if(!key_col1.isEmpty())
	 			sqlstr.append("	AND KEY_COL1 = '"+key_col1+"'	 														\n");
	 		if(!key_col2.isEmpty())
	 			sqlstr.append("	AND KEY_COL2 = '"+key_col2+"'	 														\n");
	 		sqlstr.append("	AND ATTR_6  = '0'  																				\n");
	 		search.setStatement(sqlstr);
	 		rowSet = search.execute();
	 		if(rowSet != null && rowSet.size() > 0 ) {
	 			rtnStr = rowSet.getRow(0).get("CNT");
	 		}
	 	}
	 	catch (Exception e) {
	         super.doException(e);
	         this.storage.setSuccess(false);
	         this.storage.setMessage(e.getMessage());
	         storage.setDetailMessage(e);
	 	}
	 	return rtnStr;
	 }
}