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;
            }
        }
Пример #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;
     }
 }
        private void removeBeliefButton_Click(object sender, EventArgs e)
        {
            IList <BeliefDTO> beliefsToRemove = new List <BeliefDTO>();

            for (int i = 0; i < dataGridViewBeliefs.SelectedRows.Count; i++)
            {
                var belief = ((ObjectView <BeliefDTO>)dataGridViewBeliefs.SelectedRows[i].DataBoundItem).Object;
                beliefsToRemove.Add(belief);
            }
            _knowledgeBaseVM.RemoveBeliefs(beliefsToRemove);
        }