소스 검색

Obsoleted QAQuestion

Kenric Nugteren 2 일 전
부모
커밋
26640139bf

+ 3 - 13
prs.desktop/Dashboards/Common/DigitalFormsDashboard.xaml

@@ -9,17 +9,7 @@
              xmlns:wpf="clr-namespace:InABox.WPF;assembly=InABox.Wpf"
              mc:Ignorable="d" 
              d:DesignHeight="450" d:DesignWidth="800">
-    <Grid>
-        <Grid.ColumnDefinitions>
-            <ColumnDefinition Width="Auto" />
-            <ColumnDefinition Width="*" />
-        </Grid.ColumnDefinitions>
-
-        <wpf:QAGrid x:Name="QAGrid" Grid.Column="0" BorderThickness="0" MaxWidth="500" />
-
-        <local:DigitalFormsDashboardGrid x:Name="Grid" Grid.Column="1"
-                                         OnSelectItem="Grid_OnSelectItem"
-                                         OnCellDoubleClick="Grid_OnCellDoubleClick"/>
-
-    </Grid>
+    <local:DigitalFormsDashboardGrid x:Name="Grid"
+                                     OnSelectItem="Grid_OnSelectItem"
+                                     OnCellDoubleClick="Grid_OnCellDoubleClick"/>
 </UserControl>

+ 21 - 114
prs.desktop/Dashboards/Common/DigitalFormsDashboard.xaml.cs

@@ -118,9 +118,6 @@ public partial class DigitalFormsDashboard : UserControl,
 
     public DashboardHeader Header { get; set; } = new();
 
-    private bool IsQAForm = false;
-    private List<QAQuestion> Questions = new();
-
     private bool IsSetup = false;
 
     public DigitalFormsDashboard()
