コード例 #1
0
        private void dataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            ArguedLearningExamplesDataGridItem item = (ArguedLearningExamplesDataGridItem)e.Row.Item;

            if (item.IsValid)
            {
                e.Row.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            }
            else
            {
                e.Row.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
            }

            //      int columnIndex = dataGrid.Columns.IndexOf(e.Column);
            //      for (int i = 0; i < _attributeTypeSet.PredictiveAttributeTypes.Count; i ++)
            //{
            //    if (e.Column.Header.Equals("Потому что"))
            //    {

            //    }
            //}



            //foreach (var arguedLearningExamplesDataGridItem in _items)
            //{
            //    if (item.Equals(arguedLearningExamplesDataGridItem))
            //    {
            //        continue;
            //    }


            //}
        }
コード例 #2
0
        private void buttonLoadExamples_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog()
                {
                    Filter = SerializationData.FileDialogFilter,
                    Title  = SerializationData.LoadExamplesFileDialogTitle
                };

                Nullable <bool> ofdResult = ofd.ShowDialog();

                if (ofdResult == true)
                {
                    var attributeTypes = _attributeTypeSet.GetAttributeTypes();

                    XDocument examplesXDocument = XDocument.Load(ofd.FileName);
                    foreach (var examplesXElement in examplesXDocument.Elements())
                    {
                        if (examplesXElement.Name.ToString().Equals(SerializationData.ExamplesNode))
                        {
                            foreach (var exampleXElement in examplesXElement.Elements())
                            {
                                if (exampleXElement.Name.ToString().Equals(SerializationData.ExampleNode))
                                {
                                    ArguedLearningExamplesDataGridItem item = new ArguedLearningExamplesDataGridItem();

                                    AttributeType[] predictiveValuesType       = new AttributeType[_attributeTypeSet.PredictiveAttributeTypes.Count];
                                    string[]        predictiveValues           = new string[_attributeTypeSet.PredictiveAttributeTypes.Count];
                                    bool[]          predictiveValuesIsDecisive = new bool[_attributeTypeSet.PredictiveAttributeTypes.Count];
                                    bool[]          predictiveValuesIsBecause  = new bool[_attributeTypeSet.PredictiveAttributeTypes.Count];
                                    bool[]          predictiveValuesIsDespite  = new bool[_attributeTypeSet.PredictiveAttributeTypes.Count];
                                    AttributeType   decisiveValueType          = null;
                                    string          decisiveValue            = string.Empty;
                                    bool            decisiveValuieIsDecisive = false;
                                    bool            decisiveValuieIsBecause  = false;
                                    bool            decisiveValuieIsDespite  = false;


                                    // признак того, что следует перейти к следующзему примеру
                                    bool isNeedContinue = false;

                                    foreach (var exampleXAttribute in exampleXElement.Attributes())
                                    {
                                        if (exampleXAttribute.Name.ToString().Equals(SerializationData.IsUse))
                                        {
                                            bool isUse;
                                            if (Boolean.TryParse(exampleXAttribute.Value, out isUse))
                                            {
                                                item.IsUse = isUse;
                                            }
                                            else
                                            {
                                                if (OnErrorOccured != null)
                                                {
                                                    OnErrorOccured(this, @"Недопустимое значение атрибута ""Использовать"".");
                                                    isNeedContinue = true;
                                                    break;
                                                }
                                            }
                                        }
                                    }

                                    if (isNeedContinue)
                                    {
                                        continue;
                                    }

                                    foreach (var exampleAttributeXElement in exampleXElement.Elements())
                                    {
                                        AttributeType type       = null;
                                        string        value      = string.Empty;
                                        bool          isDecisive = false;
                                        bool          isBecause  = false;
                                        bool          isDespite  = false;

                                        int predictiveAttributeIndex = -1;

                                        foreach (var exampleAttributeXAttribute in exampleAttributeXElement.Attributes())
                                        {
                                            switch (exampleAttributeXAttribute.Name.ToString())
                                            {
                                            case SerializationData.ExampleAttributeTypeName:
                                            {
                                                if (exampleAttributeXAttribute.Value.Equals(_attributeTypeSet.DecisiveAttributeType.Name))
                                                {
                                                    type = _attributeTypeSet.DecisiveAttributeType;
                                                }
                                                else
                                                {
                                                    for (int i = 0; i < _attributeTypeSet.PredictiveAttributeTypes.Count; i++)
                                                    {
                                                        var attributeType = _attributeTypeSet.PredictiveAttributeTypes[i];
                                                        if (exampleAttributeXAttribute.Value.Equals(attributeType.Name))
                                                        {
                                                            type = attributeType;
                                                            predictiveAttributeIndex = i;
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                            break;

                                            case SerializationData.ExampleAttrinuteValue:
                                            {
                                                value = exampleAttributeXAttribute.Value;
                                            }
                                            break;

                                            case SerializationData.ExampleAttributeIsDecisive:
                                            {
                                                Boolean.TryParse(exampleAttributeXAttribute.Value, out isDecisive);
                                            }
                                            break;

                                            case SerializationData.ExampleAttributeIsBecause:
                                            {
                                                Boolean.TryParse(exampleAttributeXAttribute.Value, out isBecause);
                                            }
                                            break;

                                            case SerializationData.ExampleAttributeIsDespite:
                                            {
                                                Boolean.TryParse(exampleAttributeXAttribute.Value, out isDespite);
                                            }
                                            break;
                                            }

                                            if (isNeedContinue)
                                            {
                                                break;
                                            }
                                        }

                                        //todo проверить наличие значения у типа данных и если всё хорошо

                                        if (isDecisive)
                                        {
                                            decisiveValueType        = type;
                                            decisiveValue            = value;
                                            decisiveValuieIsDecisive = isDecisive;
                                            decisiveValuieIsBecause  = isBecause;
                                            decisiveValuieIsDespite  = isDespite;
                                        }
                                        else
                                        {
                                            predictiveValuesType[predictiveAttributeIndex]       = type;
                                            predictiveValues[predictiveAttributeIndex]           = value;
                                            predictiveValuesIsDecisive[predictiveAttributeIndex] = isDecisive;
                                            predictiveValuesIsBecause[predictiveAttributeIndex]  = isBecause;
                                            predictiveValuesIsDespite[predictiveAttributeIndex]  = isDespite;
                                        }

                                        if (isNeedContinue)
                                        {
                                            break;
                                        }
                                    }

                                    if (isNeedContinue)
                                    {
                                        continue;
                                    }

                                    for (int i = 0; i < _attributeTypeSet.PredictiveAttributeTypes.Count; i++)
                                    {
                                        item.PredictiveAttributeValues.Insert(i,
                                                                              new PredictiveAttributeValue(predictiveValues[i], predictiveValuesIsBecause[i],
                                                                                                           predictiveValuesIsDespite[i]));
                                    }
                                    item.DecisiveAttributeValue = decisiveValue;
                                    _items.Add(item);
                                }
                            }
                        }
                    }

                    dataGrid.Items.Refresh();

                    if (OnFileLoaded != null)
                    {
                        OnFileLoaded(sender, "Примеры загружены из файла " + ofd.FileName + ".");
                    }
                }
            }
            catch (Exception ex)
            {
                if (OnErrorOccured != null)
                {
                    OnErrorOccured(this, ex.Message);
                }
            }
        }