ContainsCard() public static méthode

public static ContainsCard ( int cardid, SQLiteConnection connection ) : bool
cardid int
connection System.Data.SQLite.SQLiteConnection
Résultat bool
Exemple #1
0
        private void DeleteBtn_Click(object sender, EventArgs e)
        {
            int cardid;

            Int32.TryParse(CardID.Text, out cardid);

            if (cardid == 0)
            {
                MessageBox.Show("Invalid card id.", "Error", MessageBoxButtons.OK);
                return;
            }

            if (!CardManager.ContainsCard(cardid))
            {
                MessageBox.Show("Unable to find card to delete.", "Error", MessageBoxButtons.OK);
                return;
            }

            string dir = CardManager.GetDatabaseDir(CardManager.GetCard(cardid).source);

            var connection = new SQLiteConnection("Data Source=" + dir);

            connection.Open();

            if (SQLiteCommands.ContainsCard(cardid, connection))
            {
                if (MessageBox.Show("Are you sure you want to delete " + CardManager.GetCard(cardid).Name + "?", "Found", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }

            SQLiteCommands.DeleteCard(cardid, connection);

            CardManager.RemoveCard(cardid);
            Clearbtn_Click(null, EventArgs.Empty);
        }
Exemple #2
0
        private bool SaveCardtoCDB(string cdbpath)
        {
            int cardid;
            int cardalias;
            int atk;
            int def;
            int ot = (CardFormats.SelectedItem == null ? 0 : GetCardFormat());

            if (chkPre.Checked)
            {
                ot |= 0x4;
            }

            if (!Int32.TryParse(CardID.Text, out cardid))
            {
                MessageBox.Show("Invalid card id");
                return(false);
            }

            int updatecard = m_loadedCard == 0 ? cardid : m_loadedCard;

            if (!Int32.TryParse(Alias.Text, out cardalias))
            {
                cardalias = 0;
            }
            if (!Int32.TryParse(ATK.Text, out atk))
            {
                MessageBox.Show("Invalid atk value");
                return(false);
            }
            if (!Int32.TryParse(DEF.Text, out def))
            {
                MessageBox.Show("Invalid def value");
                return(false);
            }
            if (CDBSelect.Items.Count == 0)
            {
                MessageBox.Show("No loaded database");
                return(false);
            }

            CardInfos newCardInfo = new CardInfos(new[] { cardid.ToString(CultureInfo.InvariantCulture), (ot.ToString(CultureInfo.InvariantCulture)), cardalias.ToString(CultureInfo.InvariantCulture), GetSetCode().ToString(CultureInfo.InvariantCulture), GetTypeCode().ToString(CultureInfo.InvariantCulture),
                                                          GetLevelCode().ToString(), (Race.SelectedItem == null ? "0" : (Race.SelectedItem == null ? "0" : m_cardRaces[Race.SelectedIndex].ToString(CultureInfo.InvariantCulture))),
                                                          (CardAttribute.SelectedItem == null ? "0" : (CardAttribute.SelectedItem == null ? "0" : m_cardAttributes[CardAttribute.SelectedIndex].ToString(CultureInfo.InvariantCulture))), atk.ToString(CultureInfo.InvariantCulture), def.ToString(CultureInfo.InvariantCulture), GetCategoryNumber().ToString(CultureInfo.InvariantCulture) }
                                                  , CDBSelect.SelectedIndex + 1);

            var cardtextarray = new List <string> {
                cardid.ToString(CultureInfo.InvariantCulture), CardName.Text, CardDescription.Text
            };

            for (var i = 0; i < 17; i++)
            {
                cardtextarray.Add((i < EffectList.Items.Count ? EffectList.Items[i].ToString() : string.Empty));
            }

            newCardInfo.SetCardText(cardtextarray.ToArray());

            if (CardTypeList.CheckedItems.Contains("Link"))
            {
                newCardInfo.Def = GetLinkMarkers();
            }

            //check source DB

            if (CardManager.ContainsCard(cardid))
            {
                if (CardManager.GetCard(cardid).source != newCardInfo.source)
                {
                    if (MessageBox.Show("Copy to new database?", "", MessageBoxButtons.YesNo) != DialogResult.Yes)
                    {
                        return(false);
                    }
                }
            }


            //save/update card
            var connection = new SQLiteConnection("Data Source=" + CardManager.GetDatabaseDir(newCardInfo.source));

            connection.Open();
            //check if card id exsists
            bool overwrite = SQLiteCommands.ContainsCard(updatecard, connection);

            if (overwrite)
            {
                if (MessageBox.Show("Overwrite current card?", "Found", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    connection.Close();
                    return(false);
                }
            }

            SQLiteCommands.SaveCard(newCardInfo, connection, updatecard, overwrite);

            connection.Close();

            if (cardid != updatecard)
            {
                CardManager.RenameKey(updatecard, cardid);
            }

            CardManager.UpdateOrAddCard(newCardInfo);

            MessageBox.Show("Card Saved");
            return(true);
        }