コード例 #1
0
        private void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            if (ButtonDelete.Content.ToString() == "Delete")
            {
                ButtonDelete.Content = "Delected";
                //set booxes to editable
                //TextBoxDescription.Background = Brushes.White;
                //TextBoxCategoryID.Background = Brushes.White;
                //TextBoxDescription.IsReadOnly = false;
                //TextBoxCategoryID.IsReadOnly = false;
                //clear out boxes
                //TextBoxID.Text = "";
                //TextBoxCategoryID.Text = "";
                //TextBoxDescription.Text = "";
            }
            else
            {
                using (var db = new TasksDBEntities())
                {
                    var delete = db.Tasks.Find(task.TasskID);
                    db.Tasks.Remove(delete);



                    //update recode in database
                    db.SaveChanges();
                    ListBoxTasks.ItemsSource = null; //rest list box
                    tasks = db.Tasks.ToList();       //get fresh list
                    ListBoxTasks.ItemsSource = tasks;
                }
            }
        }
コード例 #2
0
        //void InitialiseListBoxOfStrings()
        //{

        //   ListBoxTasks.ItemsSource = items;

        //    using(var db = new TasksDBEntities())
        //    {


        //        tasks = db.Tasks.ToList();

        //    }
        //    // get the description and add to list
        //    foreach (var item in tasks)
        //    {
        //        items.Add($"{item.TaskId,-10}{item.Description,-40}{item.Done,-10}{item.DateCompleted}");
        //    }
        //}

        void Initialise()
        {
            using (var db = new TasksDBEntities())
            {
                tasks      = db.Tasks.ToList();
                categories = db.Categories.ToList();
            }
            ListBoxTasks.ItemsSource           = tasks;
            ListBoxTasks.DisplayMemberPath     = "Description";
            ComboBoxCategory.ItemsSource       = categories;
            ComboBoxCategory.DisplayMemberPath = "CategroyName";
        }
コード例 #3
0
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            if (ButtonAdd.Content.ToString() == "Add")
            {
                ButtonAdd.Content = "Confirm";

                // Set boxes to editable
                TextBoxDescription.IsReadOnly = false;
                TextBoxCategoryID.IsReadOnly  = false;
                TextBoxDescription.Background = Brushes.White;
                TextBoxCategoryID.Background  = Brushes.White;

                // Clear out boxes
                TextBoxID.Text          = "";
                TextBoxCategoryID.Text  = "";
                TextBoxDescription.Text = "";
            }
            else
            {
                ButtonAdd.Content = "Add";
                // Set boxes to Readonly
                TextBoxDescription.IsReadOnly = true;
                TextBoxCategoryID.IsReadOnly  = true;
                TextBoxDescription.Background = Brushes.White;
                TextBoxCategoryID.Background  = Brushes.White;

                var brush = new BrushConverter();

                TextBoxDescription.Background = (Brush)brush.ConvertFrom("#EEFAFF");
                TextBoxCategoryID.Background  = (Brush)brush.ConvertFrom("#EEFAFF");;
                TextBoxID.Background          = (Brush)brush.ConvertFrom("#EEFAFF");

                // Update description and CategoryID
                int.TryParse(TextBoxCategoryID.Text, out int categoryID);

                var taskToAdd = new Task()
                {
                    Description = TextBoxDescription.Text,
                    CategoryID  = categoryID
                };


                using (var db = new TasksDBEntities())
                {
                    db.Tasks.Add(taskToAdd);
                    db.SaveChanges();
                    ListBoxTasks.ItemsSource = null;
                    tasks = db.Tasks.ToList();
                    ListBoxTasks.ItemsSource = tasks;
                }
            }
        }
