Esempio n. 1
0
        public DeckPropertiesDialog(eFlash.Data.Deck newDeck, bool changeType)
        {
            InitializeComponent();

            deck = newDeck;

            txtTitle.Text       = deck.title;
            txtCategory.Text    = deck.category;
            txtSubcategory.Text = deck.subcategory;

            grpType.Enabled = changeType;

            switch (deck.type)
            {
            case Constant.textDeck:
                rdText.Checked = true;
                break;

            case Constant.imageDeck:
                rdImage.Checked = true;
                break;

            case Constant.soundDeck:
                rdAudio.Checked = true;
                break;

            case Constant.noQuizDeck:
                rdNoQuiz.Checked = true;
                break;
            }

            saved = false;
        }
Esempio n. 2
0
        public DeckPropertiesDialog(eFlash.Data.Deck newDeck, bool changeType)
        {
            InitializeComponent();

            deck = newDeck;

            txtTitle.Text = deck.title;
            txtCategory.Text = deck.category;
            txtSubcategory.Text = deck.subcategory;

            grpType.Enabled = changeType;

            switch (deck.type)
            {
                case Constant.textDeck:
                    rdText.Checked = true;
                    break;
                case Constant.imageDeck:
                    rdImage.Checked = true;
                    break;
                case Constant.soundDeck:
                    rdAudio.Checked = true;
                    break;
                case Constant.noQuizDeck:
                    rdNoQuiz.Checked = true;
                    break;
            }

            saved = false;
        }
Esempio n. 3
0
        private void LayoutEditor_Shown(object sender, EventArgs e)
        {
            if (deck == null)
            {
                deck     = new eFlash.Data.Deck();
                deck.uid = ProfileManager.getCurrentUserID();

                if (!showDeckPropertiesDialog(true))
                {
                    changed         = false;
                    templateChanged = false;
                    this.Close();
                    return;
                }

                if (deck.cardList.Count == 0)
                {
                    promptAtTemplateChange = false;
                }
            }

            changed = false;

            if (deck.cardList.Count == 0)
            {
                promptAtTemplateChange = false;
            }

            if (deck.type == Constant.noQuizDeck)
            {
                deleteSideToolStripMenuItem1.Enabled = true;
                addNewSideToolStripMenuItem.Enabled  = true;
            }
            else if (deck.type == Constant.textDeck || deck.type == Constant.imageDeck || deck.type == Constant.soundDeck)
            {
                tsObjects.Visible         = false;
                templateSelector          = new TemplateSelector(this, deck.type);
                templateSelector.Location = tsObjects.Location;

                this.Controls.Add(templateSelector);

                deleteSideToolStripMenuItem1.Enabled = false;
                addNewSideToolStripMenuItem.Enabled  = false;
            }
            else
            {
                throw new Exception("Invalid deck type");
            }
        }
Esempio n. 4
0
        public LayoutEditor(main newPrevWindow, eFlash.Data.Deck newDeck, bool makeCopy)
        {
            InitializeComponent();

            prevWindow = newPrevWindow;

            if (makeCopy)
            {
                deck = deepCopy(newDeck);
            }
            else
            {
                deck = newDeck;
            }

            initialize();
        }
Esempio n. 5
0
        /// <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);
        }
Esempio n. 6
0
 public static int insertToDecks(eFlash.Data.Deck d)
 {
     return(insertToDecks(d.category, d.subcategory, d.title, d.type, d.uid, d.netID));
 }
Esempio n. 7
0
        /**
        *  A function to retrieve all unranked decks belonging to a user in the local database
        * Pre: local network user id
        * Post: List of corresponding Decks
        */
        public static List<Deck> getUnrankedDecks(int netID)
        {
            List<Deck> deckList = new List<Deck>();
            string SQL;
            MySqlCommand cmd = new MySqlCommand();
            MySqlDataReader myData;

            connect();

            try
            {

                SQL = "SELECT decks.did, decks.cat, decks.subcat, decks.title FROM unranked, decks WHERE unranked.lnuid = " + Convert.ToString(netID) + " AND unranked.ldid = decks.did  ORDER BY cat, title";

                cmd.Connection = conn;
                cmd.CommandText = SQL;

                myData = cmd.ExecuteReader();

                while (myData.Read())
                {
                    Deck deck = new Deck(myData.GetInt32(myData.GetOrdinal("did")),
                                                                myData.GetString(myData.GetOrdinal("cat")),
                                                                myData.GetString(myData.GetOrdinal("subcat")),
                                                                myData.GetString(myData.GetOrdinal("title")));
                    deckList.Add(deck);
                }
                myData.Close();
                conn.Close();
                return deckList;
            }
            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();

            }
        }
