Search in sources :

Example 1 with MagicCardStock

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

the class StockPanelGUI method importFromWebSite.

private void importFromWebSite(MagicDeck deck) {
    for (MagicCard mc : deck.getMap().keySet()) {
        MagicCardStock stock = new MagicCardStock();
        stock.setMagicCard(mc);
        stock.setQte(deck.getMap().get(mc));
        stock.setComment(MTGControler.getInstance().getLangService().getCapitalize("IMPORT_FROM", deck.getName()));
        stock.setIdstock(-1);
        stock.setUpdate(true);
        model.add(stock);
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 2 with MagicCardStock

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

the class StockPanelGUI method importFromCollection.

private void importFromCollection(MagicCollection col) throws SQLException {
    for (MagicCard mc : MTGControler.getInstance().getEnabledDAO().listCardsFromCollection(col)) {
        MagicCardStock stock = new MagicCardStock();
        stock.setMagicCard(mc);
        stock.setMagicCollection(col);
        stock.setQte(1);
        stock.setComment(MTGControler.getInstance().getLangService().getCapitalize("IMPORT_FROM", col.getName()));
        stock.setIdstock(-1);
        stock.setUpdate(true);
        model.add(stock);
    }
    model.fireTableDataChanged();
}
Also used : MagicCard(org.magic.api.beans.MagicCard) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 3 with MagicCardStock

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

the class CardStockPanel method initMagicCardStock.

public void initMagicCardStock(MagicCard mc, MagicCollection col) {
    selectedCard = mc;
    selectedCol = col;
    content.removeAll();
    content.setLayout(layout);
    try {
        for (MagicCardStock stat : MTGControler.getInstance().getEnabledDAO().listStocks(mc, col)) {
            CardStockLinePanel pane = new CardStockLinePanel(mc, col);
            pane.setMagicCardState(stat);
            content.add(pane);
        }
        content.revalidate();
        content.repaint();
    } catch (Exception e) {
        MTGLogger.printStackTrace(e);
    }
}
Also used : CardStockLinePanel(org.magic.gui.components.editor.CardStockLinePanel) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 4 with MagicCardStock

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

the class HsqlDAO method listStocks.

@Override
public List<MagicCardStock> listStocks(MagicCard mc, MagicCollection col) throws SQLException {
    logger.debug("load stock for " + mc + " in " + col);
    try (PreparedStatement pst = con.prepareStatement("select * from stocks where idmc=? and collection=?")) {
        pst.setString(1, IDGenerator.generate(mc));
        pst.setString(2, col.getName());
        try (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(mc);
                state.setMagicCollection(col);
                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);
            }
            logger.debug("load " + colls.size() + " item from stock for " + mc);
            return colls;
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 5 with MagicCardStock

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

the class MongoDbDAO method deleteStock.

@Override
public void deleteStock(List<MagicCardStock> state) throws SQLException {
    logger.debug("remove " + state.size() + " items in stock");
    for (MagicCardStock s : state) {
        Bson filter = new Document("stockItem.idstock", s.getIdstock());
        db.getCollection(colStocks).deleteOne(filter);
    }
}
Also used : Document(org.bson.Document) MagicCardStock(org.magic.api.beans.MagicCardStock) Bson(org.bson.conversions.Bson)

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