package com.steering.mes.mcp.heatTreatment;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

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

import com.steering.comm.db.DBCommon;
import com.steering.mes.mcp.entity.FrmMchPersonentity;

public class HttOfficeDirect extends DBCommon{
    public CoreReturnObject doQuery(String start,String end,String heatid,String judgeNo) {

        String sql = "";
        sql = CoreXmlSqlParsersFactory
                .getSql("HttOfficeDirect.doQuery");

        if (!start.equals("")) {
            sql += " AND d.CREATE_TIME >=TO_DATE('"
                    + start
                    + "', 'YYYY-MM-DD HH24:MI:SS')AND d.CREATE_TIME <=TO_DATE('"
                    + end + "', 'YYYY-MM-DD HH24:MI:SS') ";
        }
        if (!heatid.equals("")) {
            sql += " AND T.HEAT_PLAN_NO = '" + heatid + "'";
        }
        if(!judgeNo.equals(""))
        {
        	sql +=" AND T.JUDGE_STOVE_NO = '" + judgeNo + "'";
        }
        sql += " ORDER BY T.PLINE_NAME";
        return this.getData(sql);
    }
    
/**
 * 查询离线去向
 */
    public CoreReturnObject queryOfficeD(String heatno,String plinCode) {

        String sql = "";
        sql = CoreXmlSqlParsersFactory
                .getSql("HttOfficeDirect.queryOfficeD");

        if (!heatno.equals("")) {
            sql += " AND T.HEAT_PLAN_NO ='" + heatno + "'";
        }  
        if (!plinCode.equals("")) {
            sql += " AND T.PLINE_CODE ='" + plinCode + "'";
        }  
        sql += " ORDER BY T.STATION_DESC";
        return this.getData(sql);
    }
    /**
     * 新增
     * @param load
     * @return
     */
    public CoreReturnObject addOfficeD(String heatno, String lotno, String pline,String process,String officed) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        Date now = new Date();
        SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
        SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat matter2 = new SimpleDateFormat("yyyyMMddHHmm");
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DATE));
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String systime = dateFormat.format(now);
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlAdd = CoreXmlSqlParsersFactory
                    .getSql("FrmReason.addOfficeD");// 新增废品原因
            PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
            // 新增废品原因
            patAdd.setObject(1, heatno);
            patAdd.setObject(2, lotno);
            patAdd.setObject(3, pline);
            patAdd.setObject(4, process);
            patAdd.setObject(5, officed);
            patAdd.addBatch();
            patAdd.executeBatch();
            core.setV_errMsg("新增成功！");
            core.setResult(1);
            connection.commit();
        }
        catch (Exception e) {
            core.setV_errMsg(e.getMessage());
            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return core;
    }
  
    /**
     * 删除
     * @param load
     * @return
     */
    public CoreReturnObject deletePerson(String officeD) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        Date now = new Date();
        SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
        SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat matter2 = new SimpleDateFormat("yyyyMMddHHmm");
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DATE));
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String systime = dateFormat.format(now);
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlAdd = CoreXmlSqlParsersFactory
                    .getSql("FrmReason.delete");// 修改
            PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
            // 删除废品原因
            patAdd.setObject(1, officeD);
            patAdd.addBatch();
            patAdd.executeBatch();
            core.setV_errMsg("删除成功！");
            core.setResult(1);
            connection.commit();
        }
        catch (Exception e) {
            core.setV_errMsg(e.getMessage());
            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return core;
    }
	

}
