Пример #1
0
        private void btnAddEdit_click(object sender, EventArgs e)
        {
            if (!Regex.IsMatch(txtDomainName.Text, GlobalRules.DomainRegex, RegexOptions.IgnoreCase))
            {
                MessageBox.Show(
                    "The domain name does not appear to be valid.",
                    _isEdit ? "Edit domain" : "Add domain",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                return;
            }

            System.Net.IPAddress temp;
            if (!Regex.IsMatch(txtIPAddress.Text, GlobalRules.IPRegex, RegexOptions.IgnoreCase) ||
                !System.Net.IPAddress.TryParse(txtIPAddress.Text, out temp))
            {
                MessageBox.Show(
                    "The IP address field is not a valid IP.",
                    _isEdit ? "Edit domain" : "Add domain",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                return;
            }

            if (!_isEdit &&
                HostsDatabase.Contains(LocalDomain, DomainName))
            {
                MessageBox.Show(
                    "The domain name you entered already exist in the " + (LocalDomain ? "local" : "remote") + " host list.\n" +
                    "Edit existing entry instead of attempting to overwrite.",
                    _isEdit ? "Edit domain" : "Add domain",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                return;
            }

            DialogResult = DialogResult.OK;
        }