private void addOrEditBeliefButton_Click(object sender, EventArgs e)
        {
            //clear errors
            addBeliefErrorProvider.Clear();
            var newBelief = new BeliefDTO
            {
                Name        = this.beliefNameTextBox.Text.Trim(),
                Perspective = this.beliefVisibilityComboBox.Text,
                Value       = this.beliefValueTextBox.Text.Trim()
            };

            try
            {
                if (_beliefToEdit != null)
                {
                    _knowledgeBaseVm.RemoveBeliefs(new[] { _beliefToEdit });
                    _knowledgeBaseVm.AddBelief(newBelief);
                    this.Close();
                }
                else
                {
                    _knowledgeBaseVm.AddBelief(newBelief);
                }
            }
            catch (Exception ex)
            {
                addBeliefErrorProvider.SetError(beliefNameTextBox, ex.Message);
                if (_beliefToEdit != null)
                {
                    _knowledgeBaseVm.AddBelief(_beliefToEdit);
                }
                return;
            }
        }
Exemplo n.º 2
0
 private void addOrEditBeliefButton_Click(object sender, EventArgs e)
 {
     //clear errors
     addBeliefErrorProvider.Clear();
     try
     {
         var newBelief = new BeliefDTO
         {
             Name        = this.beliefNameTextBox.Value.ToString(),
             Perspective = this.perspectiveTextBox.Value.ToString(),
             Value       = this.beliefValueTextBox.Value.ToString(),
             Certainty   = this.certaintyTextBox.Value
         };
         if (_beliefToEdit != null)
         {
             _knowledgeBaseVm.RemoveBeliefs(new[] { _beliefToEdit });
             _knowledgeBaseVm.AddBelief(newBelief);
             this.Close();
         }
         else
         {
             _knowledgeBaseVm.AddBelief(newBelief);
         }
         Close();
     }
     catch (Exception ex)
     {
         addBeliefErrorProvider.SetError(beliefNameTextBox, ex.Message);
         if (_beliefToEdit != null)
         {
             _knowledgeBaseVm.AddBelief(_beliefToEdit);
         }
         return;
     }
 }