示例#1
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

            this.db = Context.Current;

            todayList = new ObservableCollection<Todo>();
            tomorrowList = new ObservableCollection<Todo>();
            somedayList = new ObservableCollection<Todo>();
        }
示例#2
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();
        }