private SqlCeCommand GenerateSaveSqlCmd(SqliteDB dB)
        {
            SqlCeCommand cmd        = new SqlCeCommand();
            bool         needsComma = false;

            try
            {
                string sqlInsert = "INSERT INTO Card ";

                string sqlFields = string.Empty;
                sqlFields += "(";

                string sqlValues = string.Empty;
                sqlValues += "VALUES (";

                // loop through all properties for a ScryfallCard and build the string
                PropertyInfo[] pi = typeof(ScryfallCard).GetProperties();
                foreach (PropertyInfo info in pi)
                {
                    //DEBUG
                    //if (info.Name == "color_identity")
                    //{
                    //    Console.WriteLine("here");
                    //}
                    switch (info.Name)
                    {
                    case "card_PK":
                        //case "dateAdded":
                        //case "dateModified":
                        //case "modifiedMethod":
                        continue;
                    }
                    if (needsComma)
                    {
                        sqlFields += ", ";
                        sqlValues += ", ";
                    }
                    needsComma = true;
                    sqlFields += "[" + info.Name + "]";
                    sqlValues += "@" + info.Name;
                }

                sqlFields += ") ";
                sqlValues += ") ";



                cmd = new SqlCeCommand(sqlInsert + sqlFields + sqlValues, dB.connection);
            }
            catch (Exception)
            {
                throw;
            }

            return(cmd);
        }
        public ScryfallEngine(SqliteDB db)
        {
            this.db = db;
            client  = new HttpClient();
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            client.BaseAddress = new Uri("https://api.scryfall.com/");
        }
        //public string json_string;

        public void SaveToDB(SqliteDB dB)
        {
            try
            {
                SqlCeCommand testCmd = GenerateSaveSqlCmd(dB);
                LoadCardIntoSqlCmd(this, ref testCmd);

                testCmd.ExecuteNonQuery();
                Console.WriteLine(String.Format("card {0} added to DB", this.Name));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemple #4
0
 public DeckStatisticsForm(SqliteDB db, bool loadTestDeck)
 {
     InitializeComponent();
     timer2.Interval = 1000;
     engine          = new ScryfallEngine(db);
     bs                        = new BindingSource();
     bs.DataSource             = this.deck.cards;
     lstDeckList.DataSource    = bs;
     lstDeckList.DisplayMember = "Name";
     lstDeckList.ValueMember   = "id";
     lstDeckList.Sorted        = false;
     if (loadTestDeck)
     {
         this.LoadTestDeck();
     }
 }