static void Main(string[] args) { Dictionary <string, TownWeather> dict = new Dictionary <string, TownWeather>(); Regex pattern = new Regex(@"([A-Z]{2})(\d+\.\d+)([a-zA-Z]+)\|"); string input; while ((input = Console.ReadLine()) != "end") { Match match = pattern.Match(input); if (!match.Success) { continue; } string town = match.Groups[1].Value; float averageTemperature = float.Parse(match.Groups[2].Value); string weather = match.Groups[3].Value; if (!dict.ContainsKey(town)) { dict[town] = new TownWeather(town); } dict[town].AverageTemperatur = averageTemperature; dict[town].Weather = weather; } Console.WriteLine(string.Join(Environment.NewLine, dict.OrderBy(t => t.Value.AverageTemperatur).Select(t => $"{t.Key} => {t.Value.AverageTemperatur:f2} => {t.Value.Weather}"))); }
private void ButtonAdd_Click(object sender, EventArgs e) { if (towns.Find(t => t.Name == editName.Text) != null) { editName.Text = null; return; } TownWeather town = new TownWeather(editName.Text); dbAdapter.Insert(town); new WeatherTask(this).Execute(town.Name); editName.Text = null; LoadData(); }
public bool Insert(TownWeather town) { try { using (SQLiteConnection connection = new SQLiteConnection(System.IO.Path.Combine(path, name))) { connection.Insert(town); return(true); } } catch (SQLiteException ex) { Log.Info("SQLiteException", ex.Message); return(false); } }
public bool UpdateByName(TownWeather town) { try { using (SQLiteConnection connection = new SQLiteConnection(System.IO.Path.Combine(path, name))) { connection.Query <TownWeather>("UPDATE TownWeather set Temp=?,Temp_min=?,Temp_max=?,Pressure=?,Sea_level=?, Grnd_level=?, Humidity=?, Main=?, Description=?,Tommorow_temp=?,Tommorow_main=?,Tommorow_description=?,After_tmr_temp=?,After_tmr_main=?,After_tmr_description=?,After2_tmr_temp=?,After2_tmr_main=?,After2_tmr_description=? WHERE Name=?", town.Temp, town.Temp_min, town.Temp_max, town.Pressure, town.Sea_level, town.Grnd_level, town.Humidity, town.Main, town.Description, town.Tommorow_temp, town.Tommorow_main, town.Tommorow_description, town.After_tmr_temp, town.After_tmr_main, town.After_tmr_description, town.After2_tmr_temp, town.After2_tmr_main, town.After2_tmr_description, town.Name); return(true); } } catch (SQLiteException ex) { Log.Info("SQLiteException", ex.Message); return(false); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab); fab.Click += FabOnClick; listData = FindViewById <ListView>(Resource.Id.listViewTowns); dbAdapter = new DataBaseAdapter(); dbAdapter.CreateTable(); editName = FindViewById <EditText>(Resource.Id.textInputEditText); editName.Click += delegate { Button buttonEdit = FindViewById <Button>(Resource.Id.buttonEdit); if (buttonEdit.Text == "") { editName.Text = null; } }; BindButtons(); LoadData(); listData.ItemClick += ListData_ItemClick; if (towns.Count == 0) { TownWeather moskow = new TownWeather("Moscow"); towns.Add(moskow); dbAdapter.Insert(moskow); new WeatherTask(this).Execute(moskow.Name); TownWeather peterburg = new TownWeather("Saint Petersburg"); towns.Add(peterburg); dbAdapter.Insert(peterburg); new WeatherTask(this).Execute(peterburg.Name); } }
protected override void OnPostExecute(string result) { base.OnPostExecute(result); if (result == null) { return; } weatherData = JsonConvert.DeserializeObject <OpenWeatherData>(result); TownWeather tw = new TownWeather() { Name = weatherData.city.name, Temp = weatherData.list[0].main.temp, Temp_min = weatherData.list[0].main.temp_min, Temp_max = weatherData.list[0].main.temp_max, Pressure = weatherData.list[0].main.pressure, Humidity = weatherData.list[0].main.humidity, Sea_level = weatherData.list[0].main.sea_level, Grnd_level = weatherData.list[0].main.grnd_level, Main = weatherData.list[0].weather[0].main, Description = weatherData.list[0].weather[0].description, Tommorow_temp = weatherData.list[1].main.temp, Tommorow_main = weatherData.list[1].weather[0].main, Tommorow_description = weatherData.list[1].weather[0].description, After_tmr_temp = weatherData.list[2].main.temp, After_tmr_main = weatherData.list[2].weather[0].main, After_tmr_description = weatherData.list[2].weather[0].description, After2_tmr_temp = weatherData.list[3].main.temp, After2_tmr_main = weatherData.list[3].weather[0].main, After2_tmr_description = weatherData.list[3].weather[0].description, }; activity.dbAdapter.UpdateByName(tw); activity.LoadData(); }
private void ButtonEdit_Click(object sender, EventArgs e) { if (txtName == null) { return; } if ((sender as Button).Text == "Edit") { (sender as Button).Text = "Accept"; editName.Text = txtName.Text; } else { (sender as Button).Text = "Edit"; dbAdapter.Delete(towns[selectedPosition]); TownWeather town = new TownWeather(editName.Text); dbAdapter.Insert(town); new WeatherTask(this).Execute(town.Name); txtName.Text = null; LoadData(); } }