private void addClick(object sender, RoutedEventArgs e)
        {
            if (TaskField.Text == string.Empty)
            {
                MessageBox.Show("Please enter a new task.");
                return;
            }
            if (App.ViewModel.ActiveToDoCateg == null)
            {
                MessageBox.Show("The current category is null");
                return;
            }
            using (ToDoDataContext ToDoDB = new ToDoDataContext("Data Source=isostore:/ToDo.sdf"))
            {

                ToDoItem newItem = new ToDoItem
                {
                    ItemName = TaskField.Text,
                    _categoryId = App.ViewModel.ActiveToDoCateg.Id,
                    IsComplete = false
                };
                ToDoDB.Items.InsertOnSubmit(newItem);
                ToDoDB.SubmitChanges();
                MessageBox.Show("Your task was added successfully!");
                this.NavigationService.Navigate(new Uri("/TodoItems.xaml", UriKind.Relative));
            }
        }
        private void addCategoryClick(object sender, RoutedEventArgs e)
        {
            if (CategoryField.Text == string.Empty)
            {
                MessageBox.Show("Please enter a name for your new category.");
                return;
            }
            using (ToDoDataContext ToDoDB = new ToDoDataContext("Data Source=isostore:/ToDo.sdf"))
            {
                ToDoCategory newCategory = new ToDoCategory
                {
                    Name = CategoryField.Text
                };

                //check if it already exists by iterating through all
                IList<ToDoCategory> categories = this.GetCategories();
                foreach (ToDoCategory todoCateg in categories)
                {
                    if (todoCateg.Name.Equals(newCategory.Name))
                    {
                        MessageBox.Show("The category already exists");
                        return;
                    }
                }

                ToDoDB.Categories.InsertOnSubmit(newCategory);
                ToDoDB.SubmitChanges();
                MessageBox.Show("Your new category has been added successfully!");
                this.NavigationService.Navigate(new Uri("/Todo.xaml", UriKind.Relative));
            }
        }
Exemple #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();

            // 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;
            }

            // Specify the local database connection string.
            string DBConnectionString = "Data Source=isostore:/ToDo.sdf";

            // Create the database if it does not exist.
            using (ToDoDataContext db = new ToDoDataContext(DBConnectionString))
            {
                if (db.DatabaseExists() == false)
                {
                    // Create the local database.
                    db.CreateDatabase();

                    // Prepopulate the categories.
                    db.Categories.InsertOnSubmit(new ToDoCategory { Name = "Home" });
                    db.Categories.InsertOnSubmit(new ToDoCategory { Name = "Work" });
                    db.Categories.InsertOnSubmit(new ToDoCategory { Name = "School" });

                    // Save categories to the database.
                    db.SubmitChanges();
                }
            }

            // Create the ViewModel object.
            viewModel = new ToDoViewModel(DBConnectionString);

            // Query the local database and load observable collections.
            viewModel.LoadCollectionsFromDatabase();
        }
Exemple #4
0
 public IList<ToDoItem> getItems()
 {
     IList<ToDoItem> itemsList = null;
     using (ToDoDataContext TodoDB = new ToDoDataContext("Data Source=isostore:/ToDo.sdf"))
     {
         IQueryable<ToDoItem> query = from item in TodoDB.Items select item;
         itemsList = query.ToList();
     }
     return itemsList;
 }
 public IList<ToDoCategory> GetCategories()
 {
     IList<ToDoCategory> categoryList = null;
     using (ToDoDataContext context = new ToDoDataContext("Data Source=isostore:/ToDo.sdf"))
     {
         IQueryable<ToDoCategory> query = from c in context.Categories select c;
         categoryList = query.ToList();
     }
     return categoryList;
 }
Exemple #6
0
 // Class constructor, create the data context object.
 public ToDoViewModel(string toDoDBConnectionString)
 {
     toDoDB = new ToDoDataContext(toDoDBConnectionString);
 }