@@ -508,6 +505,8 @@ public partial class DigitalFormsDashboard : UserControl,
     private void DateTypeBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
     {
         var filterType = (DateFilterType)DateTypeBox.SelectedValue;
+        if (Properties.DateFilterType == filterType) return;
+
         Properties.DateFilterType = filterType;
         if (filterType == DateFilterType.Custom)
         {
@@ -534,14 +533,26 @@ public partial class DigitalFormsDashboard : UserControl,
 
     private void FromPicker_SelectedDateChanged(object? sender, SelectionChangedEventArgs e)
     {
-        Properties.FromDate = FromPicker.SelectedDate ?? DateTime.Today;
-        Refresh();
+        var value = FromPicker.SelectedDate ?? DateTime.Today;
+        if (Properties.FromDate == value) return;
+
+        Properties.FromDate = value;
+        if(Properties.DateFilterType == DateFilterType.Custom)
+        {
+            Refresh();
+        }
     }
 
     private void ToPicker_SelectedDateChanged(object? sender, SelectionChangedEventArgs e)
     {
-        Properties.ToDate = ToPicker.SelectedDate ?? DateTime.Today;
-        Refresh();
+        var value = ToPicker.SelectedDate ?? DateTime.Today;
+        if (Properties.ToDate == value) return;
+
+        Properties.ToDate = value;
+        if(Properties.DateFilterType == DateFilterType.Custom)
+        {
+            Refresh();
+        }
     }
 
     private bool _changing = false;
@@ -829,7 +840,6 @@ public partial class DigitalFormsDashboard : UserControl,
 
     public void BuildActionsMenu(ContextMenu menu)
     {
-        menu.AddItem("Export", InABox.Wpf.Resources.doc_xls, Export_Click, Form is not null && Form.ID != Guid.Empty);
         var loadingModules = menu.AddItem("Loading Modules...", null, null, false);
         Task.Run(() =>
         {
@@ -918,54 +928,6 @@ public partial class DigitalFormsDashboard : UserControl,
         }
     }
 
-    private void Export_Click()
-    {
-        // var formName = Regex.Replace(Form?.Description ?? "", "[^ a-zA-Z0-9]", "");
-        // var filename = string.Format("{0} - {1} - {2:yyyy-MM-dd} - {3:yyyy-MM-dd}.xlsx", ParentType!.Name, formName, From, To);
-
-        // var options = new ExcelExportingOptions();
-        // options.ExcelVersion = ExcelVersion.Excel2013;
-        // options.ExportStackedHeaders = true;
-        // var excelEngine = DataGrid.ExportToExcel(DataGrid.View, options);
-        // var workBook = excelEngine.Excel.Workbooks[0];
-        // var sheet = workBook.Worksheets[0];
-        // sheet.Name = "Summary";
-        // sheet.UsedRange.AutofitRows();
-        // sheet.UsedRange.AutofitColumns();
-
-        // sheet = workBook.Worksheets.Create("Questions");
-        // sheet.Move(0);
-        // var questions = new Client<QAQuestion>().Query(Filter<QAQuestion>.Where(x => x.Form.ID).IsEqualTo(Form!.ID));
-        // sheet.Range[1, 1].Text = Form?.Description ?? "";
-        // sheet.Range[1, 1, 1, 3].Merge();
-        // var i = 1;
-        // foreach (var row in questions.Rows)
-        //     if (!row.Get<QAQuestion, QAAnswer>(x => x.Answer).Equals(QAAnswer.Comment))
-        //     {
-        //         sheet.Range[i + 2, 1].Text = string.Format("{0}.", i);
-        //         sheet.Range[i + 2, 2].Text = string.Format("{0}", row.Get<QAQuestion, string>(x => x.Question));
-        //         sheet.Range[i + 2, 3].Text = string.Format("[{0}]", row.Get<QAQuestion, string>(x => x.Code));
-        //         i++;
-        //     }
-
-        // sheet.UsedRange.AutofitRows();
-        // sheet.UsedRange.AutofitColumns();
-
-        // try
-        // {
-        //     workBook.SaveAs(filename);
-
-        //     var startInfo = new ProcessStartInfo(filename);
-        //     startInfo.Verb = "open";
-        //     startInfo.UseShellExecute = true;
-        //     Process.Start(startInfo);
-        // }
-        // catch
-        // {
-        //     MessageBox.Show(string.Format("Unable to Save/Launch [{0}]!\n\nIs the file already open?", filename));
-        // }
-    }
-
     private void ManageFilters_Click()
     {
         var filters = Properties.Filters.GetValueOrDefault(ParentType!.Name) ?? new List<DFFilter>();
@@ -1372,7 +1334,7 @@ public partial class DigitalFormsDashboard : UserControl,
 
     #endregion
 
-    private void LoadDataIntoGrid(List<DigitalFormVariable> variables, List<QAQuestion> questions, CoreTable formData, List<string> additionalColumns, CoreTable? jobITPs)
+    private void LoadDataIntoGrid(List<DigitalFormVariable> variables, CoreTable formData, List<string> additionalColumns, CoreTable? jobITPs)
     {
         var cData = new CoreTable();
         cData.AddColumn<Guid>("ID");
@@ -1436,27 +1398,6 @@ public partial class DigitalFormsDashboard : UserControl,
                 }
             }
         }
-        else if (questions.Count != 0)
-        {
-            Questions = questions;
-            Progress.SetMessage("Loading Checks");
-            QAGrid.Clear();
-            QAGrid.LoadChecks(Form!.Description, Questions, new Dictionary<Guid, object>());
-            QAGrid.CollapseMargins();
-
-            var i = 1;
-            foreach (var question in Questions)
-            {
-                var id = question.ID.ToString();
-                if (!question.Answer.Equals(QAAnswer.Comment))
-                {
-                    cData.AddColumn<string>(id);
-                    var code = question.Code;
-                    Grid.QuestionCodes[id] = string.IsNullOrEmpty(code) ? string.Format("{0}.", i) : code;
-                    i++;
-                }
-            }
-        }
 
         foreach (var row in formData.Rows)
         {
@@ -1564,8 +1505,6 @@ public partial class DigitalFormsDashboard : UserControl,
         }
         Grid.ItemsSource = cData;
 
-        IsQAForm = variables.Count == 0 && questions.Count != 0;
-        QAGrid.Visibility = IsQAForm ? Visibility.Visible : Visibility.Collapsed;
         Grid.Visibility = Visibility.Visible;
     }
 
@@ -1576,9 +1515,8 @@ public partial class DigitalFormsDashboard : UserControl,
 
         var queries = new List<IKeyedQueryDef>()
             {
-                new KeyedQueryDef<QAQuestion>(Filter<QAQuestion>.Where(x => x.Form.ID).IsEqualTo(Form!.ID)),
                 new KeyedQueryDef<DigitalFormVariable>(
-                    Filter<DigitalFormVariable>.Where(x => x.Form.ID).IsEqualTo(Form.ID),
+                    Filter<DigitalFormVariable>.Where(x => x.Form.ID).IsEqualTo(Form!.ID),
                     null,
                     new SortOrder<DigitalFormVariable>(x => x.Sequence)),
                 formQuery
@@ -1592,12 +1530,11 @@ public partial class DigitalFormsDashboard : UserControl,
 
         var results = Client.QueryMultiple(queries);
 
-        var questions = results.Get<QAQuestion>().ToObjects<QAQuestion>().ToList();
         var variables = results.Get<DigitalFormVariable>().ToObjects<DigitalFormVariable>().ToList();
         var formData = results.Get(formQuery.Key);
 
         LoadDataIntoGrid(
-            variables, questions,
+            variables,
             formData,
             formQuery.Columns!.ColumnNames().Where(x => x.StartsWith("Parent.")).ToList(),
             ParentType == typeof(JobITP) ? results.Get<JobITP>() : null);
@@ -1607,13 +1544,8 @@ public partial class DigitalFormsDashboard : UserControl,
     {
         if (!IsSetup) return;
 
-        Questions.Clear();
-        QAGrid.Clear();
-        QAGrid.LoadChecks("", Array.Empty<QAQuestion>(), new Dictionary<Guid, object>());
-
         if (ParentType is null || FormType is null || Form is null || Form.ID == Guid.Empty)
         {
-            QAGrid.Visibility = Visibility.Collapsed;
             Grid.Visibility = Visibility.Collapsed;
             return;
         }
@@ -1672,27 +1604,6 @@ public partial class DigitalFormsDashboard : UserControl,
 
         if (FormType is null) return;
 
-        if (IsQAForm)
-        {
-            var values = new Dictionary<Guid, object>();
-            var formData = Serialization.Deserialize<Dictionary<string, object>>(formdata);
-            if (formData is not null)
-            {
-                foreach (var (idStr, value) in formData)
-                {
-                    if (Guid.TryParse(idStr, out var codeID))
-                    {
-                        values[codeID] = value;
-                    }
-                }
-            }
-
-            QAGrid.Clear();
-            QAGrid.LoadChecks(Form!.Description, Questions, values);
-            QAGrid.CollapseMargins();
-            return;
-        }
-
         var entityForm = typeof(DigitalFormsDashboard)
             .GetMethod(nameof(GetEntityForm), BindingFlags.NonPublic | BindingFlags.Instance)!
             .MakeGenericMethod(FormType)
@@ -1702,10 +1613,6 @@ public partial class DigitalFormsDashboard : UserControl,
             if (DynamicFormEditWindow.EditDigitalForm(entityForm, out var dataModel))
             {
                 dataModel.Update(null);
-                /*typeof(QADashboard)
-                    .GetMethod(nameof(SaveEntityForm), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)!
-                    .MakeGenericMethod(formType)
-                    .Invoke(this, new object[] { entityForm });*/
                 Refresh();
             }
         }

+ 0 - 110
prs.desktop/Grids/QAFormQuestionGrid.cs

@@ -1,110 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Media;
-using Comal.Classes;
-using InABox.Core;
-using InABox.DynamicGrid;
-using InABox.WPF;
-
-namespace PRSDesktop.Configuration;
-
-public abstract class QAFormQuestionGrid<T> : DynamicOneToManyGrid<DigitalForm, QAQuestion> where T : Entity, IRemotable, IPersistent, new()
-{
-    protected bool Preview = false;
-
-    public QAFormQuestionGrid()
-    {
-        AddButton("Fill", PRSDesktop.Resources.quality.AsBitmapImage(), PreviewForm);
-        //AddButton("Design", PRSDesktop.Resources.edit.AsBitmapImage(true), DesignForm);
-    }
-
-    public virtual string Description()
-    {
-        return "QA Checks";
-    }
-
-    //private bool DesignForm(Button arg1, CoreRow[] arg2)
-    //{
-    //    var form = new DynamicFormWindow();
-    //    bool result = form.ShowDialog() == true;
-    //    return false;
-    //}
-
-    private bool PreviewForm(Button sender, CoreRow[] rows)
-    {
-        var window = new Window { Title = "Quality Assurance Form", Width = 700 };
-        window.Background = new SolidColorBrush(Colors.WhiteSmoke);
-
-        var layout = new Grid();
-        layout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1.0F, GridUnitType.Star) });
-        layout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(100.0F) });
-        layout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(100.0F) });
-        layout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1.0F, GridUnitType.Star) });
-        layout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50.0F) });
-
-
-        var qagrid = new QAGrid();
-
-        var values = new Dictionary<Guid, object>();
-        qagrid.LoadChecks(Description(), Items, values);
-        qagrid.CollapseMargins();
-        qagrid.SetValue(Grid.RowProperty, 0);
-        qagrid.SetValue(Grid.ColumnProperty, 0);
-        qagrid.SetValue(Grid.ColumnSpanProperty, 3);
-        layout.Children.Add(qagrid);
-
-        var ok = new Button();
-        ok.SetValue(Grid.RowProperty, 1);
-        ok.SetValue(Grid.ColumnProperty, 1);
-        ok.Content = "OK";
-        ok.Margin = new Thickness(0, 0, 10, 10);
-        ok.Click += (o, e) =>
-        {
-            values.Clear();
-            window.DialogResult = true;
-            window.Close();
-        };
-        layout.Children.Add(ok);
-
-        var cancel = new Button();
-        cancel.SetValue(Grid.RowProperty, 1);
-        cancel.SetValue(Grid.ColumnProperty, 2);
-        cancel.Content = "Cancel";
-        cancel.Margin = new Thickness(0, 0, 10, 10);
-        cancel.Click += (o, e) =>
-        {
-            window.DialogResult = false;
-            window.Close();
-        };
-        layout.Children.Add(cancel);
-        window.Content = layout;
-        window.ShowDialog();
-        return false;
-    }
-}
-
-public class QAFormQuestionGrid : QAFormQuestionGrid<DigitalForm>
-{
-}
-
-public class KanbanQAQuestionGrid : QAFormQuestionGrid<Kanban>
-{
-}
-
-public class ITPQAQuestionGrid : QAFormQuestionGrid<JobITP>
-{
-}
-
-public class AssignmentQAQuestionGrid : QAFormQuestionGrid<Assignment>
-{
-}
-
-public class ManufacturingSectionQAQuestionGrid : QAFormQuestionGrid<ManufacturingSection>
-{
-}
-
-public class ManufacturingPacketStageQAQuestionGrid : QAFormQuestionGrid<ManufacturingPacketStage>
-{
-}

