using InABox.Core;
using InABox.Wpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
namespace InABox.DynamicGrid
{
public abstract class DynamicFormWindow : ThemableWindow
{
protected abstract DynamicFormDesignGrid Grid { get; }
private DFLayoutType _type;
public DFLayoutType Type
{
get => _type;
set
{
_type = value;
Width = _type == DFLayoutType.Mobile ? 600 : 1000;
Height = 800;
}
}
public DFLayout Form
{
get => Grid.Form;
set => Grid.Form = value;
}
public DigitalFormVariable[] Variables
{
get => Grid.Variables;
set => Grid.Variables = value;
}
///
/// Renders the form; after this is called, any changes to properties triggers a refresh.
///
public void Initialize()
{
Grid.Initialize();
}
public void LoadLayout(DigitalFormLayout layout, DigitalFormVariable[] variables)
{
Variables = variables;
var f = new DFLayout();
if (!string.IsNullOrWhiteSpace(layout.Layout))
{
f.LoadLayout(layout.Layout);
}
else
{
f = new DFLayout();
f.RowHeights.Add("Auto");
f.ColumnWidths.AddRange(new[] { "*", "Auto" });
}
f.LoadVariables(variables);
Form = f;
}
/*public static T LoadDigitalForm(Guid id) where T : Entity, IPersistent, IRemotable, IDigitalFormInstance, new()
{
var result = new Client().Query(
new Filter(x => x.ID).IsEqualTo(id),
new Columns(
x => x.ID,
x => x.Form.ID,
x => x.Form.Description,
x => x.FormCompleted,
x => x.FormCompletedBy.ID,
x => x.FormCompletedBy.UserID,
x => x.FormData
)
).Rows.FirstOrDefault()?.ToObject();
return result;
}*/
}
}