예제 #1
0
        private void ButtonEditClick(object sender, EventArgs e)
        {
            var selectedIndex = listView.SelectedIndices[0];

            if (radioButtonDomains.Checked)
            {
                var domainForm = new DomainForm
                {
                    KnowledgeBase = KnowledgeBase,
                    Domain        = KnowledgeBase.Domains[listView.SelectedIndices[0]]
                };
                var dialogResult = domainForm.ShowDialog();
                KnowledgeBase.Domains[listView.SelectedIndices[0]] = domainForm.Domain;
                listView.Items[listView.SelectedIndices[0]]        = CreateListViewItem(domainForm.Domain);
            }

            if (radioButtonVariables.Checked)
            {
                var variableForm = new VariableForm
                {
                    KnowledgeBase = KnowledgeBase,
                    Variable      = KnowledgeBase.Variables[listView.SelectedIndices[0]]
                };
                var dialogResult = variableForm.ShowDialog();
                KnowledgeBase.Variables[listView.SelectedIndices[0]] = variableForm.Variable;
                listView.Items[listView.SelectedIndices[0]]          = CreateListViewItem(variableForm.Variable);
            }

            if (radioButtonRules.Checked)
            {
                var ruleForm = new RuleForm
                {
                    KnowledgeBase = KnowledgeBase,
                    Rule          = KnowledgeBase.Rules[listView.SelectedIndices[0]]
                };
                var dialogResult = ruleForm.ShowDialog();
                KnowledgeBase.Rules[listView.SelectedIndices[0]] = ruleForm.Rule;
                listView.Items[listView.SelectedIndices[0]]      = CreateListViewItem(ruleForm.Rule);
            }

            listView.SelectedIndices.Add(selectedIndex);
            SetColumnsSize();
        }
예제 #2
0
        private void ButtonAddClick(object sender, EventArgs e)
        {
            if (radioButtonDomains.Checked)
            {
                var domainForm = new DomainForm {
                    KnowledgeBase = KnowledgeBase
                };
                var dialogResult = domainForm.ShowDialog();
                if (dialogResult != DialogResult.OK)
                {
                    return;
                }

                if (listView.SelectedIndices.Count > 0)
                {
                    var insertIndex = listView.SelectedIndices.Cast <int>().Max() + 1;
                    KnowledgeBase.Domains.Insert(insertIndex, domainForm.Domain);
                    listView.Items.Insert(insertIndex, CreateListViewItem(domainForm.Domain));
                    listView.SelectedIndices.Clear();
                    listView.SelectedIndices.Add(insertIndex);
                }
                else
                {
                    KnowledgeBase.Domains.Add(domainForm.Domain);
                    listView.Items.Add(CreateListViewItem(domainForm.Domain));
                    listView.SelectedIndices.Add(listView.Items.Count - 1);
                }
            }

            if (radioButtonVariables.Checked)
            {
                var variableForm = new VariableForm
                {
                    KnowledgeBase = KnowledgeBase,
                };
                var dialogResult = variableForm.ShowDialog();
                if (dialogResult != DialogResult.OK)
                {
                    return;
                }

                if (listView.SelectedIndices.Count > 0)
                {
                    var insertIndex = listView.SelectedIndices.Cast <int>().Max() + 1;
                    KnowledgeBase.Variables.Insert(insertIndex, variableForm.Variable);
                    listView.Items.Insert(insertIndex, CreateListViewItem(variableForm.Variable));
                    listView.SelectedIndices.Clear();
                    listView.SelectedIndices.Add(insertIndex);
                }
                else
                {
                    KnowledgeBase.Variables.Add(variableForm.Variable);
                    listView.Items.Add(CreateListViewItem(variableForm.Variable));
                    listView.SelectedIndices.Add(listView.Items.Count - 1);
                }
            }

            if (radioButtonRules.Checked)
            {
                var ruleForm = new RuleForm
                {
                    KnowledgeBase = KnowledgeBase
                };
                var dialogResult = ruleForm.ShowDialog();
                if (dialogResult != DialogResult.OK)
                {
                    return;
                }

                if (listView.SelectedIndices.Count > 0)
                {
                    var insertIndex = listView.SelectedIndices.Cast <int>().Max() + 1;
                    KnowledgeBase.Rules.Insert(insertIndex, ruleForm.Rule);
                    listView.Items.Insert(insertIndex, CreateListViewItem(ruleForm.Rule));
                    listView.SelectedIndices.Clear();
                    listView.SelectedIndices.Add(insertIndex);
                }
                else
                {
                    KnowledgeBase.Rules.Add(ruleForm.Rule);
                    listView.Items.Add(CreateListViewItem(ruleForm.Rule));
                    listView.SelectedIndices.Add(listView.Items.Count - 1);
                }
            }

            SetColumnsSize();
        }