package com.steering.pss.pncost.base;

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

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

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

public class ComCalculation extends DBCommon{
    public CoreReturnObject queryAll(String year){
        String sql = CoreXmlSqlParsersFactory.getSql("ComCalculation.queryAll");
        if(!year.equals("")){
            sql += " AND T.YEAR_MONTH = '" + year + "'";
        }
        return this.getData(sql);
    }
    public CoreReturnObject queryA(String year,String dingdan){
        String sql = CoreXmlSqlParsersFactory.getSql("ComCalculation.queryA");
        if(!year.equals("")){
            sql += " AND T.YEAR_MONTH = '" + year + "'";
        }
        if(!dingdan.equals("")){
            sql += " AND T.PRO_PLAN_ID LIKE '%" + dingdan + "%'";
        }
        sql += "ORDER BY T.PRO_PLAN_ID";
        return this.getData(sql);
    }
    public CoreReturnObject queryD(String year,String dingdan){
        String sql = CoreXmlSqlParsersFactory.getSql("ComCalculation.queryD");
        if(!year.equals("")){
            sql += " AND T.YEAR_MONTH = '" + year + "'";
        }
        if(!dingdan.equals("")){
            sql += " AND T.PRO_PLAN_ID LIKE '%" + dingdan + "%'";
        }
        sql += "ORDER BY T.PRO_PLAN_ID";
        return this.getData(sql);
    }
    public CoreReturnObject queryE(String year,String dingdan){
        String sql = CoreXmlSqlParsersFactory.getSql("ComCalculation.queryE");
        if(!year.equals("")){
            sql += " AND T.YEAR_MONTH = '" + year + "'" ;
        }
        if(!dingdan.equals("")){
            sql += " AND T.PRO_PLAN_ID LIKE '%" + dingdan + "%'";
        }
        sql += "ORDER BY T.PRO_PLAN_ID";
        return this.getData(sql);
    }
    public CoreReturnObject queryF(String year,String dingdan){
        String sql = CoreXmlSqlParsersFactory.getSql("ComCalculation.queryF");
        if(!year.equals("")){
            sql += " AND T.YEAR_MONTH = '" + year + "'";
        }
        if(!dingdan.equals("")){
            sql += " AND T.PRO_PLAN_ID LIKE '%" + dingdan + "%'";
        }
        sql += "ORDER BY T.PRO_PLAN_ID";
        return this.getData(sql);
    }
    public CoreReturnObject queryG(String year,String dingdan){
        String sql = CoreXmlSqlParsersFactory.getSql("ComCalculation.queryG");
        if(!year.equals("")){
            sql += " AND T.YEAR_MONTH = '" + year + "'";
        }
        if(!dingdan.equals("")){
            sql += " AND T.PRO_PLAN_ID LIKE '%" + dingdan + "%'";
        }
        sql += "ORDER BY T.PRO_PLAN_ID";
        return this.getData(sql);
    }
    public CoreReturnObject queryERR(){
        String sql = CoreXmlSqlParsersFactory.getSql("ComCalculation.queryERR");
        return this.getData(sql);
    }
    public CoreReturnObject costMain(String year){
        CoreReturnObject cro = new CoreReturnObject();
        Connection con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
        CallableStatement cs;
        try {
            cs = con.prepareCall("{call P_COST_PLAN.Cost_Main(?,?,?)}");
            cs.setString(1, year);
            cs.registerOutParameter(2,java.sql.Types.INTEGER);
            cs.registerOutParameter(3,java.sql.Types.VARCHAR);
            cs.execute();
            String[] results = new String[2];
            results[0] = String.valueOf(cs.getInt(2));
            results[1] = String.valueOf(cs.getInt(3));
            cro.setResult(results);
        }
        catch (SQLException e) {
            e.printStackTrace();
            cro.SetErrInfo(e.getMessage());
        }
        return cro;
    }
    public CoreReturnObject querypliao(){
        String sql = CoreXmlSqlParsersFactory.getSql("ComCalculation.querypliao");
        return this.getData(sql);
    }
    public CoreReturnObject querycount(String year){
        SqlBuilder b = new SqlBuilder("ComCalculation.querycount");
        b.Fill(new String[]{year});
        return this.getData(b.toString());
    }
}