瀏覽代碼

Fixed null exception issues with columns

Kenric Nugteren 1 年之前
父節點
當前提交
f1e8e8ae6d

+ 0 - 1
prs.desktop/Components/Calendar/Appointments/AssignmentAppointment.cs

@@ -29,7 +29,6 @@ namespace PRSDesktop
             };
             
             Notes = Model.Notes;
-            Image  _image;
             
             var subject = new List<string>() { model.Number.ToString() };
             if (model.JobID != Guid.Empty)

+ 1 - 1
prs.desktop/Panels/DeliveryItems/DeliveryIncomingGrid.cs

@@ -8,7 +8,7 @@ namespace PRSDesktop
     internal class DeliveryIncomingGrid : DynamicDataGrid<ManufacturingPacket>
     {
         protected override void Reload(Filters<ManufacturingPacket> criteria, Columns<ManufacturingPacket> columns,
-            ref SortOrder<ManufacturingPacket> sort, Action<CoreTable, Exception> action)
+            ref SortOrder<ManufacturingPacket>? sort, Action<CoreTable?, Exception?> action)
         {
             criteria.Add(new Filter<ManufacturingPacket>(x => x.Completed).IsNotEqualTo(DateTime.MinValue).And(x => x.Archived)
                 .IsEqualTo(DateTime.MinValue));

+ 2 - 2
prs.desktop/Panels/DeliveryItems/DeliveryOnSiteGrid.cs

@@ -7,8 +7,8 @@ namespace PRSDesktop
 {
     internal class DeliveryOnSiteGrid : DynamicDataGrid<DeliveryItem>
     {
-        protected override void Reload(Filters<DeliveryItem> criteria, Columns<DeliveryItem> columns, ref SortOrder<DeliveryItem> sort,
-            Action<CoreTable, Exception> action)
+        protected override void Reload(Filters<DeliveryItem> criteria, Columns<DeliveryItem> columns, ref SortOrder<DeliveryItem>? sort,
+            Action<CoreTable?, Exception?> action)
         {
             criteria.Add(new Filter<DeliveryItem>(x => x.DeliveredDate).IsNotEqualTo(DateTime.MinValue).And(x => x.InstalledDate)
                 .IsEqualTo(DateTime.MinValue));

+ 1 - 1
prs.desktop/Panels/DynamicCheckColumn.cs

@@ -23,7 +23,7 @@ namespace PRSDesktop
             Action = null;
         }
 
-        private BitmapImage GetImage(CoreRow row)
+        private BitmapImage GetImage(CoreRow? row)
         {
             if (row == null)
                 return Header;

+ 4 - 7
prs.desktop/Panels/DynamicMapColumn.cs

@@ -48,23 +48,20 @@ namespace PRSDesktop
 
         private bool HasLocation(CoreRow row)
         {
-            if (row == null)
-                return true;
-
             var lat = row.Get<double>(Latitude);
             var lng = row.Get<double>(Longitude);
 
             return lat != 0.0F && lng != 0.0F;
         }
 
-        private BitmapImage MapImage(CoreRow row)
+        private BitmapImage? MapImage(CoreRow? row)
         {
-            return HasLocation(row) ? milestone : null;
+            return row is null || HasLocation(row) ? milestone : null;
         }
 
-        private bool MapClick(CoreRow row)
+        private bool MapClick(CoreRow? row)
         {
-            if (HasLocation(row))
+            if (row is not null && HasLocation(row))
             {
                 var form = new MapForm(row.Get<double>(Latitude), row.Get<double>(Longitude), row.Get<DateTime>(Timestamp));
                 form.ShowDialog();

+ 13 - 2
prs.desktop/Panels/DynamicScheduleEditorColumn.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Linq;
+using System.Windows;
 using System.Windows.Media.Imaging;
 using Comal.Classes;
 using InABox.Clients;
@@ -34,7 +35,7 @@ namespace PRSDesktop
             return false;
         }
 
-        private BitmapImage ScheduleImage(CoreRow row)
+        private BitmapImage ScheduleImage(CoreRow? row)
         {
             if (row == null)
                 return bitmap_header;
@@ -42,10 +43,20 @@ namespace PRSDesktop
             return isenabled ? bitmap_enabled : bitmap_disabled;
         }
 
-        private bool EditSchedule(CoreRow row)
+        private bool EditSchedule(CoreRow? row)
         {
+            if(row is null)
+            {
+                return false;
+            }
             var id = row.Get<T, Guid>(x => x.ID);
             var item = new Client<T>().Load(new Filter<T>(x => x.ID).IsEqualTo(id)).FirstOrDefault();
+            if(item is null)
+            {
+                Logger.Send(LogType.Error, "", $"{typeof(T)} with ID {id} does not exist!");
+                MessageBox.Show("Error opening schedule.");
+                return false;
+            }
             var form = new ScheduleForm(item);
             form.ShowDialog();
             return true;