+ 1 - 0
prs.desktop/Panels/Factory/FactoryPanel.xaml

@@ -221,6 +221,7 @@
         <dynamicGrid:DynamicTabControl x:Name="PdfViewerTab"
                                        Grid.Row="0" Grid.RowSpan="3" Grid.Column="1"
                                        TabStripHeight="30"
+                                       Margin="5,0,0,0"
                                        SelectionChanged="PdfViewerTab_SelectionChanged"/>
 
         <Grid Grid.Row="3" Grid.Column="1" x:Name="ButtonGrid">

+ 129 - 64
prs.desktop/Panels/Factory/FactoryPanel.xaml.cs

@@ -58,7 +58,7 @@ namespace PRSDesktop
         private readonly string TREATED_COLOR = "DarkOrchid";
 
         private Button? _currentButton;
-        private QAGrid? QAGrid;
+        private DynamicFormDesignGrid? FormGrid;
         
         private readonly FactoryFloorLocalSettings _settings;
 
@@ -868,7 +868,7 @@ namespace PRSDesktop
                         PdfViewerTab.Items.Add(new DynamicTabItem
                         {
                             Header = "Quality Checks",
-                            Tag = typeof(QAQuestion)
+                            Tag = typeof(DigitalForm)
                         });
 
                         if (packet.Drawing.IsValid())