コード例 #4
0
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            if (ButtonAdd.Content.ToString() == "Add")
            {
                //set boxes to editable
                ButtonAdd.Content             = "Confirm";
                TextBoxDescription.Background = Brushes.White;
                CategoryID.Background         = Brushes.White;

                TextBoxDescription.IsReadOnly = false;
                CategoryID.IsReadOnly         = false;
                //clear out boxes
                TextBoxID.Text          = " ";
                TextBoxDescription.Text = " ";
                CategoryID.Text         = " ";
            }
            else
            {
                ButtonAdd.Content             = "Add";
                TextBoxDescription.IsReadOnly = true;
                CategoryID.IsReadOnly         = true;
                var brush = new BrushConverter();
                TextBoxDescription.Background = (Brush)brush.ConvertFrom("#E8FBFF");
                CategoryID.Background         = (Brush)brush.ConvertFrom("#E8FBFF");

                using (var db = new TasksDBEntities())
                {
                    Task newTask = new Task
                    {
                        Description = TextBoxDescription.Text,
                        CategoryId  = Convert.ToInt32(CategoryID.Text)
                    };

                    db.Tasks.Add(newTask);

                    // save to database
                    db.SaveChanges();

                    ListBoxTasks.ItemsSource = null;  //  reset list box
                    tasks = db.Tasks.ToList();        // get fresh link

                    ListBoxTasks.ItemsSource = tasks; // re-link
                }
                ButtonAdd.Content             = "Add";
                TextBoxDescription.IsReadOnly = true;
                CategoryID.IsReadOnly         = true;
                brush = new BrushConverter();
                TextBoxDescription.Background = (Brush)brush.ConvertFrom("#E8FBFF");
                CategoryID.Background         = (Brush)brush.ConvertFrom("#E8FBFF");
            }
        }
コード例 #5
0
        private void ButtonEdit_Click(object sender, RoutedEventArgs e)
        {
            if (ButtonEdit.Content.ToString() == "Edit")
            {
                TextBoxDescription.IsReadOnly = false;
                CategoryID.IsReadOnly         = false;
                ButtonEdit.Content            = "Save";
                TextBoxDescription.Background = Brushes.White;
                CategoryID.Background         = Brushes.White;
            }
            else
            {
                using (var db = new TasksDBEntities())
                {
                    var taskToEdit = db.Tasks.Find(task.TaskId);
                    // update description & categoryId
                    taskToEdit.Description = TextBoxDescription.Text;

                    //converting categoryid to integer from text box (string)
                    // tryparse is a safe way to do conversion: null if fails
                    int.TryParse(CategoryID.Text, out int categoryid);
                    taskToEdit.CategoryId = categoryid;

                    if (task.CategoryId != null)
                    {
                        ComboBoxCategory.SelectedIndex = (int)task.CategoryId - 1;
                    }
                    else
                    {
                        ComboBoxCategory.SelectedItem = null;
                    }
                    // save to database
                    db.SaveChanges();

                    ListBoxTasks.ItemsSource = null;  //  reset list box
                    tasks = db.Tasks.ToList();        // get fresh link

                    ListBoxTasks.ItemsSource = tasks; // re-link
                }
                ButtonEdit.Content            = "Edit";
                ButtonEdit.IsEnabled          = false;
                TextBoxDescription.IsReadOnly = true;
                CategoryID.IsReadOnly         = true;
                var brush = new BrushConverter();
                TextBoxDescription.Background = (Brush)brush.ConvertFrom("#E8FBFF");
                CategoryID.Background         = (Brush)brush.ConvertFrom("#E8FBFF");
            }
        }
コード例 #6
0
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            if (ButtonAdd.Content.ToString() == "Add")
            {
                ButtonAdd.Content = "Confirm";
                //set booxes to editable
                TextBoxDescription.Background = Brushes.White;
                TextBoxCategoryID.Background  = Brushes.White;
                TextBoxDescription.IsReadOnly = false;
                TextBoxCategoryID.IsReadOnly  = false;
                //clear out boxes
                TextBoxID.Text          = "";
                TextBoxCategoryID.Text  = "";
                TextBoxDescription.Text = "";
            }
            else
            {
                ButtonAdd.Content = "Add";
                //set booxes to editable
                TextBoxDescription.Background = Brushes.White;
                TextBoxCategoryID.Background  = Brushes.White;
                TextBoxDescription.IsReadOnly = true;
                TextBoxCategoryID.IsReadOnly  = true;

                int.TryParse(TextBoxCategoryID.Text, out int categoryID);

                var taskToAdd = new Task()
                {
                    Description = TextBoxDescription.Text,
                    CategoryID  = categoryID
                };
                //clear out boxes
                using (var db = new TasksDBEntities())
                {
                    db.Tasks.Add(taskToAdd);



                    //update recode in database
                    db.SaveChanges();
                    ListBoxTasks.ItemsSource = null; //rest list box
                    tasks = db.Tasks.ToList();       //get fresh list
                    ListBoxTasks.ItemsSource = tasks;
                }
            }
        }
