/// <summary>
        /// Restore settings from XML file
        /// </summary>
        void RestoreSettingsFromXmlFile()
        {
            if (string.IsNullOrEmpty(settingsFileName))
            {
                errorMessage = "Setting file name is empty or null";
                return;
            }

            if (!File.Exists(settingsFileName))
            {
                errorMessage = "File not found  ( " + settingsFileName + " )";
                isLoad = false;
                return;
            }

            restoreInfo.Clear();

            try
            {
                XmlTextReader xtr = new XmlTextReader(settingsFileName);

                while (xtr.Read())
                {
                    if (string.IsNullOrEmpty(xtr.Name))
                        xtr.Skip();

                    #region Color Table
                    if (xtr.IsStartElement("ColorTable"))
                    {

                        XmlReader xtrSub = xtr.ReadSubtree();
                        if (xtrSub != null)
                        {

                            while (!xtrSub.EOF)
                            {

                                xtr.Read();

                                if (string.IsNullOrEmpty(xtrSub.Name))
                                    xtrSub.Skip();

                                if (xtrSub.NodeType == XmlNodeType.Element)
                                {
                                    string strVal = xtrSub.ReadString();
                                    if (!string.IsNullOrEmpty(strVal))
                                    {
                                        object setValue = null;
                                        PropertyInfo pi = colorTable.GetType().GetProperty(xtrSub.Name);

                                        if (pi.PropertyType == typeof(float)) setValue = Convert.ToSingle(strVal);
                                        if (pi.PropertyType == typeof(bool)) setValue = strVal.Equals("True");
                                        if (pi.PropertyType == typeof(Color)) setValue = Color.FromArgb(Convert.ToInt32(strVal));
                                        if (pi.PropertyType == typeof(ContextMenuArrowStyle)) setValue = Enum.Parse(typeof(ContextMenuArrowStyle), strVal);

                                        colorTable.GetType().InvokeMember(xtrSub.Name, BindingFlags.SetProperty, null,
                                            colorTable, new object[] { setValue });

                                    }
                                }
                            }
                        }

                        xtrSub.Close();

                    }
                    #endregion

                    #region NavigateBar
                    if (xtr.Name.Equals("NavigationPaneSettings") && xtr.HasAttributes)
                    {
                        for (int i = 0; i < xtr.AttributeCount; i++)
                        {
                            xtr.MoveToAttribute(i);
                            if (xtr.Name.Equals("DiplayedButtonCount")) displayedbuttonCount = Convert.ToInt32(xtr.Value);
                            if (xtr.Name.Equals("ButtonHeight")) buttonHeight = Convert.ToInt32(xtr.Value);
                            if (xtr.Name.Equals("PaneWidth")) paneWidth = Convert.ToInt32(xtr.Value);
                            if (xtr.Name.Equals("OverFlowPanelHeight")) overFlowPanelHeight = Convert.ToInt32(xtr.Value);
                            if (xtr.Name.Equals("IsCollapsible")) isCollapsible = xtr.Value.ToUpper().Equals("TRUE");
                            if (xtr.Name.Equals("IsShowCollapseButton")) isShowCollapseButton = xtr.Value.ToUpper().Equals("TRUE");
                        }
                        continue;
                    }
                    #endregion

                    #region Buttons
                    ButtonRestoreSettings brs = new ButtonRestoreSettings();
                    brs.Key = xtr.Name;

                    if (xtr.HasAttributes)
                    {
                        for (int i = 0; i < xtr.AttributeCount; i++)
                        {
                            xtr.MoveToAttribute(i);
                            if (xtr.Name.Equals("Enabled")) brs.Enabled = xtr.Value.Equals("True");
                            if (xtr.Name.Equals("Display")) brs.Display = xtr.Value.Equals("True");
                            if (xtr.Name.Equals("Visible")) brs.Visible = xtr.Value.Equals("True");
                            if (xtr.Name.Equals("Selected")) brs.Selected = xtr.Value.Equals("True");
                            if (xtr.Name.Equals("OrderNo")) brs.Order = Convert.ToInt32(xtr.Value);
                        }
                    }

                    restoreInfo.Add(brs.Key, brs);
                    #endregion

                } //while

                xtr.Close();
            }
            catch (Exception e)
            {
                isLoad = false;
                errorMessage = e.Message;
            }
        }
