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.SlmPriceAddpriceHeadEntity;
import com.steering.pss.sale.price.entity.SlmPriceAddpriceLineEntity;
import com.steering.pss.sale.price.entity.SlmPriceBasepriceEntity;
import com.steering.pss.sale.price.entity.SlmPriceBasepriceLineEntity;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;

public class CorePriceAddPriceHead extends DBCommon {
	
    public CoreReturnObject query(String PriceAdd_ID, String PriceAdd_Desc, String valid) {
        String sql = CoreXmlSqlParsersFactory.getSql("CorePriceAddPriceHead.query");
        sql = sql.replaceAll("#PriceAdd_ID#", PriceAdd_ID);
        sql = sql.replaceAll("#PriceAdd_Desc#", PriceAdd_Desc);
        sql = sql.replaceAll("#VALIDFLAG#", valid);
        return this.getData(sql);
    }
    
    public CoreReturnObject queryById(String PRICEADD_ID, String valid) {
        String sql = CoreXmlSqlParsersFactory.getSql("CorePriceAddPriceHead.queryById");
        sql = sql.replaceAll("#PRICEADD_ID#", PRICEADD_ID);
       
        sql = sql.replaceAll("#VALIDFLAG#", valid);
        return this.getData(sql);
    }
    
    public CoreReturnObject save(ArrayList<String> listJSON,ArrayList<String> listJSON_P){
		ArrayList<String> sqllist = new ArrayList<String>();
		
		for(String strJSON : listJSON){
			SlmPriceAddpriceHeadEntity PBFS = EntityTool.getEntityByJSONStr(strJSON, SlmPriceAddpriceHeadEntity.class);
			if (PBFS.getValidflag().equals("")) {
				String sql_insert = CoreXmlSqlParsersFactory.getSql("CorePriceAddPriceHead.insert");
				sql_insert = EntityTool.fillSqlByEntity(sql_insert, PBFS);
				sqllist.add(sql_insert);
			}
			else {
				String sql_update = CoreXmlSqlParsersFactory.getSql("CorePriceAddPriceHead.update");
				sql_update = EntityTool.fillSqlByEntity(sql_update, PBFS);
				sqllist.add(sql_update);
			}				
		}
		for(String strJSON : listJSON_P){
			SlmPriceAddpriceLineEntity PBFS_P = EntityTool.getEntityByJSONStr(strJSON, SlmPriceAddpriceLineEntity.class);
			if (PBFS_P.getValidflag().equals("")) {
				String sql_insert = CoreXmlSqlParsersFactory.getSql("CorePriceAddPriceLine.insert");
				sql_insert = EntityTool.fillSqlByEntity(sql_insert, PBFS_P);
				sqllist.add(sql_insert);
			}
			else {
				String sql_update = CoreXmlSqlParsersFactory.getSql("CorePriceAddPriceLine.update");
				sql_update = EntityTool.fillSqlByEntity(sql_update, PBFS_P);
				sqllist.add(sql_update);
			}				
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
}
    
    public CoreReturnObject deleteOrResume(ArrayList<String> listJSON,ArrayList<String> listJSON_P,Boolean flag){
		ArrayList<String> sqllist = new ArrayList<String>();
		
		for(String strJSON : listJSON){
			SlmPriceAddpriceHeadEntity PBFS = EntityTool.getEntityByJSONStr(strJSON, SlmPriceAddpriceHeadEntity.class);
			if (flag) {
				String sql_delete = CoreXmlSqlParsersFactory.getSql("CorePriceAddPriceHead.Delete");
				sql_delete = EntityTool.fillSqlByEntity(sql_delete, PBFS);
				sqllist.add(sql_delete);
			}
			else {
				String sql_resume = CoreXmlSqlParsersFactory.getSql("CorePriceAddPriceHead.Resume");
				sql_resume = EntityTool.fillSqlByEntity(sql_resume, PBFS);
				sqllist.add(sql_resume);
			}				
		}
		
		for(String strJSON : listJSON_P){
			SlmPriceAddpriceLineEntity PBFS_P = EntityTool.getEntityByJSONStr(strJSON, SlmPriceAddpriceLineEntity.class);
			if (flag) {
				String sql_delete = CoreXmlSqlParsersFactory.getSql("CorePriceAddPriceLine.Delete");
				sql_delete = EntityTool.fillSqlByEntity(sql_delete, PBFS_P);
				sqllist.add(sql_delete);
			}
			else {
				String sql_resume = CoreXmlSqlParsersFactory.getSql("CorePriceAddPriceLine.Resume");
				sql_resume = EntityTool.fillSqlByEntity(sql_resume, PBFS_P);
				sqllist.add(sql_resume);
			}				
		}
		
		
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
} 


}
