/// <summary> /// Checks wheter a given DateTime is an invalid date. A check whether it is an undefined DateTime is always performed. /// </summary> /// <returns>Null if validation succeeded, otherwise a <see cref="TVerificationResult" /> is /// returned that contains details about the problem.</returns> public static TVerificationResult IsNotInvalidDate(DateTime?ADate, String ADescription, TVerificationResultCollection AVerificationResultCollection, bool ATreatNullAsInvalid = false, object AResultContext = null, System.Data.DataColumn AResultColumn = null) { return(TDateChecks.IsNotUndefinedDateTime(ADate, ADescription, ATreatNullAsInvalid, AResultContext, AResultColumn)); }
/// <summary> /// todoComment /// </summary> /// <param name="DateStarted"></param> /// <param name="DateExpired"></param> /// <param name="DateRenewed"></param> /// <param name="DateNoticeSent"></param> /// <param name="DateEnded"></param> /// <param name="DateFirstSent"></param> /// <param name="DateLastSent"></param> /// <param name="AVerificationResult"></param> /// <param name="Completed"></param> public static void VerifyDatesAgainstStartDate(DateTime DateStarted, DateTime DateExpired, DateTime DateRenewed, DateTime DateNoticeSent, DateTime DateEnded, DateTime DateFirstSent, DateTime DateLastSent, out TVerificationResult AVerificationResult, out Boolean Completed) { AVerificationResult = null; Completed = false; while (!Completed) { if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateExpired, "Start Date", "Expiry Date") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateExpired, "Start Date", "Expiry Date"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateRenewed, "Start Date", "Renewal Date") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateRenewed, "Start Date", "Renewal Date"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateEnded, "Start Date", "End Date") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateEnded, "Start Date", "End Date"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateNoticeSent, "Start Date", "Notice sent") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateNoticeSent, "Start Date", "Notice sent"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateFirstSent, "Start Date", "First sent") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateFirstSent, "Start Date", "First sent"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateLastSent, "Start Date", "Last sent") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateLastSent, "Start Date", "Last sent"); Completed = true; break; } Completed = true; } }
/// <summary> /// Checks wheter a given DateTime is an invalid date. A check whether it is an undefined DateTime is always performed. /// </summary> /// <returns>Null if validation succeeded, otherwise a <see cref="TVerificationResult" /> is /// returned that contains details about the problem.</returns> public static TVerificationResult IsNotInvalidDate(DateTime?ADate, String ADescription, TVerificationResultCollection AVerificationResultCollection, bool ATreatNullAsInvalid = false, object AResultContext = null, System.Data.DataColumn AResultColumn = null) { TVerificationResult VerificationResult; if (FDelegateSharedGetDateVerificationResult != null) { VerificationResult = TDateChecks.IsNotUndefinedDateTime(ADate, ADescription, ATreatNullAsInvalid, AResultContext, AResultColumn); // Remove Verification Result that would have been recorded earlier for the same DataColumn TVerificationResult OtherRecordedVerificationResult = AVerificationResultCollection.FindBy(AResultColumn); if (OtherRecordedVerificationResult != null) { AVerificationResultCollection.Remove(OtherRecordedVerificationResult); } } else { VerificationResult = TDateChecks.IsNotUndefinedDateTime(ADate, ADescription, ATreatNullAsInvalid, AResultContext, AResultColumn); } return(VerificationResult); }
/// <summary> /// parse a date for the txtPetraDate control /// </summary> /// <param name="AParseDate"></param> /// <param name="ADescription"></param> /// <param name="AVerificationResult"></param> /// <param name="AShowVerificationError"></param> /// <param name="ATypeWhichCallsVerification"></param> /// <returns></returns> public static DateTime LongDateStringToDateTime2(String AParseDate, String ADescription, out TVerificationResult AVerificationResult, Boolean AShowVerificationError, System.Type ATypeWhichCallsVerification) { object ResultObj = null; AVerificationResult = null; // Convert TextBox's Text to Date if (LongDateStringToDateTimeInternal(AParseDate, ADescription, out ResultObj, AShowVerificationError, ATypeWhichCallsVerification)) { // date is valid if (ResultObj != DBNull.Value) { return(Convert.ToDateTime(ResultObj)); } else { return(DateTime.MinValue); } } else { // date is invalid AVerificationResult = TDateChecks.IsValidDateTime(AParseDate, ADescription); return(DateTime.MinValue); } }
/// <summary> /// Validates the GL Batch data. /// </summary> /// <param name="AContext">Context that describes where the data validation failed.</param> /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param> /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if /// data validation errors occur.</param> /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that /// display data that is about to be validated.</param> /// <param name="AStartDateCurrentPeriod">If the caller knows this value it can be supplied. Otherwise the server will supply the value for the ledger.</param> /// <param name="AEndDateLastForwardingPeriod">If the caller knows this value it can be supplied. Otherwise the server will supply the value for the ledger.</param> /// <returns>True if the validation found no data validation errors, otherwise false.</returns> public static bool ValidateGLBatchManual(object AContext, ABatchRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict, DateTime?AStartDateCurrentPeriod = null, DateTime?AEndDateLastForwardingPeriod = null) { DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TScreenVerificationResult VerificationResult; object ValidationContext; int VerifResultCollAddedCount = 0; // Don't validate deleted or posted DataRows if ((ARow.RowState == DataRowState.Deleted) || (ARow.BatchStatus == MFinanceConstants.BATCH_POSTED)) { return(true); } bool isImporting = AContext.ToString().Contains("Importing"); // 'Effective From Date' must be valid ValidationColumn = ARow.Table.Columns[ABatchTable.ColumnDateEffectiveId]; ValidationContext = ARow.BatchNumber; DateTime StartDateCurrentPeriod; DateTime EndDateLastForwardingPeriod; if ((AStartDateCurrentPeriod == null) || (AEndDateLastForwardingPeriod == null)) { TSharedFinanceValidationHelper.GetValidPostingDateRange(ARow.LedgerNumber, out StartDateCurrentPeriod, out EndDateLastForwardingPeriod); } else { StartDateCurrentPeriod = AStartDateCurrentPeriod.Value; EndDateLastForwardingPeriod = AEndDateLastForwardingPeriod.Value; } if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = (TScreenVerificationResult)TDateChecks.IsDateBetweenDates(ARow.DateEffective, StartDateCurrentPeriod, EndDateLastForwardingPeriod, ValidationControlsData.ValidationControlLabel + (isImporting ? String.Empty : " of Batch Number " + ValidationContext.ToString()), TDateBetweenDatesCheckType.dbdctUnspecific, TDateBetweenDatesCheckType.dbdctUnspecific, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true)) { VerifResultCollAddedCount++; } } return(VerifResultCollAddedCount == 0); }
/// <summary> /// Validates the Corporate Exchange Rates screen data. /// </summary> /// <param name="AContext">Context that describes where the data validation failed.</param> /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param> /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if /// data validation errors occur.</param> /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that /// display data that is about to be validated.</param> public static void ValidateCorporateExchangeRate(object AContext, ACorporateExchangeRateRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict) { DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult; // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } // RateOfExchange must be positive (definitely not zero because we can invert it) ValidationColumn = ARow.Table.Columns[ACorporateExchangeRateTable.ColumnRateOfExchangeId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TNumericalChecks.IsPositiveDecimal(ARow.RateOfExchange, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } // Date must not be empty ValidationColumn = ARow.Table.Columns[ACorporateExchangeRateTable.ColumnDateEffectiveFromId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TDateChecks.IsNotUndefinedDateTime(ARow.DateEffectiveFrom, ValidationControlsData.ValidationControlLabel, true, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } // Date must be first of month ValidationColumn = ARow.Table.Columns[ACorporateExchangeRateTable.ColumnDateEffectiveFromId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TDateChecks.IsNotCorporateDateTime(ARow.DateEffectiveFrom, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } }
/// <summary> /// todoComment /// </summary> /// <param name="e"></param> /// <param name="AVerificationResultCollection"></param> /// <param name="AVerificationResult"></param> public static void VerifyDates(DataColumnChangeEventArgs e, TVerificationResultCollection AVerificationResultCollection, out TVerificationResult AVerificationResult) { AVerificationResult = null; DateTime DateGoodUntil = new DateTime(); DateTime DateEffective = new DateTime(); try { if (e.Column.ColumnName == PPartnerLocationTable.GetDateEffectiveDBName()) { // MessageBox.Show('p_date_effective_d: ' + e.Row['p_date_effective_d', DataRowVersion.Current].ToString); DateEffective = TSaveConvert.ObjectToDate(e.ProposedValue); DateGoodUntil = TSaveConvert.ObjectToDate(e.Row[PPartnerLocationTable.GetDateGoodUntilDBName()]); } else if (e.Column.ColumnName == PPartnerLocationTable.GetDateGoodUntilDBName()) { DateEffective = TSaveConvert.ObjectToDate(e.Row[PPartnerLocationTable.GetDateEffectiveDBName()]); DateGoodUntil = TSaveConvert.ObjectToDate(e.ProposedValue); } // MessageBox.Show('p_date_effective_d: ' + DateEffective.ToString + Environment.NewLine + // 'p_date_good_until_d: ' + DateGoodUntil.ToString); if (e.Column.ColumnName == PPartnerLocationTable.GetDateEffectiveDBName()) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateEffective, DateGoodUntil, "Valid From", "Valid To"); } else { AVerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(DateGoodUntil, DateEffective, "Valid To", "Valid From"); } if (e.Column.ColumnName == PPartnerLocationTable.GetDateEffectiveDBName()) { // delete any error that might have been there from a verification of the other column AVerificationResultCollection.Remove(PPartnerLocationTable.GetDateGoodUntilDBName()); } else { // delete any error that might have been there from a verification of the other column AVerificationResultCollection.Remove(PPartnerLocationTable.GetDateEffectiveDBName()); } } catch (Exception Exp) { MessageBox.Show("Exception occured in TPartnerAddressVerification.VerifyDates: " + Exp.ToString()); } }
/// <summary> /// Validates the GL Batch Date dialog. /// </summary> /// <param name="ABatchDate">The Data being validated</param> /// <param name="ADescription">Description of control</param> /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if /// data validation errors occur.</param> /// <param name="AStartDateCurrentPeriod">If the caller knows this value it can be supplied. Otherwise the server will supply the value for the ledger.</param> /// <param name="AEndDateLastForwardingPeriod">If the caller knows this value it can be supplied. Otherwise the server will supply the value for the ledger.</param> /// <param name="AControl"></param> /// <returns>True if the validation found no data validation errors, otherwise false.</returns> public static bool ValidateGLBatchDateManual(DateTime?ABatchDate, string ADescription, ref TVerificationResultCollection AVerificationResultCollection, DateTime AStartDateCurrentPeriod, DateTime AEndDateLastForwardingPeriod, Control AControl) { TScreenVerificationResult VerificationResult = null; int VerifResultCollAddedCount = 0; // 'Reversal Date' must be a valid date TVerificationResult Result = TSharedValidationControlHelper.IsNotInvalidDate(ABatchDate, ADescription, AVerificationResultCollection, true, AControl, null, AControl); if (Result != null) { VerificationResult = new TScreenVerificationResult(Result, null, AControl); } // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AControl, VerificationResult, null, true)) { VerifResultCollAddedCount++; } else { // 'Reversal Date' must lie within the required date range Result = TDateChecks.IsDateBetweenDates(ABatchDate, AStartDateCurrentPeriod, AEndDateLastForwardingPeriod, ADescription, TDateBetweenDatesCheckType.dbdctUnspecific, TDateBetweenDatesCheckType.dbdctUnspecific, AControl, null, AControl); if (Result != null) { VerificationResult = new TScreenVerificationResult(Result, null, AControl); } // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AControl, VerificationResult, null, true)) { VerifResultCollAddedCount++; } } return(VerifResultCollAddedCount == 0); }
/// <summary> /// Converts a String into a date time. /// </summary> /// <param name="AParseDate">String which contains the date that should be converted</param> /// <param name="ADescription">String about the conversion type that is performed. This is /// used to gather error messages.</param> /// <param name="AVerificationResult">If conversion fails it contains detailed information /// about the error. If conversion is successful: null</param> /// <param name="AShowVerificationError">True if a error message should be shown if conversion fails.</param> /// <returns>The converted date. If the conversion didn't succeed than it contains /// the Date Min value.</returns> public static DateTime LongDateStringToDateTime2(String AParseDate, String ADescription, out TVerificationResult AVerificationResult, Boolean AShowVerificationError) { DateTime ReturnValue; // DateConvertEventArgs: ConvertEventArgs; object ResultObj; ResultObj = null; AVerificationResult = null; /* Result := DateTime.MinValue; */ /* */ /* Convert TextBox's Text to Date */ /* DateConvertEventArgs := new ConvertEventArgs(AParseDate, System.Type.GetType('System.DateTime')); */ /* LongDateStringToDateTime(nil, DateConvertEventArgs); */ /* */ /* AVerificationResult := TDateChecks.IsValidDateTime( */ /* DateConvertEventArgs.Value.ToString, ''); */ /* */ /* if AVerificationResult = nil then */ /* begin */ /* Conversion was successful > return the Date */ /* Result := Convert.ToDateTime(DateConvertEventArgs.Value); */ /* end; */ if (LongDateStringToDateTimeInternal(AParseDate, ADescription, out ResultObj, AShowVerificationError)) { // MessageBox.Show('LongDateStringToDateTime2: date is valid: ' + ResultObj.ToString); if (ResultObj != DBNull.Value) { ReturnValue = Convert.ToDateTime(ResultObj); } else { ReturnValue = DateTime.MinValue; } } else { // MessageBox.Show('LongDateStringToDateTime2: date is INvalid!'); AVerificationResult = TDateChecks.IsValidDateTime(AParseDate, ADescription); ReturnValue = DateTime.MinValue; } return(ReturnValue); }
/// <summary> /// /// </summary> /// <param name="AContext"></param> /// <param name="ARow"></param> /// <param name="AVerificationResultCollection"></param> public static void ValidateAccountingPeriod(object AContext, AAccountingPeriodRow ARow, ref TVerificationResultCollection AVerificationResultCollection) { DataColumn ValidationColumn; TVerificationResult VerificationResult; // 'Period End Date' must be later than 'Period Start Date' ValidationColumn = ARow.Table.Columns[AAccountingPeriodTable.ColumnPeriodEndDateId]; if (true) { VerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(ARow.PeriodEndDate, ARow.PeriodStartDate, String.Empty, String.Empty, AContext, ValidationColumn); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult); } }
/// <summary> /// /// </summary> /// <param name="AContext"></param> /// <param name="ARow"></param> /// <param name="AVerificationResultCollection"></param> /// <param name="AValidationControlsDict"></param> public static void ValidateAccountingPeriod(object AContext, AAccountingPeriodRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict) { DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult; // 'Period End Date' must be later than 'Period Start Date' ValidationColumn = ARow.Table.Columns[AAccountingPeriodTable.ColumnPeriodEndDateId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(ARow.PeriodEndDate, ARow.PeriodStartDate, ValidationControlsData.ValidationControlLabel, ValidationControlsData.SecondValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } }
/// <summary> /// Validates the Daily Exchange Rates screen data. /// </summary> /// <param name="AContext">Context that describes where the data validation failed.</param> /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param> /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if /// data validation errors occur.</param> /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that /// display data that is about to be validated.</param> /// <param name="AMinDateTime">The earliest allowable date.</param> /// <param name="AMaxDateTime">The latest allowable date.</param> public static void ValidateDailyExchangeRate(object AContext, ADailyExchangeRateRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict, DateTime AMinDateTime, DateTime AMaxDateTime) { DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult; // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } // RateOfExchange must be positive (definitely not zero because we can invert it) ValidationColumn = ARow.Table.Columns[ADailyExchangeRateTable.ColumnRateOfExchangeId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TNumericalChecks.IsPositiveDecimal(ARow.RateOfExchange, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } // Date must not be empty and must be in range ValidationColumn = ARow.Table.Columns[ADailyExchangeRateTable.ColumnDateEffectiveFromId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TSharedValidationControlHelper.IsNotInvalidDate(ARow.DateEffectiveFrom, ValidationControlsData.ValidationControlLabel, AVerificationResultCollection, true, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); if (VerificationResult == null) { if ((AMinDateTime > DateTime.MinValue) && (AMaxDateTime < DateTime.MaxValue)) { // Check that the date is in range VerificationResult = TDateChecks.IsDateBetweenDates(ARow.DateEffectiveFrom, AMinDateTime, AMaxDateTime, ValidationControlsData.ValidationControlLabel, TDateBetweenDatesCheckType.dbdctUnspecific, TDateBetweenDatesCheckType.dbdctUnspecific, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } else if (AMaxDateTime < DateTime.MaxValue) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(ARow.DateEffectiveFrom, AMaxDateTime, ValidationControlsData.ValidationControlLabel, Ict.Common.StringHelper.DateToLocalizedString(AMaxDateTime), AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } else if (AMinDateTime > DateTime.MinValue) { VerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(ARow.DateEffectiveFrom, AMinDateTime, ValidationControlsData.ValidationControlLabel, Ict.Common.StringHelper.DateToLocalizedString(AMinDateTime), AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } } } // Time must not be negative (indicating an error) ValidationColumn = ARow.Table.Columns[ADailyExchangeRateTable.ColumnTimeEffectiveFromId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TTimeChecks.IsValidIntegerTime(ARow.TimeEffectiveFrom, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } }
/// <summary> /// Converts a string to a formatted date string /// </summary> /// <param name="AParseDate">String which contains the date that should be converted</param> /// <param name="ADescription">String about the conversion type that is performed. This is /// used to gather error messages.</param> /// <param name="AParsedDate">String that holds the parsed date (if successful)</param> /// <param name="AShowVerificationError">true if error message box should be shown if conversion fails</param> /// <returns>true if successful, otherwise false</returns> public static Boolean LongDateStringToDateTimeInternal(String AParseDate, String ADescription, out object AParsedDate, Boolean AShowVerificationError) { Boolean ReturnValue = false; Int32 DayOffset; String TmpYear; String TmpMonth; String TmpDay; String TmpMonthDayExchange = ""; String TmpShortDatePattern; Int16 YearStart = 0; Int16 RestStart = 0; AParsedDate = null; DateTimeFormatInfo CurrentDateTimeFormatInfo; // for testing purposes only // string TmpDateSeparator = CurrentDateTimeFormatInfo.DateSeparator; try { // TODO: implement parsing of localised short month names like 4GL does (according to user's default language setting), eg. accept 'M?R' instead of 'MAR' for March if the user's language setting is DE (German) // MessageBox.Show('AParseDate: ' + AParseDate); if (TDateChecks.IsValidDateTime(AParseDate, "") != null) { // MessageBox.Show('No regular DateTime'); if ((AParseDate.StartsWith("-")) || ((AParseDate.StartsWith("+")) && (AParseDate.Length != 1))) { // MessageBox.Show('Calculating date from the amount that follows the + or sign...'); // calculate date from the amount that follows the + or sign if (TNumericalChecks.IsValidInteger(AParseDate.Substring(1), "") == null) { DayOffset = System.Convert.ToInt32(AParseDate.Substring(1)); // MessageBox.Show('DayOffset: ' + DayOffset.ToString); if (AParseDate.StartsWith("+")) { AParseDate = DateTime.Now.Date.AddDays(DayOffset).ToString("D"); } else { AParseDate = DateTime.Now.Date.Subtract(new TimeSpan(DayOffset, 0, 0, 0)).ToString("D"); } } else { // characters following the + or are not an Int32 MessageBox.Show(TDateChecks.GetInvalidDateVerificationResult(ADescription).ResultText, TDateChecks.GetInvalidDateVerificationResult(ADescription).ResultTextCaption); return(ReturnValue); } } else if (((AParseDate.Length <= 6) || (AParseDate.Length <= 8)) && (AParseDate.Length != 1) && (TNumericalChecks.IsValidInteger(AParseDate, "") == null)) { // MessageBox.Show("Checking for dates entered like eg. 211105 or 21112005 ..."); /* * Checking for dates entered like eg. 211105 or 21112005. * * Notes: * Petra.NET accepts date entry dependent on current Culture * (=settings are taken from Windows Control Panel -> Regional and * Language Options). * However, 4GL Petra parses dates according to the server-wide setting * '-d'in startup.pf (Progress home directory). This should normally be * the same than the Windows Control Panel setting on the user's * machines, so there should be no deviation. */ CurrentDateTimeFormatInfo = DateTimeFormatInfo.CurrentInfo; TmpShortDatePattern = CurrentDateTimeFormatInfo.ShortDatePattern.ToUpper(); // TmpShortDatePattern := "MM DD"; // For testing purposes only if (TmpShortDatePattern.StartsWith("Y")) { YearStart = 0; switch (AParseDate.Length) { case 8: RestStart = 4; break; case 6: RestStart = 2; break; case 4: RestStart = 0; YearStart = -1; break; } } else { RestStart = 0; switch (AParseDate.Length) { case 6: case 8: YearStart = 4; break; case 4: YearStart = -1; break; } } //MessageBox.Show("TmpShortDatePattern: " + TmpShortDatePattern + "; TmpDateSeparator: " + TmpDateSeparator + // "\r\nYearStart: " + YearStart.ToString() + "; RestStart: " + RestStart.ToString()); if (AParseDate.Length <= 6) { if (YearStart != -1) { TmpYear = AParseDate.Substring(YearStart, 2); // Determine the correct century for twodigit years. /* For compatibility reasons: This is the way how it's done in 4GL, */ /* in sp_date.p/ConvertStringToDate */ if (Convert.ToInt32(TmpYear) < 80) { TmpYear = "20" + TmpYear; } else if (Convert.ToInt32(TmpYear) < 100) { TmpYear = "19" + TmpYear; } /* */ /* This would be the Windows way of doing it... */ /* I (ChristianK) found no way to retrieve the correct century from */ /* .NET, so it's hardcoded here, taking the default values of Windows */ /* XP :( */ /* */ /* if Convert.ToInt32(TmpYear) <= 29 then */ /* begin */ /* TmpYear := '20' + TmpYear; */ /* end */ /* else */ /* begin */ /* TmpYear := '19' + TmpYear; */ /* end; */ } else { TmpYear = DateTime.Now.Year.ToString(); } //MessageBox.Show("TmpYear: " + TmpYear); } else { TmpYear = AParseDate.Substring(YearStart, 4); } if ((AParseDate.Length == 4) || (AParseDate.Length == 6) || (AParseDate.Length == 8)) { if (TmpShortDatePattern.IndexOf('M') < TmpShortDatePattern.IndexOf('D')) { TmpMonth = AParseDate.Substring(RestStart, 2); TmpDay = AParseDate.Substring(RestStart + 2, 2); } else { TmpDay = AParseDate.Substring(RestStart, 2); TmpMonth = AParseDate.Substring(RestStart + 2, 2); } } else { // format with other number of digits not supported MessageBox.Show(TDateChecks.GetInvalidDateVerificationResult(ADescription).ResultText, TDateChecks.GetInvalidDateVerificationResult(ADescription).ResultTextCaption); return(ReturnValue); } if (Convert.ToInt16(TmpMonth) > 12) { TmpMonthDayExchange = TmpMonth; TmpMonth = TmpDay; TmpDay = TmpMonthDayExchange; } // AParseDate := TmpYear + TmpDateSeparator + TmpMonth + TmpDateSeparator + TmpDay; For testing purposes // MessageBox.Show('AParseDate (1): ' + AParseDate); For testing purposes try { AParseDate = new DateTime(Convert.ToInt32(TmpYear), Convert.ToInt32(TmpMonth), Convert.ToInt32(TmpDay)).ToString("D"); // TmpMonth + '/' + TmpDay + '/' + TmpYear; if (TmpMonthDayExchange != "") { MessageBox.Show(StrMonthDayExchangedInfo, StrMonthDayExchangedInfoTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception) { MessageBox.Show(TDateChecks.GetInvalidDateVerificationResult(ADescription).ResultText, TDateChecks.GetInvalidDateVerificationResult(ADescription).ResultTextCaption); return(ReturnValue); } //MessageBox.Show("TmpShortDatePattern: " + TmpShortDatePattern + "; TmpDateSeparator: " + TmpDateSeparator + // "\r\nYearStart: " + YearStart.ToString() + "; RestStart: " + RestStart.ToString() + //"; TmpDay: " + TmpDay + "; TmpMonth: " + TmpMonth + "; TmpYear: " + TmpYear + "\r\nAParseDate: " + AParseDate); AParsedDate = AParseDate; ReturnValue = true; return(ReturnValue); } else if (AParseDate == "") { //MessageBox.Show("Value = \""); AParsedDate = DBNull.Value; ReturnValue = true; return(ReturnValue); } else if ((AParseDate == "=") || (AParseDate == "+") || (AParseDate.ToLower() == "today")) { AParsedDate = DateTime.Now.ToString("D"); ReturnValue = true; return(ReturnValue); } else { if (AShowVerificationError) { // not an accepted date parse string MessageBox.Show(TDateChecks.GetInvalidDateVerificationResult(ADescription).ResultText, TDateChecks.GetInvalidDateVerificationResult(ADescription).ResultTextCaption); } return(ReturnValue); } } // AParseDate ready to be parsed AParsedDate = DateTime.Parse(AParseDate).ToString("D"); ReturnValue = true; } catch (Exception) { MessageBox.Show(TDateChecks.GetInvalidDateVerificationResult(ADescription).ResultText, TDateChecks.GetInvalidDateVerificationResult(ADescription).ResultTextCaption); } return(ReturnValue); }
/// <summary> /// Verifies the Date value. /// </summary> /// <param name="AValueText">the new value of the textbox</param> /// <param name="AShowVerificationError">Set to true to show errors if verification /// failed, or to false to suppress error messages</param> /// <returns>true if the Control has a valid date</returns> private Boolean VerifyDate(string AValueText, Boolean AShowVerificationError) { TVerificationResult DateVerificationResult = null; if (!FAllowVerification) { return(true); } if (CountVerifyDateRunningInstances > 0) { // the LostFocus and the DateValidated events overlap, and would display too messageboxes if the text can not be parsed for a date return(false); } CountVerifyDateRunningInstances++; try { // Convert TextBox's Text to Date DateTime Text2Date = DataBinding.LongDateStringToDateTime2( AValueText, FDateDescription, out DateVerificationResult, AShowVerificationError, null); if (DateVerificationResult != null) { // Date conversion was NOT successful return(false); } else { // Conversion was successful if (!AllowFutureDate) { DateVerificationResult = TDateChecks.IsCurrentOrPastDate(Text2Date, FDateDescription); if (DateVerificationResult != null) { if (AShowVerificationError) { // Show appropriate Error Message to the user TMessages.MsgGeneralError(DateVerificationResult, this.FindForm().GetType()); } return(false); } } if (!AllowPastDate) { DateVerificationResult = TDateChecks.IsCurrentOrFutureDate(Text2Date, FDateDescription); if (DateVerificationResult != null) { if (AShowVerificationError) { // Show appropriate Error Message to the user TMessages.MsgGeneralError(DateVerificationResult, this.FindForm().GetType()); } return(false); } } if (!FAllowEmpty) { DateVerificationResult = TDateChecks.IsNotUndefinedDateTime(Text2Date, FDateDescription); if (DateVerificationResult != null) { if (AShowVerificationError) { // Show appropriate Error Message to the user TMessages.MsgGeneralError(DateVerificationResult, this.FindForm().GetType()); } return(false); } } // Store the Date for later use if (Text2Date != DateTime.MinValue) { FDate = Text2Date; } else { FDate = null; } // set tag to "SuppressChangeDetection" so text change is not detected by TFrmPetraEditUtils.MultiEventHandler object OriginalTag = this.Tag; this.Tag = MCommonResourcestrings.StrCtrlSuppressChangeDetection; FSuppressTextChangeEvent = true; // Now update the TextBox's Text with the newly formatted date if (FDate != null) { if (DateTime.Compare(minimalDateValue, FDate.Value) > 0) { TMessages.DateValueMessageMinUnderrun(minimalDateValue); } if (DateTime.Compare(FDate.Value, maximalDateValue) > 0) { TMessages.DateValueMessageMaxOverrun(maximalDateValue); } String NewText = DataBinding.DateTimeToLongDateString2(FDate.Value); if (this.Text != NewText) // Don't set anything that's unchanged { base.Text = NewText; // I'm not calling my own Text Property, because I don't want to end up back here... } } else { if (this.Text != "") // Don't set anything that's unchaged { base.Text = ""; // I'm not calling my own Text Property, because I don't want to end up back here... } } // reset tag to original state this.Tag = OriginalTag; FSuppressTextChangeEvent = false; return(true); } } finally { FDateVerificationResult = DateVerificationResult; CountVerifyDateRunningInstances--; } }
// The main validation method for the controls on this tab page private void ValidateDataManual(ALedgerRow ARow) { TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult = null; // make sure that Financial Year Start Date is no later than 28th of a month // (this field is not part of a_ledger but will be stored in period 1 of a_accounting_period) if (rbtMonthly.Checked) { // make sure that Financial Year Start Date is not empty // (this field is not part of a_ledger but will be stored in period 1 of a_accounting_period) if (dtpFinancialYearStartDate.Date == null) { VerificationResult = new TScreenVerificationResult( TDateChecks.IsNotUndefinedDateTime( dtpFinancialYearStartDate.Date, lblFinancialYearStartDate.Text.Trim(':'), true, this), null, dtpFinancialYearStartDate); } else if (dtpFinancialYearStartDate.Date.Value.Day > 28) { VerificationResult = new TScreenVerificationResult( this, new DataColumn(), ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_PERIOD_START_DAY_AFTER_28).ErrorMessageText, PetraErrorCodes.ERR_PERIOD_START_DAY_AFTER_28, dtpFinancialYearStartDate, TResultSeverity.Resv_Critical); } else { VerificationResult = null; } // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, null); } // check that there no suspense accounts for this ledger if box is unticked ValidationColumn = ARow.Table.Columns[ALedgerTable.ColumnSuspenseAccountFlagId]; if (FValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (!ARow.SuspenseAccountFlag) { if (TRemote.MFinance.Common.ServerLookups.WebConnectors.HasSuspenseAccounts(FLedgerNumber)) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_NO_SUSPENSE_ACCOUNTS_ALLOWED)), ValidationColumn, ValidationControlsData.ValidationControl); } else { VerificationResult = null; } // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } // check that the number of forwarding periods is not less than the already used ones ValidationColumn = ARow.Table.Columns[ALedgerTable.ColumnNumberFwdPostingPeriodsId]; if (FValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (ARow.NumberFwdPostingPeriods < FMainForm.CurrentForwardPostingPeriods) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_NUMBER_FWD_PERIODS_TOO_SMALL, new string[] { FMainForm.CurrentForwardPostingPeriods.ToString(), FMainForm.CurrentForwardPostingPeriods.ToString() })), ValidationColumn, ValidationControlsData.ValidationControl); } else { VerificationResult = null; } // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } // check that current period is not greater than number of ledger periods ValidationColumn = ARow.Table.Columns[ALedgerTable.ColumnNumberOfAccountingPeriodsId]; if (FValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (ARow.CurrentPeriod > ARow.NumberOfAccountingPeriods) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_CURRENT_PERIOD_TOO_LATE)), ValidationColumn, ValidationControlsData.ValidationControl); } else { VerificationResult = null; } // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } }
/// <summary> /// Validates the GL Detail data. /// </summary> /// <param name="AContext">Context that describes where the data validation failed.</param> /// <param name="ABatchRow">Manually added to bring over some GL Batch fields</param> /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param> /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if /// data validation errors occur.</param> /// <param name="AValidationCostCentreTable">REQUIRED for importing. A reference to a cost centre table so that inputs can be validated.</param> /// <param name="AvalidationAccountTable">REQUIRED for importing. A reference to an account table so that inputs can be validated.</param> /// <returns>True if the validation found no data validation errors, otherwise false.</returns> public static bool ValidateGLDetailManual(object AContext, ABatchRow ABatchRow, ATransactionRow ARow, ref TVerificationResultCollection AVerificationResultCollection, ACostCentreTable AValidationCostCentreTable = null, AAccountTable AvalidationAccountTable = null) { DataColumn ValidationColumn; TVerificationResult VerificationResult = null; object ValidationContext; int VerifResultCollAddedCount = 0; // Don't validate deleted DataRows or non-unposted batches if ((ABatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED) || (ARow.RowState == DataRowState.Deleted)) { return(true); } bool isImporting = AContext.ToString().Contains("Importing"); // When used by the GUI TransactionAmount is not in the dictionary so had to pass the control directly // But when importing we do have a dictionary entry if (isImporting) { // 'GL amount must be non-zero and positive ValidationColumn = ARow.Table.Columns[ATransactionTable.ColumnTransactionAmountId]; if (true) { VerificationResult = TNumericalChecks.IsPositiveDecimal(ARow.TransactionAmount, String.Empty, AContext, ValidationColumn); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult)) { VerifResultCollAddedCount++; } } } else { if (true) { // 'GL amount must be non-zero and positive ValidationColumn = ARow.Table.Columns[ATransactionTable.ColumnTransactionAmountId]; ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})", ARow.TransactionNumber, ARow.BatchNumber, ARow.JournalNumber); VerificationResult = TNumericalChecks.IsPositiveOrZeroDecimal(ARow.TransactionAmount, "Amount of " + ValidationContext, AContext, ValidationColumn); if (VerificationResult != null) { VerificationResult.SuppressValidationToolTip = true; } // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult)) { VerifResultCollAddedCount++; } return(VerifResultCollAddedCount == 0); } } // 'Narrative must not be empty ValidationColumn = ARow.Table.Columns[ATransactionTable.ColumnNarrativeId]; ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})", ARow.TransactionNumber, ARow.BatchNumber, ARow.JournalNumber); if (true) { VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.Narrative, (isImporting) ? String.Empty : "Narrative of " + ValidationContext, AContext, ValidationColumn); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult)) { VerifResultCollAddedCount++; } } // 'Entered From Date' must be valid ValidationColumn = ARow.Table.Columns[ATransactionTable.ColumnTransactionDateId]; ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})", ARow.TransactionNumber, ARow.BatchNumber, ARow.JournalNumber); if (true) { DateTime StartDatePeriod; DateTime EndDatePeriod; TSharedFinanceValidationHelper.GetValidPeriodDates(ARow.LedgerNumber, ABatchRow.BatchYear, 0, ABatchRow.BatchPeriod, out StartDatePeriod, out EndDatePeriod); VerificationResult = (TScreenVerificationResult)TDateChecks.IsDateBetweenDates(ARow.TransactionDate, StartDatePeriod, EndDatePeriod, (isImporting) ? String.Empty : "Transaction Date for " + ValidationContext.ToString(), TDateBetweenDatesCheckType.dbdctUnspecific, TDateBetweenDatesCheckType.dbdctUnspecific, AContext, ValidationColumn); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult)) { VerifResultCollAddedCount++; } } if (true) { // "Reference" is mandatory ValidationColumn = ARow.Table.Columns[ATransactionTable.ColumnReferenceId]; ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})", ARow.TransactionNumber, ARow.BatchNumber, ARow.JournalNumber); if (true) { VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.Reference, (isImporting) ? String.Empty : "Reference of " + ValidationContext, AContext, ValidationColumn); // Handle addition/removal to/from TVerificationResultCollection if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult)) { VerifResultCollAddedCount++; } } } // 'CostCentre' must be valid ValidationColumn = ARow.Table.Columns[ATransactionTable.ColumnCostCentreCodeId]; ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})", ARow.TransactionNumber, ARow.BatchNumber, ARow.JournalNumber); if (true) { if ((AValidationCostCentreTable != null) && !ARow.IsCostCentreCodeNull()) { // Code must exist in the cost centre table ACostCentreRow foundRow = (ACostCentreRow)AValidationCostCentreTable.Rows.Find( new object[] { ARow.LedgerNumber, ARow.CostCentreCode }); if ((foundRow == null) && AVerificationResultCollection.Auto_Add_Or_AddOrRemove( ValidationContext, new TVerificationResult(ValidationContext, String.Format(Catalog.GetString("Cost centre code '{0}' does not exist."), ARow.CostCentreCode), TResultSeverity.Resv_Critical))) { VerifResultCollAddedCount++; } // cost centre must be a posting cost centre if ((foundRow != null) && !foundRow.PostingCostCentreFlag) { if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(ValidationContext, new TVerificationResult(ValidationContext, String.Format(Catalog.GetString("Cost centre code '{0}' is not a posting cost centre."), ARow.CostCentreCode), TResultSeverity.Resv_Critical))) { VerifResultCollAddedCount++; } } //TODO: Maybe add a user preference to determine what to do with inactive values on importing // cost centre must not be inactive //if ((foundRow != null) && !foundRow.CostCentreActiveFlag) //{ // if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(ValidationContext, // new TVerificationResult(ValidationContext, // String.Format(Catalog.GetString("Cost centre code '{0}' is an inactive cost centre."), ARow.CostCentreCode), // TResultSeverity.Resv_Critical), // ValidationColumn)) // { // VerifResultCollAddedCount++; // } //} } } // 'Account code' must be valid ValidationColumn = ARow.Table.Columns[ATransactionTable.ColumnAccountCodeId]; ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})", ARow.TransactionNumber, ARow.BatchNumber, ARow.JournalNumber); if (true) { if ((AvalidationAccountTable != null) && !ARow.IsAccountCodeNull()) { // Code must exist in the account table AAccountRow foundRow = (AAccountRow)AvalidationAccountTable.Rows.Find( new object[] { ARow.LedgerNumber, ARow.AccountCode }); if ((foundRow == null) && AVerificationResultCollection.Auto_Add_Or_AddOrRemove( ValidationContext, new TVerificationResult(ValidationContext, String.Format(Catalog.GetString("Account code '{0}' does not exist."), ARow.AccountCode), TResultSeverity.Resv_Critical))) { VerifResultCollAddedCount++; } // Account code must be a posting Account code if ((foundRow != null) && !foundRow.PostingStatus) { if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(ValidationContext, new TVerificationResult(ValidationContext, String.Format(Catalog.GetString("Account code '{0}' is not a posting account."), ARow.AccountCode), TResultSeverity.Resv_Critical))) { VerifResultCollAddedCount++; } } //TODO: Maybe add a user preference to determine what to do with inactive values on importing // Account code must not be inactive //if ((foundRow != null) && !foundRow.AccountActiveFlag) //{ // if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(ValidationContext, // new TVerificationResult(ValidationContext, // String.Format(Catalog.GetString("Account code '{0}' is an inactive account."), ARow.AccountCode), // TResultSeverity.Resv_Critical), // ValidationColumn)) // { // VerifResultCollAddedCount++; // } //} } } return(VerifResultCollAddedCount == 0); }
/// <summary> /// todoComment /// </summary> /// <param name="e"></param> /// <param name="AVerificationResultCollection"></param> /// <param name="AVerificationResult"></param> /// <param name="FDataColumnComparedTo"></param> public static void VerifySubscriptionDates(DataColumnChangeEventArgs e, TVerificationResultCollection AVerificationResultCollection, out TVerificationResult AVerificationResult, out DataColumn FDataColumnComparedTo) { FDataColumnComparedTo = null; AVerificationResult = null; DateTime DateStarted = new DateTime(); DateTime DateExpired = new DateTime(); DateTime DateRenewed = new DateTime(); DateTime DateNoticeSent = new DateTime(); DateTime DateEnded = new DateTime(); DateTime DateFirstSent = new DateTime(); DateTime DateLastSent = new DateTime(); Boolean Completed; Completed = false; if (e.Column.ColumnName == PSubscriptionTable.GetStartDateDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.ProposedValue); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetExpiryDateDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.ProposedValue); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetSubscriptionRenewalDateDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.ProposedValue); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetDateNoticeSentDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.ProposedValue); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetDateCancelledDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.ProposedValue); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetFirstIssueDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.ProposedValue); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetLastIssueDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.ProposedValue); } while (!Completed) { // when the StartDate has changed, do this: if (e.Column.ColumnName == PSubscriptionTable.GetStartDateDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } } if (e.Column.ColumnName == PSubscriptionTable.GetExpiryDateDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } } if (e.Column.ColumnName == PSubscriptionTable.GetSubscriptionRenewalDateDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateTime.Today, "Date Renewed", "Today") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateTime.Today, "DateRenewed", "Today"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateExpired, "Date Renewed", "Date Expired") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateExpired, "Date Renewed", "Date Expired"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateNoticeSent, "Date Renewed", "Date Notice Sent") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateNoticeSent, "Date Renewed", "Date Notice Sent"); Completed = true; break; } } if (e.Column.ColumnName == PSubscriptionTable.GetDateNoticeSentDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } } if (e.Column.ColumnName == PSubscriptionTable.GetDateCancelledDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } if (TDateChecks.FirstLesserThanSecondDate(DateTime.Today, DateEnded, "Today", "Cancelled") != null) { AVerificationResult = TDateChecks.FirstLesserThanSecondDate(DateTime.Today, DateEnded, "Today", "Cancelled"); Completed = true; break; } } if (e.Column.ColumnName == PSubscriptionTable.GetFirstIssueDBName()) { FDataColumnComparedTo = e.Column; if (TDateChecks.FirstGreaterOrEqualThanSecondDate(DateLastSent, DateFirstSent, "Last Sent", "First Sent") != null) { AVerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(DateLastSent, DateFirstSent, "Last Sent", "First Sent"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateFirstSent, "Date Started", "First Sent") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateFirstSent, "Date Started", "First Sent"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateTime.Today, "First Sent", "today") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateTime.Today, "First Sent", "today"); Completed = true; break; } } if (e.Column.ColumnName == PSubscriptionTable.GetLastIssueDBName()) { FDataColumnComparedTo = e.Column; if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateLastSent, "First Sent", "Last Sent") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateLastSent, "First Sent", "Last Sent"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateLastSent, DateTime.Today, "Last Sent", "today") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateLastSent, DateTime.Today, "Last Sent", "today"); Completed = true; break; } } Completed = true; } }
/// <summary> /// Validates the Corporate Exchange Rates screen data. /// </summary> /// <param name="AContext">Context that describes where the data validation failed.</param> /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param> /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if /// data validation errors occur.</param> /// <param name="ALedgerTableRef">A reference to a ledger table that has contains the ledgers that a client has access to</param> /// <param name="AAlternativeFirstDayOfPeriod">An alternative day (apart from 1) that is the start of an accounting period /// for at least one of the availbale ledgers</param> public static void ValidateCorporateExchangeRate(object AContext, ACorporateExchangeRateRow ARow, ref TVerificationResultCollection AVerificationResultCollection, ALedgerTable ALedgerTableRef, int AAlternativeFirstDayOfPeriod) { DataColumn ValidationColumn; TVerificationResult VerificationResult; // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } // RateOfExchange must be positive (definitely not zero because we can invert it) ValidationColumn = ARow.Table.Columns[ACorporateExchangeRateTable.ColumnRateOfExchangeId]; if (true) { VerificationResult = TNumericalChecks.IsPositiveDecimal(ARow.RateOfExchange, String.Empty, AContext, ValidationColumn); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult); } // Date must not be empty ValidationColumn = ARow.Table.Columns[ACorporateExchangeRateTable.ColumnDateEffectiveFromId]; if (true) { VerificationResult = TDateChecks.IsNotUndefinedDateTime(ARow.DateEffectiveFrom, String.Empty, true, AContext, ValidationColumn); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult); } // Date must be first of month or first day in accounting period of a ledger ValidationColumn = ARow.Table.Columns[ACorporateExchangeRateTable.ColumnDateEffectiveFromId]; if (true) { VerificationResult = null; if (AAlternativeFirstDayOfPeriod != 0) { // day must be either 1 or AAlternativeFirstDayOfPeriod VerificationResult = TDateChecks.IsNotCorporateDateTime(ARow.DateEffectiveFrom, String.Empty, AContext, ValidationColumn, AAlternativeFirstDayOfPeriod); } else { // when the value is 0 we cannot do validation because there are too many alternatives! // How complicated is this set of ledgers??? } // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult); } if (true) { // These tests are for the GUI only ValidationColumn = ARow.Table.Columns[ACorporateExchangeRateTable.ColumnToCurrencyCodeId]; if (true) { // One of the currencies should be the base currency of one of the ledgers if ((ARow.RowState == DataRowState.Added) && (ALedgerTableRef != null)) { // Only do this test on new rows TScreenVerificationResult vr = null; DataView fromView = new DataView(ALedgerTableRef, String.Format("{0}='{1}'", ALedgerTable.GetBaseCurrencyDBName(), ARow.FromCurrencyCode), String.Empty, DataViewRowState.CurrentRows); if (fromView.Count == 0) { DataView toView = new DataView(ALedgerTableRef, String.Format("{0}='{1}'", ALedgerTable.GetBaseCurrencyDBName(), ARow.ToCurrencyCode), String.Empty, DataViewRowState.CurrentRows); if (toView.Count == 0) { vr = new TScreenVerificationResult(AContext, ValidationColumn, "One of the currencies should normally be a base currency for one of the Ledgers", TResultSeverity.Resv_Noncritical); } } // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, vr); } } } }
/// <summary> /// Validates the Daily Exchange Rates screen data. /// </summary> /// <param name="AContext">Context that describes where the data validation failed.</param> /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param> /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if /// data validation errors occur.</param> /// <param name="AMinDateTime">The earliest allowable date.</param> /// <param name="AMaxDateTime">The latest allowable date.</param> /// <param name="AIgnoreZeroRateCheck">If true a zero rate will be allowed. This will be the case when the Daily Exchange Rate screen is modal.</param> /// <param name="ALedgerTableRef">A ledger table containg the available ledgers and their base currencies</param> /// <param name="AEarliestAccountingPeriodStartDate">The earliest accounting period start date in all the active ledgers</param> /// <param name="ALatestAccountingPeriodEndDate">The latest accounting period end date in all the active ledgers</param> public static void ValidateDailyExchangeRate(object AContext, ADailyExchangeRateRow ARow, ref TVerificationResultCollection AVerificationResultCollection, DateTime AMinDateTime, DateTime AMaxDateTime, bool AIgnoreZeroRateCheck, ALedgerTable ALedgerTableRef, DateTime AEarliestAccountingPeriodStartDate, DateTime ALatestAccountingPeriodEndDate) { DataColumn ValidationColumn; TVerificationResult VerificationResult; // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } // RateOfExchange must be positive (definitely not zero unless in modal mode) ValidationColumn = ARow.Table.Columns[ADailyExchangeRateTable.ColumnRateOfExchangeId]; if (true) { if (AIgnoreZeroRateCheck) { VerificationResult = TNumericalChecks.IsPositiveOrZeroDecimal(ARow.RateOfExchange, String.Empty, AContext, ValidationColumn); } else { VerificationResult = TNumericalChecks.IsPositiveDecimal(ARow.RateOfExchange, String.Empty, AContext, ValidationColumn); } // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult); } // Date must not be empty and must be in range ValidationColumn = ARow.Table.Columns[ADailyExchangeRateTable.ColumnDateEffectiveFromId]; if (true) { VerificationResult = TValidationControlHelper.IsNotInvalidDate(ARow.DateEffectiveFrom, String.Empty, AVerificationResultCollection, true, AContext, ValidationColumn); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult); if (VerificationResult == null) { if ((AMinDateTime > DateTime.MinValue) && (AMaxDateTime < DateTime.MaxValue)) { // Check that the date is in range VerificationResult = TDateChecks.IsDateBetweenDates(ARow.DateEffectiveFrom, AMinDateTime, AMaxDateTime, String.Empty, TDateBetweenDatesCheckType.dbdctUnspecific, TDateBetweenDatesCheckType.dbdctUnspecific, AContext, ValidationColumn); } else if (AMaxDateTime < DateTime.MaxValue) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(ARow.DateEffectiveFrom, AMaxDateTime, String.Empty, Ict.Common.StringHelper.DateToLocalizedString(AMaxDateTime), AContext, ValidationColumn); if ((VerificationResult == null) && (ARow.RowState == DataRowState.Added)) { // even without a specific minimum date it should not be too far back if (ARow.DateEffectiveFrom < AEarliestAccountingPeriodStartDate) { VerificationResult = new TScreenVerificationResult(AContext, ValidationColumn, Catalog.GetString( "The date is before the start of the earliest current accounting period of any active ledger."), TResultSeverity.Resv_Noncritical); } } } else if (AMinDateTime > DateTime.MinValue) { VerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(ARow.DateEffectiveFrom, AMinDateTime, String.Empty, Ict.Common.StringHelper.DateToLocalizedString(AMinDateTime), AContext, ValidationColumn); if ((VerificationResult == null) && (ARow.RowState == DataRowState.Added)) { // even without a specific maximum date it should not be too far ahead if (ARow.DateEffectiveFrom > ALatestAccountingPeriodEndDate) { VerificationResult = new TScreenVerificationResult(AContext, ValidationColumn, Catalog.GetString( "The date is after the end of the latest forwarding period of any active ledger."), TResultSeverity.Resv_Noncritical); } } } else if ((AMinDateTime == DateTime.MinValue) && (AMaxDateTime == DateTime.MaxValue) && (ARow.RowState == DataRowState.Added)) { // even without a specific maximum date it should not be too far ahead if (ARow.DateEffectiveFrom > ALatestAccountingPeriodEndDate) { VerificationResult = new TScreenVerificationResult(AContext, ValidationColumn, Catalog.GetString( "The date is after the end of the latest forwarding period of any active ledger."), TResultSeverity.Resv_Noncritical); } // even without a specific minimum date it should not be too far back else if (ARow.DateEffectiveFrom < AEarliestAccountingPeriodStartDate) { VerificationResult = new TScreenVerificationResult(AContext, ValidationColumn, Catalog.GetString( "The date is before the start of the earliest current accounting period of any active ledger."), TResultSeverity.Resv_Noncritical); } } // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult); } } // Time must not be negative (indicating an error) ValidationColumn = ARow.Table.Columns[ADailyExchangeRateTable.ColumnTimeEffectiveFromId]; if (true) { VerificationResult = TTimeChecks.IsValidIntegerTime(ARow.TimeEffectiveFrom, String.Empty, AContext, ValidationColumn); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult); } if (true) { // These tests are for the GUI only ValidationColumn = ARow.Table.Columns[ADailyExchangeRateTable.ColumnToCurrencyCodeId]; if (true) { // One of the currencies should be the base currency of one of the ledgers if (ARow.RowState == DataRowState.Added) { // Only do this test if the To Currency ComboBox is enabled TScreenVerificationResult vr = null; DataView fromView = new DataView(ALedgerTableRef, String.Format("{0}='{1}'", ALedgerTable.GetBaseCurrencyDBName(), ARow.FromCurrencyCode), String.Empty, DataViewRowState.CurrentRows); if (fromView.Count == 0) { DataView toView = new DataView(ALedgerTableRef, String.Format("{0}='{1}'", ALedgerTable.GetBaseCurrencyDBName(), ARow.ToCurrencyCode), String.Empty, DataViewRowState.CurrentRows); if (toView.Count == 0) { vr = new TScreenVerificationResult(AContext, ValidationColumn, "One of the currencies should normally be a base currency for one of the Ledgers", TResultSeverity.Resv_Noncritical); } } // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, vr); } } } }
/// <summary> /// todoComment /// </summary> /// <param name="AParseDate"></param> /// <param name="ADescription"></param> /// <param name="AParsedDate"></param> /// <param name="AShowVerificationError"></param> /// <param name="ATypeWhichCallsVerification"></param> /// <returns></returns> private static Boolean LongDateStringToDateTimeInternal(String AParseDate, String ADescription, out object AParsedDate, Boolean AShowVerificationError, System.Type ATypeWhichCallsVerification) { Boolean ReturnValue; Int32 DayOffset; String TmpYear; String TmpMonth; String TmpDay; String TmpMonthDayExchange = ""; String TmpShortDatePattern; Int16 YearStart = 0; Int16 RestStart = 0; // see StringHelper.DateToLocalizedString // Mono and .Net return different strings for month of March in german culture TExecutingOSEnum OSVersion = Utilities.DetermineExecutingOS(); bool IsPossiblyWin10 = ((OSVersion == TExecutingOSEnum.eosWin8Plus) || (OSVersion == TExecutingOSEnum.eosWin10)); string CurrentCulture = Thread.CurrentThread.CurrentCulture.ToString(); List <string> CulturesToIgnore = new List <string>(); CulturesToIgnore.Add("de-BE"); CulturesToIgnore.Add("de-CH"); CulturesToIgnore.Add("de-LI"); CulturesToIgnore.Add("de-LU"); if ((CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "de") && !(CurrentCulture == "de-AT") && !(IsPossiblyWin10 && CulturesToIgnore.Contains(CurrentCulture))) { AParseDate = AParseDate.Replace("MÄR", "MRZ"); } AParsedDate = null; DateTimeFormatInfo CurrentDateTimeFormatInfo; ReturnValue = false; try { // TODO: implement parsing of localised short month names like 4GL does (according to user's default language setting), eg. accept 'M�R' instead of 'MAR' for March if the user's language setting is DE (German) // MessageBox.Show('AParseDate: ' + AParseDate); if (TDateChecks.IsValidDateTime(AParseDate, "") != null) { // MessageBox.Show('No regular DateTime'); if ((AParseDate.StartsWith("-")) || ((AParseDate.StartsWith("+")) && (AParseDate.Length != 1))) { // MessageBox.Show('Calculating date from the amount that follows the + or sign...'); // calculate date from the amount that follows the + or sign if (TNumericalChecks.IsValidInteger(AParseDate.Substring(1), "") == null) { DayOffset = System.Convert.ToInt32(AParseDate.Substring(1)); // MessageBox.Show('DayOffset: ' + DayOffset.ToString); if (AParseDate.StartsWith("+")) { AParseDate = DateTime.Now.Date.AddDays(DayOffset).ToString("D"); } else { AParseDate = DateTime.Now.Date.Subtract(new TimeSpan(DayOffset, 0, 0, 0)).ToString("D"); } } else { // characters following the + or are not an Int32 if (AShowVerificationError) { TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification); } return(ReturnValue); } } else if ((AParseDate.Length <= 8) && (AParseDate.Length != 1) && (TNumericalChecks.IsValidInteger(AParseDate, "") == null)) { // MessageBox.Show("Checking for dates entered like eg. 211105 or 21112005 ..."); /* * Checking for dates entered like eg. 211105 or 21112005. * * Notes: * Petra.NET accepts date entry dependent on current Culture * (=settings are taken from Windows Control Panel -> Regional and * Language Options). * However, 4GL Petra parses dates according to the server-wide setting * '-d'in startup.pf (Progress home directory). This should normally be * the same than the Windows Control Panel setting on the user's * machines, so there should be no deviation. */ CurrentDateTimeFormatInfo = DateTimeFormatInfo.CurrentInfo; TmpShortDatePattern = CurrentDateTimeFormatInfo.ShortDatePattern.ToUpper(); if (TmpShortDatePattern.StartsWith("Y")) { YearStart = 0; switch (AParseDate.Length) { case 8: RestStart = 4; break; case 6: RestStart = 2; break; case 4: RestStart = 0; YearStart = -1; break; } } else { RestStart = 0; switch (AParseDate.Length) { case 6: case 8: YearStart = 4; break; case 4: YearStart = -1; break; } } //MessageBox.Show("TmpShortDatePattern: " + TmpShortDatePattern + "; TmpDateSeparator: " + TmpDateSeparator + // "\r\nYearStart: " + YearStart.ToString() + "; RestStart: " + RestStart.ToString()); if (AParseDate.Length <= 6) { if (YearStart != -1) { TmpYear = AParseDate.Substring(YearStart, 2); // Determine the correct century for twodigit years. // For compatibility reasons: This is the way how it's done in 4GL, // in sp_date.p/ConvertStringToDate if (Convert.ToInt32(TmpYear) < 80) { TmpYear = "20" + TmpYear; } else if (Convert.ToInt32(TmpYear) < 100) { TmpYear = "19" + TmpYear; } // // This would be the Windows way of doing it... // I (ChristianK) found no way to retrieve the correct century from // .NET, so it's hardcoded here, taking the default values of Windows // XP :( // // if Convert.ToInt32(TmpYear) <= 29 then // begin // TmpYear := '20' + TmpYear; // end // else // begin // TmpYear := '19' + TmpYear; // end; } else { TmpYear = DateTime.Now.Year.ToString(); } } else { TmpYear = AParseDate.Substring(YearStart, 4); } if ((AParseDate.Length == 4) || (AParseDate.Length == 6) || (AParseDate.Length == 8)) { if (TmpShortDatePattern.IndexOf('M') < TmpShortDatePattern.IndexOf('D')) { TmpMonth = AParseDate.Substring(RestStart, 2); TmpDay = AParseDate.Substring(RestStart + 2, 2); } else { TmpDay = AParseDate.Substring(RestStart, 2); TmpMonth = AParseDate.Substring(RestStart + 2, 2); } } else { // format with other number of digits not supported if (AShowVerificationError) { TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification); } return(ReturnValue); } if (Convert.ToInt16(TmpMonth) > 12) { TmpMonthDayExchange = TmpMonth; TmpMonth = TmpDay; TmpDay = TmpMonthDayExchange; } // AParseDate := TmpYear + TmpDateSeparator + TmpMonth + TmpDateSeparator + TmpDay; For testing purposes // MessageBox.Show('AParseDate (1): ' + AParseDate); For testing purposes try { // TmpMonth + '/' + TmpDay + '/' + TmpYear; AParseDate = new DateTime(Convert.ToInt32(TmpYear), Convert.ToInt32(TmpMonth), Convert.ToInt32(TmpDay)).ToString("D"); if (TmpMonthDayExchange != "") { MessageBox.Show(StrMonthDayExchangedInfo, StrMonthDayExchangedInfoTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception) { if (AShowVerificationError) { TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification); } return(ReturnValue); } //MessageBox.Show("TmpShortDatePattern: " + TmpShortDatePattern + "; TmpDateSeparator: " + TmpDateSeparator + // "\r\nYearStart: " + YearStart.ToString() + "; RestStart: " + RestStart.ToString() + //"; TmpDay: " + TmpDay + "; TmpMonth: " + TmpMonth + "; TmpYear: " + TmpYear + "\r\nAParseDate: " + AParseDate); AParsedDate = AParseDate; ReturnValue = true; return(ReturnValue); } else if (AParseDate == string.Empty) { AParsedDate = DBNull.Value; ReturnValue = true; return(ReturnValue); } else if ((AParseDate == "=") || (AParseDate == "+") || (AParseDate.ToLower() == Catalog.GetString("today").ToLower())) { AParsedDate = DateTime.Now.ToString("D"); ReturnValue = true; return(ReturnValue); } else { if (AShowVerificationError) { // not an accepted date parse string TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification); } return(ReturnValue); } } // AParseDate ready to be parsed AParsedDate = DateTime.Parse(AParseDate).ToString("D"); ReturnValue = true; } catch (Exception /* Exp */) { if (AShowVerificationError) { TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification); } } return(ReturnValue); }