package psdi.webclient.beans.pr;

import psdi.mbo.MboSetRemote;
import psdi.util.MXException;
import psdi.webclient.beans.pr.*;
import com.coolservlets.beans.jdbc.MXConnection;
import com.dbms.dbcon.DBCon;
import com.dbms.dbcon.QueryResult;
import com.dbms.dbcon.ResultRow;
import psdi.mbo.MboSetRemote;
import psdi.security.ConnectionKey;
import psdi.server.MXServer;
import psdi.util.MXException;
import psdi.util.MXSession;
import psdi.webclient.system.beans.DataBean;

import java.rmi.RemoteException;
import java.sql.Connection;

public class CustPRAppBean extends PRAppBean {
    String[] FldMain = {"location", "assetnum", "failure", "problemcode", "STOREROOMMTLSTATUS", "istask", "AVAILSTATUSDATE", "apptrequired"};

    public void initializeApp() throws MXException, RemoteException {
        super.initializeApp();
    }

    public void initialize() throws MXException, RemoteException {
        super.initialize();
    }

    public synchronized boolean fetchRecordData() throws MXException, RemoteException {
        super.fetchRecordData();
        this.app.getAppBean().getMbo().setFlag(7L, false);//设置整个 mbo 所有字段不只读
        return true;
    }

    /**
     * 保存数据 2018-6-8 修改
     */
    public int SAVE() throws MXException, RemoteException {
        super.SAVE();
        return 1;
    }
    public int INSERT() throws MXException, RemoteException {
        super.INSERT();
        String sPersonid = getMbo().getUserInfo().getPersonId();
        sPersonid = (sPersonid == null) ? "" : sPersonid.trim();
        sPersonid = sPersonid.toUpperCase();
        setValue("requestedby", getMbo().getUserInfo().getUserName(), 11L);
        setValue("urgency", "NOR", 11L);
        //setValue("lead", getMbo().getUserInfo().getUserName(), 11L);
        //setValue("worktype", "PM", 11L);
        getMbo().setFieldFlag("requestedby", 7L, true);
        //getMbo().setFieldFlag("WO18", 7L, true);
        //ConnectionKey connectionKey = getMbo().getUserInfo().getConnectionKey();
        String LaborDept[] = null;
        try {
            MboSetRemote nPersonSets = getMbo().getMboSet("$PERSON_TEMP", "PERSON");
            nPersonSets.setWhere("PERSONID ='" + sPersonid + "'");
            nPersonSets.reset();
            if (nPersonSets != null) {
                if (!nPersonSets.isEmpty()) {
                    String deptnum = nPersonSets.getMbo(0).getString("DEPARTMENT");
                    deptnum = (deptnum == null) ? "" : deptnum.trim();
                    String supervisor = nPersonSets.getMbo(0).getString("SUPERVISOR");
                    supervisor = (supervisor == null) ? "" : supervisor.trim();
                    setValue("deptnum", deptnum, 11L);
                    //setValue("HDONGROUP", deptnum, 11L);
                    setValue("supervisor", supervisor, 11L);
                    //getMbo().setFieldFlag("HDDEPT", 7L, true);
                    //getMbo().setFieldFlag("HDONGROUP", 7L, true);
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return 1;
    }
}