Esempio n. 1
0
        private void Create_Click(object sender, RoutedEventArgs e)
        {
            string    result = "";
            Singleton tmp    = Singleton.Instance;

            if (this.title.Text == "")
            {
                result += "Title can't be empty!\n";
            }
            if (this.detail.Text == "")
            {
                result += "Detail can't be empty!\n";
            }
            DateTime dt = DateTime.Now;

            if (datepick.Date < dt)
            {
                result += "The due date has passed!\n";
            }
            ShowMessageDialog(result);
            if (result == "" && this.Create.Content.ToString() == "Create")
            {
                if (current == null)
                {
                    current = new Todo();
                }
                current.Title      = this.title.Text;
                current.Detail     = this.detail.Text;
                current.Date       = this.datepick.Date.ToString();
                current.Picture    = this.pic.Source;
                current.picture_id = m_singleton.get_picture_count();
                tmp_to_save("picture" + current.picture_id + ".jpg");
                current.create_date = DateTime.Now.ToString();
                reset_RightPart();
                tmp.set_signal("add");
                m_singleton.add_picture_count();
                Frame frame = Window.Current.Content as Frame;
                frame.Navigate(typeof(MainPage), "");
                Window.Current.Content = frame;
                Window.Current.Activate();
            }
            else if (result == "" && this.Create.Content.ToString() == "Update")
            {
                current.Title   = title.Text;
                current.Detail  = detail.Text;
                current.Date    = datepick.Date.ToString();
                current.Picture = pic.Source;

                this.Create.Content = "Create";
                this.delete.Opacity = 0;

                tmp.set_signal("modify_or_simple");
                m_db.update(current);
                tmp_to_save("picture" + current.picture_id + ".jpg");
                reset_RightPart();
                Frame frame = Window.Current.Content as Frame;
                frame.Navigate(typeof(MainPage), "");
                Window.Current.Content = frame;
                Window.Current.Activate();
            }
        }
Esempio n. 2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string     background = m_db.get_background();
            ImageBrush imageBrush = new ImageBrush();

            imageBrush.ImageSource = new BitmapImage(new Uri("ms-appx:///Assets/" + background, UriKind.Absolute)); //设置背景图片
            this.main.Background   = imageBrush;
            var color = (Color)this.Resources["SystemAccentColor"];                                                 //跟随系统主题颜色

            this.bar.Background       = new SolidColorBrush(color);
            this.set_color.Foreground = m_singleton.get_color();
            if (e.NavigationMode == NavigationMode.New)
            {
                ApplicationData.Current.LocalSettings.Values.Remove("newpage");
                base.OnNavigatedTo(e);
                current = m_singleton.get_todo();

                if (m_singleton.get_signal() == "simple")
                {
                    this.Create.Content = "Create";
                    SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
                    this.delete.Opacity  = 0;
                    this.share.Opacity   = 0;
                    this.pic.DataContext = "0";
                    save_to_tmp("picture0.jpg");
                }
                else if (m_singleton.get_signal() == "update")
                {
                    SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
                    this.Create.Content  = "Update";
                    this.title.Text      = current.Title;
                    this.detail.Text     = current.Detail;
                    this.pic.DataContext = current.picture_id;
                    pic.Source           = current.Picture;
                    this.datepick.Date   = DateTimeOffset.Parse(current.Date);
                    this.delete.Opacity  = 1;
                    this.share.Opacity   = 1;
                }
            }
            else if (ApplicationData.Current.LocalSettings.Values.ContainsKey("newpage"))
            {
                var composite = ApplicationData.Current.LocalSettings.Values["newpage"] as ApplicationDataCompositeValue;
                if ((string)composite["signal"] == "update")
                {
                    this.share.Opacity  = 1;
                    this.delete.Opacity = 1;
                    this.Create.Content = "Update";
                    foreach (var item in this.ViewModel.DefaultTodo)
                    {
                        if (item.create_date == (string)composite["create_date"])
                        {
                            current = item;
                            break;
                        }
                    }
                    this.pic.DataContext = current.picture_id;
                    m_singleton.set_signal("update");
                    m_singleton.set_todo(current);
                    SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
                }
                else
                {
                    SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
                }
                title.Text          = (string)composite["title"];
                detail.Text         = (string)composite["detail"];
                datepick.Date       = (DateTimeOffset)composite["date"];
                this.delete.Opacity = 1;
                this.share.Opacity  = 1;
                this.Create.Content = "Update";
                get_cache_image();
                ApplicationData.Current.LocalSettings.Values.Remove("newpage");
            }
        }