Пример #1
0
        private void SaveItem(object sender, EventArgs e)
        {
            if (txtDescription.Text != "")
            {
                var item = new Todo
                {
                    Title = txtDescription.Text.Trim(),
                    DateInsert = DateTime.Now
                };

                if (NavigationContext.QueryString.ContainsKey("today"))
                {
                    item.DueDate = DateTime.Today;
                }
                else if (NavigationContext.QueryString.ContainsKey("tomorrow"))
                {
                    item.DueDate = DateTime.Today.AddDays(1);
                }
                else
                {
                    item.DueDate = Utilities.Someday;
                }

                var db = Context.Current;

                db.todos.InsertOnSubmit(item);
                db.SubmitChanges();

                NavigationService.GoBack();
            }
        }
Пример #2
0
        public ViewTodo()
        {
            InitializeComponent();

            this.item = (Application.Current as App).state as Todo;

            this.todoTitle.Text = this.item.Title;
            this.todoAddedDate.Text = this.item.TimeAgo;

            if (item.Overdue)
            {
                btnToday.Visibility = Visibility.Collapsed;
                btnTomorrowUp.Visibility = Visibility.Collapsed;
            }
            else if (item.DueDate == DateTime.Today.AddDays(1))
            {
                btnTomorrowDown.Visibility = Visibility.Collapsed;
                btnTomorrowUp.Visibility = Visibility.Collapsed;
            }
            else
            {
                btnSomeday.Visibility = Visibility.Collapsed;
                btnTomorrowDown.Visibility = Visibility.Collapsed;
            }

            DateTime today = DateTime.Today;
            if (item.ManualDueDate == null || item.ManualDueDate == false)
            {
                datePicker.Visibility = Visibility.Collapsed;

                if (item.DueDate == today || item.DueDate == today.AddDays(1))
                {
                    datePicker.Value = item.DueDate;
                }
                else
                {
                    datePicker.Value = today;
                }
            }
            else
            {
                datePicker.Value = item.DueDate;
                scheduledLabel.Text = "This item is scheduled for";
                datePicker.Visibility = Visibility.Visible;
                btnSchedule.Background = new SolidColorBrush((Color)Application.Current.Resources["PhoneAccentColor"]);
            }
        }
Пример #3
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            this.foregroundColor = (Resources["PhoneForegroundBrush"] as SolidColorBrush).Color;
            this.backgroundColor = (Resources["PhoneBackgroundBrush"] as SolidColorBrush).Color;
            this.OverrideColors();

            (Resources["PhoneSubtleBrush"] as SolidColorBrush).Color = Color.FromArgb(0x99, 0xFF, 0xFF, 0xFF);

            // Show graphics profiling information while debugging.
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Display the current frame rate counters
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Disable the application idle detection by setting the UserIdleDetectionMode property of the
                // application's PhoneApplicationService object to Disabled.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }

            this.db = new Context();

            if (this.db.DatabaseExists() == false)
            {
                //FIRST LOGIN

                //Create the database
                this.db.CreateDatabase();
                this.db = new Context();

                //Sample data
                Todo i = new Todo
                {
                    Title = "This item it's due today",
                    DateInsert = DateTime.Today,
                    DueDate = DateTime.Today
                };

                Todo i2 = new Todo
                {
                    Title = "This should be done very soon",
                    DateInsert = DateTime.Now.AddMinutes(-40),
                    DueDate = DateTime.Today.AddDays(1)
                };

                Todo i3 = new Todo
                {
                    Title = "Take your time, there's no rush to do this",
                    DateInsert = DateTime.Today.AddDays(-5),
                    DueDate = DateTime.Today.AddDays(60)
                };

                db.todos.InsertOnSubmit(i);
                db.todos.InsertOnSubmit(i2);
                db.todos.InsertOnSubmit(i3);

                db.SubmitChanges();
            }
            else
            {
                this.UpdateLocalDatabase();

                //Delete old todo
                var x = (from Todo t in db.todos where t.Completed == true && t.DateInsert <= DateTime.Today.AddDays(-7) select t).ToList();
                if (x.Count > 0)
                {
                    db.todos.DeleteAllOnSubmit(x);
                    db.SubmitChanges();
                }
            }

            StartPeriodicAgent();
        }