|
@@ -120,7 +120,8 @@ namespace InABox.DynamicGrid
|
|
|
return cells;
|
|
|
}
|
|
|
|
|
|
- private static Regex VariableRegex = new("^\\s*\\[(?<VAR>[^:\\]]+)(?::(?<TYPE>[^\\]]+))?\\]$");
|
|
|
+ private static Regex VariableRegex = new(@"^\[(?<VAR>[^:\]]+)(?::(?<TYPE>[^:\]]*))?(?::(?<PROPERTIES>[^\]]*))?\]$");
|
|
|
+ private static Regex HeaderRegex = new(@"^{(?<HEADER>[^:}]+)(?::(?<COLLAPSED>[^}]*))?}$");
|
|
|
|
|
|
public static DFLayout LoadLayout(ISpreadsheet spreadsheet)
|
|
|
{
|
|
@@ -163,18 +164,15 @@ namespace InABox.DynamicGrid
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /*var rowHeights = new Dictionary<int, float>();
|
|
|
for (int row = firstRow; row <= lastRow; ++row)
|
|
|
{
|
|
|
- rowHeights[row] = sheet.GetRowHeight(row);
|
|
|
+ float height = sheet.GetRowHeight(row);
|
|
|
+ float defaultheight = sheet.GetDefaultRowHeight();
|
|
|
+ float multiplier = defaultheight == 0 ? 1.0F : height/defaultheight;
|
|
|
+ var final = Math.Round(multiplier * 10,0) * 5;
|
|
|
+ layout.RowHeights.Add($"{final}");
|
|
|
}
|
|
|
- var totalHeight = rowHeights.Values.Sum();*/
|
|
|
-
|
|
|
- for(int row = firstRow; row <= lastRow; ++row)
|
|
|
- {
|
|
|
- layout.RowHeights.Add("Auto");
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
foreach(var cell in cells)
|
|
|
{
|
|
|
var style = cell.InnerCell.GetStyle();
|
|
@@ -182,50 +180,60 @@ namespace InABox.DynamicGrid
|
|
|
if (string.IsNullOrWhiteSpace(cell.Content) && style.Foreground == Color.Empty) continue;
|
|
|
|
|
|
DFLayoutControl? control;
|
|
|
+ String content = cell.Content?.Trim() ?? "";
|
|
|
|
|
|
- var match = VariableRegex.Match(cell.Content);
|
|
|
- if (match.Success)
|
|
|
- {
|
|
|
- var variableName = match.Groups["VAR"];
|
|
|
- var variableType = match.Groups["TYPE"];
|
|
|
+ var headermatch = HeaderRegex.Match(content);
|
|
|
+ var variablematch = VariableRegex.Match(content);
|
|
|
|
|
|
+ if (headermatch.Success)
|
|
|
+ {
|
|
|
+ var text = headermatch.Groups["HEADER"];
|
|
|
+ var collapsed = headermatch.Groups["COLLAPSED"];
|
|
|
+ var header = new DFLayoutHeader()
|
|
|
+ {
|
|
|
+ Header = text.Value,
|
|
|
+ Collapsed = collapsed.Success ? String.Equals(collapsed.Value.ToUpper(),"COLLAPSED") : false,
|
|
|
+ Style = CreateStyle(style)
|
|
|
+ };
|
|
|
+
|
|
|
+ control = header;
|
|
|
+ }
|
|
|
+ else if (variablematch.Success)
|
|
|
+ {
|
|
|
+ var variableName = variablematch.Groups["VAR"];
|
|
|
+ var variableType = variablematch.Groups["TYPE"];
|
|
|
+ var variableProps = variablematch.Groups["PROPERTIES"];
|
|
|
+
|
|
|
Type? fieldType = null;
|
|
|
if (variableType.Success)
|
|
|
- {
|
|
|
fieldType = DFUtils.GetFieldType(variableType.Value);
|
|
|
- }
|
|
|
fieldType ??= typeof(DFLayoutStringField);
|
|
|
-
|
|
|
+
|
|
|
var field = (Activator.CreateInstance(fieldType) as DFLayoutField)!;
|
|
|
field.Name = variableName.Value;
|
|
|
+
|
|
|
+
|
|
|
+ if (variableProps.Success)
|
|
|
+ {
|
|
|
+ if (field is DFLayoutOptionField option)
|
|
|
+ option.Properties.Options = variableProps.Value;
|
|
|
+
|
|
|
+ // need to populate other variable types here
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
control = field;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- var font = style.Font;
|
|
|
-
|
|
|
control = new DFLayoutLabel
|
|
|
{
|
|
|
Caption = cell.Content,
|
|
|
-
|
|
|
- Style = new DFLayoutTextStyle
|
|
|
- {
|
|
|
- FontSize = font.FontSize,
|
|
|
-
|
|
|
- IsItalic = font.Italic,
|
|
|
- IsBold = font.Bold,
|
|
|
- Underline = font.Underline switch
|
|
|
- {
|
|
|
- Scripting.UnderlineType.None => UnderlineType.None,
|
|
|
- Scripting.UnderlineType.Single or Scripting.UnderlineType.SingleAccounting => UnderlineType.Single,
|
|
|
- Scripting.UnderlineType.Double or Scripting.UnderlineType.DoubleAccounting => UnderlineType.Double,
|
|
|
- _ => UnderlineType.None
|
|
|
- },
|
|
|
- BackgroundColour = style.Foreground,
|
|
|
- ForegroundColour = font.Colour
|
|
|
- }
|
|
|
+ Style = CreateStyle(style)
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
if(control is not null)
|
|
|
{
|
|
|
control.Row = cell.Row - firstRow + 1;
|
|
@@ -238,7 +246,33 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
return layout;
|
|
|
}
|
|
|
+
|
|
|
+ private static DFLayoutTextStyle CreateStyle(ICellStyle style)
|
|
|
+ {
|
|
|
+ if (style == null)
|
|
|
+ return new DFLayoutTextStyle();
|
|
|
+
|
|
|
+ var result = new DFLayoutTextStyle
|
|
|
+ {
|
|
|
+ FontSize = style.Font.FontSize,
|
|
|
+
|
|
|
+ IsItalic = style.Font.Italic,
|
|
|
+ IsBold = style.Font.Bold,
|
|
|
+ Underline = style.Font.Underline switch
|
|
|
+ {
|
|
|
+ Scripting.UnderlineType.None => UnderlineType.None,
|
|
|
+ Scripting.UnderlineType.Single or Scripting.UnderlineType.SingleAccounting => UnderlineType.Single,
|
|
|
+ Scripting.UnderlineType.Double or Scripting.UnderlineType.DoubleAccounting => UnderlineType.Double,
|
|
|
+ _ => UnderlineType.None
|
|
|
+ },
|
|
|
+ BackgroundColour = style.Background,
|
|
|
+ ForegroundColour = style.Font.Colour
|
|
|
+ };
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
public abstract class DynamicFormLayoutGrid<T> : DynamicOneToManyGrid<DigitalForm, DigitalFormLayout> where T : Entity, IRemotable, IPersistent, new()
|
|
|
{
|
|
@@ -269,26 +303,34 @@ namespace InABox.DynamicGrid
|
|
|
try
|
|
|
{
|
|
|
DFLayout layout;
|
|
|
+ Dictionary<String, String> variablegroups = new Dictionary<string, string>();
|
|
|
using (var fs = new FileStream(dialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
|
|
|
{
|
|
|
layout = LoadLayoutFromSpreadsheet(new Spreadsheet(fs));
|
|
|
}
|
|
|
|
|
|
var dfLayout = CreateItem();
|
|
|
+ dfLayout.Code = Path.GetFileNameWithoutExtension(dialog.FileName).ToUpper();
|
|
|
+ dfLayout.Description = $"Imported From {Path.GetFileName(dialog.FileName)}";
|
|
|
dfLayout.Layout = layout.SaveLayout();
|
|
|
if(EditItems(new DigitalFormLayout[] { dfLayout }))
|
|
|
{
|
|
|
var newVariables = new List<DigitalFormVariable>();
|
|
|
+ String group = "";
|
|
|
foreach (var element in layout.Elements)
|
|
|
{
|
|
|
- if(element is DFLayoutField field)
|
|
|
+ if (element is DFLayoutHeader header)
|
|
|
{
|
|
|
- var variable = new DigitalFormVariable
|
|
|
- {
|
|
|
- Code = field.Name,
|
|
|
- Description = field.Name
|
|
|
- };
|
|
|
+ group = header.Header;
|
|
|
+ }
|
|
|
+ else if (element is DFLayoutField field)
|
|
|
+ {
|
|
|
+ var variable = new DigitalFormVariable();
|
|
|
variable.SetFieldType(field.GetType());
|
|
|
+ variable.SaveProperties(field.GetProperties());
|
|
|
+ variable.Group = group;
|
|
|
+ variable.Code = field.Name;
|
|
|
+ variable.Description = field.Name;
|
|
|
newVariables.Add(variable);
|
|
|
}
|
|
|
}
|