Exemplo n.º 1
0
        private void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            if ((string)ButtonDelete.Content == "Delete")
            {
                ButtonDelete.Content    = "Are You Sure?";
                ButtonDelete.Background = Brushes.Red;
            }
            else
            {
                switch (tableName)
                {
                case "Tasks":
                    using (var db = new TasksDBEntities())
                    {
                        var taskToDelete = db.Tasks.Find(task.TaskID);
                        db.Tasks.Remove(taskToDelete);
                        db.SaveChanges();
                        ListBox.ItemsSource = null;
                        tasks = db.Tasks.ToList();
                        ListBox.ItemsSource = tasks;
                    }
                    break;

                case "Categories":
                    using (var db = new TasksDBEntities())
                    {
                        var categoryToDelete = db.Categories.Find(category.CategoryID);
                        db.Categories.Remove(categoryToDelete);
                        db.SaveChanges();
                        ListBox.ItemsSource = null;
                        categories          = db.Categories.ToList();
                        ListBox.ItemsSource = categories;
                    }
                    break;

                case "Users":
                    using (var db = new TasksDBEntities())
                    {
                        var userToDelete = db.Users.Find(user.UserID);
                        db.Users.Remove(userToDelete);
                        db.SaveChanges();
                        ListBox.ItemsSource = null;
                        users = db.Users.ToList();
                        ListBox.ItemsSource = users;
                    }
                    break;

                default:
                    break;
                }
                ButtonDelete.Content = "Delete";
                BrushConverter brush = new BrushConverter();
                ButtonDelete.Background = (Brush)brush.ConvertFrom("#FFE4AB");
            }
        }
Exemplo n.º 2
0
 void Initialise()
 {
     using (var db = new TasksDBEntities())
     {
         tasks      = db.Tasks.ToList();
         categories = db.Categories.ToList();
         users      = db.Users.ToList();
     }
     ListBox.ItemsSource         = tasks;
     ListBox.DisplayMemberPath   = "Description";
     ComboBox1.ItemsSource       = categories;
     ComboBox1.DisplayMemberPath = "CategoryName";
     ComboBox2.ItemsSource       = users;
     ComboBox2.DisplayMemberPath = "UserName";
 }
Exemplo n.º 3
0
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            if ((string)ButtonAdd.Content == "Add")
            {
                switch (tableName)
                {
                case "Tasks":
                    TextBoxDescription.IsReadOnly = false;
                    TextBoxCategoryID.IsReadOnly  = false;
                    TextBoxUserID.IsReadOnly      = false;
                    TextBoxDescription.Background = Brushes.White;
                    TextBoxCategoryID.Background  = Brushes.White;
                    TextBoxUserID.Background      = Brushes.White;
                    break;

                case "Categories":
                    TextBoxDescription.IsReadOnly = false;
                    TextBoxDescription.Background = Brushes.White;
                    break;

                case "Users":
                    TextBoxDescription.IsReadOnly = false;
                    TextBoxDescription.Background = Brushes.White;
                    break;

                default:
                    break;
                }
                ButtonAdd.Content = "Confirm";
            }
            else
            {
                BrushConverter brush = new BrushConverter();
                switch (tableName)
                {
                case "Tasks":
                    using (var db = new TasksDBEntities())
                    {
                        Task newTask = new Task
                        {
                            Description = TextBoxDescription.Text,
                            CategoryID  = Convert.ToInt32(TextBoxCategoryID.Text)
                        };
                        db.Tasks.Add(newTask);
                        db.SaveChanges();
                        ListBox.ItemsSource = null;
                        tasks = db.Tasks.ToList();
                        ListBox.ItemsSource = tasks;
                    }
                    TextBoxDescription.IsReadOnly = true;
                    TextBoxCategoryID.IsReadOnly  = true;
                    TextBoxUserID.IsReadOnly      = true;
                    TextBoxDescription.Background = (Brush)brush.ConvertFrom("#E8D79B");
                    TextBoxCategoryID.Background  = (Brush)brush.ConvertFrom("#E8D79B");
                    TextBoxUserID.Background      = (Brush)brush.ConvertFrom("#E8D79B");
                    break;

                case "Categories":
                    using (var db = new TasksDBEntities())
                    {
                        Category newCategory = new Category
                        {
                            CategoryName = TextBoxDescription.Text,
                        };
                        db.Categories.Add(newCategory);
                        db.SaveChanges();
                        ListBox.ItemsSource = null;
                        categories          = db.Categories.ToList();
                        ListBox.ItemsSource = categories;
                    }
                    TextBoxDescription.IsReadOnly = true;
                    TextBoxDescription.Background = (Brush)brush.ConvertFrom("#E8D79B");
                    break;

                case "Users":
                    using (var db = new TasksDBEntities())
                    {
                        User newUser = new User
                        {
                            UserName = TextBoxDescription.Text,
                        };
                        db.Users.Add(newUser);
                        db.SaveChanges();
                        ListBox.ItemsSource = null;
                        users = db.Users.ToList();
                        ListBox.ItemsSource = users;
                    }
                    TextBoxDescription.IsReadOnly = true;
                    TextBoxDescription.Background = (Brush)brush.ConvertFrom("#E8D79B");
                    break;

                default:
                    break;
                }
                ButtonAdd.Content = "Add";
            }
        }
