Search in sources :

Example 31 with MagicCollection

use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.

the class PostgresqlDAO method listStocks.

@Override
public List<MagicCardStock> listStocks() throws SQLException {
    try (PreparedStatement pst = con.prepareStatement("select * from stocks");
        ResultSet rs = pst.executeQuery()) {
        List<MagicCardStock> colls = new ArrayList<>();
        while (rs.next()) {
            MagicCardStock state = new MagicCardStock();
            state.setComment(rs.getString("comments"));
            state.setIdstock(rs.getInt("idstock"));
            state.setMagicCard(readObject(MagicCard.class, rs.getBinaryStream(mcardField)));
            state.setMagicCollection(new MagicCollection(rs.getString("collection")));
            state.setCondition(EnumCondition.valueOf(rs.getString("conditions")));
            state.setFoil(rs.getBoolean("foil"));
            state.setSigned(rs.getBoolean("signedcard"));
            state.setLanguage(rs.getString("langage"));
            state.setQte(rs.getInt("qte"));
            state.setPrice(rs.getDouble("price"));
            colls.add(state);
        }
        return colls;
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) MagicCollection(org.magic.api.beans.MagicCollection) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 32 with MagicCollection

use of org.magic.api.beans.MagicCollection in project MtgDesktopCompanion by nicho92.

the class CSVExport method importStock.

@Override
public List<MagicCardStock> importStock(File f) throws IOException {
    try (BufferedReader read = new BufferedReader(new FileReader(f))) {
        List<MagicCardStock> stock = new ArrayList<>();
        String line = read.readLine();
        line = read.readLine();
        while (line != null) {
            String[] part = line.split(";");
            MagicCardStock mcs = new MagicCardStock();
            MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", part[1], null, true).get(0);
            for (MagicEdition ed : mc.getEditions()) if (ed.getSet().equals(part[2])) {
                mc.getEditions().add(0, ed);
                break;
            }
            mcs.setMagicCard(mc);
            mcs.setLanguage(part[3]);
            mcs.setQte(Integer.parseInt(part[4]));
            mcs.setCondition(EnumCondition.valueOf(part[5]));
            mcs.setFoil(Boolean.valueOf(part[6]));
            mcs.setAltered(Boolean.valueOf(part[7]));
            mcs.setSigned(Boolean.valueOf(part[8]));
            mcs.setMagicCollection(new MagicCollection(part[9]));
            mcs.setPrice(Double.valueOf(part[10]));
            try {
                mcs.setComment(part[11]);
            } catch (ArrayIndexOutOfBoundsException aioob) {
                mcs.setComment("");
            }
            mcs.setIdstock(-1);
            mcs.setUpdate(true);
            stock.add(mcs);
            line = read.readLine();
        }
        return stock;
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) MagicEdition(org.magic.api.beans.MagicEdition) FileReader(java.io.FileReader) MagicCollection(org.magic.api.beans.MagicCollection) MagicCardStock(org.magic.api.beans.MagicCardStock)

Aggregations

MagicCollection (org.magic.api.beans.MagicCollection)32 ArrayList (java.util.ArrayList)20 MagicCard (org.magic.api.beans.MagicCard)15 SQLException (java.sql.SQLException)14 MagicEdition (org.magic.api.beans.MagicEdition)13 PreparedStatement (java.sql.PreparedStatement)12 ResultSet (java.sql.ResultSet)12 IOException (java.io.IOException)9 MagicCardStock (org.magic.api.beans.MagicCardStock)8 File (java.io.File)7 List (java.util.List)6 BorderLayout (java.awt.BorderLayout)4 Map (java.util.Map)4 JButton (javax.swing.JButton)4 JLabel (javax.swing.JLabel)4 JPanel (javax.swing.JPanel)4 JScrollPane (javax.swing.JScrollPane)4 BasicDBObject (com.mongodb.BasicDBObject)3 DeleteResult (com.mongodb.client.result.DeleteResult)3 Point (java.awt.Point)3