Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7468


Ignore:
Timestamp:
02/15/12 10:40:17 (12 years ago)
Author:
mkommend
Message:

#1758: Minor code improvements (variable naming, return conditions)

Location:
branches/ChangeDatasetOfRegressionModel/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ChangeDatasetOfRegressionModel/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.Designer.cs

    r7399 r7468  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       this.btnImport = new System.Windows.Forms.Button();
     47      this.importButton = new System.Windows.Forms.Button();
    4848      this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
    4949      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
     
    6060      // splitContainer.Panel2
    6161      //
    62       this.splitContainer.Panel2.Controls.Add(this.btnImport);
     62      this.splitContainer.Panel2.Controls.Add(this.importButton);
    6363      //
    6464      // itemsGroupBox
     
    7676      // btnImport
    7777      //
    78       this.btnImport.Location = new System.Drawing.Point(3, 4);
    79       this.btnImport.Name = "btnImport";
    80       this.btnImport.Size = new System.Drawing.Size(75, 23);
    81       this.btnImport.TabIndex = 7;
    82       this.btnImport.Text = "Import";
    83       this.btnImport.UseVisualStyleBackColor = true;
    84       this.btnImport.Click += new System.EventHandler(this.btnImport_Click);
     78      this.importButton.Location = new System.Drawing.Point(3, 4);
     79      this.importButton.Name = "btnImport";
     80      this.importButton.Size = new System.Drawing.Size(75, 23);
     81      this.importButton.TabIndex = 7;
     82      this.importButton.Text = "Import";
     83      this.importButton.UseVisualStyleBackColor = true;
     84      this.importButton.Click += new System.EventHandler(this.importButton_Click);
    8585      //
    8686      // openFileDialog
     
    106106    #endregion
    107107
    108     private System.Windows.Forms.Button btnImport;
     108    private System.Windows.Forms.Button importButton;
    109109    private System.Windows.Forms.OpenFileDialog openFileDialog;
    110110  }
  • branches/ChangeDatasetOfRegressionModel/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.cs

    r7399 r7468  
    4545    protected override void SetEnabledStateOfControls() {
    4646      base.SetEnabledStateOfControls();
    47       btnImport.Enabled = !Locked && !ReadOnly && Content != null;
     47      importButton.Enabled = !Locked && !ReadOnly && Content != null;
    4848    }
    4949
     
    6262    #endregion
    6363
    64     private void btnImport_Click(object sender, System.EventArgs e) {
    65       if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
    66         object hlFile = null;
    67         try {
    68           hlFile = XmlParser.Deserialize(openFileDialog.FileName);
    69         }
    70         catch (Exception ex) {
    71           ErrorHandling.ShowErrorDialog(this, ex);
    72         }
     64    private void importButton_Click(object sender, EventArgs e) {
     65      if (openFileDialog.ShowDialog(this) != DialogResult.OK) return;
    7366
    74         if (hlFile != null) {
    75           IRegressionProblemData problemData = null;
    76           if (hlFile is RegressionProblemData) {
    77             problemData = (RegressionProblemData)hlFile;
    78           } else if (hlFile is IRegressionProblem) {
    79             problemData = ((IRegressionProblem)hlFile).ProblemData;
    80           } else if (hlFile is IRegressionSolution) {
    81             problemData = ((IRegressionSolution)hlFile).ProblemData;
    82           }
     67      object hlFile = null;
     68      try {
     69        hlFile = XmlParser.Deserialize(openFileDialog.FileName);
     70      }
     71      catch (Exception ex) {
     72        ErrorHandling.ShowErrorDialog(this, ex);
     73        return;
     74      }
    8375
    84           if (problemData == null) {
    85             ErrorHandling.ShowErrorDialog(this,
    86               new NullReferenceException("The problem data is null." + Environment.NewLine
    87                                        + "The .hl-file is no RegressionProblemData or RegressionProblem."));
    88           } else {
    89             StringBuilder message = new StringBuilder();
    90             if (!problemData.TargetVariable.Equals(Content.ProblemData.TargetVariable))
    91               message.AppendLine("The target variables are not matching. Old target variable: '"
    92                                + Content.ProblemData.TargetVariable
    93                                + "'. New targetvariable: '" + problemData.TargetVariable + "'");
     76      IRegressionProblemData problemData = null;
     77      if (hlFile is IRegressionProblemData) {
     78        problemData = (IRegressionProblemData)hlFile;
     79      } else if (hlFile is IRegressionProblem) {
     80        problemData = ((IRegressionProblem)hlFile).ProblemData;
     81      } else if (hlFile is IRegressionSolution) {
     82        problemData = ((IRegressionSolution)hlFile).ProblemData;
     83      }
    9484
    95             List<string> variables = problemData.InputVariables.Select(x => x.Value).ToList();
     85      if (problemData == null) {
     86        ErrorHandling.ShowErrorDialog(this,
     87          new NullReferenceException("The problem data is null." + Environment.NewLine
     88                                   + "The .hl-file is no RegressionProblemData or RegressionProblem."));
     89        return;
     90      }
    9691
    97             foreach (var item in Content.ProblemData.InputVariables.CheckedItems) {
    98               if (!variables.Contains(item.Value.Value))
    99                 message.AppendLine("Input variable '" + item.Value.Value + "' is not in the new problem data.");
    100             }
     92      StringBuilder message = new StringBuilder();
     93      if (!problemData.TargetVariable.Equals(Content.ProblemData.TargetVariable))
     94        message.AppendLine("The target variables are not matching. Old target variable: '"
     95                         + Content.ProblemData.TargetVariable
     96                         + "'. New targetvariable: '" + problemData.TargetVariable + "'");
    10197
    102             if (message.Length != 0)
    103               ErrorHandling.ShowErrorDialog(this, new Exception(message.ToString()));
    104             else
    105               Content.ProblemData = problemData;
    106           }
    107         }
     98      List<string> variables = problemData.InputVariables.Select(x => x.Value).ToList();
     99      foreach (var item in Content.ProblemData.InputVariables.CheckedItems) {
     100        if (!variables.Contains(item.Value.Value))
     101          message.AppendLine("Input variable '" + item.Value.Value + "' is not in the new problem data.");
    108102      }
     103
     104      if (message.Length != 0)
     105        ErrorHandling.ShowErrorDialog(this, new Exception(message.ToString()));
     106      else
     107        Content.ProblemData = problemData;
     108
    109109    }
    110110  }
Note: See TracChangeset for help on using the changeset viewer.