Esempio n. 1
0
        private void saveBtn_Click(object sender, RoutedEventArgs e)
        {
            if (ListOfTasks.SelectedItems.Count == 0)
            {
                MessageBox.Show("Сначала выберите задачу!");
                return;
            }

            LastSelectedTask.Name        = taskNameTB.Text;
            LastSelectedTask.Description = descriptionTB.Text;
            LastSelectedTask.DueDate     = dueDateDP.SelectedDate;

            using (TaskListDB db = new TaskListDB())
            {
                if (Convert.ToInt32(assignedCB.SelectedValue) != user.ID)
                {
                    DB.Task task = new DB.Task();
                    task.Name        = LastSelectedTask.Name;
                    task.IDFrom      = LastSelectedTask.IDFrom;
                    task.IDTo        = Convert.ToInt32(assignedCB.SelectedValue);
                    task.IsActive    = LastSelectedTask.IsActive;
                    task.IsCompleted = LastSelectedTask.IsCompleted;
                    task.DueDate     = LastSelectedTask.DueDate;
                    task.Description = LastSelectedTask.Description;

                    db.Entry(LastSelectedTask).State = System.Data.Entity.EntityState.Deleted;
                    db.Tasks.Add(task);
                }
                else
                {
                    db.Entry(LastSelectedTask).State = System.Data.Entity.EntityState.Modified;
                }
                db.SaveChanges();
            }
            UpdateLastList();
        }
Esempio n. 2
0
        private void isCompletedBtn_Click(object sender, RoutedEventArgs e)
        {
            if (ListOfTasks.SelectedItems.Count == 0)
            {
                MessageBox.Show("Сначала выберите задачу!");
                return;
            }

            using (TaskListDB db = new TaskListDB())
            {
                LastSelectedTask.IsCompleted     = !LastSelectedTask.IsCompleted;
                db.Entry(LastSelectedTask).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            UpdateLastList();
        }
Esempio n. 3
0
        private void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            if (LoginTB.Text.Length == 0 || PasswordTB.Text.Length == 0 || FirstNameTB.Text.Length == 0 || LastNameTB.Text.Length == 0)
            {
                MessageBox.Show("Все поля должны быть заполнены!");
                return;
            }

            using (TaskListDB db = new TaskListDB())
            {
                if (db.Users.Where(u => u.Login == LoginTB.Text && u.ID != user.ID).FirstOrDefault() != null)
                {
                    MessageBox.Show("Придумайте другой логин, пользователь с таким логином уже существует!");
                    return;
                }

                user.Login     = LoginTB.Text;
                user.Password  = PasswordTB.Text;
                user.FirstName = FirstNameTB.Text;
                user.LastName  = LastNameTB.Text;

                if (isUpdating)
                {
                    db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    db.Users.Add(user);
                }

                db.SaveChanges();
            }

            MessageBox.Show("Успешно!");
            if (isUpdating)
            {
                NavigationService.Content = new MenuPage(user);
            }
            else
            {
                NavigationService.GoBack();
            }
        }
Esempio n. 4
0
        private void deleteBtn_Click(object sender, RoutedEventArgs e)
        {
            if (ListOfTasks.SelectedItems.Count == 0)
            {
                MessageBox.Show("Сначала выберите задачу!");
                return;
            }

            using (TaskListDB db = new TaskListDB())
            {
                db.Entry(LastSelectedTask).State = System.Data.Entity.EntityState.Deleted;
                db.SaveChanges();
            }
            UpdateLastList();

            taskNameTB.Text        = "";
            dueDateDP.SelectedDate = null;
            descriptionTB.Text     = "";

            using (TaskListDB db = new TaskListDB())
            {
                assignedCB.SelectedValue = user.ID;
            }
        }