package com.webclient.beans.pmstdard;

import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.server.MXServer;
import psdi.util.MXApplicationYesNoCancelException;
import psdi.util.MXException;
import psdi.webclient.system.beans.DataBean;

import java.rmi.RemoteException;

/**
 * 点检保养标准子表DataBean
 * edit 20230825
 */
public class PmstdardLineDataBean extends DataBean {

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

    @Override
    public int toggledeleterow() throws MXException {
        try {
            int msgRet = MXApplicationYesNoCancelException.getUserInput("confirmcontinueid", MXServer.getMXServer(),this.clientSession.getUserInfo());
            if (msgRet < 0) {
                throw new MXApplicationYesNoCancelException("confirmcontinueid", "jspmessages", "deletassetdj");
            }
            if (msgRet == 8) {
                MboRemote mbo=this.getMbo();
                int pmstdardlinesid=mbo.getInt("PMSTDARDLINESID");
                int num=mbo.getInt("NUM");
                MboSetRemote pmAssetlineSet=mbo.getMboSet("$PMSTDARDLINES", "PMSTDARDLINES", "PARENTID="+pmstdardlinesid+" and NUM="+num+" ");
                if(null!=pmAssetlineSet && !pmAssetlineSet.isEmpty()){
                    pmAssetlineSet.deleteAll(2L);
                }else{

                }
            }
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return super.toggledeleterow();
    }
}
