1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Data;
|
---|
5 | using System.Drawing;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Windows.Forms;
|
---|
9 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
10 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
11 | using HeuristicLab.Hive.Contracts;
|
---|
12 |
|
---|
13 | namespace 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.Id, u.Id);
|
---|
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.Id, ugs.Id);
|
---|
85 | }
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | private void btnClose_Click(object sender, EventArgs e) {
|
---|
92 | this.Close();
|
---|
93 | }
|
---|
94 | }
|
---|
95 | }
|
---|