Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/27/12 16:58:29 (12 years ago)
Author:
spimming
Message:

#1680:

  • ErrorProvider added to form
  • Implemented Validation methods for controls
  • Check Validation methods for controls in form when btn is clicked
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/AddAzureServiceDialog.cs

    r7421 r7424  
    22using System.Collections.Generic;
    33using System.ComponentModel;
     4using System.Text.RegularExpressions;
    45using System.Windows.Forms;
    56using HeuristicLab.Clients.Hive.CloudManager.Azure;
     
    108109          }
    109110      }
    110     }
    111 
    112     private bool ValidateInput() {
    113       bool valid = true;
    114       // TODO: input validation
    115       // see http://stackoverflow.com/questions/769184/winform-ui-validation
    116       return valid;
    117111    }
    118112
     
    166160      if (cmbChooseSubscription.SelectedItem != null) {
    167161        Subscription sub = (Subscription)cmbChooseSubscription.SelectedItem;
    168         if (ValidateInput()) {
     162        // the controls collection can be the whole form or just a panel or group
     163        if (Validation.hasValidationErrors(this.Controls)) {
     164          return;
     165        } else {
    169166          bool newHostedServiceChecked = cbNewHostedService.Checked;
    170167          bool regionChecked = rbRegion.Checked;
     
    301298      }
    302299    }
     300
     301    private void tbServiceName_Validating(object sender, CancelEventArgs e) {
     302      if (cbNewHostedService.Checked) {
     303        string url = tbServiceName.Text.Trim();
     304        if (url == String.Empty) {
     305          errorProvider.SetError(tbServiceName, "A URL is required for the hosted service.");
     306          e.Cancel = true;
     307        } else if (!isValidHostedServiceUrl(url)) {
     308          errorProvider.SetError(tbLabel, "A hosted service name must be between 1 and 63 " +
     309                                          "characters long, and be composed of letters, numbers " +
     310                                          "and hyphens. Hyphens shouldn't be first or last letter.");
     311          e.Cancel = true;
     312        } else {
     313          errorProvider.SetError(tbServiceName, "");
     314        }
     315      }
     316    }
     317
     318    private void tbLabel_Validating(object sender, CancelEventArgs e) {
     319      if (cbNewHostedService.Checked) {
     320        if (tbLabel.Text.Trim() == String.Empty) {
     321          errorProvider.SetError(tbLabel, "A name is required for the hosted service.");
     322          e.Cancel = true;
     323        } else {
     324          errorProvider.SetError(tbLabel, "");
     325        }
     326      }
     327    }
     328
     329    private bool isValidHostedServiceUrl(string url) {
     330      string regexString = @"[a-zA-Z0-9]+[a-zA-Z0-9-]{0,61}[a-zA-Z0-9]+";  //TODO
     331      Regex regex = new Regex(regexString);
     332      if (regex.IsMatch(url)) {
     333        return true;
     334      } else {
     335        return false;
     336      }
     337    }
    303338  }
    304339}
Note: See TracChangeset for help on using the changeset viewer.