Ver código fonte

Fixed DBNull issues

Kenric Nugteren 1 ano atrás
pai
commit
ce33a03925
2 arquivos alterados com 16 adições e 5 exclusões
  1. 10 5
      InABox.Core/BaseObject.cs
  2. 6 0
      inabox.wpf/DynamicGrid/DynamicGrid.cs

+ 10 - 5
InABox.Core/BaseObject.cs

@@ -109,13 +109,18 @@ namespace InABox.Core
 
 
             if (!bApplyingChanges)
             if (!bApplyingChanges)
             {
             {
-                bApplyingChanges = true;
-
-                DoPropertyChanged(name, before, after);
+                try
+                {
+                    bApplyingChanges = true;
 
 
-                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
+                    DoPropertyChanged(name, before, after);
 
 
-                bApplyingChanges = false;
+                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
+                }
+                finally
+                {
+                    bApplyingChanges = false;
+                }
             }
             }
         }
         }
 
 

+ 6 - 0
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -21,6 +21,7 @@ using System.Windows.Threading;
 using InABox.Clients;
 using InABox.Clients;
 using InABox.Core;
 using InABox.Core;
 using InABox.WPF;
 using InABox.WPF;
+using Microsoft.CodeAnalysis.CSharp.Syntax;
 using Microsoft.Xaml.Behaviors;
 using Microsoft.Xaml.Behaviors;
 using Syncfusion.Data;
 using Syncfusion.Data;
 using Syncfusion.DocIO.ReaderWriter.DataStreamParser.Escher;
 using Syncfusion.DocIO.ReaderWriter.DataStreamParser.Escher;
@@ -977,6 +978,7 @@ namespace InABox.DynamicGrid
 
 
         private void DataGrid_CurrentCellValueChanged(object? sender, CurrentCellValueChangedEventArgs e)
         private void DataGrid_CurrentCellValueChanged(object? sender, CurrentCellValueChangedEventArgs e)
         {
         {
+            // Are we sure that this function is ever useful? It seems that since the data in the grid hasn't been updated by this point, this function is essentially useless (the data is updated in EndEdit). Probably need to check the GridCheckBoxColumn
             var headerrows = HasOption(DynamicGridOption.FilterRows) ? 2 : 1;
             var headerrows = HasOption(DynamicGridOption.FilterRows) ? 2 : 1;
             if (e.RowColumnIndex.RowIndex < headerrows)
             if (e.RowColumnIndex.RowIndex < headerrows)
                 return;
                 return;
@@ -1153,6 +1155,10 @@ namespace InABox.DynamicGrid
             var colno = DataGridItems.Columns.IndexOf(mappedname);
             var colno = DataGridItems.Columns.IndexOf(mappedname);
             var column = Data.Columns[colno];
             var column = Data.Columns[colno];
             var value = DataGridItems.Rows[iRow][mappedname];
             var value = DataGridItems.Rows[iRow][mappedname];
+            if(value is DBNull)
+            {
+                value = CoreUtils.GetDefault(column.DataType);
+            }
             
             
             UpdateData(new Dictionary<CoreColumn, object?>() { { column, value } });
             UpdateData(new Dictionary<CoreColumn, object?>() { { column, value } });