コード例 #7
0
        //void InitialiseListBoxOfStrings()
        //{
        //    ListBoxTasks.ItemsSource = items;
        //    using (var db = new TasksDBEntities())
        //    {
        //        tasks = db.Tasks.ToList();
        //    }
        //    // get description and add to list
        //    foreach(var item in tasks)
        //    {
        //        items.Add($"{item.TaskID,-10}{item.Description,-40}{item.Done,-10}{item.DateCompleted}");
        //    }
        //}
        #endregion
        #region InitialiseApplication
        void Initialise()
        {
            using (var db = new TasksDBEntities())
            {
                tasks      = db.Tasks.ToList();
                categories = db.Categories.ToList();
            }
            ListBoxTasks.ItemsSource           = tasks;
            ListBoxTasks.DisplayMemberPath     = "Description";
            ComboBoxCategory.ItemsSource       = categories;
            ComboBoxCategory.DisplayMemberPath = "CategoryName";


            // Inner Join
            using (var db = new TasksDBEntities())
            {
                // task but it has a CATEGORYID.  INNER JOIN => CATEGORYNAME
                var taskList =
                    from task in db.Tasks
                    join category in db.Categories on
                    task.CategoryID equals category.CategoryId
                    // HAVE TO CREATE A NEW OUTPUT OBJECT (CUSTOM)
                    //select new
                    //{
                    //    taskID = task.TaskID,
                    //    description = task.Description,
                    //    category = category.CategoryName.
                    //};
                    // make new instance of our custom class
                    select new TaskWithCategory()
                {
                    TaskId = task.TaskID
                };
                // add to list
                taskswithcategories = taskList.ToList();
                // PRINT LIST
                foreach (var task in taskList.ToList())
                {
                    //System.Diagnostics.Trace.WriteLine($"{task.taskID,-10}{task.description,-20}{task.category}");
                }
            }
        }
コード例 #8
0
        private void ButtonEdit_Click(object sender, EventArgs e)
        {
            if (ButtonEdit.Content.ToString() == "Edit")
            {
                TextBoxDescription.IsReadOnly = false;
                TextBoxCategoryID.IsReadOnly  = false;
                ButtonEdit.Content            = "Save";
            }
            else
            {
                using (var db = new TasksDBEntities())
                {
                    var tasktoEdit = db.Tasks.Find(task.TasskID);
                    //update description & categorieID
                    tasktoEdit.Description = TextBoxDescription.Text;

                    //converting category id to interher from text box (string)
                    //tryparse is a safe way to do conversion : null i fails
                    int.TryParse(TextBoxCategoryID.Text, out int categoryID);
                    tasktoEdit.CategoryID = categoryID;

                    //update recode in database
                    db.SaveChanges();
                    ListBoxTasks.ItemsSource = null; //rest list box
                    tasks = db.Tasks.ToList();       //get fresh list
                    ListBoxTasks.ItemsSource = tasks;
                }

                ButtonEdit.Content            = "Edit";
                ButtonEdit.IsEnabled          = false;
                TextBoxDescription.IsReadOnly = true;
                TextBoxCategoryID.IsReadOnly  = true;

                var brush = new BrushConverter();



                TextBoxDescription.Background = (Brush)brush.ConvertFrom("#EEFAFF");
                TextBoxCategoryID.Background  = (Brush)brush.ConvertFrom("#EEFAFF");;
                TextBoxID.Background          = (Brush)brush.ConvertFrom("#EEFAFF");
            }
        }
コード例 #9
0
        private void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            if (ButtonDelete.Content.ToString() == "Delete")
            {
                ButtonDelete.Content          = "Are You Sure?";
                TextBoxDescription.Background = Brushes.White;
                CategoryID.Background         = Brushes.White;
                TextBoxDescription.IsReadOnly = false;
                CategoryID.IsReadOnly         = false;
                TextBoxID.Background          = Brushes.Red;
                TextBoxDescription.Background = Brushes.Red;
                CategoryID.Background         = Brushes.Red;
            }
            else
            {
                using (var db = new TasksDBEntities())
                {
                    var taskToDelete = db.Tasks.Find(task.TaskId);
                    db.Tasks.Remove(taskToDelete);

                    db.SaveChanges();

                    ListBoxTasks.ItemsSource = null;     //  reset list box
                    tasks = db.Tasks.ToList();           // get fresh link

                    ListBoxTasks.ItemsSource = tasks;    // re-link
                }

                ButtonDelete.Content    = "Delete";
                ButtonDelete.IsEnabled  = false;
                TextBoxID.Text          = " ";
                TextBoxDescription.Text = " ";
                CategoryID.Text         = " ";
                var brush = new BrushConverter();
                TextBoxID.Background          = (Brush)brush.ConvertFrom("#E8FBFF");
                TextBoxDescription.Background = (Brush)brush.ConvertFrom("#E8FBFF");
                CategoryID.Background         = (Brush)brush.ConvertFrom("#E8FBFF");
            }
        }
