package com.webclient.beans.udworkorder;

import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.util.MXApplicationException;
import psdi.util.MXException;
import psdi.webclient.system.beans.DataBean;
import psdi.webclient.system.controller.WebClientEvent;

import java.rmi.RemoteException;

/**
 * 日常维修工单-任务子表DataBean
 * edit 20230504
 */
public class UdwotaskDataBean extends DataBean {

    @Override
    public int addrow() throws MXException {
        int add=super.addrow();
        try {
            MboRemote mbo=this.getMbo();
            mbo.setValue("TASKID", mbo.getThisMboSet().count()+"",2L);//序号
        } catch (Exception e) {
            e.printStackTrace();
        }
        app.getAppBean().refreshTable();
        return add;
    }

    @Override
    public int toggledeleterow() throws MXException {
        try {
            MboRemote mbo=getMbo();
            int taskid=mbo.getInt("TASKID");
            MboSetRemote plmawtSet=mbo.getMboSet("$UDPLMAWT","UDPLMAWT","TASKID="+taskid+"");
            if(null!=plmawtSet || !plmawtSet.isEmpty()){
                WebClientEvent webclientevent = this.clientSession.getCurrentEvent();
                this.clientSession.showMessageBox(webclientevent, new MXApplicationException("cannotdelete", "cannotdelete2", new String[0]));
                return 1;
            }
        } catch (RemoteException e) {
            e.printStackTrace();
        }

        return super.toggledeleterow();
    }
}