@@ -954,33 +954,106 @@ namespace PRSDesktop
             }
         }
 
-        private void PdfViewerTab_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        private DynamicFormDesignGrid GetFormGrid(DigitalFormVariable[] variables, DigitalFormLayout layout, DFLoadStorage values)
         {
-            var tab = PdfViewerTab.SelectedTab;
-            if (tab is null || tab.Content is not null || CurrentKanban is null) return;
+            var FormGrid = new DynamicFormDesignGrid();
+            FormGrid.BackgroundBrush = Colors.White.ToBrush();
 
-            var packet = KanbanToPacket(CurrentKanban);
+            FormGrid.Variables = variables;
+            FormGrid.Mode = FormMode.Filling;
+
+            var f = new DFLayout();
+            f.LoadLayout(layout.Layout);
+            f.LoadVariables(variables);
 
+            FormGrid.OnChanged += FormGrid_OnChanged;
+            FormGrid.Form = f;
+            FormGrid.Initialize();
+            FormGrid.LoadValues(values);
+
+            return FormGrid;
+        }
+
+        private void LoadFormTab(DynamicTabItem tab, ManufacturingPacket packet)
+        {
             var stage = GetPacketStage(packet.ID);
 
-            if(tab.Tag is Type type && type == typeof(QAQuestion))
+            if(stage is null
+                || CurrentSection is null)
             {
-                QAGrid = new QAGrid();
+                tab.Content = null;
+                return;
+            }
 
-                var qadata = stage?.FormData ?? "";
+            var values = DigitalForm.DeserializeFormData(stage) ?? new();
 
-                var values = string.IsNullOrWhiteSpace(qadata)
-                    ? new Dictionary<Guid, object>()
-                    : Serialization.Deserialize<Dictionary<Guid, object>>(qadata) ?? new();
+            var result = LoadForm(packet);
+            if(result is null)
+            {
+                tab.Content = null;
+                return;
+            }
 
-                if (CurrentSection is not null && packet is not null)
-                {
-                    var genquestions = LoadQAQuestions(packet, true, false);
-                    QAGrid.LoadChecks("Global Checks for " + CurrentSection.Name, genquestions, values);
-                }
+            var (variables, layout) = result.Value;
 
-                QAGrid.OnChanged += QAGridChanged;
-                tab.Content = QAGrid;
+            if (layout.Layout.IsNullOrWhiteSpace())
+            {
+                tab.Content = null;
+                return;
+            }
+
+            FormGrid = GetFormGrid(variables, layout, values);
+
+            var grid = new Grid();
+            grid.Background = Colors.WhiteSmoke.ToBrush();
+            grid.AddColumn(GridUnitType.Star, 0.25);
+            grid.AddColumn(GridUnitType.Star);
+            grid.AddColumn(GridUnitType.Star, 0.25);
+
+            var outerBorder = new Border
+            {
+                BorderBrush = new SolidColorBrush(Colors.Gray),
+                BorderThickness = new Thickness(0.75),
+                Margin = new(0, 5, 0, 5),
+                CornerRadius = new(10, 10, 0, 0)
+            };
+            var outerGrid = new Grid();
+
+            var border = new Border();
+            border.Background = Colors.WhiteSmoke.ToBrush();
+            border.CornerRadius = new(10, 10, 0, 0);
+
+            outerGrid.OpacityMask = new VisualBrush
+            {
+                Visual = border
+            };
+
+            outerGrid.Children.Add(border);
+            outerGrid.Children.Add(FormGrid);
+
+            outerBorder.Child = outerGrid;
+
+            grid.AddChild(outerBorder, 0, 1);
+
+            var scrollViewer = new ScrollViewer
+            {
+                VerticalScrollBarVisibility = ScrollBarVisibility.Auto
+            };
+            scrollViewer.Content = grid;
+
+            tab.Content = scrollViewer;
+        }
+
+        private void PdfViewerTab_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            var tab = PdfViewerTab.SelectedTab;
+            if (tab is null || tab.Content is not null || CurrentKanban is null) return;
+
+            var packet = KanbanToPacket(CurrentKanban);
+
+            if(tab.Tag is Type type && type == typeof(DigitalForm))
+            {
+                LoadFormTab(tab, packet);
             }
             else if(tab.Tag is EntityLink<Document> pdfDocument)
             {
@@ -1148,21 +1221,15 @@ namespace PRSDesktop
                 if (stage != null)
                 {
                     var qadata = stage.FormData;
-                    var questions = LoadQAQuestions(packet, true, true);
-
-                    var answers = string.IsNullOrWhiteSpace(qadata)
-                        ? new Dictionary<Guid, object>()
-                        : Serialization.Deserialize<Dictionary<Guid, object>>(qadata) ?? new();
-
-                    foreach (var question in questions)
+                    var result = LoadForm(packet);
+                    if(result is not null)
                     {
-                        var parameters = question.ParseParameters();
-                        var bAnswerRequired = question.Answer != QAAnswer.Comment &&
-                                              (!parameters.ContainsKey("Default") || string.IsNullOrWhiteSpace(parameters["Default"]));
-                        if (bAnswerRequired && (!answers.ContainsKey(question.ID) || answers[question.ID] == null))
+                        var (variables, layout) = result.Value;
+                        var values = DigitalForm.DeserializeFormData(stage) ?? new();
+                        var formGrid = FormGrid ?? GetFormGrid(variables, layout, values);
+                        if(!formGrid.Validate(out var messages))
                         {
                             qacomplete = false;
-                            break;
                         }
                     }
                 }
@@ -2211,17 +2278,14 @@ namespace PRSDesktop
         #region QAChecks
 
         private ManufacturingTemplateStage[]? TemplateStages;
-        private QAQuestion[]? Questions;
 
-        private IEnumerable<QAQuestion> LoadQAQuestions(ManufacturingPacket packet, bool section, bool template)
-        {
-            if (CurrentSection is null) return [];
+        private DigitalFormVariable[]? Variables;
+        private DigitalFormLayout? Layout;
+        private Guid FormID;
 
-            Questions ??=
-                Client.Query(
-                    Filter<QAQuestion>.Where(x => x.Form.Active).IsEqualTo(true),
-                    Columns.None<QAQuestion>())
-                .ToArray<QAQuestion>();
+        private (DigitalFormVariable[] Variables, DigitalFormLayout Layout)? LoadForm(ManufacturingPacket packet)
+        {
+            if (CurrentSection is null) return null;
 
             TemplateStages ??=
                 Client.Query(
@@ -2235,38 +2299,39 @@ namespace PRSDesktop
                 x.Template.ID == packet.ManufacturingTemplateLink.ID
                 && x.Section.ID == CurrentSection.ID);
 
-            if (template)
+            var formID = tstage?.DigitalForm.ID ?? Guid.Empty;
+            if(formID == Guid.Empty)
             {
-                if (tstage is null)
-                    return [];
-                if (section)
-                {
-                    return Questions.Where(x => x.Form.ID == CurrentSection.DigitalForm.ID || x.Form.ID == tstage.DigitalForm.ID);
-                }
-                else
-                {
-                    return Questions.Where(x => x.Form.ID == tstage.DigitalForm.ID);
-                }
+                formID = CurrentSection.DigitalForm.ID;
             }
-            else
+            if (FormID == formID)
             {
-                if (section)
-                {
-                    return Questions.Where(x => x.Form.ID == CurrentSection.DigitalForm.ID);
-                }
-                else
-                {
-                    return [];
-                }
+                if (Variables is null || Layout is null) return null;
+                return (Variables, Layout);
             }
+
+            FormID = formID;
+
+            var results = Client.QueryMultiple(
+                new KeyedQueryDef<DigitalFormVariable>(Filter<DigitalFormVariable>.Where(x => x.Form.ID).IsEqualTo(formID)),
+                new KeyedQueryDef<DigitalFormLayout>(
+                    Filter<DigitalFormLayout>.Where(x => x.Form.ID).IsEqualTo(formID)
+                        .And(x => x.Active).IsEqualTo(true)
+                        .And(x => x.Layout).IsNotEqualTo("")));
+
+            Variables = results.GetArray<DigitalFormVariable>();
+            Layout = results.GetObjects<DigitalFormLayout>().FirstOrDefault();
+            if (Layout is null) return null;
+
+            return (Variables, Layout);
         }
 
-        private void QAGridChanged(object sender, Dictionary<Guid, object> values)
+        private void FormGrid_OnChanged(DynamicFormDesignGrid sender, string fieldName)
         {
-            SaveQAData(values);
+            SaveQAData(sender.SaveValues());
         }
 
-        private void SaveQAData(Dictionary<Guid, object> values)
+        private void SaveQAData(DFSaveStorage values)
         {
             if (CurrentSection is null) return;
 
@@ -2277,7 +2342,7 @@ namespace PRSDesktop
                 if (stage is not null)
                 {
                     stage.Form.ID = CurrentSection.DigitalForm.ID;
-                    stage.FormData = Serialization.Serialize(values);
+                    DigitalForm.SerializeFormData(stage, values);
                     stage.Description = CurrentSection.DigitalForm.Description;
                     updates.Add(stage);
                 }

+ 0 - 18
prs.desktop/Panels/Jobs/ITPs/JobITPGrid.cs

@@ -82,22 +82,4 @@ public class JobITPGrid : DynamicDataGrid<JobITP>, IMasterDetailControl<Job,JobI
         criteria.Add(MasterDetailFilter);
         base.Reload(criteria, columns, ref sort, token, action);
     }
-
-    protected override Dictionary<string, object?> EditorValueChanged(IDynamicEditorForm editor, JobITP[] items, string name, object value)
-    {
-        var result = base.EditorValueChanged(editor, items, name, value);
-        if (name == "ITPTypeLink.ID" && value is Guid id)
-        {
-            var type = typeof(IDynamicEnclosedListGrid<,>).MakeGenericType(typeof(JobITP), typeof(QAQuestion));
-            var page = editor.Pages?.FirstOrDefault(x => x.GetType().GetInterface(type.Name) != null);
-            if (page != null)
-            {
-                var template = new Client<DigitalForm>().Load(Filter<DigitalForm>.Where(x => x.ID).IsEqualTo(id)).FirstOrDefault();
-                var load = page.GetType().GetMethod("LoadItems");
-                //load.Invoke(page, new object[] { template != null ? template.Questions : null });
-            }
-        }
-
-        return result;
-    }
 }

+ 11 - 6
prs.shared/Database Update Scripts/Update_8_58.cs

@@ -149,7 +149,6 @@ internal class Update_8_58 : DatabaseUpdateScript
 
             var layout = new DFLayout();
             layout.ColumnWidths.Add("Auto");
-            layout.ColumnWidths.Add("Auto");
             layout.ColumnWidths.Add("*");
 
             var codes = new HashSet<string>();
@@ -167,6 +166,8 @@ internal class Update_8_58 : DatabaseUpdateScript
 
             var mappings = variableMappings.GetValueOrAdd(item.FormID);
 
+            var nButtons = 0;
+
             var i = 1;
             foreach(var question in item.Questions)
             {
@@ -220,6 +221,8 @@ internal class Update_8_58 : DatabaseUpdateScript
                                     colourExpression = $"If([{code}] == {QuoteString(option)}, {QuoteString(colour)}, {colourExpression})";
                                 }
                                 optionProperties.ColourExpression = colourExpression;
+
+                                nButtons = Math.Max(nButtons, buttons.Length);
                             }
                             break;
                         case QAAnswer.Number:
