Esempio n. 1
0
        public static connItem fn_getConnectionByName(string connectionName, string path)
        {
            List <connItem> list = fn_getSavedConnections(path);
            connItem        item = (from i in list
                                    where i.connName == connectionName
                                    select i).FirstOrDefault();

            if (item != null)
            {
                return(item);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        // Saves new or existing connection to XML
        private void btnSaveConnction_Click(object sender, EventArgs e)
        {
            // Just simple validation
            if (txtConnName.Text == "" || txtDatabase.Text == "" || txtHostname.Text == "" || txtPort.Text == "")
            {
                MessageBox.Show("Enter Server information and Connection name.");
                return;
            }

            // search items with same connection name, if any found, delete all
            var itemz = connItems.Where(i => i.connName == txtConnName.Text).ToList();

            if (itemz.Count > 0)
            {
                foreach (var item in itemz)
                {
                    connItems.Remove(item);
                }
            }

            // create new connItem object and populate it with data from controls
            var newItem = new connItem();

            newItem.connName = txtConnName.Text;
            newItem.dbDriver = cboDatabaseDriver.SelectedItem.ToString();
            newItem.Hostname = txtHostname.Text;
            newItem.Port     = txtPort.Text;
            newItem.Database = txtDatabase.Text;
            newItem.Username = txtUsername.Text;
            newItem.Password = txtPassword.Text;
            if (chkSavePassword.Checked == true)
            {
                newItem.savePassword = "******";
            }
            else
            {
                newItem.savePassword = "******";
            }

            connItems.Add(newItem);                                     // add item to main list

            fn_saveConfiguration();                                     // save to XML
            fn_loadConfiguration();                                     // read from XML

            lstConnections.SelectedValue = newItem.connName.ToString(); // select manipulated object in list box
        }