private bool GetLoot(string pageSource) { const string lootPattern = @"<img class=""res"" src=""img/un/r/[1234].gif"">([0-9]{0,7})"; MatchCollection lootMatchCollection = Regex.Matches(pageSource, lootPattern); if (lootMatchCollection.Count != 4) { return false; } loot = new Loot { Wood = Int32.Parse(lootMatchCollection[0].Groups[1].Value.Trim()), Clay = Int32.Parse(lootMatchCollection[1].Groups[1].Value.Trim()), Iron = Int32.Parse(lootMatchCollection[2].Groups[1].Value.Trim()), Crop = Int32.Parse(lootMatchCollection[3].Groups[1].Value.Trim()) }; loot.Total = loot.Sum(); return true; }
public static void SaveData2SQL(Loot loot) { // Create a connection and a command using (DbConnection cnn = new SQLiteConnection("Data Source=loot.db3")) using (DbCommand cmd = cnn.CreateCommand()) { // Open the connection. If the database doesn't exist, // it will be created automatically cnn.Open(); // Create a table in the database //cmd.CommandText = "CREATE TABLE FOO (ID INTEGER PRIMARY KEY, MYVALUE VARCHAR(50))"; //cmd.ExecuteNonQuery(); // Create a parameterized insert command cmd.CommandText = "INSERT INTO Loot (MYVALUE) VALUES(?)"; cmd.Parameters.Add(cmd.CreateParameter()); // Insert 10 rows into the database for (int n = 0; n < 10; n++) { cmd.Parameters[0].Value = "Value " + n.ToString(); cmd.ExecuteNonQuery(); } // Now read them back //cmd.CommandText = "SELECT * FROM FOO"; //using (DbDataReader reader = cmd.ExecuteReader()) //{ // while (reader.Read()) // { // Console.WriteLine(String.Format("ID = {0}, MYVALUE = {1}", reader[0], // reader[1])); // } //} } }