Ejemplo n.º 1
0
        private void LoadItems(XDocument doc)
        {
            try
            {
                PrintWorkItems = new Collection<WorkItemPrintData>();
                var xitem = from item in doc.Descendants("item")
                            select new
                                       {
                                           type = item.Attribute("type").Value,
                                           bgcolor = int.Parse(item.Attribute("bgColor").Value),
                                           txtcolor = int.Parse(item.Attribute("txtColor").Value),
                                           layout = item.Element("layout")
                                       };

                foreach (var item in xitem)
                {
                    var printWorkItem = new WorkItemPrintData
                                            {
                                                Type = item.type,
                                                BackGroundColor = item.bgcolor,
                                                TextColor = item.txtcolor,
                                            };
                    try
                    {
                        var xrow = from row in item.layout.Descendants("row")
                                   select new
                                              {
                                                  font = row.Attribute("font").Value,
                                                  alignment = row.Attribute("alignment"),
                                                  rowLayout = row
                                              };
                        foreach (var row in xrow)
                        {
                            var r = new Row
                                        {
                                            Font = row.font,
                                            RowElements = CreateRowElements(row.rowLayout)
                                        };

                            if (row.alignment != null)
                            {
                                r.Alignment = row.alignment.Value;
                            }

                            printWorkItem.Rows.Add(r);
                        }
                    }
                    catch (Exception e)
                    {
                        if (!(e is SettingsLoadException))
                        {
                            throw new SettingsLoadException("Error loading workitem:" + printWorkItem.Type);
                        }

                        throw;
                    }

                    PrintWorkItems.Add(printWorkItem);
                }
            }
            catch (Exception e)
            {
                if (!(e is SettingsLoadException))
                {
                    throw new SettingsLoadException("Error loading workitem setting");
                }

                throw;
            }
        }
Ejemplo n.º 2
0
        private static object[] CreateXmlRowElements(Row row)
        {
            var xelements = new Collection<object>();
            foreach (IRowElement rowElement in row.RowElements)
            {
                var rowElementText = rowElement as RowElementText;
                if (rowElementText != null)
                {
                    xelements.Add(new XElement("element", new object[]
                                                              {
                                                                  new XAttribute("type", "text"),
                                                                  new XAttribute("maxLength", rowElement.MaxLength),
                                                                  rowElementText.Data
                                                              }));
                }

                var rowElementField = rowElement as RowElementField;
                if (rowElementField != null)
                {
                    xelements.Add(new XElement("element", new object[]
                                                              {
                                                                  new XAttribute("type", "field"),
                                                                  new XAttribute("maxLength", rowElement.MaxLength),
                                                                  new XAttribute("dateFormatting",
                                                                                 rowElement.DateFormatting),
                                                                  rowElementField.FieldName
                                                              }));
                }

                var rowElementRelatedItem = rowElement as RowElementRelatedItem;
                if (rowElementRelatedItem != null)
                {
                    xelements.Add(new XElement("element", new object[]
                                                              {
                                                                  new XAttribute("type", "relatedItem"),
                                                                  new XAttribute("maxLength",
                                                                                 rowElementRelatedItem.MaxLength),
                                                                  new XAttribute("dateFormatting",
                                                                                 rowElementRelatedItem.DateFormatting),
                                                                  new XAttribute("searchField",
                                                                                 rowElementRelatedItem.SearchField),
                                                                  new XAttribute("searchData",
                                                                                 rowElementRelatedItem.SearcData),
                                                                  new XAttribute("resultField",
                                                                                 rowElementRelatedItem.ResultField)
                                                              }));
                }
            }

            return xelements.ToArray();
        }