Esempio n. 8
0
        /**
         *  A function to retrieve all the decks in the local database, ordered by input specification
         * Pre: order (0 = cat, 1 = alphabetical, 2 = time)
         * Post: List of corresponding Decks
         */
        public static List<Deck> getDecksOrdered(int order)
        {
            List<Deck> deckList = new List<Deck>();
            deckList.Clear();
            string SQL;
            MySqlCommand cmd = new MySqlCommand();
            MySqlDataReader myData;

            connect();

            try
            {
                //the if statement spliced in by Daniel for main menu selecting all decks
                switch (order)
                {
                    case 0:
                        SQL = "SELECT did,type,cat,subcat,title,uid,nuid FROM decks ORDER BY cat, title";
                        break;
                    case 1:
                        SQL = "SELECT did,type,cat,subcat,title,uid,nuid FROM decks ORDER BY title";
                        break;
                    case 2:
                        SQL = "SELECT did,type,cat,subcat,title,uid,nuid FROM decks ORDER BY cat, title";
                        break;//change this case when timestamp implemented
                    default:
                        MessageBox.Show("Error: corrupted order input to getDecksOrdered");
                        SQL = "SELECT did,type,cat,subcat,title,uid,nuid FROM decks ORDER BY cat, title";
                        break;
                }

                cmd.Connection = conn;
                cmd.CommandText = SQL;

                myData = cmd.ExecuteReader();

                while (myData.Read())
                {
                    Deck deck = new Deck(myData.GetInt32(myData.GetOrdinal("did")),
                                         myData.GetString(myData.GetOrdinal("type")),
                                         myData.GetString(myData.GetOrdinal("cat")),
                                         myData.GetString(myData.GetOrdinal("subcat")),
                                         myData.GetString(myData.GetOrdinal("title")),
                                         myData.GetInt32(myData.GetOrdinal("uid")),
                                         myData.GetInt32(myData.GetOrdinal("nuid")));
                    deckList.Add(deck);
                }
                myData.Close();
                conn.Close();
                return deckList;
            }
            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();

            }
        }
Esempio n. 9
0
 public LayoutEditor(main newPrevWindow, eFlash.Data.Deck newDeck) : this(newPrevWindow, newDeck, false)
 {
 }
Esempio n. 10
0
 public static void updateDeck(eFlash.Data.Deck d)
 {
     updateDecks(d.id, d.type, d.category, d.subcategory, d.title, d.uid, d.netID);
 }
Esempio n. 11
0
        public static byte[] buildNetBLOB(Deck deck, int uploaderID)
        {
            Card curCard;
            eObject curObj;
            IEnumerator objEnum;
            IEnumerator cardEnum;
            MemoryStream stream = new MemoryStream();
            XmlTextWriter writer = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

            //Use automatic indentation for readability.
            writer.Formatting = Formatting.Indented;

            //Write the root element
            writer.WriteStartElement("eFlash-Network");

            //Start an element
            writer.WriteStartElement("Deck");

            //Add attribute to Deck
            writer.WriteAttributeString("cat", deck.category);
            writer.WriteAttributeString("subcat", deck.subcategory);
            writer.WriteAttributeString("title", deck.title);
            writer.WriteAttributeString("type", deck.type);
            writer.WriteAttributeString("nuid", Convert.ToString(uploaderID));

            cardEnum = deck.cardList.GetEnumerator();
            while (cardEnum.MoveNext())
            {
                //Load the cards belonging to this deck
                 curCard = (Card)cardEnum.Current;
                 writer.WriteStartElement("Card");
                 writer.WriteAttributeString("tag",curCard.tag);

                objEnum = curCard.eObjectList.GetEnumerator();
                while (objEnum.MoveNext())
                {
                    curObj = (eObject)objEnum.Current;

                    writer.WriteStartElement("Object");
                    writer.WriteAttributeString("size", Convert.ToString(curObj.efile.size));
                    writer.WriteAttributeString("side", Convert.ToString(curObj.side));
                    writer.WriteAttributeString("type", Convert.ToString(curObj.type));
                    writer.WriteAttributeString("quizType", Convert.ToString(curObj.quizType));
                    writer.WriteAttributeString("x1", Convert.ToString(curObj.x1));
                    writer.WriteAttributeString("x2", Convert.ToString(curObj.x2));
                    writer.WriteAttributeString("y1", Convert.ToString(curObj.y1));
                    writer.WriteAttributeString("y2", Convert.ToString(curObj.y2));

                    writer.WriteBase64(curObj.efile.rawData, 0, curObj.efile.size);

                    // end the Object element
                    writer.WriteEndElement();
                }
                // end the Card element
                writer.WriteEndElement();
            }
            // end the Deck element
            writer.WriteEndElement();

            // end the root element
            writer.WriteFullEndElement();
            //writer.WriteEndDocument();

            //Close the writer and stream
            writer.Close();
            stream.Close();

            return stream.ToArray();
        }
Esempio n. 12
0
        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;
        }
Esempio n. 13
0
        private void LayoutEditor_Shown(object sender, EventArgs e)
        {
            if (deck == null)
            {
                deck = new eFlash.Data.Deck();
                deck.uid = ProfileManager.getCurrentUserID();

                if (!showDeckPropertiesDialog(true))
                {
                    changed = false;
                    templateChanged = false;
                    this.Close();
                    return;
                }

                if (deck.cardList.Count == 0)
                {
                    promptAtTemplateChange = false;
                }
            }

            changed = false;

            if (deck.cardList.Count == 0)
            {
                promptAtTemplateChange = false;
            }

            if (deck.type == Constant.noQuizDeck)
            {
                deleteSideToolStripMenuItem1.Enabled = true;
                addNewSideToolStripMenuItem.Enabled = true;
            }
            else if (deck.type == Constant.textDeck || deck.type == Constant.imageDeck || deck.type == Constant.soundDeck)
            {
                tsObjects.Visible = false;
                templateSelector = new TemplateSelector(this, deck.type);
                templateSelector.Location = tsObjects.Location;

                this.Controls.Add(templateSelector);

                deleteSideToolStripMenuItem1.Enabled = false;
                addNewSideToolStripMenuItem.Enabled = false;
            }
            else
            {
                throw new Exception("Invalid deck type");
            }
        }
Esempio n. 14
0
        /// <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;
        }