package com.steering.pss.sale.price.server;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;

import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.sale.price.entity.SlmPriceBasepriceEntity;
import com.steering.pss.sale.price.entity.SlmPriceDocEntity;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.pss.sale.price.entity.SlmPriceBasepriceLineEntity;


public class CorePriceFramePrice extends DBCommon{

	 public CoreReturnObject FactorBind(String TableName, String DataValue, String DataDesc,String sql_getSQL) {
	       String sql_getFactorBind="";
		 if (sql_getSQL!="") {
			 sql_getFactorBind = "select " + DataValue + "," + DataDesc + "  from   " + TableName + " order by " + DataDesc ;
		}
		 
		        
	        return this.getData(sql_getFactorBind);
	    }	
	 
	 public CoreReturnObject GetFactorInfo(String FactorName) {
		 Object[] obj = new Object[] { FactorName };
	        return this.getDataBySqlID("CorePriceBasePrice.GetFactorInfo", obj);
	    }
	 public CoreReturnObject GetRangeInfo(String frame_id) {
		 Object[] obj = new Object[] { frame_id };
	        return this.getDataBySqlID("CorePriceBasePrice.GetRangeInfo", obj);
	    }
	 
	 
	 public CoreReturnObject save(ArrayList<String> listJSON,ArrayList<String> listJSON_P){
			ArrayList<String> sqllist = new ArrayList<String>();
			
			for(String strJSON : listJSON){
				SlmPriceBasepriceEntity PBFS = EntityTool.getEntityByJSONStr(strJSON, SlmPriceBasepriceEntity.class);
				if (PBFS.getValidflag().equals("")) {
					String sql_insert = CoreXmlSqlParsersFactory.getSql("CorePriceBasePrice.insert");
					sql_insert = EntityTool.fillSqlByEntity(sql_insert, PBFS);
					sqllist.add(sql_insert);
				}
				else {
					String sql_update = CoreXmlSqlParsersFactory.getSql("CorePriceBasePrice.update");
					sql_update = EntityTool.fillSqlByEntity(sql_update, PBFS);
					sqllist.add(sql_update);
				}				
			}
			for(String strJSON : listJSON_P){
				SlmPriceBasepriceLineEntity PBFS_P = EntityTool.getEntityByJSONStr(strJSON, SlmPriceBasepriceLineEntity.class);
				if (PBFS_P.getValidflag().equals("")) {
					String sql_insert = CoreXmlSqlParsersFactory.getSql("CorePriceFramePriceLine.insert");
					sql_insert = EntityTool.fillSqlByEntity(sql_insert, PBFS_P);
					sqllist.add(sql_insert);
				}
				else {
					String sql_update = CoreXmlSqlParsersFactory.getSql("CorePriceFramePriceLine.update");
					sql_update = EntityTool.fillSqlByEntity(sql_update, PBFS_P);
					sqllist.add(sql_update);
				}				
			}
			return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
	}
	 
	 /**
	     * @param valid
	     * @return
	     */
	    public CoreReturnObject query( ) {
	          //  return this.getDataBySqlID("CorePriceBasePrice.query");
	    	//String sqllist = CoreXmlSqlParsersFactory.getSql("CorePriceBasePrice.query");
	    	ArrayList<String> sqllist = new ArrayList<String>();
	    	String sql_query = CoreXmlSqlParsersFactory.getSql("CorePriceBasePrice.query");
	    
	    	
	    	 return this.getData( sql_query);
	    }
	 
	    /**
	     * 查询数据是否能够恢复
	     * @param CLASS_D_ID
	   
	     * @return
	     * @throws SQLException 
	     */
	    public CoreReturnObject canResume(ArrayList<String> listJSON) throws SQLException {

			String strJSON = listJSON.get(0);
			SlmPriceBasepriceEntity PBFS = EntityTool.getEntityByJSONStr(
					strJSON, SlmPriceBasepriceEntity.class);

			String sql_canResume = CoreXmlSqlParsersFactory
					.getSql("CorePriceBasePrice.canResume");
			sql_canResume = EntityTool.fillSqlByEntity(sql_canResume, PBFS);
				
			return this.getData(sql_canResume);
	    }
	    public CoreReturnObject deleteOrResume(ArrayList<String> listJSON,ArrayList<String> listJSON_P,Boolean flag){
			ArrayList<String> sqllist = new ArrayList<String>();
			
			for(String strJSON : listJSON){
				SlmPriceBasepriceEntity PBFS = EntityTool.getEntityByJSONStr(strJSON, SlmPriceBasepriceEntity.class);
				if (flag) {
					String sql_delete = CoreXmlSqlParsersFactory.getSql("CorePriceBasePrice.Delete");
					sql_delete = EntityTool.fillSqlByEntity(sql_delete, PBFS);
					sqllist.add(sql_delete);
				}
				else {
					String sql_resume = CoreXmlSqlParsersFactory.getSql("CorePriceBasePrice.Resume");
					sql_resume = EntityTool.fillSqlByEntity(sql_resume, PBFS);
					sqllist.add(sql_resume);
				}				
			}
			
			for(String strJSON : listJSON_P){
				SlmPriceBasepriceLineEntity PBFS_P = EntityTool.getEntityByJSONStr(strJSON, SlmPriceBasepriceLineEntity.class);
				if (flag) {
					String sql_delete = CoreXmlSqlParsersFactory.getSql("CorePriceFramePriceLine.Delete");
					sql_delete = EntityTool.fillSqlByEntity(sql_delete, PBFS_P);
					sqllist.add(sql_delete);
				}
				else {
					String sql_resume = CoreXmlSqlParsersFactory.getSql("CorePriceFramePriceLine.Resume");
					sql_resume = EntityTool.fillSqlByEntity(sql_resume, PBFS_P);
					sqllist.add(sql_resume);
				}				
			}
			
			
			return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
	} 
	 
}
