Beispiel #1
0
        void addNewCard()
        {
            //check to see if the card should maybe be added to a CardList
            if (cardListPlayList.CardListIDs.Count > 0)
            {
                //If the user needs to select which cardLists to add it to
                if (_chooseCardListsDialog == null || _chooseCardListsDialog.Description != cardListPlayList.Description || !_chooseCardListsDialog.RememberSelection)
                {
                    _chooseCardListsDialog = new ChooseCardListsDialog(cardListPlayList.CardListIDs, cardListPlayList.Description);
                    _chooseCardListsDialog.ShowDialog();

                    if (_chooseCardListsDialog.DialogResult != DialogResult.OK)
                    {
                        _chooseCardListsDialog = null;
                        return;
                    }
                }
            }

            //Create the card
            LanguageData dataLayer = new LanguageData();
            dsLanguageData.CardRow newCard = new dsLanguageData.CardDataTable().MakeNewCardRow();
            int tmp = dataLayer.InsertOrUpdateCard(newCard);

            //Add the card to the selected CardLists
            if (_chooseCardListsDialog != null)
            {
                foreach (int id in _chooseCardListsDialog.SelectedCardListIDs)
                {
                    int i = dataLayer.InsertCardListDataItem(id, newCard.ID);
                }
            }

            //Load the card and refresh the lists
            cardListPlayList.RefreshCards();
            cardControl.LoadCard(newCard);

            cardListPlayList.AddCard(newCard);
        }
        /// <summary>
        /// Gets all the cards in the desired CardLists
        /// </summary>
        /// <param name="cardListIDs"></param>
        /// <returns></returns>
        public dsLanguageData.CardDataTable GetCardsWhere(string whereClause)
        {
            dsLanguageData.CardDataTable cards = new dsLanguageData.CardDataTable();

            whereClause = whereClause.Trim();
            if (!whereClause.StartsWith("WHERE", StringComparison.CurrentCultureIgnoreCase))
                whereClause = "WHERE " + whereClause;

            string sql = string.Format(@"SELECT Card.ID, Card.Question, Card.Answer, Card.Notes, Card.[Count], Card.DateCreated, Card.LastModified, Card.MarkForReview, Card.Difficulty
                            FROM Card {0}", whereClause);
            SQLiteCommand cmd = new SQLiteCommand(sql, new SQLiteConnection(conString));
            System.Data.SQLite.SQLiteDataAdapter cardAdapter = new SQLiteDataAdapter(cmd);

            cardAdapter.Fill(cards);
            return cards;
        }
        /// <summary>
        /// Gets all the cards in the desired CardLists
        /// </summary>
        /// <param name="cardListIDs"></param>
        /// <returns></returns>
        public dsLanguageData.CardDataTable GetCardsInCardLists(List<int> cardListIDs)
        {
            //NOTE! Using joins in SQLite is very slow so this method has been written for performance reasons

            dsLanguageData.CardDataTable dtCards = new dsLanguageData.CardDataTable();

            List<int> cardIDs = GetCardIDsInLists(cardListIDs);
            return GetCardsByIDs(cardIDs);
        }
        /// <summary>
        /// Gets all the cards with the IDs
        /// </summary>
        /// <param name="cardIDs"></param>
        /// <returns></returns>
        public dsLanguageData.CardDataTable GetCardsByIDs(List<int> cardIDs)
        {
            dsLanguageData.CardDataTable cards = new dsLanguageData.CardDataTable();

            if (cardIDs == null || cardIDs.Count < 1)
                return cards;

            string ids = string.Empty;
            foreach (int id in cardIDs)
            {
                ids += ", " + id.ToString();
            }

            ids = ids.Remove(0, 1);

            string sql = string.Format(@"SELECT DISTINCT Card.ID, Card.Question, Card.Answer, Card.Notes, Card.[Count], Card.DateCreated, Card.LastModified, Card.MarkForReview, Card.Difficulty
                            FROM Card WHERE (ID IN ({0}))", ids);
            SQLiteCommand cmd = new SQLiteCommand(sql, new SQLiteConnection(conString));
            System.Data.SQLite.SQLiteDataAdapter cardAdapter = new SQLiteDataAdapter(cmd);

            cardAdapter.Fill(cards);
            return cards;
        }
        /// <summary>
        /// Gets all the cards in the desired CardLists
        /// </summary>
        /// <param name="cardListIDs"></param>
        /// <returns></returns>
        public dsLanguageData.CardDataTable GetCardsBeginningWith(string letter, string column)
        {
            dsLanguageData.CardDataTable cards = new dsLanguageData.CardDataTable();

            string sql = string.Format(@"SELECT ID, Question, Answer, Notes, [Count], DateCreated, LastModified, MarkForReview, Difficulty
                            FROM Card WHERE {0} like '{1}%' Order By {0}", column, letter);

            SQLiteCommand cmd = new SQLiteCommand(sql, new SQLiteConnection(conString));
            System.Data.SQLite.SQLiteDataAdapter cardAdapter = new SQLiteDataAdapter(cmd);

            cardAdapter.Fill(cards);
            return cards;
        }
        /// <summary>
        /// Refreshes all the loaded cards without getting the from the DB
        /// </summary>
        /// <param name="fromDB"></param>
        public void RefreshCards(bool fromDB)
        {
            listView.Items.Clear();

            if (fromDB && Cards.Rows.Count > 0)
            {
                try
                {
                    LanguageData dataLayer = new LanguageData();
                    _cards = dataLayer.GetCardsByIDs(_cards.GetIDList());
                }
                catch (FileNotFoundException e)
                {
                    //TODO send a message here that the main form will pick up and display on the bottom
                }
            }

            foreach (dsLanguageData.CardRow row in Cards)
            {
                listView.Items.Add(new IDListViewItem(row.ID, getDisplayText(row)));
            }

            listView.Refresh();
        }
        /// <summary>
        /// Clears the cards in the list
        /// </summary>
        public void ClearCards()
        {
            bool wasEmpty = Cards.Rows.Count < 1;

            Description = string.Empty;
            _cards = new dsLanguageData.CardDataTable();
            _cardListIDs = new List<int>();

            btnHeading.Text = headingText;

            listView.Items.Clear();
            _lastSelectedID = -1;

            if(!wasEmpty)
                onPlayListChanged(PlaylistAction.Cleared);
        }
 public CardsSelectedEventArgs(dsLanguageData.CardDataTable cards, List<int> cardListIDs, string selectionDescription)
 {
     CardListIDs = cardListIDs;
     Cards = cards;
     SelectionDescription = selectionDescription;
 }
        CardsSelectedEventArgs getSelectedCardsEventArgs()
        {
            List<int> cardListIDs = new List<int>();
            dsLanguageData.CardDataTable cards = new dsLanguageData.CardDataTable();

            if (cardsTabControl.SelectedTab == tpDictionary)
            {

                MyTreeNodeType selNodeType = getSelectedNodeType();
                switch (selNodeType)
                {
                    case MyTreeNodeType.Letter:
                        cards = getSelectedCardsBySelectedLetters();
                        //TODO Get Selected Letters and change the Event Args to hold them
                        break;
                    case MyTreeNodeType.Card:
                        cards = getSelectedCardsBySelectedCardsInDictionary();
                        break;
                    case MyTreeNodeType.Other:
                        return null;
                }
            }
            else if (cardsTabControl.SelectedTab == tpCardLists)
            {
                cards = getSelectedCardsBySelectedCardLists();

                foreach (MWCommon.MWTreeNodeWrapper node in cardListsTreeView.SelNodes.Values)
                {
                    MyTreeNode tmp = node.Node as MyTreeNode;
                    if (tmp.Type == MyTreeNodeType.CardList)
                        cardListIDs.Add(tmp.ID);
                }
            }

            return new CardsSelectedEventArgs(cards, cardListIDs, getSelectedItemDescription());
        }
        dsLanguageData.CardDataTable getSelectedCardsBySelectedCardLists()
        {
            dsLanguageData.CardDataTable cards = new dsLanguageData.CardDataTable();
            List<int> cardListIDs = new List<int>();

            foreach (MWCommon.MWTreeNodeWrapper node in cardListsTreeView.SelNodes.Values)
            {
                MyTreeNode tmp = node.Node as MyTreeNode;
                if (tmp.Type == MyTreeNodeType.CardList)
                    cardListIDs.Add(tmp.ID);
            }

            if (cardListIDs.Count > 0)
            {
                LanguageData dataLayer = new LanguageData();
                cards = dataLayer.GetCardsInCardLists(cardListIDs);
            }

            return cards;
        }