Beispiel #1
0
        //---Метод: Отмечает все подключения как НЕвыбранный-----------------------------------------------------------------
        public static void DeSelectAllConnections()
        {
            try
            {
                XmlDocument document = new XmlDocument();
                document.Load(path);
                XmlElement RootElement = document.DocumentElement;

                foreach (XmlElement El in RootElement) // Пробежимся по Элементам Корневого элемента
                {
                    if (El.Name == "Connections")      // Если имя элемента "Connections"
                    {
                        foreach (XmlNode childnode in El.ChildNodes)
                        {
                            if (childnode.Name == "Connection")
                            {
                                childnode.Attributes[0].Value = Cryption.Encrypt("N");
                            }
                        }
                    }
                }
                document.Save(path);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "XmlClass.DeSelectAllConnections()");
            }
        }
Beispiel #2
0
        //---Метод: Отмечает подключение как выбранный-----------------------------------------------------------------------
        public static void SetSelectConnection(string ConnectionName)
        {
            try
            {
                DeSelectAllConnections();
                XmlDocument document = new XmlDocument();
                document.Load(path);
                XmlElement RootElement = document.DocumentElement;

                foreach (XmlElement El in RootElement) // Пробежимся по Элементам Корневого элемента
                {
                    if (El.Name == "Connections")      // Если имя элемента "Connections"
                    {
                        foreach (XmlNode childnode in El.ChildNodes)
                        {
                            if (childnode.Name == "Connection")
                            {
                                XmlNode атрибут = childnode.Attributes.GetNamedItem("Name");

                                if (Cryption.Decrypt(атрибут.Value) == ConnectionName) // Если "Название" равно
                                {
                                    childnode.Attributes[0].Value = Cryption.Encrypt("Y");
                                }
                            }
                        }
                    }
                }
                document.Save(path);
            }
            catch (Exception ex)
            {
                //if (MessageBox.Show("Close Application?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                //{
                //    //do no stuff
                //}
                //else
                //{
                //    //do yes stuff
                //}

                MessageBox.Show(ex.Message, "SetSelectConnection(string ConnectionName)");
            }
        }
Beispiel #3
0
        //---Добавление Параметра подключения--------------------------------------------------------------------------------
        public static bool CreateConnectionString(string Name, string ConnectionString)
        {
            bool flag = false;

            try
            {
                CreateConfigFile();
                DeSelectAllConnections();

                XmlDocument document = new XmlDocument();
                document.Load(path);
                XmlElement RootElement = document.DocumentElement;

                foreach (XmlNode xnode in RootElement)
                {
                    if (xnode.Name == "Connections")
                    {
                        XmlNode Connection = document.CreateElement("Connection");

                        XmlAttribute Selected = document.CreateAttribute("Selected");
                        Selected.Value = Cryption.Encrypt("Y");
                        Connection.Attributes.Append(Selected);

                        XmlAttribute ConnName = document.CreateAttribute("Name");
                        ConnName.Value = Cryption.Encrypt(Name);
                        Connection.Attributes.Append(ConnName);

                        XmlAttribute connectionString = document.CreateAttribute("ConnString");
                        connectionString.Value = Cryption.Encrypt(ConnectionString);
                        Connection.Attributes.Append(connectionString);

                        xnode.AppendChild(Connection);
                    }
                }
                document.Save(path);
                flag = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "AddConnectSetting(string Name, string ConnectionString)");
            }
            return(flag);
        }