Browse Source

Merge remote-tracking branch 'origin/kenric' into frank

Frank van den Bos 2 năm trước cách đây
mục cha
commit
ff16939eb5

+ 2 - 2
InABox.Core/Client/Request.cs

@@ -9,9 +9,9 @@ namespace InABox.Clients
     public class Credentials
     {
         [Obsolete]
-        public string UserID { get; set; }
+        public string? UserID { get; set; }
         [Obsolete]
-        public string Password { get; set; }
+        public string? Password { get; set; }
 
         public string Platform { get; set; }
         public string Version { get; set; }

+ 4 - 1
InABox.Core/DataTable.cs

@@ -791,8 +791,11 @@ namespace InABox.Core
             writer.WriteEndObject();
         }
 
-        public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
+        public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
         {
+            if (reader.TokenType == JsonToken.Null)
+                return null;
+
             var result = new CoreTable();
             try
             {

+ 1 - 1
InABox.DynamicGrid/DynamicEditorForm.xaml.cs

@@ -441,7 +441,7 @@ namespace InABox.DynamicGrid
 
         private void OKButton_Click(object sender, RoutedEventArgs e)
         {
-            var errors = OnValidateData != null ? OnValidateData.Invoke(this, Items) : null;
+            var errors = OnValidateData?.Invoke(this, Items);
 
             if (errors != null && errors.Any())
             {

+ 32 - 11
InABox.Reports/ReportGrid.cs

@@ -39,7 +39,7 @@ public class Report
 
 }}";
 
-        private ReportTemplate SelectedTemplate;
+        private ReportTemplate? SelectedTemplate;
 
         public ReportGrid()
         {
@@ -63,7 +63,7 @@ public class Report
 
         public bool Populate { get; set; }
 
-        private bool ScriptClick(CoreRow arg)
+        private bool ScriptClick(CoreRow? arg)
         {
             if (arg != null)
             {
@@ -83,7 +83,7 @@ public class Report
             return false;
         }
 
-        private BitmapImage ScriptImage(CoreRow arg)
+        private BitmapImage? ScriptImage(CoreRow? arg)
         {
             return arg == null ? Properties.Resources.edit.AsBitmapImage() :
                 arg.Get<ReportTemplate, bool>(x => x.IsRDL) ? null : Properties.Resources.edit.AsBitmapImage();
@@ -102,8 +102,8 @@ public class Report
             return columns;
         }
 
-        protected override void Reload(Filters<ReportTemplate> criteria, Columns<ReportTemplate> columns, ref SortOrder<ReportTemplate> sort,
-            Action<CoreTable, Exception> action)
+        protected override void Reload(Filters<ReportTemplate> criteria, Columns<ReportTemplate> columns, ref SortOrder<ReportTemplate>? sort,
+            Action<CoreTable?, Exception?> action)
         {
             criteria.Add(new Filter<ReportTemplate>(x => x.DataModel).IsEqualTo(DataModel.Name).And(x => x.Section).IsEqualTo(Section));
             base.Reload(criteria, columns, ref sort, action);
@@ -118,15 +118,22 @@ public class Report
             return bOK;
         }
 
-        private DynamicGridColumns Editor_OnDefineGridColumns(object sender, DynamicGridColumns master)
+        private DynamicGridColumns Editor_OnDefineGridColumns(object sender, DynamicGridColumns? master)
         {
             return LoadColumns();
         }
 
-        private bool ExportClick(CoreRow row)
+        private bool ExportClick(CoreRow? row)
         {
+            if (row is null) return false;
+
             var id = row.Get<ReportTemplate, Guid>(x => x.ID);
             SelectedTemplate = new Client<ReportTemplate>().Load(new Filter<ReportTemplate>(x => x.ID).IsEqualTo(id)).FirstOrDefault();
+            if(SelectedTemplate is null)
+            {
+                Logger.Send(LogType.Error, "", $"Report Template {id} does not exist!");
+                return false;
+            }
             var dlg = new SaveFileDialog
             {
                 Filter = "RDL Files|*.rdl"
@@ -136,8 +143,10 @@ public class Report
             return false;
         }
 
-        private bool ImportClick(CoreRow row)
+        private bool ImportClick(CoreRow? row)
         {
+            if (row is null) return false;
+
             var id = row.Get<ReportTemplate, Guid>(x => x.ID);
 
             var dlg = new OpenFileDialog
@@ -147,6 +156,11 @@ public class Report
             if (dlg.ShowDialog() == true)
             {
                 SelectedTemplate = new Client<ReportTemplate>().Load(new Filter<ReportTemplate>(x => x.ID).IsEqualTo(id)).FirstOrDefault();
+                if (SelectedTemplate is null)
+                {
+                    Logger.Send(LogType.Error, "", $"Report Template {id} does not exist!");
+                    return false;
+                }
                 SelectedTemplate.RDL = File.ReadAllText(dlg.FileName);
                 new Client<ReportTemplate>().Save(SelectedTemplate, "Imported from " + dlg.FileName);
             }
@@ -154,10 +168,17 @@ public class Report
             return false;
         }
 
-        private bool DesignClick(CoreRow row)
+        private bool DesignClick(CoreRow? row)
         {
+            if (row is null) return false;
+
             var id = row.Get<ReportTemplate, Guid>(x => x.ID);
             SelectedTemplate = new Client<ReportTemplate>().Load(new Filter<ReportTemplate>(x => x.ID).IsEqualTo(id)).FirstOrDefault();
+            if (SelectedTemplate is null)
+            {
+                Logger.Send(LogType.Error, "", $"Report Template {id} does not exist!");
+                return false;
+            }
             ReportUtils.DesignReport(SelectedTemplate, DataModel, Populate);
             return false;
         }
@@ -171,7 +192,7 @@ public class Report
             return template;
         }
 
-        private void ReportGrid_OnAddItem(object sender, object item)
+        /*private void ReportGrid_OnAddItem(object sender, object item)
         {
             SelectedTemplate = (ReportTemplate)item;
             SelectedTemplate.DataModel = DataModel.Name;
@@ -189,6 +210,6 @@ public class Report
             {
                 client.Save(SelectedTemplate, "Report Saved from Designer");
             }
-        }
+        }*/
     }
 }

+ 3 - 1
InABox.Server/RestService.cs

@@ -41,7 +41,9 @@ namespace InABox.API
                 }
                 return valid;
             }
-            else if(CredentialsCache.IsBypassed(request.Credentials.UserID, request.Credentials.Password))
+            else if(request.Credentials.UserID is not null
+                && request.Credentials.Password is not null
+                && CredentialsCache.IsBypassed(request.Credentials.UserID, request.Credentials.Password))
             {
                 userID = "";
                 return CoreUtils.FullGuid;