Free cookie consent management tool by TermsFeed Policy Generator

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.