Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Console/3.2/AddUserForm.cs @ 2908

Last change on this file since 2908 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Data;
26using System.Drawing;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.Hive.Contracts.Interfaces;
31using HeuristicLab.Hive.Contracts.BusinessObjects;
32using HeuristicLab.Hive.Contracts;
33
34namespace HeuristicLab.Hive.Server.ServerConsole {
35  public partial class AddUserForm : Form {
36
37    public event addDelegate addUserEvent;
38    ResponseList<UserGroup> userGroups = null;
39    IUserRoleManager userRoleManager;
40    bool group;
41
42    public AddUserForm(string addForm, bool group) {
43      this.group = group;
44      InitializeComponent();
45      this.Name = "Add " + addForm;
46
47      lblOne.Text = addForm;
48      if (group) {
49        lblOne.Text += " Group";
50      }
51
52      lblGroup.Text = addForm + " Groups";
53
54      if (addForm == "User") {
55        AddUser();
56      }
57    }
58
59    private void AddUser() {
60     userRoleManager = ServiceLocator.GetUserRoleManager();
61      userGroups = userRoleManager.GetAllUserGroups();
62      cbGroups.Items.Add("none");
63      cbGroups.SelectedIndex = 0;
64      foreach (UserGroup ug in userGroups.List) {
65        cbGroups.Items.Add(ug.Name);
66      }
67    }
68
69    private void BtnAdd_Click(object sender, EventArgs e) {
70      if (!group) {
71        if (tbOne.Text != "") {
72          User u = new User() { Name = tbOne.Text, Password = tbPwd.Text };
73          ResponseObject<User> respUser = userRoleManager.AddNewUser(u);
74          if (respUser.Success == true) {
75            if (cbGroups.SelectedIndex != 0) {
76              u = respUser.Obj;
77              foreach (UserGroup ug in userGroups.List) {
78                if (cbGroups.SelectedItem.ToString().Equals(ug.Name)) {
79                  Response resp = userRoleManager.AddUserToGroup
80                    (ug.Id, u.Id);
81                }
82              }
83            }
84          }
85        }
86      } else {
87        UserGroup ug = new UserGroup { Name = tbOne.Text };
88        ResponseObject<UserGroup> respug = userRoleManager.AddNewUserGroup(ug);
89        if (respug.Success == true) {
90          if (!cbGroups.SelectedText.Equals("none")) {
91            ug = respug.Obj;
92            foreach (UserGroup ugs in userGroups.List) {
93              if (cbGroups.SelectedText.Equals(ugs.Name)) {
94                Response resp = userRoleManager.AddUserGroupToGroup
95                  (ug.Id, ugs.Id);
96              }
97            }
98          }
99        }
100      }
101      if (addUserEvent != null) {
102        addUserEvent();
103      }
104      this.Close();
105    }
106
107    private void BtnClose_Click(object sender, EventArgs e) {
108      this.Close();
109    }
110  }
111}
Note: See TracBrowser for help on using the repository browser.