示例#2
0
        /// <summary>
        /// Restore settings from XML file
        /// </summary>
        void RestoreSettingsFromXmlFile()
        {
            if (string.IsNullOrEmpty(settingsFileName))
            {
                errorMessage = "Setting file name is empty or null";
                return;
            }

            if (!File.Exists(settingsFileName))
            {
                errorMessage = "File not found  ( " + settingsFileName + " )";
                isLoad       = false;
                return;
            }

            restoreInfo.Clear();

            try
            {
                XmlTextReader xtr = new XmlTextReader(settingsFileName);

                while (xtr.Read())
                {
                    if (string.IsNullOrEmpty(xtr.Name))
                    {
                        xtr.Skip();
                    }

                    #region Color Table
                    if (xtr.IsStartElement("ColorTable"))
                    {
                        XmlReader xtrSub = xtr.ReadSubtree();
                        if (xtrSub != null)
                        {
                            while (!xtrSub.EOF)
                            {
                                xtr.Read();

                                if (string.IsNullOrEmpty(xtrSub.Name))
                                {
                                    xtrSub.Skip();
                                }

                                if (xtrSub.NodeType == XmlNodeType.Element)
                                {
                                    string strVal = xtrSub.ReadString();
                                    if (!string.IsNullOrEmpty(strVal))
                                    {
                                        object       setValue = null;
                                        PropertyInfo pi       = colorTable.GetType().GetProperty(xtrSub.Name);

                                        if (pi.PropertyType == typeof(float))
                                        {
                                            setValue = Convert.ToSingle(strVal);
                                        }
                                        if (pi.PropertyType == typeof(bool))
                                        {
                                            setValue = strVal.Equals("True");
                                        }
                                        if (pi.PropertyType == typeof(Color))
                                        {
                                            setValue = Color.FromArgb(Convert.ToInt32(strVal));
                                        }
                                        if (pi.PropertyType == typeof(ContextMenuArrowStyle))
                                        {
                                            setValue = Enum.Parse(typeof(ContextMenuArrowStyle), strVal);
                                        }

                                        colorTable.GetType().InvokeMember(xtrSub.Name, BindingFlags.SetProperty, null,
                                                                          colorTable, new object[] { setValue });
                                    }
                                }
                            }
                        }

                        xtrSub.Close();
                    }
                    #endregion

                    #region NavigateBar
                    if (xtr.Name.Equals("NavigationPaneSettings") && xtr.HasAttributes)
                    {
                        for (int i = 0; i < xtr.AttributeCount; i++)
                        {
                            xtr.MoveToAttribute(i);
                            if (xtr.Name.Equals("DiplayedButtonCount"))
                            {
                                displayedbuttonCount = Convert.ToInt32(xtr.Value);
                            }
                            if (xtr.Name.Equals("ButtonHeight"))
                            {
                                buttonHeight = Convert.ToInt32(xtr.Value);
                            }
                            if (xtr.Name.Equals("PaneWidth"))
                            {
                                paneWidth = Convert.ToInt32(xtr.Value);
                            }
                            if (xtr.Name.Equals("OverFlowPanelHeight"))
                            {
                                overFlowPanelHeight = Convert.ToInt32(xtr.Value);
                            }
                            if (xtr.Name.Equals("IsCollapsible"))
                            {
                                isCollapsible = xtr.Value.ToUpper().Equals("TRUE");
                            }
                            if (xtr.Name.Equals("IsShowCollapseButton"))
                            {
                                isShowCollapseButton = xtr.Value.ToUpper().Equals("TRUE");
                            }
                        }
                        continue;
                    }
                    #endregion

                    #region Buttons
                    ButtonRestoreSettings brs = new ButtonRestoreSettings();
                    brs.Key = xtr.Name;

                    if (xtr.HasAttributes)
                    {
                        for (int i = 0; i < xtr.AttributeCount; i++)
                        {
                            xtr.MoveToAttribute(i);
                            if (xtr.Name.Equals("Enabled"))
                            {
                                brs.Enabled = xtr.Value.Equals("True");
                            }
                            if (xtr.Name.Equals("Display"))
                            {
                                brs.Display = xtr.Value.Equals("True");
                            }
                            if (xtr.Name.Equals("Visible"))
                            {
                                brs.Visible = xtr.Value.Equals("True");
                            }
                            if (xtr.Name.Equals("Selected"))
                            {
                                brs.Selected = xtr.Value.Equals("True");
                            }
                            if (xtr.Name.Equals("OrderNo"))
                            {
                                brs.Order = Convert.ToInt32(xtr.Value);
                            }
                        }
                    }

                    restoreInfo.Add(brs.Key, brs);
                    #endregion
                } //while

                xtr.Close();
            }
            catch (Exception e)
            {
                isLoad       = false;
                errorMessage = e.Message;
            }
        }
        /// <summary>
        /// Restore settings from XML file
        /// </summary>
        void RestoreSettingsFromXmlFile()
        {
            if (!File.Exists(settingsFileName))
            {
                isLoad = false;
                return;
            }

            restoreInfo.Clear();

            try
            {
                XmlTextReader xtr = new XmlTextReader(settingsFileName);

                while (xtr.Read())
                {

                    if (xtr.NodeType == XmlNodeType.Element)
                    {
                        // NavigateBar
                        if (xtr.Name.Equals("NavigateBarSettings") && xtr.HasAttributes)
                        {
                            for (int i = 0; i < xtr.AttributeCount; i++)
                            {
                                xtr.MoveToAttribute(i);
                                if (xtr.Name.Equals("DiplayedButtonCount")) displayedbuttonCount = Convert.ToInt32(xtr.Value);
                                if (xtr.Name.Equals("ButtonHeight")) buttonHeight = Convert.ToInt32(xtr.Value);
                                if (xtr.Name.Equals("PaintAngle")) paintAngle = (float)Convert.ToInt32(xtr.Value);
                                if (xtr.Name.Equals("LightColor")) theme.LightColor = Color.FromArgb(Convert.ToInt32(xtr.Value));
                                if (xtr.Name.Equals("DarkColor")) theme.DarkColor = Color.FromArgb(Convert.ToInt32(xtr.Value));
                                if (xtr.Name.Equals("DarkDarkColor")) theme.DarkDarkColor = Color.FromArgb(Convert.ToInt32(xtr.Value));
                                if (xtr.Name.Equals("MouseOverLightColor")) theme.MouseOverLightColor = Color.FromArgb(Convert.ToInt32(xtr.Value));
                                if (xtr.Name.Equals("MouseOverDarkColor")) theme.MouseOverDarkColor = Color.FromArgb(Convert.ToInt32(xtr.Value));
                                if (xtr.Name.Equals("SelectedLightColor")) theme.SelectedLightColor = Color.FromArgb(Convert.ToInt32(xtr.Value));
                                if (xtr.Name.Equals("SelectedDarkColor")) theme.SelectedDarkColor = Color.FromArgb(Convert.ToInt32(xtr.Value));
                            }
                            continue;
                        }

                        // Buttons
                        ButtonRestoreSettings brs = new ButtonRestoreSettings();
                        brs.Key = xtr.Name;

                        if (xtr.HasAttributes)
                        {
                            for (int i = 0; i < xtr.AttributeCount; i++)
                            {
                                xtr.MoveToAttribute(i);
                                if (xtr.Name.Equals("Enabled")) brs.Enabled = xtr.Value.Equals("True");
                                if (xtr.Name.Equals("Display")) brs.Display = xtr.Value.Equals("True");
                                if (xtr.Name.Equals("Visible")) brs.Visible = xtr.Value.Equals("True");
                                if (xtr.Name.Equals("Selected")) brs.Selected = xtr.Value.Equals("True");
                                if (xtr.Name.Equals("OrderNo")) brs.Order = Convert.ToInt32(xtr.Value);
                            }
                        }

                        restoreInfo.Add(brs.Key, brs);
                    }

                } //while
            }
            catch { isLoad = false; }
        }