package com.steering.pss.qcm;

import java.util.ArrayList;

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

import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.SqlBuilder;
import com.steering.pss.qcm.model.ComBaseSplineStdEntity;

public class ComBaseSplineStdSize extends DBCommon{
	
	public CoreReturnObject querySplineSize(String id){
		SqlBuilder b = new SqlBuilder("ComBaseSplineStdSize.Query");
		b.Fill(new String[]{ id });
		return this.getData(b.toString());
	}
	
	public CoreReturnObject querySplineStd(){
		SqlBuilder b = new SqlBuilder("ComBaseSplineStd.query");
		
		return this.getData(b.toString());
	}
	
	public CoreReturnObject querySplineSpec(String id){
		SqlBuilder b = new SqlBuilder("ComBaseSplineStdSpec.Query");
		b.Fill(new String[]{ id });
		return this.getData(b.toString());
	}
	
	public CoreReturnObject save(String[] stdParm, ArrayList<String[]> sizeParms,
			ArrayList<String[]> specParms){
		ArrayList<String> sqlList = new ArrayList<String>();
		SqlBuilder b;
		if(stdParm[0] != null){
			if(stdParm[2].equals("")){
				b = new SqlBuilder("ComBaseSplineStd.getMaxId");
				ComBaseSplineStdEntity splineStd = EntityTool.getEntityBySql(
						b.toString(), this.getDao(CoreConstantData.sysbeanstr).getConnection(),
						ComBaseSplineStdEntity.class);
				b = new SqlBuilder("ComBaseSplineStd.insert");
				stdParm[2] = splineStd.getId();
			}else{
				b = new SqlBuilder("ComBaseSplineStd.update");
			}
			b.Fill(stdParm);
			sqlList.add(b.toString());
		}
		
		for(String[] parm : sizeParms){
			if(parm[7].equals("")){
				b = new SqlBuilder("ComBaseSplineStdSize.insert");
				b.Fill(parm);
			}else{
				b = new SqlBuilder("ComBaseSplineStdSize.update");
				b.Fill(parm);
			}
			sqlList.add(b.toString());
		}
		
		for(String[] parm : specParms){
			if(parm[10].equals("")){
				b = new SqlBuilder("ComBaseSplineStdSpec.insert");
				b.Fill(parm);
			}else{
				b = new SqlBuilder("ComBaseSplineStdSpec.update");
				b.Fill(parm);
			}
			sqlList.add(b.toString());
		}
		
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqlList);
	}
	
	public CoreReturnObject delete(String stdId, ArrayList<String[]> sizeParms,
			ArrayList<String[]> specParms){
		ArrayList<String> sqlList = new ArrayList<String>();
		SqlBuilder b;
		if(!stdId.equals("")){
			b = new SqlBuilder("ComBaseSplineStd.delete");
			b.Fill(new String[]{stdId});
			sqlList.add(b.toString());
			b = new SqlBuilder("ComBaseSplineStdSize.deleteById");
			b.Fill(new String[]{stdId});
			sqlList.add(b.toString());
			b = new SqlBuilder("ComBaseSplineStdSpec.deleteById");
			b.Fill(new String[]{stdId});
			sqlList.add(b.toString());
		}
		for(String[] parm : sizeParms){
			b = new SqlBuilder("ComBaseSplineStdSize.delete");
			b.Fill(new String[]{parm[0], parm[1]});
			sqlList.add(b.toString());
		}
		for(String[] parm : specParms){
			b = new SqlBuilder("ComBaseSplineStdSpec.delete");
			b.Fill(new String[]{parm[0], parm[1]});
			sqlList.add(b.toString());
		}
		
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqlList);
	}
}
