/// <summary> /// Delete data from SQL table Countries /// </summary> public void DeleteData() { try { string sql = "delete from countries"; command = new SQLiteCommand(sql, connection); command.ExecuteNonQuery(); currencyDataService = new CurrencyDataService(); currencyDataService.DeleteData(); languageDataService = new LanguageDataService(); languageDataService.DeleteData(); regionalBlocsDataService = new RegionalBlocsDataService(); regionalBlocsDataService.DeleteData(); } catch (Exception e) { dialogService.ShowMessage("Error", e.Message); } }
/// <summary> /// Saving data of Countries in SQL with insert command /// </summary> /// <param name="countries"></param> public async Task SaveData(List <Country> countries, IProgress <ProgressReport> progress) { ProgressReport report = new ProgressReport(); byte p = 1; await Task.Run(() => { try { foreach (var country in countries) { string sql = string.Format("insert into countries (name, alpha2Code, alpha3Code, capital, region, subregion, population, demonym, area, gini, nativeName, numericCode, cioc) values (\"{0}\", '{1}', '{2}', \"{3}\", '{4}', '{5}', {6}, '{7}', '{8}', '{9}', \"{10}\", '{11}', '{12}')", country.Name, country.Alpha2Code, country.Alpha3Code, country.Capital, country.Region, country.Subregion, country.Population, country.Demonym, country.Area, country.Gini, country.NativeName, country.NumericCode, country.Cioc); command = new SQLiteCommand(sql, connection); command.ExecuteNonQuery(); currencyDataService = new CurrencyDataService(); currencyDataService.SaveData(country.Currencies, country.Alpha3Code); languageDataService = new LanguageDataService(); languageDataService.SaveData(country.Languages, country.Alpha3Code); regionalBlocsDataService = new RegionalBlocsDataService(); regionalBlocsDataService.SaveData(country.RegionalBlocs, country.Alpha3Code); report.Percentage = Convert.ToByte((p * 100) / countries.Count); progress.Report(report); p++; } connection.Close(); } catch (Exception e) { dialogService.ShowMessage("Error", e.Message); } }); }