示例#1
0
 private void buttonSave_Click(object sender, EventArgs e)
 {
     if (check())
     {
         if (_id.HasValue)
         {
             var project = _context.Projects.FirstOrDefault(p => p.ProjectId == _id);
             if (project == null)
             {
                 throw new Exception("При загрузке возникла ошибка");
             }
             project.Title       = textBoxTitle.Text;
             project.Description = textBoxDescription.Text;
         }
         else
         {
             _context.Projects.Add(new Project {
                 ProjectId = Guid.NewGuid(), Title = textBoxTitle.Text, Description = textBoxDescription.Text
             });
             groupBox.Enabled = true;
             tabControl.TabPages.Add(tabPageTasks);
         }
         _context.SaveChanges();
         Close();
     }
 }
示例#2
0
 private void buttonSave_Click(object sender, EventArgs e)
 {
     if (check())
     {
         TaskStatus status;
         Enum.TryParse <TaskStatus>(comboBoxStatus.SelectedValue.ToString(), out status);
         var user = _context.Users.FirstOrDefault(u => u.Login == comboBoxImp.SelectedItem.ToString());
         if (_id.HasValue)
         {
             var task = _context.Tasks.FirstOrDefault(t => t.TaskId == _id);
             if (task == null)
             {
                 throw new Exception("При загрузке возникла ошибка");
             }
             task.Title       = textBoxTitle.Text;
             task.Description = textBoxDescription.Text;
             task.Status      = (int)status;
             task.UserId      = user.UserId;
         }
         else if (first)
         {
             first = false;
             if (_idProject.ToString() != "00000000-0000-0000-0000-000000000000")
             {
                 _context.Tasks.Add(new Model.Task {
                     TaskId = Guid.NewGuid(), Title = textBoxTitle.Text, Description = textBoxDescription.Text, ProjectId = _idProject, UserId = user.UserId, Status = 0
                 });
             }
             else
             {
                 _context.Tasks.Add(new Model.Task {
                     TaskId = Guid.NewGuid(), Title = textBoxTitle.Text, Description = textBoxDescription.Text, SubtaskId = _idSubtask, UserId = user.UserId, Status = 0
                 });
             }
             groupBoxFile.Enabled   = true;
             buttonShowFile.Enabled = false;
             if (!subtask)
             {
                 tabControl1.TabPages.Add(tabPageSubtasks);
             }
         }
         if (user.Email != null)
         {
             SendEmail.SendMessage(user.Email, LetterTemplates.addTask(user.Login, textBoxTitle.Text));
         }
         _context.SaveChanges();
         Close();
     }
 }
示例#3
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (check())
            {
                UserRoles role;
                Enum.TryParse <UserRoles>(comboBoxRole.SelectedValue.ToString(), out role);
                if (_id.HasValue)
                {
                    var user = _context.Users.FirstOrDefault(u => u.UserId == _id);
                    if (user == null)
                    {
                        throw new Exception("При загрузке возникла ошибка");
                    }
                    user.Login    = textBoxLogin.Text;
                    user.Password = textBoxPassword.Text;
                    user.UserRole = (int)role;
                    if (user.Email != null)
                    {
                        SendEmail.SendMessage(user.Email, LetterTemplates.updatePasswordLetter(user.Login));
                    }
                }
                else
                {
                    _context.Users.Add(new User {
                        UserId = Guid.NewGuid(), Login = textBoxLogin.Text, Password = textBoxPassword.Text, IsActive = false, UserRole = (int)role
                    });
                }


                _context.SaveChanges();
                Close();
            }
        }
示例#4
0
        private void buttonSavePassword_Click(object sender, EventArgs e)
        {
            if (check())
            {
                var user = _context.Users.FirstOrDefault(u => u.IsActive == true);
                if (user.Password == textBoxOld.Text)
                {
                    user.Password = textBoxNew.Text;
                    _context.SaveChanges();
                    if (user.Email != null)
                    {
                        SendEmail.SendMessage(user.Email, LetterTemplates.updatePasswordLetter(user.Login));
                    }

                    MessageBox.Show("Успешно!");
                }
            }
            MessageBox.Show("Ошибка!");
        }
示例#5
0
 private void toolStripButtonDel_Click(object sender, EventArgs e)
 {
     if (dataGridViewProjects.SelectedRows.Count == 1)
     {
         Guid id      = new Guid(dataGridViewProjects.SelectedRows[0].Cells[0].Value.ToString());
         var  project = _context.Projects.FirstOrDefault(p => p.ProjectId == id);
         if (project == null)
         {
             throw new Exception("При загрузке возникла ошибка");
         }
         _context.Projects.Remove(project);
         _context.SaveChanges();
     }
     LoadData();
 }
示例#6
0
 private void toolStripButtonDel_Click(object sender, EventArgs e)
 {
     if (dataGridViewUsers.SelectedRows.Count == 1)
     {
         Guid id   = new Guid(dataGridViewUsers.SelectedRows[0].Cells[0].Value.ToString());
         var  user = _context.Users.FirstOrDefault(u => u.UserId == id);
         if (user == null)
         {
             throw new Exception("При загрузке возникла ошибка");
         }
         if (user.IsActive == true)
         {
             MessageBox.Show("Данный пользователь в настоящее время активен");
             return;
         }
         _context.Users.Remove(user);
         _context.SaveChanges();
     }
     LoadData();
 }