Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/22/10 05:54:13 (14 years ago)
Author:
swagner
Message:

Worked on OKB (#1174)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/OKB/HeuristicLab.Clients.OKB-3.3/Views/AlgorithmView.cs

    r4441 r4466  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
    2224using System.Linq;
    2325using System.Windows.Forms;
    2426using HeuristicLab.MainForm;
    2527using HeuristicLab.MainForm.WindowsForms;
     28using System.IO;
    2629
    2730namespace HeuristicLab.Clients.OKB {
     
    4245      platformComboBox.DataSource = Administrator.Instance.Platforms.ToList();
    4346      algorithmClassComboBox.DataSource = Administrator.Instance.AlgorithmClasses.ToList();
     47      dataTypeComboBox.DataSource = Administrator.Instance.DataTypes.ToList();
    4448    }
    4549
     
    6266        algorithmClassComboBox.SelectedItem = Administrator.Instance.AlgorithmClasses.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
    6367      }
     68      usersListBox.DataSource = null;
     69      fileTextBox.Text = "";
     70      dataTypeComboBox.SelectedIndex = -1;
    6471    }
    6572
     
    6875      platformComboBox.Enabled = Content != null;
    6976      algorithmClassComboBox.Enabled = Content != null;
     77      refreshUsersButton.Enabled = Content != null;
     78      storeUsersButton.Enabled = usersListBox.DataSource != null;
     79      usersListBox.Enabled = usersListBox.DataSource != null;
     80      storeDataButton.Enabled = !string.IsNullOrEmpty(fileTextBox.Text) && dataTypeComboBox.SelectedIndex != -1;
    7081    }
    7182
     
    93104      }
    94105    }
     106
     107    private void refreshUsersButton_Click(object sender, System.EventArgs e) {
     108      Guid[] ids = Administrator.Instance.GetAlgorithmUsers(Content.Id);
     109      if (ids != null) {
     110        List<User> users = Administrator.Instance.Users.ToList();
     111        usersListBox.DataSource = users;
     112        usersListBox.DisplayMember = "Name";
     113        usersListBox.SelectedItems.Clear();
     114        foreach (Guid id in ids)
     115          usersListBox.SelectedItems.Add(users.First(u => u.Id == id));
     116        usersListBox.Enabled = true;
     117        storeUsersButton.Enabled = false;
     118      }
     119    }
     120    private void storeUsersButton_Click(object sender, System.EventArgs e) {
     121      if (Administrator.Instance.StoreAlgorithmUsers(Content.Id, usersListBox.SelectedItems.Cast<User>().Select(u => u.Id).ToArray()))
     122        storeUsersButton.Enabled = false;
     123    }
     124    private void usersListBox_SelectedIndexChanged(object sender, EventArgs e) {
     125      storeUsersButton.Enabled = true;
     126    }
     127
     128    private void storeDataButton_Click(object sender, EventArgs e) {
     129      AlgorithmData data = new AlgorithmData();
     130      data.AlgorithmId = Content.Id;
     131      data.DataTypeId = ((DataType)dataTypeComboBox.SelectedItem).Id;
     132
     133      using (FileStream stream = new FileStream(fileTextBox.Text, FileMode.Open, FileAccess.Read)) {
     134        byte[] bytes = new byte[stream.Length];
     135        stream.Read(bytes, 0, bytes.Length);
     136        stream.Close();
     137        data.Data = bytes;
     138      }
     139
     140      if (Administrator.Instance.StoreAlgorithmData(data))
     141        storeDataButton.Enabled = false;
     142    }
     143    private void openFileButton_Click(object sender, EventArgs e) {
     144      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
     145        fileTextBox.Text = openFileDialog.FileName;
     146        storeDataButton.Enabled = true;
     147      }
     148    }
     149    private void dataTypeComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     150      storeDataButton.Enabled = !string.IsNullOrEmpty(fileTextBox.Text);
     151    }
    95152  }
    96153}
Note: See TracChangeset for help on using the changeset viewer.