public NewPage() { this.InitializeComponent(); this.bitmapImage = pic.Source as BitmapImage; if (this.ori == null) { this.ori = new Model.Class1("", "", DateTimeOffset.Now, MySlider.Value, path, this.bitmapImage); this.isDelete = false; } pic.Width = picSize.Width * MySlider.Value; pic.Height = picSize.Height * MySlider.Value; }
private void Create(object sender, RoutedEventArgs e) { bool isReload = false; string message = ""; if (title.Text == "") { message += "title不能为空\n"; } if (detail.Text == "") { message += "detail不能为空\n"; } if (date.Date <= System.DateTimeOffset.Now.AddDays(-1)) { message += "无效日期"; } if (message == "") { if (isDelete == false) { Model.Class1 a = new Model.Class1(title.Text, detail.Text, date.Date, MySlider.Value, path, bitmapImage); App.db.insert(a); MainPage.one.AddItem(a); message += "创建成功"; title.Text = ""; detail.Text = ""; date.Date = DateTimeOffset.Now.AddDays(-1); MySlider.Value = 1.0; path = "Assets/document.jpg"; bitmapImage = new BitmapImage(new Uri("ms-appx:///" + path)); pic.Source = bitmapImage; } else { MainPage.one.Update(new Model.Class1(title.Text, detail.Text, date.Date, MySlider.Value, path, bitmapImage)); isReload = true; message += "更新成功"; } Service.TileService.Update(); } new MessageDialog(message).ShowAsync(); if (isReload) { Frame rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(MainPage)); } }
private void CheckBox_Unchecked(object sender, RoutedEventArgs e) { DependencyObject parent = VisualTreeHelper.GetParent((CheckBox)sender); CheckBox ls = (CheckBox)VisualTreeHelper.GetChild(parent, 0); Line line = (Line)VisualTreeHelper.GetChild(parent, 3); line.Visibility = Visibility.Collapsed; Model.Class1 a = (sender as FrameworkElement).DataContext as Model.Class1; if (a == null) { return; } a.ischecked = false; one.selectedItem = a; one.Update(a); }
private void Cancel(object sender, RoutedEventArgs e) { if (MainPage.one.selectedItem == null) { return; } ori = MainPage.one.selectedItem; title.Text = ori.title; detail.Text = ori.detail; date.Date = ori.date; pic.Source = ori.pic; path = ori.picPath; MySlider.Value = ori.size; pic.Width = picSize.Width * MySlider.Value; pic.Height = picSize.Height * MySlider.Value; bitmapImage = ori.pic; }
private bool find(Model.Class1 a, Model.Class1 b) { return(a.id == b.id); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { if (e.NavigationMode == NavigationMode.New) { if (MainPage.one.selectedItem != null) { ori = MainPage.one.selectedItem; title.Text = ori.title; detail.Text = ori.detail; pic.Source = ori.pic; date.Date = ori.date; MySlider.Value = ori.size; path = ori.picPath; pic.Width = picSize.Width * MySlider.Value; pic.Height = picSize.Height * MySlider.Value; isDelete = true; create.Content = "Update"; bitmapImage = ori.pic; DeleteAppBarButton.Visibility = Visibility; } } else { if (ApplicationData.Current.LocalSettings.Values.ContainsKey("NewPage")) { ApplicationDataCompositeValue composite = ApplicationData.Current.LocalSettings.Values["NewPage"] as ApplicationDataCompositeValue; title.Text = (string)composite["title"]; detail.Text = (string)composite["detail"]; path = (string)composite["Path"]; if (path != "Assets/document.jpg") { file = await Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.GetFileAsync(path); try { using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read)) { bitmapImage = new BitmapImage(); await bitmapImage.SetSourceAsync(fileStream); pic.Source = bitmapImage; } } catch (Exception) { throw new Exception(file.ToString()); } } else { pic.Source = bitmapImage = new BitmapImage(new Uri("ms-appx:///" + path)); } date.Date = (DateTimeOffset)composite["date"]; MySlider.Value = (double)composite["MySlider"]; pic.Width = picSize.Width * MySlider.Value; pic.Height = picSize.Height * MySlider.Value; isDelete = (bool)composite["isDelete"]; if (isDelete) { create.Content = "Update"; DeleteAppBarButton.Visibility = Visibility; } } } ApplicationData.Current.LocalSettings.Values.Remove("NewPage"); SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; }