예제 #1
0
        private void dataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            ExamineExamplesDataGridItem item = (ExamineExamplesDataGridItem)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));
            }
        }
예제 #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)
                {
                    List <ExamineExamplesDataGridItem> items = new List <ExamineExamplesDataGridItem>();

                    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))
                                {
                                    ExamineExamplesDataGridItem item = new ExamineExamplesDataGridItem();

                                    string[] predictiveValues = new string[_attributeTypeSet.PredictiveAttributeTypes.Count];
                                    string   decisiveValue    = string.Empty;

                                    // признак того, что следует перейти к следующзему примеру
                                    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())
                                    {
                                        int    j     = -2;
                                        string value = string.Empty;

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

                                                if (j == -2)
                                                {
                                                    OnErrorOccured(this,
                                                                   @"Тип атрибута """ + exampleAttributeXAttribute.Value +
                                                                   @""" не определён в текущем наборе типов атрибутов.");
                                                    isNeedContinue = true;
                                                    break;
                                                }
                                            }
                                            break;

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

                                            if (isNeedContinue)
                                            {
                                                break;
                                            }
                                        }

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

                                        if (j == -1)
                                        {
                                            decisiveValue = value;
                                        }
                                        else
                                        {
                                            predictiveValues[j] = value;
                                        }

                                        if (isNeedContinue)
                                        {
                                            break;
                                        }
                                    }

                                    if (isNeedContinue)
                                    {
                                        continue;
                                    }

                                    for (int i = 0; i < _attributeTypeSet.PredictiveAttributeTypes.Count; i++)
                                    {
                                        item.PredictiveAttributeValues.Insert(i, predictiveValues[i]);
                                    }
                                    item.DecisiveAttributeValue = decisiveValue;
                                    item.ExaminedAttributeValue = string.Empty;
                                    items.Add(item);
                                }
                            }
                        }
                    }

                    dataGrid.ItemsSource = items;

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