Example #1
0
        private void PopulateDBConnections()
        {
            ListViewItem  item  = null;
            ListViewGroup group = null;

            _connParams = ConnectionParamsFactory.GetConnections();
            lvConnections.Items.Clear();
            string serverName = String.Empty;
            int    cnt        = 0;

            foreach (ConnectionParams connSpec in _connParams)
            {
#if PERSONAL_EDITION
                cnt++;
                if (cnt > _maxPersonalEditionConnCnt)
                {
                    lblPersonalEdLimit.Visible     = true;
                    lblPersonalEdLimit.Text        = String.Format("Only {0} connections are listed.", _maxPersonalEditionConnCnt);
                    lblPersonalEdLimit.ToolTipText = String.Format("Personal Edition does not support more than {0} saved connections.", _maxPersonalEditionConnCnt);

                    break;
                }
#endif
                string key       = ConnectionParams.PrepareConnKey(connSpec);
                string normalKey = key.Replace(((Char)29).ToString(), " as ");
                serverName = connSpec.Server.Trim().ToLowerInvariant();

                if (_groups.ContainsKey(serverName))
                {
                    group = _groups[serverName];
                }
                else
                {
                    group = new ListViewGroup(serverName, connSpec.Server);
                    lvConnections.Groups.Add(group);
                    _groups.Add(serverName, group);
                }
                item = new ListViewItem(normalKey, group);
                item.SubItems.Add(connSpec.Database);
                item.Tag = connSpec.ID;
                lvConnections.Items.Add(item);
            }

            if (_connParams.Count > 0)
            {
                lvConnections.Items[0].Selected = true;
            }

            InvalidateButtons();
        }
Example #2
0
        public static void Save(ConnectionParamsCollection connParams)
        {
            foreach (ConnectionParams cp in connParams)
            {
                cp.IsEncrypted = true;
                cp.Password    = EncryiptionHelper.Encrypt(cp.Password);
            }

            /*
             * string filename = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DBConnections.config");
             * XmlSerializer ser = new XmlSerializer(typeof(ConnectionParamsCollection));
             * TextWriter writer = new StreamWriter(filename);
             * ser.Serialize(writer, connParams);
             * writer.Close();
             */

            ObjectXMLSerializer <ConnectionParamsCollection> .Save(connParams, _path);

            // Reset password
            foreach (ConnectionParams cp in connParams)
            {
                cp.Password = EncryiptionHelper.Decrypt(cp.Password);
            }
        }