Exemplo n.º 1
0
        private void StoreValues()
        {
            Properties.Settings.Default.ExcludeTrunksSearch      = chkExcludeTrunks.Checked;
            Properties.Settings.Default.DefaultUserName          = txtUserName.Text;
            Properties.Settings.Default.DefaultEncryptedPassword = Functions.EncryptPassword(txtPassword.Text);
            Properties.Settings.Default.Save();

            Close();
        }
Exemplo n.º 2
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            try
            {
                using (CsvFileReader reader = new CsvFileReader(openFileDialog1.OpenFile()))
                {
                    CsvRow row = new CsvRow();
                    reader.ReadRow(row);

                    int nameIndex    = row.FindIndex(delegate(string str) { return(str == "Name"); });
                    int addressIndex = row.FindIndex(delegate(string str) { return(str == "Network Address"); });
                    int userIndex    = row.FindIndex(delegate(string str) { return(str == "Username"); });
                    int passIndex    = row.FindIndex(delegate(string str) { return(str == "Password"); });

                    if (nameIndex == -1 || addressIndex == -1)
                    {
                        MessageBox.Show("Please ensure your CSV file contains the following column names in the header row:\r\n\r\nName\r\nNetwork Address\r\nUsername (Optional)\r\nPassword (Optional)",
                                        "Invalid Header Row", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    DialogResult dr = MessageBox.Show("Any existing switches with the same name or address in the imported data will be removed and is irreversible.\r\n\r\nAre you sure you wish to continue?",
                                                      "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (dr != DialogResult.Yes)
                    {
                        return;
                    }

                    bool added = false;

                    while (reader.ReadRow(row))
                    {
                        string nameVal    = "";
                        string addressVal = "";
                        string userVal    = "";
                        string passVal    = "";

                        nameVal    = row.ElementAt(nameIndex).Trim();
                        addressVal = row.ElementAt(addressIndex).Trim();
                        if (userIndex > -1)
                        {
                            userVal = row.ElementAt(userIndex).Trim();
                        }
                        if (passIndex > -1)
                        {
                            passVal = row.ElementAt(passIndex);
                        }

                        if (string.IsNullOrEmpty(nameVal) || string.IsNullOrEmpty(addressVal))
                        {
                            continue;
                        }

                        // delete any existing switches
                        List <SwitchInfo> dellist = new List <SwitchInfo>();
                        foreach (SwitchInfo sw in MainForm.switches)
                        {
                            if (sw.Name.ToLower().Trim().Equals(nameVal.ToLower()))
                            {
                                dellist.Add(sw);
                            }

                            if (sw.Address.ToLower().Trim().Equals(addressVal.ToLower()))
                            {
                                dellist.Add(sw);
                            }
                        }
                        foreach (SwitchInfo sw in dellist)
                        {
                            MainForm.deleteSwitch(sw);
                        }

                        // Add new switch
                        SwitchInfo swtch = new SwitchInfo(nameVal, addressVal, userVal, Functions.EncryptPassword(passVal));
                        MainForm.switches.Add(swtch);
                        added = true;
                    }

                    if (added)
                    {
                        update = true;
                        populateListData();
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
Exemplo n.º 3
0
        private bool addSwitch()
        {
            foreach (SwitchInfo sw in MainForm.switches)
            {
                if (sw.Name.ToLower().Equals(txtName.Text.ToLower().Trim()))
                {
                    MessageBox.Show("That switch name is already in use, please try something else.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(false);
                }

                if (sw.Address.ToLower().Equals(txtAddress.Text.ToLower().Trim()))
                {
                    MessageBox.Show("That switch address is already in use, please try something else.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(false);
                }
            }

            SwitchInfo swtch = new SwitchInfo(txtName.Text, txtAddress.Text, txtUserName.Text, Functions.EncryptPassword(txtPassword.Text));

            MainForm.switches.Add(swtch);
            return(true);
        }