public static int insertToCards(eFlash.Data.Card c) { if (c.cardID != -1) { throw new ArgumentException("Trying to create a new card that already exists"); } c.cardID = insertToCards(c.tag, c.uid); return(c.cardID); }
private CreatorCard(LayoutEditor newCreator, int newCardID, int newUID, string newTag, List<eObject> newObjects, int newIndex) { _cardID = newCardID; _uid = newUID; _tag = newTag; _objects = new List<CreatorObject>(); index = newIndex; creator = newCreator; originalCard = null; CreatorObject curNewObj; foreach (eObject curEObj in newObjects) { curNewObj = CreatorObject.newFromEObject(creator, curEObj, (objects.Count * 2) + 10); objects.Add(curNewObj); } }
/** * A function to retrieve all the cards belonging to a deck from the card and cdrelation table in local database * Pre: local deck id * Post: List of corresponding Cards */ public static List<Card> getCards(int did) { List<Card> cardList = new List<Card>(); string SQL; MySqlCommand cmd = new MySqlCommand(); MySqlDataReader myData; connect(); try { SQL = "SELECT Cards.cid,tag,uid FROM CDRelations,Cards WHERE CDRelations.did = " + Convert.ToString(did) + " AND CDRelations.cid = Cards.cid"; cmd.Connection = conn; cmd.CommandText = SQL; myData = cmd.ExecuteReader(); while (myData.Read()) { Card card = new Card(myData.GetInt32(myData.GetOrdinal("cid")), myData.GetString(myData.GetOrdinal("tag")), myData.GetInt32(myData.GetOrdinal("uid"))); cardList.Add(card); } myData.Close(); conn.Close(); return cardList; } catch (MySql.Data.MySqlClient.MySqlException ex) { MessageBox.Show("Error " + ex.Number + " has occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); conn.Close(); throw new Exception(); } }
public static void updateCards(eFlash.Data.Card card) { updateCards(card.cardID, card.tag, card.uid); }
public CreatorCard(LayoutEditor newCreator, Card card, int newIndex) : this(newCreator, card.cardID, card.uid, card.tag, card.eObjectList, newIndex) { originalCard = card; }
public static int parseBLOB(byte[] blob, int uid) { int size = 0; int curDid = -1; int curCid = -1; byte[] data = null; Deck deck = null; eObject curObj = null; Card curCard = null; MemoryStream stream = new MemoryStream(blob); XmlTextReader reader = new XmlTextReader(stream); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name == "Deck") { deck = new Deck(reader.GetAttribute("cat"), reader.GetAttribute("subcat"), reader.GetAttribute("title"), reader.GetAttribute("type"),Convert.ToInt32(reader.GetAttribute("nuid")), uid); try { //Insert to Decks table in local database curDid = deck.saveToDB(); } catch { throw new Exception("Error Writting Deck!!!"); } } else if (reader.Name == "Card") { curCard = new Card(reader.GetAttribute("tag"), uid); try { //Insert to Cards table in local database curCid = curCard.saveToDB(curDid); } catch { throw new Exception("Error Writting Card!!!"); } } else if (reader.Name == "Object") { //First create the array of bytes for the blob size = Convert.ToInt32(reader.GetAttribute("size")); data = new byte[size]; curObj = new eObject( curCid, Convert.ToInt32(reader.GetAttribute("side")), reader.GetAttribute("type"), Convert.ToInt32(reader.GetAttribute("x1")), Convert.ToInt32(reader.GetAttribute("x2")), Convert.ToInt32(reader.GetAttribute("y1")), Convert.ToInt32(reader.GetAttribute("y2")) ); try { string qType = reader.GetAttribute("quizType"); if (qType == Constant.nonePrefix || qType == Constant.answerPrefix || qType == Constant.questionPrefix) { curObj.quizType = qType; } } catch {} try { reader.ReadElementContentAsBase64(data, 0, size); curObj.efile = new eFile(data); //save to file and update DB curObj.save(); } catch { throw new Exception("Error Saving Object !!!"); } } break; } } return curDid; }
/// <summary> /// Creates a new Card for the current deck. Deck must already be set. /// </summary> /// <returns>A new card</returns> private Card newCard() { if (deck == null) { throw new Exception("Tried to create new card without specifying deck"); } Card newCard = new Card("", ProfileManager.getCurrentUserID()); return newCard; }
/// <summary> /// Makes a deep copy of deck, duplicating all its cards, /// objects, and files, and sets it to be the current deck. /// </summary> /// <param name="otherDeck">Deck to copy</param> /// <returns>Deck object of copy of deck</returns> private eFlash.Data.Deck deepCopy(eFlash.Data.Deck otherDeck) { otherDeck.load(); _deck = new eFlash.Data.Deck(-1, otherDeck.type, otherDeck.category, otherDeck.subcategory, otherDeck.title, ProfileManager.getCurrentUserID(), ProfileManager.getCurrentNetID()); // Put deck entry into DB saveDeck(); Card newCard; eObject newObj; CreatorObject newCreatorObj; foreach (Card curCard in otherDeck.cardList) { newCard = new Card(curCard.tag, ProfileManager.getCurrentUserID()); // Add each card to the DB newCard.cardID = dbAccess.insertLocalDB.insertToCards(newCard); dbAccess.insertLocalDB.insertToCDRelations(deck.id, newCard.cardID); foreach (eObject curObj in curCard.eObjectList) { newObj = new eObject(newCard.cardID, curObj.side, curObj.type, curObj.x1, curObj.x2, curObj.y1, curObj.y2, curObj.data); // Make a CreatorObject to let it load up the data file newCreatorObj = CreatorObject.newFromEObject(this, newObj, 0); newCreatorObj.initialize(); newObj.actualFilename = newObj.generateFileName(); // Save each object to DB and file saveObject(newCreatorObj); } } return deck; }
/// <summary> /// Applies a template into this flashcard /// </summary> /// <param name="template">Template to use</param> public void loadTemplate(Template template) { Card card = new Card("", ProfileManager.getCurrentUserID()); if (currentCard.cardID == -1) { card.cardID = NEW_TEMPLATE_CARD; } else { card.cardID = currentCard.cardID; } eObject curEObj; TemplateObject curObj; // Fill the sides with objects for (int i = 0; i < template.objects.Count; i++) { curObj = template.objects[i]; curEObj = new eObject(-1, curObj.side, curObj.type, curObj.x1, curObj.x2, curObj.y1, curObj.y2, curObj.quizType + "noFile.txt"); card.eObjectList.Add(curEObj); } if (deck.cardList.Count == 0) { deck.cardList.Add(card); setFlashcard(card, 0); } else if (currentCard.index == -1) { deck.cardList.Add(card); setFlashcard(card, deck.cardList.Count - 1); } else { //deck.cardList[currentCard.index] = card; setFlashcard(card, currentCard.index); } templateChanged = true; changed = false; promptAtTemplateChange = false; }
private void setFlashcard(Card newCard, int index) { stopAllSounds(); _currentCard = new CreatorCard(this, newCard, index); if (newCard.cardID == -1) { // If card is new, then fill its objects with the // objects currently on the canvas currentCard.loadObjects(tabSides); changed = true; } else { // If card is not new, then load its objects onto the canvas loadObjects(currentCard.objects); changed = false; if (newCard.cardID == NEW_TEMPLATE_CARD) { newCard.cardID = -1; currentCard.cardID = -1; changed = true; } } setSide(0); updateButtonStates(); updateCurCard(); promptAtTemplateChange = true; templateChanged = false; }