Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Console/AddNewForm.cs @ 978

Last change on this file since 978 was 978, checked in by aleitner, 16 years ago

Added functionality to AddForm - User can be added to server (#380)

File size: 2.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using HeuristicLab.Hive.Contracts.Interfaces;
10using HeuristicLab.Hive.Contracts.BusinessObjects;
11using HeuristicLab.Hive.Contracts;
12
13namespace HeuristicLab.Hive.Server.Console {
14  public partial class AddNewForm : Form {
15
16    ResponseList<Job> jobGroups = null;
17    ResponseList<UserGroup> userGroups = null;
18    IUserRoleManager userRoleManager;
19    bool group;
20
21    public AddNewForm(string addForm, bool group) {
22      this.group = group;
23      InitializeComponent();
24      this.Name = "Add " + addForm;
25
26      lblOne.Text = addForm;
27      if (group) {
28        lblOne.Text += " Group";
29      }
30
31      lblGroup.Text = addForm + " Groups";
32
33      if (addForm == "Job") {
34        addJob();
35      }
36      if (addForm == "User") {
37        addUser();
38      }
39    }
40
41    private void addJob() {
42      IJobManager jobManager =
43        ServiceLocator.GetJobManager();
44      jobGroups = jobManager.GetAllJobs();
45      cbGroups.Items.Add("none");
46      foreach (UserGroup ug in userGroups.List) {
47        cbGroups.Items.Add(ug.Name);
48      }
49    }
50
51    private void addUser() {
52     userRoleManager = ServiceLocator.GetUserRoleManager();
53      userGroups = userRoleManager.GetAllUserGroups();
54      cbGroups.Items.Add("none");
55      cbGroups.SelectedItem = cbGroups.Items.Count;
56      foreach (UserGroup ug in userGroups.List) {
57        cbGroups.Items.Add(ug.Name);
58      }
59    }
60
61    private void btnAdd_Click(object sender, EventArgs e) {
62      if (!group) {
63        if (tbOne.Text != "") {
64          User u = new User() { Name = tbOne.Text, Password = tbPwd.Text };
65          ResponseObject<User> respUser = userRoleManager.AddNewUser(u);
66          if (!cbGroups.SelectedText.Equals("none")) {
67            u = respUser.Obj;
68            foreach (UserGroup ug in userGroups.List) {
69              if (cbGroups.SelectedItem.ToString().Equals(ug.Name)) {
70                Response resp = userRoleManager.AddUserToGroup
71                  (ug.PermissionOwnerId, u.PermissionOwnerId);
72              }
73            }
74          }
75        }
76      } else {
77        UserGroup ug = new UserGroup { Name = tbOne.Text };
78        ResponseObject<UserGroup> respug = userRoleManager.AddNewUserGroup(ug);
79        if (!cbGroups.SelectedText.Equals("none")) {
80          ug = respug.Obj;
81          foreach (UserGroup ugs in userGroups.List) {
82            if (cbGroups.SelectedText.Equals(ugs.Name)) {
83              Response resp = userRoleManager.AddUserGroupToGroup
84                (ug.PermissionOwnerId, ugs.PermissionOwnerId);
85            }
86          }
87        }
88      }
89    }
90
91    private void btnClose_Click(object sender, EventArgs e) {
92      this.Close();
93    }
94  }
95}
Note: See TracBrowser for help on using the repository browser.