public void OnSessionButtonClick(Dictionary <string, string> session)
        {
            // determine whether the session is connected or not
            // so we know what to do with it.
            if (session["connected"] == "false")
            {
                foreach (UserControl c in ContentWindowTabs.Children)
                {
                    c.Visibility = Visibility.Hidden;
                }

                AddConnectionForm acf = (AddConnectionForm)FindName("EditSessionFormID_" + session["name"]);
                acf.Visibility = Visibility.Visible;
            }
        }
        public void createNewSession(string name, string host, string port, string lusername)
        {
            // load the data into a dataset for easy retrival.
            Dictionary <string, string> newSession = new Dictionary <string, string>();

            newSession["name"]           = name;
            newSession["host"]           = host;
            newSession["port"]           = port;
            newSession["lusername"]      = lusername;
            newSession["connected"]      = "false";
            sessList[newSession["name"]] = newSession;

            // create some xaml objects, buttons etc.
            Button    btn  = new Button();
            Grid      grid = new Grid();
            TextBlock tb1  = new TextBlock();
            TextBlock tb2  = new TextBlock();

            // fill the textboxes in etc
            tb1.Text = newSession["name"];
            tb2.Text = newSession["host"];
            tb2.HorizontalAlignment = HorizontalAlignment.Right;

            // style the button and some other stuff
            btn.Style             = (Style)FindResource("LeftBarConnButtonRed");
            btn.VerticalAlignment = VerticalAlignment.Top;
            LayoutRoot.RegisterName("SessionButtonID_" + name, grid);

            // handle the click event for the button
            btn.Click += (o, e) => OnSessionButtonClick(sessList[newSession["name"]]);

            // add the button to the stack panel
            grid.Children.Add(tb1);
            grid.Children.Add(tb2);
            btn.Content = grid;
            ConnectionStackPanel.Children.Add(btn);

            // create a edit connection form
            AddConnectionForm acf = new AddConnectionForm();

            acf.AssignSessionToForm(sessList[newSession["name"]]);
            acf.Visibility = Visibility.Hidden;

            // assign a name to it and add it to the layout
            LayoutRoot.RegisterName("EditSessionFormID_" + name, acf);
            ContentWindowTabs.Children.Add(acf);
        }
        public void updateSession(Dictionary <string, string> session, string name, string host, string port, string lusername)
        {
            // determine if we can find the session first.
            if (!sessList.ContainsValue(session))
            {
                return;
            }

            // load the data into a dataset for easy retrival.
            Dictionary <string, string> newSession = new Dictionary <string, string>();

            newSession["name"]      = name;
            newSession["host"]      = host;
            newSession["port"]      = port;
            newSession["lusername"] = lusername;
            newSession["connected"] = "false";
            sessList.Remove(session["name"]);
            sessList[name] = newSession;

            // update the element on screen
            Grid btnGrid          = (Grid)FindName("SessionButtonID_" + session["name"]);
            AddConnectionForm acf = (AddConnectionForm)FindName("EditSessionFormID_" + session["name"]);

            foreach (TextBlock tb in btnGrid.Children)
            {
                MessageBox.Show(tb.Text);
                if (tb.Text == session["name"])
                {
                    tb.Text = name;
                }
                else if (tb.Text == session["host"])
                {
                    tb.Text = host;
                }
            }

            // update element ids etc
            LayoutRoot.UnregisterName("SessionButtonID_" + session["name"]);
            LayoutRoot.UnregisterName("EditSessionFormID_" + session["name"]);
            LayoutRoot.RegisterName("SessionButtonID_" + name, btnGrid);
            LayoutRoot.RegisterName("EditSessionFormID_" + name, acf);
            acf.AssignSessionToForm(newSession);

            databaseSave();
        }
        public void createNewSession(string name, string host, string port, string lusername)
        {
            // load the data into a dataset for easy retrival.
            Dictionary<string, string> newSession = new Dictionary<string, string>();
            newSession["name"] = name;
            newSession["host"] = host;
            newSession["port"] = port;
            newSession["lusername"] = lusername;
            newSession["connected"] = "false";
            sessList[newSession["name"]] = newSession;

            // create some xaml objects, buttons etc.
            Button btn = new Button();
            Grid grid = new Grid();
            TextBlock tb1 = new TextBlock();
            TextBlock tb2 = new TextBlock();

            // fill the textboxes in etc
            tb1.Text = newSession["name"];
            tb2.Text = newSession["host"];
            tb2.HorizontalAlignment = HorizontalAlignment.Right;

            // style the button and some other stuff
            btn.Style = (Style) FindResource("LeftBarConnButtonRed");
            btn.VerticalAlignment = VerticalAlignment.Top;
            LayoutRoot.RegisterName("SessionButtonID_" + name, grid);

            // handle the click event for the button
            btn.Click += (o, e) => OnSessionButtonClick(sessList[newSession["name"]]);

            // add the button to the stack panel
            grid.Children.Add(tb1);
            grid.Children.Add(tb2);
            btn.Content = grid;
            ConnectionStackPanel.Children.Add(btn);

            // create a edit connection form
            AddConnectionForm acf = new AddConnectionForm();
            acf.AssignSessionToForm(sessList[newSession["name"]]);
            acf.Visibility = Visibility.Hidden;

            // assign a name to it and add it to the layout
            LayoutRoot.RegisterName("EditSessionFormID_" + name, acf);
            ContentWindowTabs.Children.Add(acf);
        }