Search in sources :

Example 31 with MagicCardStock

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

the class StockPanelGUI method addCard.

public void addCard(MagicCard mc) {
    MagicCardStock ms = new MagicCardStock();
    ms.setIdstock(-1);
    ms.setUpdate(true);
    ms.setMagicCard(mc);
    model.add(ms);
}
Also used : MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 32 with MagicCardStock

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

the class CardStockTableModel method removeRows.

public void removeRows(List<MagicCardStock> stocks) throws SQLException {
    list.removeAll(stocks);
    for (Iterator<MagicCardStock> iter = stocks.listIterator(); iter.hasNext(); ) {
        MagicCardStock a = iter.next();
        if (a.getIdstock() == -1) {
            iter.remove();
        }
    }
    if (!stocks.isEmpty())
        MTGControler.getInstance().getEnabledDAO().deleteStock(stocks);
    fireTableDataChanged();
}
Also used : MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 33 with MagicCardStock

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

the class PostgresqlDAO method deleteStock.

@Override
public void deleteStock(List<MagicCardStock> state) throws SQLException {
    logger.debug("remove " + state.size() + " items in stock");
    StringBuilder st = new StringBuilder();
    st.append("delete from stocks where idstock IN (");
    for (MagicCardStock sto : state) {
        st.append(sto.getIdstock()).append(",");
    }
    st.append(")");
    String sql = st.toString().replace(",)", ")");
    try (Statement pst = con.createStatement()) {
        pst.executeUpdate(sql);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 34 with MagicCardStock

use of org.magic.api.beans.MagicCardStock 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 35 with MagicCardStock

use of org.magic.api.beans.MagicCardStock 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

MagicCardStock (org.magic.api.beans.MagicCardStock)38 ArrayList (java.util.ArrayList)17 MagicDeck (org.magic.api.beans.MagicDeck)14 PreparedStatement (java.sql.PreparedStatement)9 MagicCard (org.magic.api.beans.MagicCard)9 ResultSet (java.sql.ResultSet)6 MagicCollection (org.magic.api.beans.MagicCollection)6 File (java.io.File)5 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 Statement (java.sql.Statement)3 Gson (com.google.gson.Gson)2 FileReader (java.io.FileReader)2 Article (org.api.mkm.modele.Article)2 Document (org.bson.Document)2 Bson (org.bson.conversions.Bson)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonReader (com.google.gson.stream.JsonReader)1