From 6a0bea5c54785a19b87656ccd5036522bdd636fa Mon Sep 17 00:00:00 2001 From: Aleksandrov_IS Date: Thu, 26 Feb 2026 12:38:40 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20Sql?= =?UTF-8?q?DateTime=20overflow.=20Must=20be=20between=201/1/1753=2012:00:0?= =?UTF-8?q?0=20AM=20and=2012/31/9999=2011:59:59=20PM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ImportData/Entities/Entity.cs | 32 +++++++++---------- .../Models/IContractualDocuments.cs | 8 ++--- .../Models/ISupAgreements.cs | 4 +-- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/ImportData/Entities/Entity.cs b/src/ImportData/Entities/Entity.cs index 626f43f..bda44fc 100644 --- a/src/ImportData/Entities/Entity.cs +++ b/src/ImportData/Entities/Entity.cs @@ -99,9 +99,9 @@ public class Entity ResultValues.Add(property.Name, null); continue; } - + // Добавляем поля и значения для поиска или создания сущностей. - var propertiesForSearch = GetPropertiesForSearch(property.PropertyType, exceptionList, logger); + var propertiesForSearch = GetPropertiesForSearch(property.PropertyType, exceptionList, logger); if (propertiesForSearch == null) propertiesForSearch = new Dictionary(); @@ -151,7 +151,7 @@ public class Entity entity = (IEntityBase)MethodCall(EntityType, Constants.EntityActions.CreateOrUpdate, entity, isNewEntity, isBatch, exceptionList, logger); // При необходимость дозаполнить свойства-коллекции. - if(entity != null) + if (entity != null) FillCollections(exceptionList, logger); } catch (Exception ex) @@ -244,7 +244,7 @@ private void UpdateProperties(IEntityBase entity) continue; if (property.PropertyType == typeof(double)) - { + { if (string.IsNullOrWhiteSpace(ResultValues[property.Name].ToString())) property.SetValue(entity, 0d); else @@ -264,22 +264,20 @@ private void UpdateProperties(IEntityBase entity) /// Культура. /// Преобразованная дата. /// - private DateTimeOffset ParseDate(string value, NumberStyles style, CultureInfo culture) + private DateTimeOffset? ParseDate(string value, NumberStyles style, CultureInfo culture) { - if (!string.IsNullOrEmpty(value)) - { - DateTimeOffset date; - if (DateTimeOffset.TryParse(value.Trim(), culture.DateTimeFormat, DateTimeStyles.AssumeUniversal, out date)) - return date; + if (string.IsNullOrEmpty(value)) + return null; - var dateDouble = 0.0; - if (double.TryParse(value.Trim(), style, culture, out dateDouble)) - return new DateTimeOffset(DateTime.FromOADate(dateDouble), TimeSpan.Zero); + DateTimeOffset date; + if (DateTimeOffset.TryParse(value.Trim(), culture.DateTimeFormat, DateTimeStyles.AssumeUniversal, out date)) + return date; - throw new FormatException("Неверный формат строки."); - } - else - return DateTimeOffset.MinValue; + var dateDouble = 0.0; + if (double.TryParse(value.Trim(), style, culture, out dateDouble)) + return new DateTimeOffset(DateTime.FromOADate(dateDouble), TimeSpan.Zero); + + throw new FormatException("Неверный формат строки."); } /// diff --git a/src/ImportData/IntegrationServicesClient/Models/IContractualDocuments.cs b/src/ImportData/IntegrationServicesClient/Models/IContractualDocuments.cs index aca2649..ad2fd97 100644 --- a/src/ImportData/IntegrationServicesClient/Models/IContractualDocuments.cs +++ b/src/ImportData/IntegrationServicesClient/Models/IContractualDocuments.cs @@ -6,8 +6,8 @@ namespace ImportData.IntegrationServicesClient.Models { public class IContractualDocuments : IOfficialDocuments { - private DateTimeOffset? validFrom; - private DateTimeOffset? validTill; + private DateTimeOffset? validFrom = null; + private DateTimeOffset? validTill = null; public IEmployees Assignee { get; set; } [PropertyOptions("Наша организация", RequiredType.Required, PropertyType.Entity, AdditionalCharacters.ForSearch)] @@ -25,14 +25,14 @@ public class IContractualDocuments : IOfficialDocuments public DateTimeOffset? ValidFrom { get { return validFrom; } - set { validFrom = value.HasValue ? new DateTimeOffset(value.Value.Date, TimeSpan.Zero) : new DateTimeOffset?(); } + set { validFrom = value.HasValue ? new DateTimeOffset(value.Value.Date, TimeSpan.Zero) : null; } } [PropertyOptions("Действует по", RequiredType.NotRequired, PropertyType.Simple, AdditionalCharacters.ForSearch)] public DateTimeOffset? ValidTill { get { return validTill; } - set { validTill = value.HasValue ? new DateTimeOffset(value.Value.Date, TimeSpan.Zero) : new DateTimeOffset?(); } + set { validTill = value.HasValue ? new DateTimeOffset(value.Value.Date, TimeSpan.Zero) : null; } } [PropertyOptions("Сумма", RequiredType.NotRequired, PropertyType.Simple)] diff --git a/src/ImportData/IntegrationServicesClient/Models/ISupAgreements.cs b/src/ImportData/IntegrationServicesClient/Models/ISupAgreements.cs index 0db0f0d..f08142e 100644 --- a/src/ImportData/IntegrationServicesClient/Models/ISupAgreements.cs +++ b/src/ImportData/IntegrationServicesClient/Models/ISupAgreements.cs @@ -28,14 +28,14 @@ public class ISupAgreements : IContractualDocuments new public DateTimeOffset? DocumentDate { get { return documentDate; } - set { documentDate = value.HasValue ? new DateTimeOffset(value.Value.Date, TimeSpan.Zero) : new DateTimeOffset?(); } + set { documentDate = value.HasValue ? new DateTimeOffset(value.Value.Date, TimeSpan.Zero) : null; } } [PropertyOptions("Действует с", RequiredType.Required, PropertyType.Simple)] new public DateTimeOffset? ValidFrom { get { return validFrom; } - set { validFrom = value.HasValue ? new DateTimeOffset(value.Value.Date, TimeSpan.Zero) : new DateTimeOffset?(); } + set { validFrom = value.HasValue ? new DateTimeOffset(value.Value.Date, TimeSpan.Zero) : null; } } [PropertyOptions("Действует по", RequiredType.Required, PropertyType.Simple)]