using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace RDPManager
{
public partial class frmDisplayMUs : Form
{
public frmDisplayMUs()
{
InitializeComponent();
#if DEBUG
this.Text = this.Text + " *";
#endif
}
private void DisplayMUs_Load(object sender, EventArgs e)
{
LoadListBox();
}
private void btnClose_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
Close();
}
private void btnClear_Click(object sender, EventArgs e)
{
if (lbMUs.SelectedIndex == -1) return;
String selMachName = (String)lbMUs.SelectedItem;
selMachName = selMachName.Substring(selMachName.IndexOf('\t') + 1);
var MUkeys = from MUKey in RdpManager.MostedUsedMachines orderby MUKey.Value descending select new KeyValuePair<Int32, Int32>(MUKey.Key, MUKey.Value);
foreach (KeyValuePair<Int32, Int32> kvp in MUkeys)
{
if (RdpManager.Machines.ContainsKey(kvp.Key) && RdpManager.Machines[kvp.Key].DisplayName == selMachName)
{
RdpManager.MostedUsedMachines.Remove(kvp.Key);
RdpManager.SaveMU();
RdpManager.reloadConfig();
LoadListBox();
break;
}
}
}
private void btnClearAll_Click(object sender, EventArgs e)
{
RdpManager.MostedUsedMachines.Clear();
RdpManager.SaveMU();
RdpManager.reloadConfig();
lbMUs.Items.Clear();
}
private void LoadListBox()
{
lbMUs.Items.Clear();
var MUkeys = from MUKey in RdpManager.MostedUsedMachines orderby MUKey.Value descending select new KeyValuePair<Int32, Int32>(MUKey.Key, MUKey.Value);
foreach (KeyValuePair<Int32, Int32> kvp in MUkeys)
{
// if machine in MU is not in the main machine list, delete it from list. This can happen from removing or changing an entry.
if (RdpManager.Machines.ContainsKey(kvp.Key))
{
lbMUs.Items.Add(String.Format(" {0}\t{1}", RdpManager.MostedUsedMachines[kvp.Key], RdpManager.Machines[kvp.Key].DisplayName));
}
#if DEBUG
else
{
lbMUs.Items.Add(String.Format("{0}\tKey: {1}", RdpManager.MostedUsedMachines[kvp.Key], kvp.Key));
}
#endif
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
EditSelectedEntry();
}
private void lbMUs_MouseDoubleClick(object sender, MouseEventArgs e)
{
EditSelectedEntry();
}
private void EditSelectedEntry()
{
if (lbMUs.SelectedIndex == -1) return;
String selMachName = (String)lbMUs.SelectedItem;
selMachName = selMachName.Substring(selMachName.IndexOf('\t') + 1);
foreach (KeyValuePair<Int32, Int32> kvp in RdpManager.MostedUsedMachines)
{
if (RdpManager.Machines[kvp.Key].DisplayName == selMachName)
{
frmEditConnectionCount dlgConnCount = new frmEditConnectionCount();
dlgConnCount.txtMach.Text = selMachName;
dlgConnCount.txtCount.Text = kvp.Value.ToString();
dlgConnCount.ShowDialog();
int count = System.Convert.ToInt32(dlgConnCount.txtCount.Text);
if (count == 0)
{
RdpManager.MostedUsedMachines.Remove(kvp.Key);
}
else
{
RdpManager.MostedUsedMachines[kvp.Key] = System.Convert.ToInt32(dlgConnCount.txtCount.Text);
}
RdpManager.SaveMU();
RdpManager.reloadConfig();
LoadListBox();
break;
}
}
}
}
}