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);
}
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();
}
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);
}
}
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;
}
}
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;
}
}
Aggregations