コード例 #1
0
        private bool GetCheckerValue(string s, out double result)     // s - Rx, число или название поля; true - успех парсинга, false - некорректные входные данные
        {
            if (s == "Rx")
            {
                Layout layout = Layout.GetInstance();
                result = layout.GetResistorXResistance();
                return(true);
            }

            double tmp;

            if (SolutionsNames.ContainsKey(s))
            {
                if (double.TryParse(SolutionsNames[s].Text, out tmp))
                {
                    result = tmp;
                    return(true);
                }
                else
                {
                    result = double.NaN;
                    return(false);
                }
            }

            if (double.TryParse(s, out tmp))
            {
                result = tmp;
                return(true);
            }

            throw new XMLValidationException("<checker> field value error!");
        }
コード例 #2
0
        private void DrawSolutionLines()                            // Отрисовка строк решения из текущего задания
        {
            var externalSolutionLines = SelectedTask
                                        .Element("solution")
                                        .Descendants("line");

            SolutionLines.Clear();
            SolutionsNames.Clear();

            foreach (var line in externalSolutionLines)
            {
                StackPanel sp = new StackPanel()
                {
                    Orientation = Orientation.Horizontal, Margin = new Thickness(5)
                };
                foreach (var item in line.Descendants())
                {
                    if (item.Name == "text")
                    {
                        sp.Children.Add(ParseToStackPanel(item.Value));
                    }
                    else if (item.Name == "field")
                    {
                        TextBox tb = new TextBox()
                        {
                            Width = 60, VerticalAlignment = VerticalAlignment.Center
                        };
                        sp.Children.Add(tb);
                        if (item.Attribute("name") != null)
                        {
                            SolutionsNames.Add(item.Attribute("name").Value, tb);
                        }
                    }
                }
                SolutionLines.Add(sp);
            }
            checker = SelectedTask.Element("solution").Element("checker");
            ButtonCheckerVisibility = checker == null ? Visibility.Collapsed : Visibility.Visible;
        }