private clsConfig.ComputerGroupRegexCollection CollateForm()
        {
            clsConfig.ComputerGroupRegexCollection c = new clsConfig.ComputerGroupRegexCollection();
            // Resort grid
            SortByPriority();

            // Loop through each line in the form and add it if it's valid.
            foreach (DataGridViewRow r in grdRegEx.Rows)
            {
                if (ValidateRow(r) == "OK" && !r.IsNewRow)
                {
                    clsConfig.ComputerGroupRegEx rx = new clsConfig.ComputerGroupRegEx();

                    rx.Priority          = int.Parse(r.Cells["rxPriority"].Value.ToString());
                    rx.ComputerNameRegex = (string)r.Cells["rxComputerRegEx"].Value;
                    rx.IPRegex           = (string)r.Cells["rxIPRegEx"].Value;
                    rx.ComputerGroup     = (string)r.Cells["rxComputerGroup"].Value;
                    rx.Comment           = (string)r.Cells["rxComment"].Value;
                    if (r.Cells["rxEnabled"].Value == null)
                    {
                        rx.Enabled = false;
                    }
                    else
                    {
                        rx.Enabled = (bool)r.Cells["rxEnabled"].Value;
                    }

                    c.Add(rx);
                }
            }

            return(c);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            SortByPriority();

            // Check to see if grid is valid
            if (ValidateGrid())
            {
                // Get grid and save it to the XML file
                clsConfig.ComputerGroupRegexCollection c = CollateForm();

                cfg.ComputerRegExList = c;
            }
        }
        private clsConfig.ComputerGroupRegexCollection CollateForm()
        {
            clsConfig.ComputerGroupRegexCollection c = new clsConfig.ComputerGroupRegexCollection();
            // Resort grid
            SortByPriority();

            // Loop through each line in the form and add it if it's valid.
            foreach (DataGridViewRow r in grdRegEx.Rows)
            {
                if (ValidateRow(r) == "OK" && !r.IsNewRow)
                {
                    clsConfig.ComputerGroupRegEx rx = new clsConfig.ComputerGroupRegEx();

                    rx.Priority = int.Parse(r.Cells["rxPriority"].Value.ToString());
                    rx.ComputerNameRegex = (string)r.Cells["rxComputerRegEx"].Value;
                    rx.IPRegex = (string)r.Cells["rxIPRegEx"].Value;
                    rx.ComputerGroup = (string)r.Cells["rxComputerGroup"].Value;
                    rx.Comment = (string)r.Cells["rxComment"].Value;
                    if (r.Cells["rxEnabled"].Value == null)
                        rx.Enabled = false;
                    else
                        rx.Enabled = (bool)r.Cells["rxEnabled"].Value;

                    c.Add(rx);
                }
            }

            return c;
        }
        private void btnPCsNotCovered_Click(object sender, EventArgs e)
        {
            // Ensure changes are committed to the datagrid
            this.Validate();

            // Clear the list and start searching for PCs
            lstResults.Items.Clear();

            // Collate list of rules
            clsConfig.ComputerGroupRegexCollection rules = CollateForm();

            // Get list of PCs and which groups they're in
            DataTable t = wsus.GetComputerGroups();

            // Loop through the list of PCs and see if they match a rule
            foreach (DataRow d in t.Rows)
            {
                bool matched = false;

                // Loop through each rule and see if this PC matches
                foreach (clsConfig.ComputerGroupRegEx rx in rules)
                {
                    // Assume match unless all of the non-null rules match
                    matched = true;

                    if (rx.ComputerNameRegex != null && rx.ComputerNameRegex != "")
                    {
                        Match m = Regex.Match(d["name"].ToString(), rx.ComputerNameRegex);
                        if (!m.Success)
                        {
                            matched = false;
                        }
                    }

                    if (rx.IPRegex != null && rx.IPRegex != "")
                    {
                        Match m = Regex.Match(d["ipaddress"].ToString(), rx.IPRegex);
                        if (!m.Success)
                        {
                            matched = false;
                        }
                    }

                    if (matched)
                    {
                        // We found a matching rule - break from loop
                        break;
                    }
                }

                // Did any rule match?
                if (!matched)
                {
                    lstResults.Items.Add(d["name"].ToString() + " (" + d["ipaddress"].ToString() + ") not matched by any existing rule");
                }
            }

            // Did any PCs fail to match?
            if (lstResults.Items.Count == 0)
            {
                lstResults.Items.Add("All PCs matched an available rule (Please note, this includes disabled rules)");
            }
        }