using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Phidgets;
using Phidgets.Events;

namespace ManagerTest
{
    public partial class Form1 : Form
    {
        Phidgets.Manager manager;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender1, EventArgs e1)
        {
            manager = new Phidgets.Manager();
            manager.Attach+= delegate(object sender, AttachEventArgs e) 
                { addDevice(new String[] { e.Device.Name, "" + e.Device.SerialNumber, "" + e.Device.Version, e.Device.Tag }); };
            manager.Detach += delegate(object sender, DetachEventArgs e)
                { removeDevice(new String[] { e.Device.Name, "" + e.Device.SerialNumber, "" + e.Device.Version, e.Device.Tag }); };
            manager.start();
        }

        public void addDevice(String[] data)
        {
            dataTable.Rows.Add(data);
        }

        public void removeDevice(String[] data)
        {
            foreach (DataGridViewRow row in dataTable.Rows)
            {
                int j;
                for (j = 0; j < 3; j++)
                {
                    if (!row.Cells[j].Value.Equals(data[j]))
                        break;
                }
                if (j == 3)
                {
                    dataTable.Rows.Remove(row);
                    return;
                }
            }

        }
    }
}