Exemple #1
0
 public override Object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
 {
     if (value == null)
     {
         return(null);
     }
     if (value is String)
     {
         SheetRows rows = new SheetRows();
         SheetRow  row  = new SheetRow();
         rows.Add(row);
         foreach (var s in value.ToString().Split(','))
         {
             row.Cells.Add(new SheetCell()
             {
                 Content = s.Trim()
             });
         }
         return(rows);
     }
     throw new XamlException($"Invalid SheetRows value '{value}'");
 }
Exemple #2
0
        void GenerateFromDataModel(RenderContext context, String propertyName)
        {
            var dm = context.DataModel;

            if (dm == null)
            {
                return;
            }
            var coll   = dm.Eval <List <ExpandoObject> >(propertyName);
            var rootMd = dm.Metadata["TRoot"];

            if (!rootMd.Fields.ContainsKey(propertyName))
            {
                throw new XamlException($"Pproperty {propertyName} not found in the root of the data model");
            }
            var fieldData = rootMd.Fields[propertyName];
            var fieldsMD  = dm.Metadata[fieldData.RefObject];

            var header = new SheetRow()
            {
                Style = RowStyle.Header
            };
            var dataRow = new SheetRow();

            Header.Add(header);

            var dataSect = new SheetSection();

            dataSect.SetBinding(nameof(dataSect.ItemsSource), new Bind(propertyName));
            dataSect.Children.Add(dataRow);
            Sections.Add(dataSect);

            foreach (var field in fieldsMD.Fields)
            {
                header.Cells.Add(new SheetCell()
                {
                    Content = field.Key
                });
                var cellBind = new Bind(field.Key);
                cellBind.SetWrapped();
                var cell = new SheetCell();
                cell.SetBinding(nameof(cell.Content), cellBind);
                switch (field.Value.SqlDataType)
                {
                case SqlDataType.DateTime:
                    cellBind.DataType = DataType.DateTime;
                    cell.Wrap         = WrapMode.NoWrap;
                    cell.Align        = TextAlign.Center;
                    break;

                case SqlDataType.Date:
                    cellBind.DataType = DataType.Date;
                    cell.Wrap         = WrapMode.NoWrap;
                    cell.Align        = TextAlign.Center;
                    break;

                case SqlDataType.Time:
                    cellBind.DataType = DataType.Time;
                    cell.Wrap         = WrapMode.NoWrap;
                    cell.Align        = TextAlign.Center;
                    break;

                case SqlDataType.Currency:
                    cellBind.DataType = DataType.Currency;
                    cell.Wrap         = WrapMode.NoWrap;
                    cell.Align        = TextAlign.Right;
                    break;

                case SqlDataType.Float:
                case SqlDataType.Decimal:
                    cellBind.DataType = DataType.Number;
                    cell.Wrap         = WrapMode.NoWrap;
                    cell.Align        = TextAlign.Right;
                    break;

                case SqlDataType.Int:
                case SqlDataType.Bigint:
                    cell.Align = TextAlign.Right;
                    cell.Wrap  = WrapMode.NoWrap;
                    break;
                }
                dataRow.Cells.Add(cell);
            }
        }