Exemplo n.º 4
0
        private void ButtonEdit_Click(object sender, RoutedEventArgs e)
        {
            if ((string)ButtonEdit.Content == "Edit")
            {
                switch (tableName)
                {
                case "Tasks":
                    TextBoxDescription.IsReadOnly = false;
                    TextBoxCategoryID.IsReadOnly  = false;
                    TextBoxUserID.IsReadOnly      = false;
                    TextBoxDescription.Background = Brushes.White;
                    TextBoxCategoryID.Background  = Brushes.White;
                    TextBoxUserID.Background      = Brushes.White;
                    break;

                case "Categories":
                    TextBoxDescription.IsReadOnly = false;
                    TextBoxDescription.Background = Brushes.White;
                    break;

                case "Users":
                    TextBoxDescription.IsReadOnly = false;
                    TextBoxDescription.Background = Brushes.White;
                    break;

                default:
                    break;
                }

                ButtonEdit.Content = "Save";
            }
            else
            {
                BrushConverter brush = new BrushConverter();
                switch (tableName)
                {
                case "Tasks":
                    using (var db = new TasksDBEntities())
                    {
                        var taskToEdit = db.Tasks.Find(task.TaskID);
                        taskToEdit.Description = TextBoxDescription.Text;
                        taskToEdit.CategoryID  = Convert.ToInt32(TextBoxCategoryID.Text);
                        taskToEdit.UserID      = Convert.ToInt32(TextBoxUserID.Text);
                        db.SaveChanges();
                        ListBox.ItemsSource = null;
                        tasks = db.Tasks.ToList();
                        ListBox.ItemsSource = tasks;
                    }
                    TextBoxDescription.IsReadOnly = true;
                    TextBoxCategoryID.IsReadOnly  = true;
                    TextBoxUserID.IsReadOnly      = true;
                    TextBoxDescription.Background = (Brush)brush.ConvertFrom("#E8D79B");
                    TextBoxCategoryID.Background  = (Brush)brush.ConvertFrom("#E8D79B");
                    TextBoxUserID.Background      = (Brush)brush.ConvertFrom("#E8D79B");
                    break;

                case "Categories":
                    using (var db = new TasksDBEntities())
                    {
                        var categoryToEdit = db.Categories.Find(category.CategoryID);
                        categoryToEdit.CategoryName = TextBoxDescription.Text;
                        db.SaveChanges();
                        ListBox.ItemsSource = null;
                        categories          = db.Categories.ToList();
                        ListBox.ItemsSource = categories;
                    }
                    TextBoxDescription.IsReadOnly = true;
                    TextBoxDescription.Background = (Brush)brush.ConvertFrom("#E8D79B");
                    break;

                case "Users":
                    using (var db = new TasksDBEntities())
                    {
                        var userToEdit = db.Users.Find(user.UserID);
                        userToEdit.UserName = TextBoxDescription.Text;
                        db.SaveChanges();
                        ListBox.ItemsSource = null;
                        users = db.Users.ToList();
                        ListBox.ItemsSource = users;
                    }
                    TextBoxDescription.IsReadOnly = true;
                    TextBoxDescription.Background = (Brush)brush.ConvertFrom("#E8D79B");
                    break;

                default:
                    break;
                }
                ButtonEdit.Content = "Edit";
            }
        }