// 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 psdi.app.mr.*;
import psdi.mbo.MboRemote;
import psdi.util.MXException;
import psdi.webclient.system.beans.AppBean;
import psdi.webclient.system.beans.DataBean;
import psdi.webclient.system.controller.*;

public class WoreqAppBean extends AppBean
{

    public WoreqAppBean()
    {
        reqFromTemplate = false;
    }

    public void initialize()
        throws MXException, RemoteException
    {
        if(!reqFromTemplate && app.getApp().equalsIgnoreCase("woreq") && (sessionContext.getCurrentEvent().getAdditionalEvent() == null || sessionContext.getCurrentEvent().getAdditionalEvent().length() == 0))
        {
            DataBean databean = app.getAppBean();
            super.initialize();
            reqFromTemplate = false;
            MboRemote mboremote = getMbo();
            if(mboremote == null || !mboremote.isNew())
                databean.insert();
            return;
        } else
        {
            return;
        }
    }
    /**
    public int newrecord()
        throws MXException, RemoteException
    {
        Utility.sendEvent(new WebClientEvent("dialogclose", app.getCurrentPageId(), null, sessionContext));
        initialize();
        Utility.sendEvent(new WebClientEvent("resetwizard", app.getCurrentPageId(), null, sessionContext));
        return 1;
    }

    public void editdr()
        throws MXException, RemoteException
    {
        long l = Utility.getDataSource(sessionContext, app.getAppHandler()).getMbo().getInt("mrid");
        editdraft(l);
    }

    public void editdrfromlist()
        throws MXException, RemoteException
    {
        long l = app.getDataBean("results_showlist").getMbo(getRowIndexFromEvent(sessionContext.getCurrentEvent())).getLong("mrid");
        editdraft(l);
    }

    public int editdraft(long l)
        throws MXException, RemoteException
    {
        sessionContext.queueEvent(new WebClientEvent("changeapp", app.getId(), "createdr", null, null, l, sessionContext));
        return 1;
    }

    public void createdrfromtmpl()
        throws MXException, RemoteException
    {
        MRRemote mrremote = (MRRemote)app.getAppBean().getMbo();
        createdrfromtemplate(mrremote);
    }

    public void createdrfromtmpllist()
        throws MXException, RemoteException
    {
        MRRemote mrremote = (MRRemote)app.getDataBean("results_showlist").getMbo(getRowIndexFromEvent(sessionContext.getCurrentEvent()));
        createdrfromtemplate(mrremote);
    }

    public int createdrfromtemplate(MRRemote mrremote)
        throws MXException, RemoteException
    {
        MRSetRemote mrsetremote = (MRSetRemote)getMboSet();
        MboRemote mboremote = mrremote.copy(mrsetremote);
        long l = mboremote.getInt("mrid");
        reqFromTemplate = true;
        noResultSet = false;
        save();
        sessionContext.queueEvent(new WebClientEvent("changeapp", app.getId(), "createdr", null, "fromtemplate", l, sessionContext));
        return 1;
    }
    */
    public int viewreqdetails()
        throws MXException, RemoteException
    {
        Utility.sendEvent(new WebClientEvent("dialogclose", app.getCurrentPageId(), null, sessionContext));
        DataBean databean = Utility.getDataSource(sessionContext, app.getAppHandler());
        long l = databean.getMbo().getInt("mrid");
        sessionContext.queueEvent(new WebClientEvent("changeapp", app.getId(), "viewworeq", null, null, l, sessionContext));
        return 1;
    }
    /**
    public int viewdraftdetails()
        throws MXException, RemoteException
    {
        Utility.sendEvent(new WebClientEvent("dialogclose", app.getCurrentPageId(), null, sessionContext));
        DataBean databean = Utility.getDataSource(sessionContext, app.getAppHandler());
        long l = databean.getMbo().getInt("mrid");
        sessionContext.queueEvent(new WebClientEvent("changeapp", app.getId(), "viewdrft", null, null, l, sessionContext));
        return 1;
    }

    public void submit()
        throws MXException, RemoteException
    {
        DataBean databean = app.getAppBean();
        MRRemote mrremote = (MRRemote)databean.getMbo();
        if(((MRSetRemote)getMboSet()).checkWFEnabled())
            mrremote.unApproveMR();
        else
            mrremote.approveMR();
        if(!reqFromTemplate)
            noResultSet = false;
        else
            noResultSet = true;
        save();
        reqFromTemplate = false;
        if(appName != null)
        {
            if(appName.equalsIgnoreCase("createdr"))
                RequestHandler.showDialog(sessionContext, "drsubmit");
            else
                Utility.showMessageBox(sessionContext.getCurrentEvent(), "mr", "reqSibmitted", null);
        } else
        {
            Utility.showMessageBox(sessionContext.getCurrentEvent(), "mr", "reqSibmitted", null);
        }
    }

    public void fakesave()
        throws MXException
    {
        noResultSet = false;
        save();
    }

    public void savedraft()
        throws MXException
    {
        if(!reqFromTemplate)
            noResultSet = false;
        else
            noResultSet = true;
        save();
        reqFromTemplate = false;
        if(appName != null)
        {
            if(appName.equalsIgnoreCase("createdr"))
                RequestHandler.showDialog(sessionContext, "drsavedraft");
            else
                Utility.showMessageBox(sessionContext.getCurrentEvent(), "mr", "savedAsDraft", null);
        } else
        {
            Utility.showMessageBox(sessionContext.getCurrentEvent(), "mr", "savedAsDraft", null);
        }
    }

    public int nexttabvalidate()
        throws MXException, RemoteException
    {
        DataBean databean = app.getDataBean("reqlines_table");
        if(databean != null)
        {
            MRLineSetRemote mrlinesetremote = (MRLineSetRemote)databean.getMboSet();
            int i = mrlinesetremote.count();
            for(int j = 0; j < i; j++)
            {
                MRLineRemote mrlineremote = (MRLineRemote)mrlinesetremote.getMbo(j);
                mrlineremote.appValidate();
            }

        }
        DataBean databean1 = app.getDataBean("reqlinesro_table");
        databean1.refreshTable();
        sessionContext.queueEvent(new WebClientEvent("changetab", "createreq_tabgroup", "createreq_tabgroup_st3", sessionContext));
        return 1;
    }
    */
   public int returnWoreq() throws MXException, RemoteException {
     DataBean databean = app.getDataBean("results_showlist");
     databean.setQbe("wonum", "");
     databean.saveCurrentQbeSettings(true);
     databean.restoreSavedQbeSettings();
     databean.reset();
     sessionContext.queueEvent(new WebClientEvent("gototab",sessionContext.getCurrentAppId(),"list", sessionContext));
     sessionContext.queueRefreshEvent();
     return 1;
   }
    protected boolean reqFromTemplate;
}
