Beispiel #1
0
        public int Add()
        {
            int result = 0;

            if (User.Current != null)
            {
                Security security = new Security();
                bool check = CheckExists(Name);

                if (check)
                {
                    result = -1;
                }
                else
                {
                    XmlDocument connections = security.ReadConnectionConfiguration(User.Current.Path);

                    XmlNode node = connections.SelectSingleNode("/root/connections");
                    XmlNode connectionNode = connections.CreateElement("connection");

                    node.AppendChild(connectionNode);

                    XmlNode nameNode = connections.CreateElement("name");
                    nameNode.AppendChild(connections.CreateTextNode(Name));
                    connectionNode.AppendChild(nameNode);

                    XmlNode serverNode = connections.CreateElement("server");
                    serverNode.AppendChild(connections.CreateTextNode(Server));
                    connectionNode.AppendChild(serverNode);

                    XmlNode dbNode = connections.CreateElement("dbname");
                    dbNode.AppendChild(connections.CreateTextNode(Database));
                    connectionNode.AppendChild(dbNode);

                    XmlNode dbuserNode = connections.CreateElement("dbuser");
                    dbuserNode.AppendChild(connections.CreateTextNode(Username));
                    connectionNode.AppendChild(dbuserNode);

                    XmlNode dbPassNode = connections.CreateElement("dbpass");
                    dbPassNode.AppendChild(connections.CreateTextNode(Password));
                    connectionNode.AppendChild(dbPassNode);

                    XmlNode dbproviderNode = connections.CreateElement("provider");
                    dbproviderNode.AppendChild(connections.CreateTextNode(Provider));
                    connectionNode.AppendChild(dbproviderNode);

                    security.SaveConnectionConfiguration(User.Current.Path, connections.InnerXml);

                    result = 1;
                }
            }
            else
            {
                result = -2;
            }

            return result;
        }
Beispiel #2
0
        public string GetByJSON(string name)
        {
            string result = "";

            Connection conn = new Connection();

            if (User.Current != null)
            {
                Security security = new Security();
                XmlDocument connections = security.ReadConnectionConfiguration(User.Current.Path);

                XmlNode node = connections.SelectSingleNode("/root/connections/connection[name='" + name + "']");
                if (node != null)
                {
                    conn.Name = node.SelectSingleNode("name").InnerText;
                    conn.Server = node.SelectSingleNode("server").InnerText;
                    conn.Database = node.SelectSingleNode("dbname").InnerText;
                    conn.Username = node.SelectSingleNode("dbuser").InnerText;
                    conn.Password = node.SelectSingleNode("dbpass").InnerText;
                    conn.Provider = node.SelectSingleNode("provider").InnerText;

                    result = new JavaScriptSerializer().Serialize(conn);
                }
            }

            return result;
        }
Beispiel #3
0
        public int Update()
        {
            int result = 0;

            if (User.Current != null)
            {
                bool check = CheckExists(Name);

                if (!check)
                {
                    result = -1;
                }
                else
                {
                    Security security = new Security();
                    XmlDocument connections = security.ReadConnectionConfiguration(User.Current.Path);

                    XmlNode node = connections.SelectSingleNode("/root/connections/connection[name='" + Name + "']");
                    if (node != null)
                    {
                        node.SelectSingleNode("name").InnerText = Name;
                        node.SelectSingleNode("server").InnerText = Server;
                        node.SelectSingleNode("dbname").InnerText = Database;
                        node.SelectSingleNode("dbuser").InnerText = Username;
                        node.SelectSingleNode("dbpass").InnerText = Password;
                        node.SelectSingleNode("provider").InnerText = Provider;

                        security.SaveConnection(User.Current.Path, connections);

                        result = 1;
                    }
                    else
                    {
                        result = -3;
                    }
                }
            }
            else
            {
                result = -2;
            }

            return result;
        }
Beispiel #4
0
        public Connection GetBy(string name)
        {
            Connection conn = new Connection();

            if (User.Current != null)
            {
                Security security = new Security();
                XmlDocument connections = security.ReadConnectionConfiguration(User.Current.Path);

                XmlNode node = connections.SelectSingleNode("/root/connections/connection[name='" + name + "']");
                if (node != null)
                {
                    conn.Name = node.SelectSingleNode("name").InnerText;
                    conn.Server = node.SelectSingleNode("server").InnerText;
                    conn.Database = node.SelectSingleNode("dbname").InnerText;
                    conn.Username = node.SelectSingleNode("dbuser").InnerText;
                    conn.Password = node.SelectSingleNode("dbpass").InnerText;
                    conn.Provider = node.SelectSingleNode("provider").InnerText;
                }
                else
                {
                    conn = null;
                }
            }
            else
            {
                conn = null;
            }

            return conn;
        }
Beispiel #5
0
        public string GetAllJSON()
        {
            string result = "";

            List<Connection> listConnection = new List<Connection>();

            if (User.Current != null)
            {
                Security security = new Security();
                XmlDocument connections = security.ReadConnectionConfiguration(User.Current.Path);

                foreach (XmlNode node in connections.SelectNodes("root/connections/connection"))
                {
                    Connection conn = new Connection();
                    conn.Name = node.SelectSingleNode("name").InnerText;
                    conn.Server = node.SelectSingleNode("server").InnerText;
                    conn.Database = node.SelectSingleNode("dbname").InnerText;
                    conn.Username = node.SelectSingleNode("dbuser").InnerText;
                    conn.Password = node.SelectSingleNode("dbpass").InnerText;
                    conn.Provider = node.SelectSingleNode("provider").InnerText;
                    listConnection.Add(conn);
                }

                result = new JavaScriptSerializer().Serialize(listConnection);
            }

            return result;
        }
Beispiel #6
0
        public List<Connection> GetAll()
        {
            List<Connection> listConnection = new List<Connection>();

            if (User.Current != null)
            {
                Security security = new Security();
                XmlDocument connections = security.ReadConnectionConfiguration(User.Current.Path);

                foreach (XmlNode node in connections.SelectNodes("root/connections/connection"))
                {
                    Connection conn = new Connection();
                    conn.Name = node.SelectSingleNode("name").InnerText;
                    conn.Server = node.SelectSingleNode("server").InnerText;
                    conn.Database = node.SelectSingleNode("dbname").InnerText;
                    conn.Username = node.SelectSingleNode("dbuser").InnerText;
                    conn.Password = node.SelectSingleNode("dbpass").InnerText;
                    conn.Provider = node.SelectSingleNode("provider").InnerText;
                    listConnection.Add(conn);
                }
            }

            return listConnection;
        }
Beispiel #7
0
        public bool Delete()
        {
            bool result = false;

            if (User.Current != null)
            {
                Security security = new Security();
                XmlDocument connections = security.ReadConnectionConfiguration(User.Current.Path);

                XmlNode node = connections.SelectSingleNode("/root/connections/connection[name='" + Name + "']");
                if (node != null)
                {
                    node.ParentNode.RemoveChild(node);
                    security.SaveConnectionConfiguration(User.Current.Path, connections.InnerXml);
                    result = true;
                }
            }

            return result;
        }
Beispiel #8
0
        public bool CheckExists(string name)
        {
            bool result = false;

            if (User.Current != null)
            {
                Security security = new Security();
                XmlDocument connections = security.ReadConnectionConfiguration(User.Current.Path);

                foreach (XmlNode node in connections.SelectNodes("root/connections/connection"))
                {
                    string _name = node.SelectSingleNode("name").InnerText;

                    if (name == _name)
                    {
                        result = true;
                        break;
                    }
                    else
                    {
                        result = false;
                    }
                }
            }

            return result;
        }