Free cookie consent management tool by TermsFeed Policy Generator

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

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

panel for details which shows an image and a close button if details should be closed (#452)

File size: 3.4 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    ResponseList<UserGroup> userGroups = null;
38    IUserRoleManager userRoleManager;
39    bool group;
40
41    public AddUserForm(string addForm, bool group) {
42      this.group = group;
43      InitializeComponent();
44      this.Name = "Add " + addForm;
45
46      lblOne.Text = addForm;
47      if (group) {
48        lblOne.Text += " Group";
49      }
50
51      lblGroup.Text = addForm + " Groups";
52
53      if (addForm == "User") {
54        AddUser();
55      }
56    }
57
58    private void AddUser() {
59     userRoleManager = ServiceLocator.GetUserRoleManager();
60      userGroups = userRoleManager.GetAllUserGroups();
61      cbGroups.Items.Add("none");
62      cbGroups.SelectedIndex = 0;
63      foreach (UserGroup ug in userGroups.List) {
64        cbGroups.Items.Add(ug.Name);
65      }
66    }
67
68    private void BtnAdd_Click(object sender, EventArgs e) {
69      if (!group) {
70        if (tbOne.Text != "") {
71          User u = new User() { Name = tbOne.Text, Password = tbPwd.Text };
72          ResponseObject<User> respUser = userRoleManager.AddNewUser(u);
73          if (respUser.Success == true) {
74            if (cbGroups.SelectedIndex != 0) {
75              u = respUser.Obj;
76              foreach (UserGroup ug in userGroups.List) {
77                if (cbGroups.SelectedItem.ToString().Equals(ug.Name)) {
78                  Response resp = userRoleManager.AddUserToGroup
79                    (ug.Id, u.Id);
80                }
81              }
82            }
83          }
84        }
85      } else {
86        UserGroup ug = new UserGroup { Name = tbOne.Text };
87        ResponseObject<UserGroup> respug = userRoleManager.AddNewUserGroup(ug);
88        if (respug.Success == true) {
89          if (!cbGroups.SelectedText.Equals("none")) {
90            ug = respug.Obj;
91            foreach (UserGroup ugs in userGroups.List) {
92              if (cbGroups.SelectedText.Equals(ugs.Name)) {
93                Response resp = userRoleManager.AddUserGroupToGroup
94                  (ug.Id, ugs.Id);
95              }
96            }
97          }
98        }
99      }
100      this.Close();
101    }
102
103    private void BtnClose_Click(object sender, EventArgs e) {
104      this.Close();
105    }
106  }
107}
Note: See TracBrowser for help on using the repository browser.