Package bpntojava.model.bpndata

Source Code of bpntojava.model.bpndata.BPN

package bpntojava.model.bpndata;

import bpntojava.controller.ErrorHandling;
import jp.ne.so_net.ga2.no_ji.jcom.IDispatch;
import jp.ne.so_net.ga2.no_ji.jcom.JComException;
import jp.ne.so_net.ga2.no_ji.jcom.ReleaseManager;

/**
* BPN-Tools.
*
* @author mschuessler
*/
public class BPN {

    /**
     * Release-Manager für die Com-Schnittstelle.
     */
    private ReleaseManager rm;
    /**
     * BPN-Application.
     */
    private IDispatch app;
    /**
     * ob die erstellt wurde.
     */
    private boolean appusable;

    /**
     * Konstruktor.
     */
    public BPN() {
        rm = new ReleaseManager();
        try {
            try {
                try {
                    app = new IDispatch(rm, "BpNT.Application");
                    appusable = true;
                } catch (JComException ex) {
                    ErrorHandling.showError("BPN nicht erreichbar.");
                    appusable = false;
                }
            } catch (UnsatisfiedLinkError ex) {
                ErrorHandling.showError("BPN nicht erreichbar.");
                appusable = false;
            }
        } catch (NoClassDefFoundError e) {
            ErrorHandling.showError("BPN nicht erreichbar.");
            appusable = false;
        }

    }

    /**
     * BPN schließen. Geht noch nicht.
     */
    public void closeApp() {
        try {
            app.method("LogOff", null);
        } catch (JComException ex) {
            ErrorHandling.showError("BPN kann nicht geschlossen werden.");
        }
    }

    /**
     * BPN login.
     *
     * @param firma Firma
     * @param user User
     * @param password Password
     * @param mandant Mandant
     */
    public void login(String firma, String user, String password, String mandant) {
        Object[] param = new Object[]{firma, "", user, password};
        try {
            app.method("Init", param);
            app.method("SelectMand", new Object[]{mandant});
        } catch (JComException ex) {
            ErrorHandling.showError("Login nicht möglich.");
        }
    }

    /**
     * Gibt ein bestimmtes DataSet zurück.
     *
     * @param name Name des DataSets
     * @return DataSet
     */
    public IDispatch getDataSet(String name) {
        IDispatch toReturn = null;
        try {
            IDispatch dataSetInfos = (IDispatch) app.get("DataSetInfos", new Object[]{name});
            toReturn = (IDispatch) dataSetInfos.method("CreateDataSet", null);
        } catch (JComException ex) {
            ErrorHandling.showError("DataSet " + name + " nicht vorhanden.");
        }
        return toReturn;
    }

    /**
     * Setzt ein DataSet auf First Field.
     *
     * @param dataset DataSet
     */
    public void first(IDispatch dataset) {
        try {
            dataset.method("First", null);
        } catch (JComException ex) {
            ErrorHandling.showError("Aktion First nicht möglich.");
        }
    }

    /**
     * Nächstes Field des DataSets.
     *
     * @param dataset DataSet
     */
    public void next(IDispatch dataset) {
        try {
            dataset.method("Next", null);
        } catch (JComException ex) {
            ErrorHandling.showError("Aktion Next nicht möglich.");
        }
    }

    /**
     * Gibt Fields eines DataSets zurück
     *
     * @param dataset DataSet
     * @return Field
     */
    public IDispatch getFields(IDispatch dataset) {
        IDispatch toReturn = null;
        try {
            toReturn = (IDispatch) dataset.get("Fields");
        } catch (JComException ex) {
            ErrorHandling.showError("Fields nicht erreichbar.");
        }
        return toReturn;
    }

    /**
     * Gibt ein bestimmtes Item eines Fields zurück.
     *
     * @param fields Field
     * @param art Itemname
     * @return Item
     */
    public IDispatch getItem(IDispatch fields, String art) {
        IDispatch toReturn = null;
        try {
            toReturn = (IDispatch) fields.get("Item", new Object[]{art});
        } catch (JComException ex) {
            ErrorHandling.showError("Item nicht erreichbar.");
        }
        return toReturn;
    }

    /**
     * Gibt den Item Text eines bestimmten Items zurück.
     *
     * @param fields Field
     * @param art Itemname
     * @return Itemtext
     */
    public String getItemInfo(IDispatch fields, String art) {
        String toReturn = null;
        try {
            IDispatch zwischen = (IDispatch) fields.get("Item", new Object[]{art});
            toReturn = (String) zwischen.get("Text", null);
        } catch (JComException ex) {
            ErrorHandling.showError("ItemInfo nicht erreichbar.");
        }
        return toReturn;
    }

    /**
     * Gibt ein Item als String zurück
     *
     * @param item Item
     * @return Itemstring
     */
    public String itemAsString(IDispatch item) {
        String toReturn = "";
        try {
            toReturn = item.get("AsString", null).toString();
        } catch (JComException ex) {
            ErrorHandling.showError("ItemAsString nicht möglich.");
        }
        return toReturn;
    }

    /**
     * Setzt die Indices eines DataSets.
     *
     * @param dataset DataSet
     * @param name Indice-Name
     */
    public void sort(IDispatch dataset, String name) {
        try {
            IDispatch tosort = (IDispatch) dataset.get("Indices", new Object[]{name});
            tosort.method("Select", null);
        } catch (JComException ex) {
            ErrorHandling.showError("Indices " + name + " nicht vorhanden.");
        }
    }

    /**
     * Setzt den Range eines DataSet.
     *
     * @param dataset DataSet
     * @param art RangeFeld
     * @param startvalue Anfang
     * @param endvalue Ende
     */
    public void setRange(IDispatch dataset, String art, String startvalue, String endvalue) {
        try {
            dataset.method("editrangestart", null);
            IDispatch fields = (IDispatch) dataset.get("Fields", new Object[]{art});
            fields.put("AsString", startvalue);
            dataset.method("editrangeend", null);
            fields = (IDispatch) dataset.get("Fields", new Object[]{art});
            fields.put("AsString", endvalue);
            dataset.method("applyrange", null);
        } catch (JComException ex) {
            ErrorHandling.showError("SetRange nicht möglich.");
        }
    }

    /**
     * Ob die App erstellt wurde.
     *
     * @return true/false
     */
    public boolean getAppUsable() {
        return appusable;
    }
}
TOP

Related Classes of bpntojava.model.bpndata.BPN

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.