// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)

package psdi.webclient.beans.woreq;

import java.rmi.RemoteException;
import java.util.*;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.security.UserInfo;
import psdi.util.MXException;
import psdi.util.MXSession;
import psdi.util.MXApplicationException;
import psdi.webclient.system.beans.AppBean;
import psdi.webclient.system.beans.DataBean;
import psdi.webclient.system.controller.*;
import psdi.security.*;
import psdi.server.*;
import com.coolservlets.beans.jdbc.*;
import com.coolservlets.beans.method.*;
import com.dbms.dbcon.*;
import java.sql.*;

public class WoReqsAppBean extends AppBean
{

    public WoReqsAppBean()
    {
    }

    protected void initialize() throws MXException, RemoteException
    {
        DataBean databean = app.getAppBean();
        super.initialize();
        databean.insert();
        //databean.setDefaultValue();
        String sPersonid = databean.getMbo().getUserInfo().getPersonId();
        sPersonid =(sPersonid == null) ?"":sPersonid.trim();
        sPersonid = sPersonid.toUpperCase();
        setValue("reportedby", getMbo().getUserInfo().getUserName(),11L);
        setValue("WO18", getMbo().getUserInfo().getUserName(),11L);
        setValue("lead", getMbo().getUserInfo().getUserName(),11L);
        setValue("worktype", "CM", 11L);
        getMbo().setFieldFlag("reportedby",7L,true);
        getMbo().setFieldFlag("WO18",7L,true);
        setValue("WOLO10", "0");
        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("HDDEPT", deptnum,11L);
                    setValue("HDONGROUP", deptnum,11L);
                    //setValue("supervisor", supervisor,11L);
                    getMbo().setFieldFlag("HDDEPT",7L,true);
                    getMbo().setFieldFlag("HDONGROUP",7L,true);
                }
            }
        } catch (Exception ex) {
          ex.printStackTrace();
        }
    }

    public int newrecord() throws MXException, RemoteException
    {
        Utility.sendEvent(new WebClientEvent("dialogclose", app.getCurrentPageId(), null, sessionContext));
        AppInstance appinstance = sessionContext.getCurrentApp();
        PageInstance pageinstance = appinstance.getCurrentPage();
        String s = null;
        if(boundInputs != null && !boundInputs.isEmpty())
        {
            Iterator iterator = boundInputs.keySet().iterator();
            do
            {
                if(!iterator.hasNext())
                    break;
                Object obj = iterator.next();
                BoundControl boundcontrol = (BoundControl)boundInputs.get(obj);
                Iterator iterator1 = boundcontrol.getBoundAttributes();
                do
                    if(!iterator1.hasNext())
                        continue;
                while(!((psdi.webclient.system.controller.BoundControl.BoundAttribute)iterator1.next()).getDataAttribute().equalsIgnoreCase("description"));
                s = obj.toString();
            } while(s == null);
        }
        pageinstance.put("currentfocus", s + "_textbox");
        sessionContext.queueEvent(new WebClientEvent("setfieldfocus", pageinstance.getPageId(), null, sessionContext));
        initialize();
        return 1;
    }
    public int returnworeqck() throws MXException, RemoteException
    {
        Utility.sendEvent(new WebClientEvent("dialogclose", app.getCurrentPageId(), null, sessionContext));
        DataBean databean = Utility.getDataSource(sessionContext, app.getAppHandler());
        //long l = databean.getMbo().getInt("wonum");
        //long l = databean.getMbo().getInt("WORKORDERID");
        long l = databean.getMbo().getUniqueIDValue();
        //System.out.println("l =" + l);
        sessionContext.queueEvent(new WebClientEvent("changeapp", app.getId(), "wodaily", null, null, l, sessionContext));
        return 1;
    }
    public int viewdetails()
        throws MXException, RemoteException
    {
        MXSession mxsession = sessionContext.getMXSession();
        UserInfo userinfo = mxsession.getUserInfo();
        String s = userinfo.getUserName();
        String s1 = getMbo().getString("reportedby");
        if(!s1.equals(s))
        {
            Utility.showMessageBox(sessionContext.getCurrentEvent(), "access", "notauthorized", null);
            return 1;
        } else
        {
            Utility.sendEvent(new WebClientEvent("dialogclose", app.getCurrentPageId(), null, sessionContext));
            DataBean databean = Utility.getDataSource(sessionContext, app.getAppHandler());
            long l = databean.getMbo().getInt("wonum");
            sessionContext.queueEvent(new WebClientEvent("changeapp", app.getId(), "viewworeq", null, null, l, sessionContext));
            //sessionContext.queueEvent(new WebClientEvent("changeapp", app.getId(), "viewsr", null, null, l, sessionContext));
            return 1;
        }
    }

    public synchronized void saverecord()
        throws MXException, RemoteException
    {
        if(mboSetRemote == null)
            return;
        MboRemote mboremote;
        app.getAppBean().getMboSet().setFlag(8L, false);
        mboremote = null;
        if(isNewRow())
        {
            try
            {
                //System.out.println("isNewRow ="+isNewRow());
                long l = getUniqueIdValue();
                String sWopm1 = mboSetRemote.getString("WOPM1");
                sWopm1 = (sWopm1 == null)?"":sWopm1.trim();
                //System.out.println("sWopm1="+sWopm1);
                if(sWopm1.length() > 0){
                   mboSetRemote.save();
                }else{
                  throw new MXApplicationException("woreq", "NotWriteWopm1Values");
                }
                mboremote = getMboForUniqueId(l);
                fireStructureChangedEvent();//2023年以后添加修改
                RequestHandler.showDialog(sessionContext, "woreqsubmit");//2023年以后添加修改
            }
            catch(NullPointerException nullpointerexception) { }
        } else
        {
            //System.out.println("else isNewRow ="+isNewRow());
            autoInitiateWorkflow();//2023年以后添加修改
            mboSetRemote.save();//2023年以后添加修改
            //System.out.println("wfinitiated ="+app.get("wfinitiated")+", wfinitiated =" + app.get("wfinitiated"));
            if(app.get("wfinitiated") != null && app.get("wfinitiated").equals("false"))
            {
                fireStructureChangedEvent();
                RequestHandler.showDialog(sessionContext, "woreqsubmit");
            }
            return;
        }
        try
        {
            if(mboremote == null)
            {
                currentRecordData = null;
                currentRow = -1;
            } else
            {
                currentRecordData = mboremote.getMboData(getAttributes());
                //autoInitiateWorkflow();
            }
            if(app.get("wfinitiated") != null && app.get("wfinitiated").equals("false"))
            {
                fireStructureChangedEvent();
                RequestHandler.showDialog(sessionContext, "woreqsubmit");
            }
        }
        catch(RemoteException remoteexception)
        {
            handleRemoteException(remoteexception);
        }
        return;
    }
}