@@ -264,7 +267,7 @@ internal class Update_8_58 : DatabaseUpdateScript
 
                     properties.Code = code;
                     properties.Description = question.Description.NotWhiteSpaceOr(question.Question);
-                    properties.Required = !parameters.GetValueOrDefault("Default").IsNullOrWhiteSpace();
+                    properties.Required = parameters.GetValueOrDefault("Default").IsNullOrWhiteSpace();
 
                     variable.SaveProperties(fieldType, properties);
 
@@ -284,6 +287,8 @@ internal class Update_8_58 : DatabaseUpdateScript
                 question.Converted = true;
             }
 
+            layout.ColumnWidths.Add(Math.Max(150, nButtons * 80).ToString());
+
             var dfLayout = new DigitalFormLayout();
             dfLayout.Form.ID = item.FormID;
             dfLayout.Layout = layout.SaveLayout();
@@ -293,6 +298,10 @@ internal class Update_8_58 : DatabaseUpdateScript
             layouts.Add(dfLayout);
         }
 
+        provider.Save(variables);
+        provider.Save(layouts);
+        provider.Save(qaQuestions.SelectMany(x => x.Questions));
+
         FormUpdater.UpdateAllForms(
             (form, variables) => false,
             (formType, instance, form, variables) =>
@@ -313,10 +322,6 @@ internal class Update_8_58 : DatabaseUpdateScript
                 return true;
             },
             filter: Filter<DigitalForm>.Where(x => x.ID).InList(qaQuestions.ToArray(x => x.FormID)));
-
-        provider.Save(variables);
-        provider.Save(layouts);
-        provider.Save(qaQuestions.SelectMany(x => x.Questions));
     }
 
     public override bool Update()