private void dicoTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            PDODictionaryEntry selected = (PDODictionaryEntry)e.Node.Tag;

            if (e.Node.Parent == null)
            {
                IndexValue.Value    = selected.Index;
                SubIndexValue.Value = -1;
            }
            else
            {
                SubIndexValue.Value = selected.Index;
                selected            = (PDODictionaryEntry)e.Node.Parent.Tag;
                IndexValue.Value    = selected.Index;
            }
        }
        public static List <PDODictionaryEntry> GetDictionary(String DatabaseName, EthCATDevice slave)
        {
            string connectionString = "Data Source=" + DatabaseName;

            System.Data.SqlServerCe.SqlCeConnection con = new System.Data.SqlServerCe.SqlCeConnection(connectionString);
            try
            {
                con.Open();

                int databaseid = DeviceDescrProvider.GetSlaveDatabaseId(con, slave._ManufacturerId, slave._TypeId, slave.Revision);
                if (databaseid == -1)
                {
                    return(null);
                }

                List <PDODictionaryEntry> ret = new List <PDODictionaryEntry>();

                string          command = "SELECT * FROM PDO_Dictionary WHERE SlaveId=" + databaseid.ToString();
                SqlCeCommand    cmd     = new SqlCeCommand(command, con);
                SqlCeDataReader reader  = cmd.ExecuteReader();

                while (reader.Read())
                {
                    string FinalType = GetFinalType(con, databaseid, (string)reader[4]);
                    // At this level RW is unknow (not in the XML file)
                    PDODictionaryEntry e = new PDODictionaryEntry(Convert.ToInt32(reader[1]), Convert.ToUInt32(reader[2]),
                                                                  (string)reader[3], FinalType, PDOAccessLevel.Unknow);
                    ret.Add(e);
                    e.AddSubIndexData(con, databaseid);
                }
                con.Close();

                return(ret);
            }
            catch
            {
                Trace.WriteLine("Database content Error");
            }

            return(null);
        }
        public ReadWritePDO(EthCATDevice slave)
        {
            this.slave = slave;
            InitializeComponent();
            lbldevice.Text = slave.ToString();

            // Get the dictionnary if exist
            List <PDODictionaryEntry> dico = PDODictionaryEntry.GetDictionary(Properties.Settings.Default.DatabaseFile, slave);

            // Fill the Treeview with it
            if (dico != null)
            {
                foreach (PDODictionaryEntry entry in dico)
                {
                    string name = entry.ToString();
                    if (Properties.Settings.Default.ShowSDOIdx)
                    {
                        name = name + " (x" + entry.Index.ToString("X4") + ")";
                    }
                    TreeNode tn = new TreeNode(name);
                    tn.Tag = entry;
                    tn.SelectedImageIndex = tn.ImageIndex = Type2ico(entry.type);

                    dicoTree.Nodes.Add(tn);

                    int ro = 0, rw = 0;

                    if (entry.SubIdx != null)
                    {
                        foreach (PDODictionaryEntry entry2 in entry.SubIdx)
                        {
                            TreeNode tn2 = new TreeNode(entry2.ToString());
                            tn2.Tag                = entry2;
                            tn2.ToolTipText        = entry2.type;
                            tn2.SelectedImageIndex = tn2.ImageIndex = Type2ico(entry2.type);

                            if (entry2.Access == PDOAccessLevel.ReadOnly)
                            {
                                tn2.ForeColor = Properties.Settings.Default.ReadOnlyAttributColor;
                                ro++;
                            }
                            if (entry2.Access == PDOAccessLevel.ReadWrite)
                            {
                                tn2.ForeColor = Properties.Settings.Default.ReadWriteAttributColor;
                                rw++;
                            }
                            tn.Nodes.Add(tn2);
                        }
                    }
                    else
                    {
                        tn.ToolTipText = entry.type;
                    }

                    if ((ro != 0) && (rw == 0))
                    {
                        tn.ForeColor = Properties.Settings.Default.ReadOnlyAttributColor;
                    }
                    if ((rw != 0) && (ro == 0))
                    {
                        tn.ForeColor = Properties.Settings.Default.ReadOnlyAttributColor;
                    }
                }
            }
        }