コード例 #1
0
        private clsConfig.CredentialCollection CollateForm()
        {
            clsConfig.CredentialCollection cc = new clsConfig.CredentialCollection();

            // Loop through each row and (if it's valid) add it to the collection
            foreach (DataGridViewRow r in grdCredentials.Rows)
            {
                if (!r.IsNewRow && ValidateRow(r))
                {
                    clsConfig.SecurityCredential c = new clsConfig.SecurityCredential();

                    c.ip = IPAddress.Parse(r.Cells[crNetwork.Index].Value.ToString()).ToString();
                    c.netmask = byte.Parse(r.Cells[crNetmask.Index].Value.ToString());
                    c.description = r.Cells[crDescription.Index].Value.ToString();

                    if (r.Cells[crDomain.Index].Value == null)
                        c.domain = "";
                    else
                        c.domain = r.Cells[crDomain.Index].Value.ToString();

                    c.username = r.Cells[crUser.Index].Value.ToString();
                    c.password = r.Cells[crPassword.Index].Value.ToString();

                    cc.Add(c);
                }
            }

            return cc;
        }
コード例 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            // Sort the datagrid
            grdCredentials.Sort(new SortByMaskedIP(crNetwork.Index, crNetmask.Index));

            // Validate each row
            bool ok = true;

            foreach (DataGridViewRow r in grdCredentials.Rows)
            {
                if (!r.IsNewRow && !ValidateRow(r))
                {
                    ok = false; break;
                }
            }

            // Save without prompting if all rows are OK.  Prompt if not all rows are OK.
            if (ok || (!ok && MessageBox.Show("Not all rows are valid - rows with errors (highlighted) will not be saved if you continue.  Save security credentials?", "Not all rows are valid", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes))
            {
                clsConfig.CredentialCollection cc = CollateForm();

                // Sort the collection, then save it.
                cc.SortByMaskedIP();

                cfg.CredentialList = cc;

                // Close form
                this.Close();
            }
        }
コード例 #3
0
        private void frmCredentials_Load(object sender, EventArgs e)
        {
            // Populate grid
            clsConfig.CredentialCollection cc = cfg.CredentialList;

            // Sort the collection before populating the grid
            cc.SortByMaskedIP();

            foreach (clsConfig.SecurityCredential c in cc)
            {
                DataGridViewRow r = grdCredentials.Rows[grdCredentials.Rows.Add()];

                r.Cells["crNetwork"].Value     = c.ip.ToString();
                r.Cells["crNetmask"].Value     = c.netmask;
                r.Cells["crDescription"].Value = c.description;
                r.Cells["crDomain"].Value      = c.domain;
                r.Cells["crUser"].Value        = c.username;
                r.Cells["crPassword"].Value    = c.password;
            }

            // Sort the datagrid
            grdCredentials.Sort(new SortByMaskedIP(crNetwork.Index, crNetmask.Index));

            // Set default selected cell to the first column of the last row
            grdCredentials.CurrentCell = grdCredentials.Rows[grdCredentials.Rows.Count - 1].Cells[0];
        }
コード例 #4
0
        private clsConfig.CredentialCollection CollateForm()
        {
            clsConfig.CredentialCollection cc = new clsConfig.CredentialCollection();

            // Loop through each row and (if it's valid) add it to the collection
            foreach (DataGridViewRow r in grdCredentials.Rows)
            {
                if (!r.IsNewRow && ValidateRow(r))
                {
                    clsConfig.SecurityCredential c = new clsConfig.SecurityCredential();

                    c.ip          = IPAddress.Parse(r.Cells[crNetwork.Index].Value.ToString()).ToString();
                    c.netmask     = byte.Parse(r.Cells[crNetmask.Index].Value.ToString());
                    c.description = r.Cells[crDescription.Index].Value.ToString();

                    if (r.Cells[crDomain.Index].Value == null)
                    {
                        c.domain = "";
                    }
                    else
                    {
                        c.domain = r.Cells[crDomain.Index].Value.ToString();
                    }

                    c.username = r.Cells[crUser.Index].Value.ToString();
                    c.password = r.Cells[crPassword.Index].Value.ToString();

                    cc.Add(c);
                }
            }

            return(cc);
        }