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
Location:
branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3
Files:
1 added
4 edited

Legend:

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

    r7402 r7424  
    6767      foreach (HostedService serv in services) {
    6868        serv.Subscription = subscription;
    69         foreach (Deployment dep in serv.Deployments) {
    70           dep.Subscription = subscription;
     69        if (serv.Deployments != null) {
     70          foreach (Deployment dep in serv.Deployments) {
     71            dep.Subscription = subscription;
     72          }
    7173        }
    7274      }
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/HeuristicLab.Clients.Hive.CloudManager-3.3.csproj

    r7403 r7424  
    7676      <DependentUpon>Resources.resx</DependentUpon>
    7777    </Compile>
     78    <Compile Include="Validation.cs" />
    7879    <Compile Include="Views\AddAzureServiceDialog.cs">
    7980      <SubType>Form</SubType>
  • branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.CloudManager/3.3/Views/AddAzureServiceDialog.Designer.cs

    r7362 r7424  
    2424    /// </summary>
    2525    private void InitializeComponent() {
     26      this.components = new System.ComponentModel.Container();
    2627      this.label1 = new System.Windows.Forms.Label();
    2728      this.cmbChooseSubscription = new System.Windows.Forms.ComboBox();
     
    5354      this.btnCancel = new System.Windows.Forms.Button();
    5455      this.lblCertificateFile = new System.Windows.Forms.Label();
     56      this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
    5557      this.gbNewHostedService.SuspendLayout();
    5658      this.panelDeploymentOptions.SuspendLayout();
     59      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5760      this.SuspendLayout();
    5861      //
     
    171174      this.tbServiceName.Size = new System.Drawing.Size(377, 20);
    172175      this.tbServiceName.TabIndex = 3;
     176      this.tbServiceName.Validating += new System.ComponentModel.CancelEventHandler(this.tbServiceName_Validating);
    173177      //
    174178      // label4
     
    187191      this.tbLabel.Size = new System.Drawing.Size(453, 20);
    188192      this.tbLabel.TabIndex = 1;
     193      this.tbLabel.Validating += new System.ComponentModel.CancelEventHandler(this.tbLabel_Validating);
    189194      //
    190195      // label3
     
    330335      this.lblCertificateFile.TabIndex = 19;
    331336      //
     337      // errorProvider
     338      //
     339      this.errorProvider.ContainerControl = this;
     340      //
    332341      // AddAzureServiceDialog
    333342      //
    334343      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    335344      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     345      this.AutoValidate = System.Windows.Forms.AutoValidate.EnableAllowFocusChange;
    336346      this.ClientSize = new System.Drawing.Size(496, 436);
    337347      this.Controls.Add(this.lblCertificateFile);
     
    358368      this.panelDeploymentOptions.ResumeLayout(false);
    359369      this.panelDeploymentOptions.PerformLayout();
     370      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    360371      this.ResumeLayout(false);
    361372      this.PerformLayout();
     
    394405    private System.Windows.Forms.Button btnCancel;
    395406    private System.Windows.Forms.Label lblCertificateFile;
     407    private System.Windows.Forms.ErrorProvider errorProvider;
    396408  }
    397409}
  • 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.