コード例 #10
0
        private void ButtonEdit_Click(object sender, RoutedEventArgs e)
        {
            if (ButtonEdit.Content.ToString() == "Edit")
            {
                TextBoxDescription.IsReadOnly = false;
                TextBoxCategoryID.IsReadOnly  = false;
                ButtonEdit.Content            = "Save";
                TextBoxDescription.Background = Brushes.White;
                TextBoxCategoryID.Background  = Brushes.White;
                TextBoxID.Background          = Brushes.White;
            }
            else
            {
                using (var db = new TasksDBEntities())
                {
                    var taskToEdit = db.Tasks.Find(task.TaskID);
                    // Update description and CategoryID
                    taskToEdit.Description = TextBoxDescription.Text;
                    int.TryParse(TextBoxCategoryID.Text, out int categotyID);
                    taskToEdit.CategoryID = categotyID;
                    db.SaveChanges();

                    // Update List Box
                    ListBoxTasks.ItemsSource = null; // Reset the listbox
                    tasks = db.Tasks.ToList();       // Get fresh list
                    ListBoxTasks.ItemsSource = tasks;
                }
                ButtonEdit.Content            = "Edit";
                ButtonEdit.IsEnabled          = false;
                TextBoxDescription.IsReadOnly = true;
                TextBoxCategoryID.IsReadOnly  = true;

                var brush = new BrushConverter();

                TextBoxDescription.Background = (Brush)brush.ConvertFrom("#EEFAFF");
                TextBoxCategoryID.Background  = (Brush)brush.ConvertFrom("#EEFAFF");;
                TextBoxID.Background          = (Brush)brush.ConvertFrom("#EEFAFF");
            }
        }
コード例 #11
0
 private void ButtonDelete_Click(object sender, RoutedEventArgs e)
 {
     if (ButtonDelete.Content.ToString() == "Delete")
     {
         ButtonDelete.Content          = "Are You Sure?";
         TextBoxId.Background          = Brushes.OrangeRed;
         TextBoxDescription.Background = Brushes.OrangeRed;
         TextBoxCategoryId.Background  = Brushes.OrangeRed;
     }
     else
     {
         if (task != null)
         {
             using (var db = new TasksDBEntities())
             {
                 var taskToRemove = db.Tasks.Find(task.TaskID);
                 db.Tasks.Remove(taskToRemove);
                 db.SaveChanges();
                 // update list
                 ListBoxTasks.ItemsSource = null;
                 tasks = db.Tasks.ToList();
                 ListBoxTasks.ItemsSource = tasks;
             }
         }
         ButtonDelete.Content          = "Delete";
         TextBoxDescription.IsReadOnly = true;
         TextBoxCategoryId.IsReadOnly  = true;
         var brush = new BrushConverter();
         TextBoxId.Background          = (Brush)brush.ConvertFrom("#EEFAFF");
         TextBoxDescription.Background = (Brush)brush.ConvertFrom("#EEFAFF");
         TextBoxCategoryId.Background  = (Brush)brush.ConvertFrom("#EEFAFF");
         // clear out boxes
         TextBoxId.Text          = "";
         TextBoxDescription.Text = "";
         TextBoxCategoryId.Text  = "";
     }
 }
コード例 #12
0
        public void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            if (ButtonDelete.Content.ToString() == "Delete")
            {
                ButtonDelete.Content = "Confirm";

                // Set boxes to editable
                TextBoxDescription.IsReadOnly = false;
                TextBoxCategoryID.IsReadOnly  = false;

                TextBoxDescription.Background = Brushes.Red;
                TextBoxCategoryID.Background  = Brushes.Red;
            }
            else
            {
                using (var db = new TasksDBEntities())
                {
                    var delete = db.Tasks.Find(task.TaskID);
                    db.Tasks.Remove(delete);


                    db.SaveChanges();
                    ListBoxTasks.ItemsSource = null;
                    tasks = db.Tasks.ToList();
                    ListBoxTasks.ItemsSource = tasks;
                }
                ButtonDelete.Content   = "Delete";
                ButtonDelete.IsEnabled = false;
                // Clear out boxes
                TextBoxID.Text                = "";
                TextBoxCategoryID.Text        = "";
                TextBoxDescription.Text       = "";
                TextBoxDescription.Background = Brushes.White;
                TextBoxCategoryID.Background  = Brushes.White;
            }
        }