public Result deserialize(String json)
        {
            if (json == null || json.Equals(""))
            {
                return null;
            }
            Result result = new Result();
            try
            {
                JObject jObject = JObject.Parse(json);
                result.Cookie = (String)jObject["cookie"];
                result.Title = (String)jObject["title"];
                result.HideCancel = (Boolean)jObject["hideCancel"];
                result.ShowBack = (Boolean)jObject["showBack"];
                JArray jArray = (JArray)jObject["resultParts"];

                foreach (JObject obj in jArray)
                {
                    int type = (int)obj["type"];
                    switch (type)
                    {
                        case 0:
                            result.ResultParts.Add((String)obj["message"]);
                            break;
                        case 1:
                            ResultList resultList = new ResultList();
                            resultList.MultiSelectionEnable = (Boolean)obj["isMultiSelection"];
                            resultList.Title = (String)obj["title"];
                            JArray records = (JArray)obj["records"];
                            if (records != null)
                            {
                                foreach (JObject jRecord in records)
                                {
                                    Record record = new Record();
                                    record.Code = (String)jRecord["code"];
                                    JArray cells = (JArray)jRecord["cells"];
                                    foreach (JObject jCell in cells)
                                    {
                                        Cell cell = new Cell();
                                        cell.Title = (String)jCell["title"];
                                        cell.Value = (String)jCell["value"];
                                        record.Cells.Add(cell);
                                    }
                                    resultList.Records.Add(record);
                                }
                            }
                            result.ResultParts.Add(resultList);
                            break;
                        case 2:
                            CommandsList commandsList = new CommandsList();
                            JArray jCommands = (JArray)obj["commandNames"];
                            if (jCommands != null)
                            {
                                foreach (JObject jCommand in jCommands)
                                {
                                    Command command = new Command();
                                    command.Name = (String)jCommand["name"];
                                    command.Code = (String)jCommand["code"];
                                    commandsList.Commands.Add(command);
                                }
                            }
                            result.ResultParts.Add(commandsList);
                            break;
                        case 3:
                            InputType inputType = new InputType();
                            inputType.Type = (int)obj["inputType"];
                            inputType.Name = (String)obj["name"];
                            inputType.Value = (String)obj["value"];
                            result.ResultParts.Add(inputType);
                            break;
                    }
                }
            }
            catch (Exception exception)
            {
                Console.Write(exception.StackTrace);
            }

            return result;
        }
Esempio n. 2
0
        private void addResultList(ResultList resultList)
        {
            Grid grid = new Grid();
            List<Record> resultRecords = resultList.Records;
            foreach (Record gridRecord in resultRecords)
            {
                foreach (Cell cell in gridRecord.Cells)
                {
                    RowDefinition rowDef = new RowDefinition() { Height = GridLength.Auto };
                    grid.RowDefinitions.Add(rowDef);
                }
            }

            GridLength cellWidth = new GridLength(1, GridUnitType.Star);
            ColumnDefinition column1Def = new ColumnDefinition() { Width = cellWidth };
            grid.ColumnDefinitions.Add(column1Def);

            ColumnDefinition column2Def = new ColumnDefinition() { Width = cellWidth };
            grid.ColumnDefinitions.Add(column2Def);

            Style style = new Style(typeof(TextBlock));
            style.Setters.Add(new Setter(TextBlock.FontSizeProperty, 25));
            style.Setters.Add(new Setter(TextBlock.TextWrappingProperty, TextWrapping.Wrap));

            int recordIndex = 0;
            foreach (Record gridRecord in resultRecords)
            {
                List<Cell> cells = gridRecord.Cells;
                int cellCount = cells.Count;

                int firstCellIndex = recordIndex;
                foreach (Cell cell in cells)
                {

                        TextBlock nameText = new TextBlock()
                        {
                            Text = cell.Title,
                            Name = gridRecord.Code,
                            Style = style,
                            VerticalAlignment = VerticalAlignment.Center,
                            HorizontalAlignment = HorizontalAlignment.Stretch,
                            Margin = new Thickness(10, 2, 2, 2),
                            TextAlignment = TextAlignment.Left
                        };
                        Grid.SetColumn(nameText, 0);
                        Grid.SetRow(nameText, recordIndex);
                        nameText.MouseLeftButtonDown += Record_Click;
                        grid.Children.Add(nameText);

                    TextBlock valueText = new TextBlock()
                    {
                        Text = cell.Value,
                        Name = gridRecord.Code,
                        Style = style,
                        VerticalAlignment = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Stretch
                    };

                    if (cell.HasTitle())
                    {
                        valueText.TextAlignment = TextAlignment.Right;
                        Grid.SetColumn(valueText, 1);
                        valueText.Margin = new Thickness(2, 2, 10, 2);
                        if (!cell.HasValue())
                        {
                            Grid.SetColumnSpan(nameText, 2);
                        }
                    } else
                    {
                        valueText.TextAlignment = TextAlignment.Left;
                        Grid.SetColumn(valueText, 0);
                        Grid.SetColumnSpan(valueText, 2);
                        valueText.Margin = new Thickness(10, 2, 2, 2);
                    }
                    Grid.SetRow(valueText, recordIndex);
                    valueText.MouseLeftButtonDown += Record_Click;
                    grid.Children.Add(valueText);

                    recordIndex++;
                }

                if (resultRecords.Last() != gridRecord)
                {
                    Border columnBottom = new Border()
                    {
                        BorderThickness = new Thickness(0, 0, 0, 1),
                        BorderBrush = new SolidColorBrush(Colors.White),
                        Margin =new Thickness(0, 0, 0, 1)
                    };
                    Grid.SetRow(columnBottom, recordIndex - 1);
                    Grid.SetColumnSpan(columnBottom, 2);
                    grid.Children.Add(columnBottom);
                }
            }

            Border resultListBorder = getBorder();
            resultListBorder.Child = grid;
            StackPanel resultListPane = new StackPanel() { Margin = new Thickness(5, 3, 0, 3) };
            TextBlock resultListTitle = new TextBlock() { Text = resultList.Title, TextWrapping = TextWrapping.Wrap };
            resultListPane.Children.Add(resultListTitle);
            resultListPane.Children.Add(resultListBorder);
            ContentPanel.Children.Add(resultListPane);
        }