private void AddSiteToList(Sites s, StackPanel listName) { Button hpDel = new Button { Content = "X", Name = "shb_" + s.Id, }; hpDel.Click += deleteSite; TextBox tbt = new TextBox { Text = s.Name, Name = "stt_" + s.Id, BorderThickness = new Thickness(0), MaxLength = 15, }; tbt.TextChanging += SettingChanged; TextBox tb = new TextBox { Name = "stb_" + s.Id, Text = s.Url, }; tb.TextChanging += SettingChanged; sitesDict.Add(tbt, tb); Grid grd = new Grid(); grd.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); grd.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); grd.Children.Add(tb); Grid.SetColumn(tb, 0); grd.Children.Add(hpDel); Grid.SetColumn(hpDel, 1); listName.Children.Add(tbt); listName.Children.Add(grd); listName.Children.Add(new TextBlock { }); }
private async void Button_Click(object sender, RoutedEventArgs e) { string msg = string.Empty; try { Sites s = new Sites(); s.Name = "Bez nazwy"; s.Url = "http://zmien.to"; DbConnection.Insert(s); msg = "Strona dodana!"; this.RefreshSitesList(stackOfPages); } catch (SQLiteException ex) { msg = "Błąd bazy danych"; } finally { await (new MessageDialog(msg)).ShowAsync(); } }
private async void btnSaveSettings_Click(object sender, RoutedEventArgs e) { Uri uriResult; bool success = true; foreach (KeyValuePair<TextBox, TextBox> t in sitesDict) { int id = Convert.ToInt32(t.Key.Name.Replace("stt_", "")); if (t.Key.Text == string.Empty) t.Key.Text = "Bez nazwy"; if (Uri.TryCreate(t.Value.Text, UriKind.Absolute, out uriResult)) { Sites s = new Sites(); s.Id = id; s.Name = t.Key.Text; s.Url = t.Value.Text; DbConnection.Update(s); } else { success = false; string msg = "Adres " + t.Value.Text + " jest błędny!"; var dialog = new MessageDialog(msg); await dialog.ShowAsync(); } } if (success) { var dialog = new MessageDialog("Ustawienia zapisane!"); await dialog.ShowAsync(); btnSaveSettings.Visibility = Visibility.Collapsed; } else { var dialog = new MessageDialog("Proszę poprawić dane!"); await dialog.ShowAsync(); } }