package com.steering.pss.plnsaleord.zgcheck;


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


import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.StringTool;

public class ZgGxCheck extends DBCommon {
	public CoreReturnObject getDataFromView(String PLINE,String CREATETIMEFROM,String CREATETIMETO,String ORDERNO) {
		CoreReturnObject returnObject = null;
		boolean isfirstparam = true;
		String sqlString = CoreXmlSqlParsersFactory.getSql("ZgGxCheck.queryV_ZG_PCORDERS_CX");
		if(!StringTool.isNullOrEmpty(PLINE))
		{
			sqlString  += String.format(" where CX = '%s' ", PLINE);
			isfirstparam = false;
		}
		if(!StringTool.isNullOrEmpty(ORDERNO))
		{
			sqlString += isfirstparam ? String.format(" where ORDERNO LIKE '%%%s%%' ", ORDERNO) : String.format(" and ORDERNO like '%%%s%%' ", ORDERNO);
			isfirstparam = false;
		}
		if(!StringTool.isNullOrEmpty(CREATETIMEFROM) )
		{
			sqlString += isfirstparam ? String.format(" where OPDATE >= '%s' ", CREATETIMEFROM) : String.format(" and OPDATE >= '%s' ", CREATETIMEFROM);
			isfirstparam=false;
		}
		if(!StringTool.isNullOrEmpty(CREATETIMETO))
		{
			sqlString += isfirstparam ? String.format(" where OPDATE <= '%s' ", CREATETIMETO) : String.format(" and OPDATE <= '%s' ", CREATETIMETO);
			isfirstparam=false;
		}
		returnObject = this.getDao("MSSQL2Dao").ExcuteSortResultByQuery(sqlString);
		return returnObject;
	}
	
	public CoreReturnObject queryZgOrderbyOrderNo(String OrderNo,String OrderSeq) {
		CoreReturnObject returnObject = null;
		String sqlString = CoreXmlSqlParsersFactory.getSql("ZgGxCheck.queryZGOrderS");
		boolean isfirstparam=true;
		if(!StringTool.isNullOrEmpty(OrderNo))
		{
			sqlString  += String.format("  where ORDER_NO = '%s' ", OrderNo);
			isfirstparam=false;
		}
		if(!StringTool.isNullOrEmpty(OrderSeq))
		{
			sqlString += isfirstparam ? String.format(" where ORDER_SEQ = '%s' ", OrderSeq) : String.format(" and ORDER_SEQ = '%s' ", OrderSeq);
			isfirstparam=false;
		}
		returnObject = this.getData(sqlString);
		return returnObject;
	}
	
	public CoreReturnObject queryOrdersCount(String OrderNo,String OrderSeq) {
		CoreReturnObject returnObject = null;
		returnObject = this.getDataBySqlID("ZgGxCheck.queryOrdersCount", new Object[]{OrderNo,OrderSeq});
		return returnObject;
	}
}
