/// <summary> /// Checks whether an Object is null. /// </summary> /// <param name="AValue">The Object to check.</param> /// <param name="ADescription">Description what the value is about (for the /// error message).</param> /// <param name="AResultContext">Context of verification (can be null).</param> /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param> /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null).</param> /// <returns>Null if <paramref name="AValue" /> is not null, /// otherwise a <see cref="TVerificationResult" /> is returned that /// contains details about the problem, with a message that uses <paramref name="ADescription" />.</returns> public static TVerificationResult ValueMustNotBeNull(object AValue, string ADescription, object AResultContext = null, System.Data.DataColumn AResultColumn = null, System.Windows.Forms.Control AResultControl = null) { TVerificationResult ReturnValue = null; String Description = THelper.NiceValueDescription(ADescription); // Check if (AValue == null) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NONULL, StrValueMustNotBeNull, new string[] { Description })); if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl); } } return ReturnValue; }
/// <summary> /// Check that Foreign Currency Accounts are using a valid currency /// </summary> /// <param name="AContext">Context that describes what I'm validating.</param> /// <param name="ARow">DataRow with the the data I'm validating</param> /// <param name="AVerificationResultCollection">Will be filled with 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 ValidateAccountDetailManual(object AContext, GLSetupTDSAAccountRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict) { // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } TValidationControlsData ValidationControlsData; // If this account is foreign, its currency must be assigned! if (ARow.ForeignCurrencyFlag) { if (ARow.ForeignCurrencyCode == "") { DataColumn ValidationColumn = ARow.Table.Columns[AAccountTable.ColumnForeignCurrencyCodeId]; Control targetControl = null; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { targetControl = ValidationControlsData.ValidationControl; } TScreenVerificationResult VerificationResult = new TScreenVerificationResult( AContext, ValidationColumn, Catalog.GetString("Currency Code must be specified for foreign accounts."), targetControl, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } } else // If the Account is not foreign, I have nothing at all to say about the contents of the currency field. { AVerificationResultCollection.AddOrRemove(null, ARow.Table.Columns[AAccountTable.ColumnForeignCurrencyCodeId]); } }
/// <summary> /// Checks whether an International Postal Type is valid. Null values are accepted. /// </summary> /// <param name="AInternatPostalTypeCode">The International Postal Type to check.</param> /// <param name="ADescription">Description what the value is about (for the /// error message).</param> /// <param name="AResultContext">Context of verification (can be null).</param> /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param> /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null).</param> /// <returns>Null if <paramref name="AInternatPostalTypeCode" /> is null, /// otherwise a <see cref="TVerificationResult" /> is returned that /// contains details about the problem, with a message that uses <paramref name="ADescription" />.</returns> public static TVerificationResult IsValidInternationalPostalCode(string AInternatPostalTypeCode, string ADescription = "", object AResultContext = null, System.Data.DataColumn AResultColumn = null, System.Windows.Forms.Control AResultControl = null) { TVerificationResult ReturnValue = null; Ict.Common.Data.TTypedDataTable IntPostalDT; if (AInternatPostalTypeCode != null) { if (AInternatPostalTypeCode != String.Empty) { TSharedValidationHelper.GetData(PInternationalPostalTypeTable.GetTableDBName(), null, out IntPostalDT); if (IntPostalDT.Rows.Find(new object[] { AInternatPostalTypeCode }) == null) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_INVALIDINTERNATIONALPOSTALCODE)); if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl); } } } else { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_INVALIDINTERNATIONALPOSTALCODE)); if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl); } } } return ReturnValue; }
/// <summary> /// Validates SUser Details /// </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 ValidateSUserDetails(object AContext, SUserRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict) { DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult = null; // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } ValidationColumn = ARow.Table.Columns[SUserTable.ColumnPasswordHashId]; AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData); // PasswordHash must not be empty. if ((ARow.RowState != DataRowState.Unchanged) && string.IsNullOrEmpty(ARow.PasswordHash)) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_MISSING_PASSWORD, new string[] { ARow.UserId })), ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } // If this is a first password (no salt) check that the password is valid. if ((ARow.RowState != DataRowState.Unchanged) && string.IsNullOrEmpty(ARow.PasswordSalt) && !string.IsNullOrEmpty(ARow.PasswordHash)) { VerificationResult = null; if (!CheckPasswordQuality(ARow.PasswordHash, out VerificationResult)) { VerificationResult = new TScreenVerificationResult(VerificationResult, ValidationColumn, ValidationControlsData.ValidationControl); AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } } }
/// <summary> /// Checks whether the date is within a specified date range. Null values are accepted. /// </summary> /// <remarks>This Method is capable of returning varying<see cref="TVerificationResult" /> objects! The objects /// returned are determined by the values specified for <paramref name="ALowerRangeCheckType" /> and /// <paramref name="AUpperRangeCheckType" />!</remarks> /// <param name="ADate">Date to check.</param> /// <param name="ALowerDateRangeEnd">Lower end of the valid Date Range.</param> /// <param name="AUpperDateRangeEnd">Upper end of the valid Date Range.</param> /// <param name="ADescription">Name of the date value.</param> /// <param name="ALowerRangeCheckType">Type of Date Check: lower end of the valid Date Range (defaults to <see cref="TDateBetweenDatesCheckType.dbdctUnspecific" />).</param> /// <param name="AUpperRangeCheckType">Type of Date Check: upper end of the valid Date Range (defaults to <see cref="TDateBetweenDatesCheckType.dbdctUnspecific" />).</param> /// <param name="AResultContext">Context of verification (can be null).</param> /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param> /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null).</param> /// <returns>Null if the date <paramref name="ADate" /> is between the lower and the upper end of the Date Range specified /// (lower and upper end dates are included), otherwise a verification result with a message that uses /// <paramref name="ADescription" />. /// </returns> public static TVerificationResult IsDateBetweenDates(DateTime? ADate, DateTime? ALowerDateRangeEnd, DateTime? AUpperDateRangeEnd, String ADescription, TDateBetweenDatesCheckType ALowerRangeCheckType = TDateBetweenDatesCheckType.dbdctUnspecific, TDateBetweenDatesCheckType AUpperRangeCheckType = TDateBetweenDatesCheckType.dbdctUnspecific, object AResultContext = null, System.Data.DataColumn AResultColumn = null, System.Windows.Forms.Control AResultControl = null) { TVerificationResult ReturnValue = null; DateTime TheDate = TSaveConvert.ObjectToDate(ADate); DateTime LowerDateRangeEndDate = TSaveConvert.ObjectToDate(ALowerDateRangeEnd); DateTime UpperDateRangeEndDate = TSaveConvert.ObjectToDate(AUpperDateRangeEnd); String Description = THelper.NiceValueDescription(ADescription); if ((!ADate.HasValue) || (!ALowerDateRangeEnd.HasValue) || (!AUpperDateRangeEnd.HasValue)) { return null; } // Check if ((TheDate < LowerDateRangeEndDate) || (TheDate > UpperDateRangeEndDate)) { if ((ALowerRangeCheckType == TDateBetweenDatesCheckType.dbdctUnspecific) && (AUpperRangeCheckType == TDateBetweenDatesCheckType.dbdctUnspecific)) { ReturnValue = GetUnspecificDateRangeCheckVerificationResult(LowerDateRangeEndDate, UpperDateRangeEndDate, Description, AResultContext); } else if (TheDate < LowerDateRangeEndDate) { if (ALowerRangeCheckType == TDateBetweenDatesCheckType.dbdctNoPastDate) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOPASTDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateMustNotBePastDate, new string[] { Description })); } else if (ALowerRangeCheckType == TDateBetweenDatesCheckType.dbdctUnrealisticDate) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_UNREALISTICDATE_ERROR, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateNotSensible, new string[] { Description })); } else { ReturnValue = GetUnspecificDateRangeCheckVerificationResult(LowerDateRangeEndDate, UpperDateRangeEndDate, Description, AResultContext); } } else if (TheDate > UpperDateRangeEndDate) { if (AUpperRangeCheckType == TDateBetweenDatesCheckType.dbdctNoFutureDate) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOFUTUREDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateMustNotBeFutureDate, new string[] { Description })); } else if (AUpperRangeCheckType == TDateBetweenDatesCheckType.dbdctUnrealisticDate) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_UNREALISTICDATE_ERROR, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateNotSensible, new string[] { Description })); } else { ReturnValue = GetUnspecificDateRangeCheckVerificationResult(LowerDateRangeEndDate, UpperDateRangeEndDate, Description, AResultContext); } } if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl); } } else { ReturnValue = null; } return ReturnValue; }
/// <summary> /// Checks whether the date is today or in the past. Null values are accepted. /// </summary> /// <param name="ADate">The date to check.</param> /// <param name="ADescription">The name of the date value.</param> /// <param name="AResultContext">Context of verification (can be null).</param> /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param> /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null).</param> /// <returns>Null if the date <paramref name="ADate" /> is today or in the past, /// otherwise a verification result with a message that uses <paramref name="ADescription" />. /// </returns> public static TVerificationResult IsCurrentOrPastDate(DateTime? ADate, String ADescription, object AResultContext = null, System.Data.DataColumn AResultColumn = null, System.Windows.Forms.Control AResultControl = null) { TVerificationResult ReturnValue; String Description = THelper.NiceValueDescription(ADescription); if (!ADate.HasValue) { return null; } // Check if (ADate <= DateTime.Today) { //MessageBox.Show('Date <= Today'); ReturnValue = null; } else { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOFUTUREDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateMustNotBeFutureDate, new string[] { Description })); if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl); } } return ReturnValue; }
/// <summary> /// This procedure verifies the changes of the DataSource. /// </summary> /// <returns>void</returns> protected void OnDataboundTableColumnChanged(System.Object sender, DataColumnChangeEventArgs e) { // mVerified: System.Boolean; bool mDelegateVerified; // mErrorMessage: System.String; mCaption: System.String; String mColumnName; TResultSeverity mResultSev; TScreenVerificationResult mVerificationResult; bool mPartnerExists; String mVerifiedString; System.Int64 mPartnerKey; TPartnerClass mPartnerClass; bool mPartnerIsMerged; String mExtractName; // was a set of TPartnerClass Object[] mPartnerClassSet; String[] mPartnerValues; Char[] mPartnerClassDelimiter; /* This works in two different ways depending on whether it is * partner key mode of occupation mode. * * It is triggered by the datatable the control is bound to firing * a column changed event, indicating new data. * * If occupation mode - we use a VerifyLookupValue in txtButtonLabel to * determine whether it is a valid value or not. Because the control is bound * to a datatable, it can simply check against the values in the databound table. * * In partner key mode, we invoke the delegate VerifyUserEntry, which * the hosting form must implement, which returns true if the value is value, * or false if not. * (hope to do this in-control soon) * */ if (e.ProposedValue == null) { // we can't possibly do anything useful here return; } // Initialization mColumnName = e.Column.ColumnName; mDelegateVerified = false; this.FErrorData.RVerified = false; mResultSev = TResultSeverity.Resv_Critical; mVerifiedString = null; mPartnerClassDelimiter = new char[] { ',' }; mPartnerValues = this.PartnerClass.Split(mPartnerClassDelimiter); // Needs the event handling here? if (mColumnName.Equals(this.FValueMember) == false) { // we are not concerned, out of here! return; } // we need to verify the data: switch (this.FListTable) { case TListTableEnum.OccupationList: #region TListTableEnum.OccupationList // TLogging.Log('Verification Branch: ' + Enum.GetName(typeof(TListTableEnum), TListTableEnum.OccupationList)); // TLogging.Log('mColumn.ColumnName: ' + mColumnName); // Do all things necessary to verify the Occupation code: // mDataRow := this.txtAutoPopulated.GetLookUpRow('p_occupation_code_c', e.ProposedValue.ToString); // SPECIAL CASE: an empty string IS a valid value! if (e.ProposedValue.ToString() == "") { this.FErrorData.RVerified = true; return; } mVerifiedString = this.txtAutoPopulated.VerifyLookUpValue("p_occupation_code_c", e.ProposedValue.ToString(), false); // TLogging.Log('mVerifiedString: ' + mVerifiedString); if ((mVerifiedString == null) || (mVerifiedString == "")) { // Occupation Code does not exist in the LookUpTable this.FDisplayLabelString = UNIT_NO_VALID_OCCUPATIONCODE; // this.FErrorData.RErrorMessage := 'The specified occupation code "' + e.ProposedValue.ToString + '" is invalid!' + "\n" + 'Please check spelling!'; this.FErrorData.RErrorMessage = String.Format(Catalog.GetString("The specified Occupation Code '{0}' is invalid!\r\n" + "Please check spelling!"), e.ProposedValue); this.FErrorData.RCaption = Catalog.GetString("Invalid Occupation Code"); //mErrorName = "OccupationCode Error"; mResultSev = TResultSeverity.Resv_Noncritical; //mResultField = "OccupationCode"; // suppress error message this.FErrorData.RVerified = false; } else { // Occupation Code does exist in the LookUpTable this.FErrorData.RVerified = true; } // End TListTableEnum.OccupationList: #endregion break; case TListTableEnum.PartnerKey: #region TListTableEnum.PartnerKey // TLogging.Log('Verification Branch: ' + Enum.GetName(typeof(TListTableEnum), TListTableEnum.PartnerKey)); mPartnerKey = Convert.ToInt64(e.ProposedValue); // sort out the set mPartnerClassSet = new Object[0]; mPartnerClassDelimiter = new char[] { ',' }; mPartnerValues = PartnerClass.Split(mPartnerClassDelimiter); // we end up with a set of values if (PartnerClass != "") { for (Int32 counter = 0; counter <= mPartnerValues.Length - 1; counter += 1) { try { mPartnerClass = (TPartnerClass)(System.Enum.Parse(typeof(TPartnerClass), mPartnerValues[counter], true)); mPartnerClassSet = Utilities.AddToArray(mPartnerClassSet, mPartnerClass); } catch (Exception) { MessageBox.Show("Invalid entry in PartnerClass property: " + mPartnerValues[counter]); } // end try } } // If the delegate is defined, the host form is allowed to dictate what is valid if (this.VerifyUserEntry != null) { // delegate IS defined // TLogging.Log('VerifyUserEntry is assigned!', [TLoggingType.ToLogfile]); // TLogging.Log('VerifyUserEntry proposed Value: ' + e.ProposedValue.ToString, [TLoggingType.ToLogfile]); try { mDelegateVerified = this.VerifyUserEntry(mPartnerKey.ToString(), out mVerifiedString); this.FVerifiedString = mVerifiedString; } catch (Exception) { this.FVerifiedString = UNIT_NO_DATA_MESSAGE; throw new EVerificationMissing("this.VerifyUserEntry could not be called!"); } // end try } // end IS assigned else { // delegate IS NOT defined // look it up for ourself TPartnerClass[] temp = new TPartnerClass[mPartnerClassSet.Length]; Int32 counter = 0; foreach (object obj in mPartnerClassSet) { temp[counter] = (TPartnerClass)obj; counter++; } mDelegateVerified = TServerLookup.TMPartner.VerifyPartner(mPartnerKey, temp, out mPartnerExists, out mVerifiedString, out mPartnerClass, out mPartnerIsMerged); } // end delegate IS NOT defined // OK, now process result if (mDelegateVerified == true) { // TLogging.Log('(mDelegateVerified = true)'); this.txtAutoPopulated.lblLabel.Text = mVerifiedString; this.FErrorData.RVerified = true; } else { // TLogging.Log('NOT(mDelegateVerified = true))'); this.FErrorData.RVerified = false; this.FVerifiedString = UNIT_NO_DATA_MESSAGE; this.txtAutoPopulated.lblLabel.Text = UNIT_NO_DATA_MESSAGE; this.FErrorData.RErrorMessage = String.Format(Catalog.GetString("The specified {0} '{1}' is invalid!"), ApplWideResourcestrings.StrPartnerKey, e.ProposedValue); this.FErrorData.RCaption = String.Format(Catalog.GetString("Invalid "), ApplWideResourcestrings.StrPartnerKey); this.FErrorData.RErrorCode = PetraErrorCodes.ERR_PARTNERKEY_INVALID; //mErrorName = "PartnerKey Error"; mResultSev = TResultSeverity.Resv_Critical; //mResultField = "PartnerKey"; } // End TListTableEnum.PartnerKey: #endregion break; case TListTableEnum.Extract: #region TListTableEnum.Extract // TLogging.Log('Verification Branch: ' + Enum.GetName(typeof(TListTableEnum), TListTableEnum.Extract)); if (e.ProposedValue.ToString() == "") { this.FErrorData.RVerified = false; this.FErrorData.RErrorMessage = Catalog.GetString("No valid Extract selected"); this.FErrorData.RCaption = Catalog.GetString("Error"); return; } mExtractName = e.ProposedValue.ToString(); String ExtractDescription = mExtractName; if (mExtractName != "") { TServerLookup.TMPartner.GetExtractDescription(mExtractName, out ExtractDescription); } this.txtAutoPopulated.lblLabel.Text = ExtractDescription; this.FErrorData.RVerified = true; // End TListTableEnum.Extract: #endregion break; case TListTableEnum.Conference: case TListTableEnum.Event: #region TListTableEnum.Conference and TListTableEnum.Event /* TLogging.Log('Verification Branch: ' + Enum.GetName(typeof(TListTableEnum), TListTableEnum.Conference)); */ mPartnerKey = Convert.ToInt64(e.ProposedValue); /* If the delegate is defined, the host form is allowed to dictate what is valid */ if (this.VerifyUserEntry != null) { /* delegate IS defined */ /* TLogging.Log('VerifyUserEntry is assigned!', [TLoggingType.ToLogfile]); */ /* TLogging.Log('VerifyUserEntry proposed Value: ' + e.ProposedValue.ToString, [TLoggingType.ToLogfile]); */ try { mDelegateVerified = this.VerifyUserEntry(mPartnerKey.ToString(), out mVerifiedString); this.FVerifiedString = mVerifiedString; } catch (Exception) { this.FVerifiedString = UNIT_NO_DATA_MESSAGE; throw new EVerificationMissing("this.VerifyUserEntry could not be called!"); } /* end try */ } /* end IS assigned */ else { /* delegate IS NOT defined */ /* look it up for ourself */ TPartnerClass[] temp = new TPartnerClass[1]; temp[0] = TPartnerClass.UNIT; mDelegateVerified = TServerLookup.TMPartner.VerifyPartner(mPartnerKey, temp, out mPartnerExists, out mVerifiedString, out mPartnerClass, out mPartnerIsMerged); } /* end delegate IS NOT defined */ /* OK, now process result */ if (mDelegateVerified == true) { /* TLogging.Log('(mDelegateVerified = true)'); */ this.txtAutoPopulated.lblLabel.Text = mVerifiedString; this.FErrorData.RVerified = true; } else { /* TLogging.Log('NOT(mDelegateVerified = true))'); */ this.FErrorData.RVerified = false; this.FVerifiedString = UNIT_NO_DATA_MESSAGE; this.txtAutoPopulated.lblLabel.Text = UNIT_NO_DATA_MESSAGE; this.FErrorData.RErrorMessage = String.Format(Catalog.GetString("The specified {0} '{1}' is invalid!"), ApplWideResourcestrings.StrPartnerKey, e.ProposedValue); this.FErrorData.RCaption = String.Format(Catalog.GetString("Invalid "), ApplWideResourcestrings.StrPartnerKey); this.FErrorData.RErrorCode = PetraErrorCodes.ERR_PARTNERKEY_INVALID; mResultSev = TResultSeverity.Resv_Critical; } /* End TListTableEnum.Conference and TListTableEnum.Event: */ #endregion break; case TListTableEnum.Bank: #region TListTableEnum.Bank // TLogging.Log('Verification Branch: ' + Enum.GetName(typeof(TListTableEnum), TListTableEnum.PartnerKey)); mPartnerKey = Convert.ToInt64(e.ProposedValue); // sort out the set mPartnerClassSet = new Object[0]; mPartnerClassDelimiter = new char[] { ',' }; mPartnerValues = PartnerClass.Split(mPartnerClassDelimiter); // we end up with a set of values if (PartnerClass != "") { for (Int32 counter = 0; counter <= mPartnerValues.Length - 1; counter += 1) { try { mPartnerClass = (TPartnerClass)(System.Enum.Parse(typeof(TPartnerClass), mPartnerValues[counter], true)); mPartnerClassSet = Utilities.AddToArray(mPartnerClassSet, mPartnerClass); } catch (Exception) { MessageBox.Show("Invalid entry in PartnerClass property: " + mPartnerValues[counter]); } // end try } } // If the delegate is defined, the host form is allowed to dictate what is valid if (this.VerifyUserEntry != null) { // delegate IS defined // TLogging.Log('VerifyUserEntry is assigned!', [TLoggingType.ToLogfile]); // TLogging.Log('VerifyUserEntry proposed Value: ' + e.ProposedValue.ToString, [TLoggingType.ToLogfile]); try { mDelegateVerified = this.VerifyUserEntry(mPartnerKey.ToString(), out mVerifiedString); this.FVerifiedString = mVerifiedString; } catch (Exception) { this.FVerifiedString = UNIT_NO_DATA_MESSAGE; throw new EVerificationMissing("this.VerifyUserEntry could not be called!"); } // end try } // end IS assigned else { // delegate IS NOT defined // look it up for ourself TPartnerClass[] temp = new TPartnerClass[mPartnerClassSet.Length]; Int32 counter = 0; foreach (object obj in mPartnerClassSet) { temp[counter] = (TPartnerClass)obj; counter++; } mDelegateVerified = TServerLookup.TMPartner.VerifyPartner(mPartnerKey, temp, out mPartnerExists, out mVerifiedString, out mPartnerClass, out mPartnerIsMerged); } // end delegate IS NOT defined // OK, now process result if (mDelegateVerified == true) { // TLogging.Log('(mDelegateVerified = true)'); this.txtAutoPopulated.lblLabel.Text = mVerifiedString; this.FErrorData.RVerified = true; } else { // TLogging.Log('NOT(mDelegateVerified = true))'); this.FErrorData.RVerified = false; this.FVerifiedString = UNIT_NO_DATA_MESSAGE; this.txtAutoPopulated.lblLabel.Text = UNIT_NO_DATA_MESSAGE; this.FErrorData.RErrorMessage = String.Format(Catalog.GetString("The specified {0} '{1}' is invalid!"), ApplWideResourcestrings.StrPartnerKey, e.ProposedValue); this.FErrorData.RCaption = String.Format(Catalog.GetString("Invalid "), ApplWideResourcestrings.StrPartnerKey); this.FErrorData.RErrorCode = PetraErrorCodes.ERR_PARTNERKEY_INVALID; //mErrorName = "PartnerKey Error"; mResultSev = TResultSeverity.Resv_Critical; //mResultField = "PartnerKey"; } // End TListTableEnum.PartnerKey: #endregion break; } // End "case this.FListTable of" #region Marking errors // If the entered values could not be verified // TLogging.Log('Event ColumnName: ' + mColumnName); // TLogging.Log('Right ColumnName: ' + this.FValueMember); if (this.FErrorData.RVerified == false) { // Creata and show error message mVerificationResult = new TScreenVerificationResult(this.Parent, e.Column, this.FErrorData.RErrorMessage, this.FErrorData.RCaption, FErrorData.RErrorCode, this, mResultSev); if (FVerificationResultCollection != null) { FVerificationResultCollection.Add(mVerificationResult); } TMessages.MsgGeneralError(mVerificationResult, this.ParentForm.GetType()); } else { // If there was previously an error delete it if (FVerificationResultCollection != null) { if (FVerificationResultCollection.Contains(e.Column)) { FVerificationResultCollection.Remove(e.Column); } } // if (e.Row.GetColumnError(e.Column) <> '') then // begin // e.Row.SetColumnError(e.Column, nil); // / TLogging.Log('Error unmarked!'); // end; } #endregion }
/// validate all data not in a DataRow private void ValidateEverything() { TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; TScreenVerificationResult VerificationResult; // Validate Reference if (!string.IsNullOrEmpty(txtFromReference.Text) && (txtFromReference.Text.Length > 100)) { // 'Reference' must not contain more than 100 characters VerificationResult = new TScreenVerificationResult(TStringChecks.StringLengthLesserOrEqual(txtFromReference.Text, 100, "Reference", txtFromReference), null, txtFromReference); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(txtFromReference, VerificationResult, null); } else if (string.IsNullOrEmpty(txtFromReference.Text)) { // 'Reference' must not be empty VerificationResult = new TScreenVerificationResult(TStringChecks.StringMustNotBeEmpty(txtFromReference.Text, "Reference", txtFromReference), null, txtFromReference); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(txtFromReference, VerificationResult, null); } // Validate Narrative if (!string.IsNullOrEmpty(txtFromNarrative.Text) && (txtFromNarrative.Text.Length > 500)) { // 'Narrative' must not contain more than 100 characters VerificationResult = new TScreenVerificationResult(TStringChecks.StringLengthLesserOrEqual(txtFromNarrative.Text, 500, "Narrative", txtFromNarrative), null, txtFromNarrative); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(txtFromNarrative, VerificationResult, null); } // Validate FromCostCentreCode if (string.IsNullOrEmpty(cmbFromCostCentreCode.GetSelectedString())) { // 'Cost Centre Code' must not be empty VerificationResult = new TScreenVerificationResult(TStringChecks.StringMustNotBeEmpty(cmbFromCostCentreCode.Text, "Cost Centre Code", cmbFromCostCentreCode), null, cmbFromCostCentreCode); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(cmbFromCostCentreCode, VerificationResult, null); } // Validate FromAccountCode if (string.IsNullOrEmpty(cmbFromAccountCode.GetSelectedString())) { // 'Account Code' must not be empty VerificationResult = new TScreenVerificationResult(TStringChecks.StringMustNotBeEmpty(cmbFromAccountCode.Text, "Account Code", cmbFromAccountCode), null, cmbFromAccountCode); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(cmbFromAccountCode, VerificationResult, null); } // Validate TotalAmount if (string.IsNullOrEmpty(txtTotalAmount.Text) || (Convert.ToDecimal(txtTotalAmount.Text) <= 0)) { if (string.IsNullOrEmpty(txtTotalAmount.Text)) { txtTotalAmount.NumberValueDecimal = 0; } // From Amount must not = 0 VerificationResult = new TScreenVerificationResult(TNumericalChecks.IsPositiveDecimal(Convert.ToDecimal(txtTotalAmount.Text), "Amount", txtTotalAmount), null, txtTotalAmount); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(txtTotalAmount, VerificationResult, null); } else { // Validate Allocations' amounts if (rbtAmountOption.Checked) { if (GetAmountTotal() != Convert.ToDecimal(txtTotalAmount.Text)) { VerificationResult = new TScreenVerificationResult(this, null, Catalog.GetString( "The amounts entered do not match the total amount of the Allocation. Please check the amounts entered."), txtTotalAmount, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(txtTotalAmount, VerificationResult, null); } } // Validate Allocations' percentages else { if (GetPercentageTotal() != 100) { VerificationResult = new TScreenVerificationResult(this, null, Catalog.GetString("The percentages entered must add up to 100%."), txtDetailPercentage, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(txtDetailPercentage, VerificationResult, null); } } } if (grdDetails.Rows.Count <= 2) { VerificationResult = new TScreenVerificationResult(this, null, Catalog.GetString("You must include at least 2 destination allocations."), btnNew, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(btnNew, VerificationResult, null); } else if (grdDetails.Rows.Count > 11) { VerificationResult = new TScreenVerificationResult(this, null, Catalog.GetString("You must include no more than 10 destination allocations."), btnDeleteAllocation, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(btnDeleteAllocation, VerificationResult, null); } if (!FAnalysisAttributesLogic.AccountAnalysisAttributeCountIsCorrect(FJournal.LastTransactionNumber + 1, cmbFromAccountCode.GetSelectedString(), FTempFromDS)) { VerificationResult = new TScreenVerificationResult(this, null, String.Format(Catalog.GetString( "A value must be entered for the 'Analysis Attribute' for the 'From Allocation's' Account Code {0}."), cmbFromAccountCode.GetSelectedString()), grdFromAnalAttributes, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(grdFromAnalAttributes, VerificationResult, null); } String ValueRequiredForType; if (!FAnalysisAttributesLogic.AccountAnalysisAttributesValuesExist( FJournal.LastTransactionNumber + 1, cmbFromAccountCode.GetSelectedString(), FTempFromDS, out ValueRequiredForType)) { VerificationResult = new TScreenVerificationResult(this, null, String.Format(Catalog.GetString( "A value must be entered for the 'Analysis code {0} for Account Code {1}."), ValueRequiredForType, cmbFromAccountCode.GetSelectedString()), grdFromAnalAttributes, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(grdFromAnalAttributes, VerificationResult, null); } }
/// <summary> /// Creates a Data Validation *Error* for E-Mail ComboBoxes. /// </summary> private void ValidationEmailAddrSetButNotAmongEmailAddrs(TOverallContactComboType AContactComboType) { const string ResCont = "ContactDetails_EmailAddress_Set_But_Not_Among_Email_Addrs"; TScreenVerificationResult VerificationResult; TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; string ErrorCode; TCmbAutoComplete ComboBoxForContactComboType; string ComboTypeStr; // Ignored, but needed as this is an out Argument of GetDataAccordingToContactComboType... if (AContactComboType == TOverallContactComboType.occtPrimaryEmail) { ErrorCode = PetraErrorCodes.ERR_PRIMARY_EMAIL_ADDR_SET_BUT_NOT_AMONG_EMAIL_ADDR; } else if (AContactComboType == TOverallContactComboType.occtSecondaryEmail) { ErrorCode = PetraErrorCodes.ERR_SECONDARY_EMAIL_ADDR_SET_BUT_NOT_AMONG_EMAIL_ADDR; } else if (AContactComboType == TOverallContactComboType.occtEmailWithinOrganisation) { ErrorCode = PetraErrorCodes.ERR_OFFICE_EMAIL_ADDR_SET_BUT_NOT_AMONG_EMAIL_ADDR; } else { throw new EOPAppException("AContactComboType Argument must designate an E-Mail ComboBox"); } GetDataAccordingToContactComboType(AContactComboType, out ComboBoxForContactComboType, out ComboTypeStr); VerificationResult = new TScreenVerificationResult( new TVerificationResult((object)ResCont, ErrorCodes.GetErrorInfo(ErrorCode), FPetraUtilsObject.VerificationResultCollection.CurrentDataValidationRunID), null, ComboBoxForContactComboType, FPetraUtilsObject.VerificationResultCollection.CurrentDataValidationRunID); VerificationResultCollection.Remove(ResCont); if (VerificationResult != null) { VerificationResultCollection.Add(VerificationResult); } }
/// <summary> /// Creates a Data Validation *Warning* for specifically for cmbPrimaryEmail. /// </summary> private void ValidationPrimaryEmailAddrNotSet() { const string ResCont = "ContactDetails_PrimaryEmailAddress_Not_Set"; TScreenVerificationResult VerificationResult; TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; VerificationResult = new TScreenVerificationResult( new TVerificationResult((object)ResCont, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_PRIMARY_EMAIL_ADDR_NOT_SET_DESIPITE_EMAIL_ADDR_AVAIL), FPetraUtilsObject.VerificationResultCollection.CurrentDataValidationRunID), null, cmbPrimaryEMail, FPetraUtilsObject.VerificationResultCollection.CurrentDataValidationRunID); VerificationResultCollection.Remove(ResCont); if (VerificationResult != null) { VerificationResultCollection.Add(VerificationResult); } }
/// <summary> /// Checks whether the date is not undefined. DateTime.MinValue is seen as undefined by this Method. /// Null values are accepted. They are treated as valid, unless <paramref name="ATreatNullAsInvalid" /> is /// set to true. /// </summary> /// <param name="ADate">The date to check.</param> /// <param name="ADescription">The name of the date value.</param> /// <param name="ATreatNullAsInvalid">Set this to true to treated null value in <paramref name="ADate" /> as invalid.</param> /// <param name="AResultContext">Context of verification (can be null).</param> /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param> /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null).</param> /// <remarks>Usage in the Data Validation Framework: rather than using this Method, use Method /// 'TSharedValidationControlHelper.IsNotInvalidDate' for checking the validity of dates as the latter can deal not only with /// empty dates, but dates that are invalid in other respects (e.g. exceeding a valid date range)!!!</remarks> /// <returns>Null if validation succeeded, otherwise a <see cref="TVerificationResult" /> is /// returned that contains details about the problem.</returns> public static TVerificationResult IsNotUndefinedDateTime(DateTime? ADate, String ADescription, bool ATreatNullAsInvalid = false, object AResultContext = null, System.Data.DataColumn AResultColumn = null, System.Windows.Forms.Control AResultControl = null) { TVerificationResult ReturnValue; DateTime TheDate = TSaveConvert.ObjectToDate(ADate); String Description = THelper.NiceValueDescription(ADescription); if (!ADate.HasValue) { if (!ATreatNullAsInvalid) { return null; } else { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOUNDEFINEDDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateMustNotBeEmpty, new string[] { Description })); if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl); } } } // Check if (TheDate != DateTime.MinValue) { //MessageBox.Show('Date <> DateTime.MinValue'); ReturnValue = null; } else { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOUNDEFINEDDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateMustNotBeEmpty, new string[] { Description })); if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl); } } return ReturnValue; }
/// <summary> /// Checks wheter a given DateTime is an invalid date. A check whether it is an undefined DateTime is always performed. /// If Delegate <see cref="SharedGetDateVerificationResultDelegate" /> is set up and Argument /// <paramref name="AResultControl" /> isn't null, the 'DateVerificationResult' of the TtxtPetraDate Control is /// returned by this Method through this Method if it isn't null. That way the Data Validation Framework can /// use the detailed Data Verification error that is held by the Control. /// </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, Control AResultControl = null) { TVerificationResult VerificationResult; if (FDelegateSharedGetDateVerificationResult != null) { if ((AResultControl != null)) { VerificationResult = FDelegateSharedGetDateVerificationResult(AResultControl); if (VerificationResult == null) { VerificationResult = TDateChecks.IsNotUndefinedDateTime(ADate, ADescription, ATreatNullAsInvalid, AResultContext, AResultColumn, AResultControl); } else { VerificationResult.OverrideResultContext(AResultContext); VerificationResult = new TScreenVerificationResult(VerificationResult, AResultColumn, AResultControl); } } else { VerificationResult = TDateChecks.IsNotUndefinedDateTime(ADate, ADescription, ATreatNullAsInvalid, AResultContext, AResultColumn, AResultControl); } // 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, AResultControl); } return VerificationResult; }
/// <summary> /// TODO: Replace this with the Data Validation Framework - once it supports user interaction as needed /// in this case (=asking the user to make a decision). /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnUnitDataColumnChanging(System.Object sender, DataColumnChangeEventArgs e) { TVerificationResult VerificationResultReturned; TScreenVerificationResult VerificationResultEntry; Control BoundControl; // MessageBox.Show('Column ''' + e.Column.ToString + ''' is changing...'); try { if (TPartnerVerification.VerifyUnitData(e, FMainDS, out VerificationResultReturned) == false) { if (VerificationResultReturned.ResultCode != PetraErrorCodes.ERR_UNITNAMECHANGEUNDONE) { TMessages.MsgVerificationError(VerificationResultReturned, this.GetType()); BoundControl = TDataBinding.GetBoundControlForColumn(BindingContext[FMainDS.PUnit], e.Column); // MessageBox.Show('Bound control: ' + BoundControl.ToString); // TODO BoundControl.Focus(); VerificationResultEntry = new TScreenVerificationResult(this, e.Column, VerificationResultReturned.ResultText, VerificationResultReturned.ResultTextCaption, VerificationResultReturned.ResultCode, BoundControl, VerificationResultReturned.ResultSeverity); FPetraUtilsObject.VerificationResultCollection.Add(VerificationResultEntry); // MessageBox.Show('After setting the error: ' + e.ProposedValue.ToString); } else { // undo the change in the DataColumn e.ProposedValue = e.Row[e.Column.ColumnName, DataRowVersion.Original]; // need to assign this to make the change actually visible... txtUnitName.Text = e.ProposedValue.ToString(); // TODO BoundControl = TDataBinding.GetBoundControlForColumn(BindingContext[FMainDS.PUnit], e.Column); // MessageBox.Show('Bound control: ' + BoundControl.ToString); // TODO BoundControl.Focus(); } } else { if (FPetraUtilsObject.VerificationResultCollection.Contains(e.Column)) { FPetraUtilsObject.VerificationResultCollection.Remove(e.Column); } } } catch (Exception Exp) { MessageBox.Show(Exp.ToString()); } }
private void ValidateRecord(AAccountingPeriodRow ARow, Boolean ACheckGapToPrevious, Boolean ACheckGapToNext) { TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult = null; AAccountingPeriodRow OtherRow; DataRow OtherDataRow; string CurrentDateRangeErrorCode; if (FDuringSave) { CurrentDateRangeErrorCode = PetraErrorCodes.ERR_PERIOD_DATE_RANGE; } else { CurrentDateRangeErrorCode = PetraErrorCodes.ERR_PERIOD_DATE_RANGE_WARNING; } // first run through general checks related to the current AccountingPeriod row TSharedFinanceValidation_GLSetup.ValidateAccountingPeriod(this, ARow, ref VerificationResultCollection, FPetraUtilsObject.ValidationControlsDict); // the following checks need to be done in this ManualCode file as they involve other rows on the screen: // check that there is no gap to previous accounting period if (ACheckGapToPrevious) { ValidationColumn = ARow.Table.Columns[AAccountingPeriodTable.ColumnPeriodStartDateId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (!ARow.IsPeriodStartDateNull() && (ARow.PeriodStartDate != DateTime.MinValue)) { OtherDataRow = FMainDS.AAccountingPeriod.Rows.Find( new string[] { FLedgerNumber.ToString(), (ARow.AccountingPeriodNumber - 1).ToString() }); if (OtherDataRow != null) { OtherRow = (AAccountingPeriodRow)OtherDataRow; if (OtherRow.PeriodEndDate != ARow.PeriodStartDate.Date.AddDays(-1)) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(CurrentDateRangeErrorCode, new string[] { (ARow.AccountingPeriodNumber - 1).ToString() })), ValidationColumn, ValidationControlsData.ValidationControl); } else { VerificationResult = null; } // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } } } // check that there is no gap to next accounting period if (ACheckGapToNext) { ValidationColumn = ARow.Table.Columns[AAccountingPeriodTable.ColumnPeriodEndDateId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (!ARow.IsPeriodEndDateNull() && (ARow.PeriodEndDate != DateTime.MinValue)) { OtherDataRow = FMainDS.AAccountingPeriod.Rows.Find( new string[] { FLedgerNumber.ToString(), (ARow.AccountingPeriodNumber + 1).ToString() }); if (OtherDataRow != null) { OtherRow = (AAccountingPeriodRow)OtherDataRow; if (OtherRow.PeriodStartDate != ARow.PeriodEndDate.Date.AddDays(1)) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(CurrentDateRangeErrorCode, new string[] { (ARow.AccountingPeriodNumber).ToString() })), ValidationColumn, ValidationControlsData.ValidationControl); } else { VerificationResult = null; } // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } } } }
private void ValidateDataManual(PSubscriptionRow ARow) { DataColumn ValidationColumn; DataColumn ValidationColumn2; TValidationControlsData ValidationControlsData; TValidationControlsData ValidationControlsData2; TVerificationResult VerificationResult = null; bool NoClearingOfVerificationResult = false; TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; if (!chkChangeReasonSubsGivenCode.Checked) { if (VerificationResultCollection.Contains(ARow.Table.Columns[PSubscriptionTable.ColumnReasonSubsGivenCodeId])) { VerificationResultCollection.Remove(ARow.Table.Columns[PSubscriptionTable.ColumnReasonSubsGivenCodeId]); } } if (!chkChangeStartDate.Checked) { if (VerificationResultCollection.Contains(ARow.Table.Columns[PSubscriptionTable.ColumnStartDateId])) { VerificationResultCollection.Remove(ARow.Table.Columns[PSubscriptionTable.ColumnStartDateId]); } } // if 'SubscriptionStatus' is CANCELLED or EXPIRED then 'Reason Ended' and 'End Date' must be set ValidationColumn = ARow.Table.Columns[PSubscriptionTable.ColumnSubscriptionStatusId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if ((!ARow.IsSubscriptionStatusNull()) && ((ARow.SubscriptionStatus == "CANCELLED") || (ARow.SubscriptionStatus == "EXPIRED"))) { if (ARow.IsReasonSubsCancelledCodeNull() || (ARow.ReasonSubsCancelledCode == String.Empty)) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SUBSCRIPTION_REASONENDEDMANDATORY_WHEN_EXPIRED)), ValidationColumn, ValidationControlsData.ValidationControl); } else if (ARow.IsDateCancelledNull()) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SUBSCRIPTION_DATEENDEDMANDATORY_WHEN_EXPIRED)), ValidationColumn, ValidationControlsData.ValidationControl); } } else { // if 'SubscriptionStatus' is not CANCELLED or EXPIRED then 'Reason Ended' and 'End Date' must NOT be set if (chkChangeReasonSubsCancelledCode.Checked) { if ((ARow.IsReasonSubsCancelledCodeNull()) || (ARow.ReasonSubsCancelledCode == String.Empty)) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SUBSCRIPTION_REASONENDEDSET_WHEN_ACTIVE)), ValidationColumn, ValidationControlsData.ValidationControl); } } else if (!chkChangeReasonSubsCancelledCode.Checked) { if (ARow.SubscriptionStatus != String.Empty) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SUBSCRIPTION_REASONENDEDSET_WHEN_ACTIVE)), ValidationColumn, ValidationControlsData.ValidationControl); VerificationResult.OverrideResultText(Catalog.GetString( "Reason Ended must be cleared when a Subscription is made active.")); NoClearingOfVerificationResult = true; } } if ((!ARow.IsReasonSubsCancelledCodeNull()) && (ARow.ReasonSubsCancelledCode != String.Empty)) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SUBSCRIPTION_REASONENDEDSET_WHEN_ACTIVE)), ValidationColumn, ValidationControlsData.ValidationControl); } else if (!ARow.IsDateCancelledNull()) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SUBSCRIPTION_DATEENDEDSET_WHEN_ACTIVE)), ValidationColumn, ValidationControlsData.ValidationControl); } else if (!chkChangeDateCancelled.Checked) { if (ARow.SubscriptionStatus != String.Empty) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SUBSCRIPTION_DATEENDEDSET_WHEN_ACTIVE)), ValidationColumn, ValidationControlsData.ValidationControl); VerificationResult.OverrideResultText(Catalog.GetString("Date Ended must be cleared when a Subscription is made active.")); } } else { if (!NoClearingOfVerificationResult) { VerificationResult = null; } } } // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); // perform checks that include 'Start Date' ---------------------------------------------------------------- if (chkChangeStartDate.Checked) { ValidationColumn = ARow.Table.Columns[PSubscriptionTable.ColumnStartDateId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { // 'Start Date' must not be later than 'Expiry Date' if (chkChangeExpiryDate.Checked) { ValidationColumn2 = ARow.Table.Columns[PSubscriptionTable.ColumnExpiryDateId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn2, out ValidationControlsData2)) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate (ARow.StartDate, ARow.ExpiryDate, ValidationControlsData.ValidationControlLabel, ValidationControlsData2.ValidationControlLabel, this, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } // 'Start Date' must not be later than 'Renewal Date' if (chkChangeRenewalDate.Checked) { ValidationColumn2 = ARow.Table.Columns[PSubscriptionTable.ColumnSubscriptionRenewalDateId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn2, out ValidationControlsData2)) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate (ARow.StartDate, ARow.SubscriptionRenewalDate, ValidationControlsData.ValidationControlLabel, ValidationControlsData2.ValidationControlLabel, this, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } // 'Start Date' must not be later than 'End Date' if (chkChangeDateCancelled.Checked) { ValidationColumn2 = ARow.Table.Columns[PSubscriptionTable.ColumnDateCancelledId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn2, out ValidationControlsData2)) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate (ARow.StartDate, ARow.DateCancelled, ValidationControlsData.ValidationControlLabel, ValidationControlsData2.ValidationControlLabel, this, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } // 'Start Date' must not be later than 'Notice Sent' if (chkChangeDateNoticeSent.Checked) { ValidationColumn2 = ARow.Table.Columns[PSubscriptionTable.ColumnDateNoticeSentId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn2, out ValidationControlsData2)) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate (ARow.StartDate, ARow.DateNoticeSent, ValidationControlsData.ValidationControlLabel, ValidationControlsData2.ValidationControlLabel, this, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } // 'Start Date' must not be later than 'First Sent' if (chkChangeFirstIssue.Checked) { ValidationColumn2 = ARow.Table.Columns[PSubscriptionTable.ColumnFirstIssueId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn2, out ValidationControlsData2)) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate (ARow.StartDate, ARow.FirstIssue, ValidationControlsData.ValidationControlLabel, ValidationControlsData2.ValidationControlLabel, this, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } // 'Start Date' must not be later than 'Last Date' if (chkChangeLastIssue.Checked) { ValidationColumn2 = ARow.Table.Columns[PSubscriptionTable.ColumnLastIssueId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn2, out ValidationControlsData2)) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate (ARow.StartDate, ARow.LastIssue, ValidationControlsData.ValidationControlLabel, ValidationControlsData2.ValidationControlLabel, this, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } } } // perform checks that include 'Date Renewed' ---------------------------------------------------------------- if (chkChangeRenewalDate.Checked) { ValidationColumn = ARow.Table.Columns[PSubscriptionTable.ColumnSubscriptionRenewalDateId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { // 'Date Renewed' must not be later than today VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate (ARow.SubscriptionRenewalDate, DateTime.Today, ValidationControlsData.ValidationControlLabel, Catalog.GetString("Today's Date"), this, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); // 'Date Renewed' must not be later than 'Date Expired' if (chkChangeExpiryDate.Checked) { ValidationColumn2 = ARow.Table.Columns[PSubscriptionTable.ColumnExpiryDateId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn2, out ValidationControlsData2)) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate (ARow.SubscriptionRenewalDate, ARow.ExpiryDate, ValidationControlsData.ValidationControlLabel, ValidationControlsData2.ValidationControlLabel, this, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } // 'Date Renewed' must not be later than 'Date Notice Sent' if (chkChangeDateNoticeSent.Checked) { ValidationColumn2 = ARow.Table.Columns[PSubscriptionTable.ColumnDateNoticeSentId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn2, out ValidationControlsData2)) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate (ARow.SubscriptionRenewalDate, ARow.DateNoticeSent, ValidationControlsData.ValidationControlLabel, ValidationControlsData2.ValidationControlLabel, this, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } } } // 'Date Cancelled' must not be before today if (chkChangeDateCancelled.Checked) { ValidationColumn = ARow.Table.Columns[PSubscriptionTable.ColumnDateCancelledId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate (ARow.DateCancelled, DateTime.Today, ValidationControlsData.ValidationControlLabel, Catalog.GetString("Today's Date"), this, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } // 'First Sent' must not be later than 'Last Sent' if (chkChangeFirstIssue.Checked && chkChangeLastIssue.Checked) { ValidationColumn = ARow.Table.Columns[PSubscriptionTable.ColumnFirstIssueId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { ValidationColumn2 = ARow.Table.Columns[PSubscriptionTable.ColumnLastIssueId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn2, out ValidationControlsData2)) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate (ARow.FirstIssue, ARow.LastIssue, ValidationControlsData.ValidationControlLabel, ValidationControlsData2.ValidationControlLabel, this, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } } // 'First Sent' must not be later than today if (chkChangeFirstIssue.Checked) { ValidationColumn = ARow.Table.Columns[PSubscriptionTable.ColumnFirstIssueId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate (ARow.FirstIssue, DateTime.Today, ValidationControlsData.ValidationControlLabel, Catalog.GetString("Today's Date"), this, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } // 'Date Started' must not be later than 'First Sent' if (chkChangeFirstIssue.Checked && chkChangeStartDate.Checked) { ValidationColumn = ARow.Table.Columns[PSubscriptionTable.ColumnStartDateId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { ValidationColumn2 = ARow.Table.Columns[PSubscriptionTable.ColumnFirstIssueId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn2, out ValidationControlsData2)) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate (ARow.StartDate, ARow.FirstIssue, ValidationControlsData.ValidationControlLabel, ValidationControlsData2.ValidationControlLabel, this, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } } // 'Last Sent' must not be later than today if (chkChangeLastIssue.Checked) { ValidationColumn = ARow.Table.Columns[PSubscriptionTable.ColumnLastIssueId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate (ARow.LastIssue, DateTime.Today, ValidationControlsData.ValidationControlLabel, Catalog.GetString("Today's Date"), this, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } } }
private void ValidateDataDetailsManual(AMotivationDetailRow ARow) { TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult; Boolean KeyMinistryActive; // Partner Key must be for a Key Ministry and Key Ministry must not be deactivated if (Convert.ToInt64(txtDetailRecipientKey.Text) != 0) { ValidationColumn = FMainDS.AMotivationDetail[0].Table.Columns[AMotivationDetailTable.ColumnRecipientKeyId]; if (FPetraUtilsObject.ValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (TRemote.MFinance.Gift.WebConnectors.KeyMinistryExists(Convert.ToInt64(txtDetailRecipientKey.Text), out KeyMinistryActive)) { if (!KeyMinistryActive) { // Key Ministry is deactivated and therefore can't be used here VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_KEY_MINISTRY_DEACTIVATED)), ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection. VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } else { // Partner Key does not refer to Key Ministry VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_NOT_A_KEY_MINISTRY)), ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection. VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } } TSharedFinanceValidation_Gift.ValidateGiftMotivationSetupManual(this, ARow, FTaxDeductiblePercentageEnabled, ref VerificationResultCollection, FPetraUtilsObject.ValidationControlsDict); }
/// <summary> /// Validates the Gift Motivation Setup. /// </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="ATaxDeductiblePercentageEnabled">True if Tax Deductible Percentage is enabled</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> /// <returns>void</returns> public static void ValidateGiftMotivationSetupManual(object AContext, AMotivationDetailRow ARow, bool ATaxDeductiblePercentageEnabled, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict) { DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult; // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } // 'Motivation Group' must not be unassignable ValidationColumn = ARow.Table.Columns[AMotivationDetailTable.ColumnMotivationGroupCodeId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { AMotivationGroupTable MotivationGroupTable; AMotivationGroupRow MotivationGroupPointRow; VerificationResult = null; if ((!ARow.IsMotivationGroupCodeNull()) && (ARow.MotivationGroupCode != String.Empty)) { MotivationGroupTable = (AMotivationGroupTable)TSharedDataCache.TMFinance.GetCacheableFinanceTable( TCacheableFinanceTablesEnum.MotivationGroupList); MotivationGroupPointRow = (AMotivationGroupRow)MotivationGroupTable.Rows.Find( new object[] { ARow.LedgerNumber, ARow.MotivationGroupCode }); // 'Motivation Group' must not be unassignable if ((MotivationGroupPointRow != null) && !MotivationGroupPointRow.GroupStatus) { // if 'Motivation Group' is unassignable then check if the value has been changed or if it is a new record if (TSharedValidationHelper.IsRowAddedOrFieldModified(ARow, AMotivationDetailTable.GetMotivationGroupCodeDBName())) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_VALUEUNASSIGNABLE_WARNING, new string[] { ValidationControlsData.ValidationControlLabel, ARow.MotivationGroupCode })), ValidationColumn, ValidationControlsData.ValidationControl); } } } // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } if (ATaxDeductiblePercentageEnabled) { // 'TaxDeductibleAccount' must have a value (NOT NULL constraint) ValidationColumn = ARow.Table.Columns[AMotivationDetailTable.ColumnTaxDeductibleAccountCodeId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.TaxDeductibleAccountCode, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } } }
/// <summary> /// Checks whether the first submitted date is later than the second submitted /// date. Null dates are accepted. /// </summary> /// <param name="ADate1">First date.</param> /// <param name="ADate2">Second date.</param> /// <param name="AFirstDateDescription">Description what the first date is about (for the /// error message).</param> /// <param name="ASecondDateDescription">Description what the second date is about (for /// the error message).</param> /// <param name="AResultContext">Context of verification (can be null).</param> /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param> /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null).</param> /// <returns>Null if validation succeeded, otherwise a <see cref="TVerificationResult" /> is /// returned that contains details about the problem, with a message that uses /// <paramref name="AFirstDateDescription" /> and <paramref name="ASecondDateDescription" />.</returns> public static TVerificationResult FirstGreaterThanSecondDate(DateTime? ADate1, DateTime? ADate2, string AFirstDateDescription, string ASecondDateDescription, object AResultContext = null, System.Data.DataColumn AResultColumn = null, System.Windows.Forms.Control AResultControl = null) { TVerificationResult ReturnValue; String FirstDateDescription = THelper.NiceValueDescription(AFirstDateDescription); String SecondDateDescription = THelper.NiceValueDescription(ASecondDateDescription); if ((!ADate1.HasValue) || (!ADate2.HasValue)) { return null; } // Check if (ADate1 > ADate2) { //MessageBox.Show('ADate1 <= ADate2'); ReturnValue = null; } else { if (ADate1 != new DateTime(0001, 1, 1)) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_INVALIDDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateCannotBeEarlierOrEqual, new string[] { FirstDateDescription, SecondDateDescription })); if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl); } } else { ReturnValue = null; } } return ReturnValue; }
/// <summary> /// Checks whether an integer time is in the range 0..86399 /// </summary> /// <param name="AValue">Integer number.</param> /// <param name="ADescription">Description what the integer number is about (for the error /// message).</param> /// <param name="AResultContext">Context of verification (can be null).</param> /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param> /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null).</param> /// <returns>Null if <paramref name="AValue" /> contains a valid integer number or is null, /// otherwise a <see cref="TVerificationResult" /> is returned that contains details about the problem, /// with a message that uses <paramref name="ADescription" />.</returns> public static TVerificationResult IsValidIntegerTime(Int64? AValue, String ADescription, object AResultContext = null, System.Data.DataColumn AResultColumn = null, System.Windows.Forms.Control AResultControl = null) { TVerificationResult ReturnValue = null; String Description = THelper.NiceValueDescription(ADescription); if (!AValue.HasValue) { return null; } // Check if ((AValue.Value < 0) || (AValue.Value >= 86400)) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_INVALIDINTEGERTIME, CommonResourcestrings.StrInvalidStringEntered + Environment.NewLine + StrMustBeTime, new string[] { Description })); if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl); } } return ReturnValue; }
// 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> /// Check that Foreign Currency Accounts are using a valid currency /// </summary> /// <param name="AContext">Context that describes what I'm validating.</param> /// <param name="ARow">DataRow with the the data I'm validating</param> /// <param name="AVerificationResultCollection">Will be filled with 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 ValidateAccountDetailManual(object AContext, GLSetupTDSAAccountRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict) { // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } TValidationControlsData ValidationControlsData; if (ARow.ForeignCurrencyFlag) { if ((ARow.AccountType != MFinanceConstants.ACCOUNT_TYPE_ASSET) && (ARow.AccountType != MFinanceConstants.ACCOUNT_TYPE_LIABILITY)) { DataColumn ValidationColumn = ARow.Table.Columns[AAccountTable.ColumnAccountTypeId]; Control targetControl = null; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { targetControl = ValidationControlsData.ValidationControl; } TScreenVerificationResult VerificationResult = new TScreenVerificationResult( AContext, ValidationColumn, string.Format(Catalog.GetString("A foreign currency account's Account Type must be either '{0}' or '{1}'."), MFinanceConstants.ACCOUNT_TYPE_ASSET, MFinanceConstants.ACCOUNT_TYPE_LIABILITY), targetControl, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } if (!ARow.PostingStatus) { DataColumn ValidationColumn = ARow.Table.Columns[AAccountTable.ColumnPostingStatusId]; Control targetControl = null; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { targetControl = ValidationControlsData.ValidationControl; } TScreenVerificationResult VerificationResult = new TScreenVerificationResult( AContext, ValidationColumn, Catalog.GetString("A foreign currency account must be a posting account; it cannot be a summary account."), targetControl, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } // If this account is foreign, its currency must be assigned! if (ARow.ForeignCurrencyCode == "") { DataColumn ValidationColumn = ARow.Table.Columns[AAccountTable.ColumnForeignCurrencyCodeId]; Control targetControl = null; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { targetControl = ValidationControlsData.ValidationControl; } TScreenVerificationResult VerificationResult = new TScreenVerificationResult( AContext, ValidationColumn, Catalog.GetString("Currency Code must be specified for foreign accounts."), targetControl, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } } else // If the Account is not foreign, I have nothing at all to say about the contents of the currency field. { AVerificationResultCollection.AddOrRemove(null, ARow.Table.Columns[AAccountTable.ColumnForeignCurrencyCodeId]); } }
private void ValidateDataDetailsManual(ADailyExchangeRateRow ARow) { if ((ARow.RowState == DataRowState.Detached) || FSkipValidation) { return; } TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; TSharedFinanceValidation_GLSetup.ValidateDailyExchangeRate(this, ARow, ref VerificationResultCollection, FPetraUtilsObject.ValidationControlsDict, minModalEffectiveDate, maxModalEffectiveDate, blnIsInModalMode, FMainDS.ALedgerInfo, FEarliestAccountingPeriodStartDate, FLatestAccountingPeriodEndDate); // Now make an additional manual check that the rate is sensible TScreenVerificationResult verificationResultSensible = null; TScreenVerificationResult verificationResultDuplicate = null; if ((ARow.RowState == DataRowState.Added) || (ARow.RowState == DataRowState.Modified)) { // We are going to check if the rate of exchange is sensible. We need our own view because we don't know how the grid is currently sorted // If we are in modal mode we may not be seeing the 'neighbouring' rate. But this filter will include it in the test. string filter = ADailyExchangeRateTable.GetFromCurrencyCodeDBName() + " = '" + ARow.FromCurrencyCode + "' and " + ADailyExchangeRateTable.GetToCurrencyCodeDBName() + " = '" + ARow.ToCurrencyCode + "'"; DataView myView = new DataView(FMainDS.ADailyExchangeRate, filter, SortByDateDescending, DataViewRowState.CurrentRows); // Find our current row int nThis = FindRowInDataView(myView, ARow.FromCurrencyCode, ARow.ToCurrencyCode, ARow.DateEffectiveFrom, ARow.TimeEffectiveFrom); ADailyExchangeRateRow drThis = null; ADailyExchangeRateRow drPrev = null; ADailyExchangeRateRow drNext = null; decimal ratio = 1.0m; if ((nThis >= 0) && (ARow.RateOfExchange != 0.0m)) { drThis = (ADailyExchangeRateRow)(myView[nThis]).Row; if (nThis >= 1) { drPrev = (ADailyExchangeRateRow)(myView[nThis - 1]).Row; } if (nThis < myView.Count - 1) { drNext = (ADailyExchangeRateRow)(myView[nThis + 1]).Row; } if ((drPrev != null) && (drPrev.RateOfExchange > 0.0m)) { ratio = drThis.RateOfExchange / drPrev.RateOfExchange; if (ratio < 1.0m) { ratio = drPrev.RateOfExchange / drThis.RateOfExchange; } } if ((drNext != null) && (drNext.RateOfExchange > 0.0m)) { decimal tryRatio = drThis.RateOfExchange / drNext.RateOfExchange; if (tryRatio < 1.0m) { tryRatio = drNext.RateOfExchange / drThis.RateOfExchange; } if (tryRatio > ratio) { ratio = tryRatio; } } if (ratio > EXCHANGE_RATE_WARNING_RATIO) { string validationMessage = String.Format( ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_EXCH_RATE_MAY_BE_INCORRECT).ErrorMessageText, ARow.RateOfExchange, ARow.FromCurrencyCode, ARow.ToCurrencyCode, dtpDetailDateEffectiveFrom.Text, txtDetailTimeEffectiveFrom.Text, ratio - 1.0m); // So we have a new warning to raise on a row that has been added/edited verificationResultSensible = new TScreenVerificationResult( this, ARow.Table.Columns[ADailyExchangeRateTable.ColumnRateOfExchangeId], validationMessage, Catalog.GetString("Exchange Rate Alert"), PetraErrorCodes.ERR_EXCH_RATE_MAY_BE_INCORRECT, txtDetailRateOfExchange, TResultSeverity.Resv_Noncritical); } } // Now check to see if it is a duplicate rate filter += String.Format(" and {0}={1} and {2}=#{3}#", ADailyExchangeRateTable.GetRateOfExchangeDBName(), ARow.RateOfExchange.ToString(CultureInfo.InvariantCulture), ADailyExchangeRateTable.GetDateEffectiveFromDBName(), ARow.DateEffectiveFrom.ToString("d", CultureInfo.InvariantCulture)); myView = new DataView(FMainDS.ADailyExchangeRate, filter, String.Empty, DataViewRowState.CurrentRows); if (myView.Count > 1) { verificationResultDuplicate = new TScreenVerificationResult( this, ARow.Table.Columns[ADailyExchangeRateTable.ColumnRateOfExchangeId], Catalog.GetString("A row with this date and exchange rate already exists"), Catalog.GetString("Exchange Rate Alert"), PetraErrorCodes.ERR_EXCH_RATE_IS_DUPLICATE, txtDetailRateOfExchange, TResultSeverity.Resv_Noncritical); } } VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, verificationResultSensible, ARow.Table.Columns[ADailyExchangeRateTable.ColumnRateOfExchangeId]); VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, verificationResultDuplicate, ARow.Table.Columns[ADailyExchangeRateTable.ColumnRateOfExchangeId]); }
/// <summary> /// Creates a Data Validation *Warning* for specifically for cmbSecondaryEmail. /// </summary> private void ValidationSecondaryEmailAddrEqualsPrimaryEmailAddr() { const string ResCont = "ContactDetails_SecondaryEmailAddr_Equals_PrimaryEmailAddr"; TScreenVerificationResult VerificationResult; TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; VerificationResult = new TScreenVerificationResult( new TVerificationResult((object)ResCont, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_SECONDARY_EMAIL_ADDR_EQUALS_PRIMARY_EMAIL_ADDR, new string[] { cmbSecondaryEMail.GetSelectedString() }), FPetraUtilsObject.VerificationResultCollection.CurrentDataValidationRunID), null, cmbSecondaryEMail, FPetraUtilsObject.VerificationResultCollection.CurrentDataValidationRunID); VerificationResultCollection.Remove(ResCont); if (VerificationResult != null) { VerificationResultCollection.Add(VerificationResult); } }
/// validate all data not in a DataRow private void ValidateEverything() { TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; TScreenVerificationResult VerificationResult; // Validate Reference if (!string.IsNullOrEmpty(txtFromReference.Text) && (txtFromReference.Text.Length > 100)) { // 'Reference' must not contain more than 100 characters VerificationResult = new TScreenVerificationResult(TStringChecks.StringLengthLesserOrEqual(txtFromReference.Text, 100, "Reference", txtFromReference), null, txtFromReference); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(txtFromReference, VerificationResult, null); } else if (string.IsNullOrEmpty(txtFromReference.Text)) { // 'Reference' must not be empty VerificationResult = new TScreenVerificationResult(TStringChecks.StringMustNotBeEmpty(txtFromReference.Text, "Reference", txtFromReference), null, txtFromReference); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(txtFromReference, VerificationResult, null); } // Validate Narrative if (!string.IsNullOrEmpty(txtFromNarrative.Text) && (txtFromNarrative.Text.Length > 500)) { // 'Narrative' must not contain more than 100 characters VerificationResult = new TScreenVerificationResult(TStringChecks.StringLengthLesserOrEqual(txtFromNarrative.Text, 500, "Narrative", txtFromNarrative), null, txtFromNarrative); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(txtFromNarrative, VerificationResult, null); } if (rbtFromAmountOption.Checked) { // Validate txtFromTransactionAmount if (string.IsNullOrEmpty(txtFromTransactionAmount.Text) || (Convert.ToDecimal(txtFromTransactionAmount.Text) == 0) || (Convert.ToDecimal(txtFromTransactionAmount.Text) > Math.Abs((decimal)FPreviouslySelectedAccountsRow[AGeneralLedgerMasterPeriodTable.GetActualBaseDBName()]))) { if (string.IsNullOrEmpty(txtFromTransactionAmount.Text)) { txtFromTransactionAmount.NumberValueDecimal = 0; } // From Amount must not be 0 or greater than |account balance| VerificationResult = new TScreenVerificationResult(this, null, string.Format(Catalog.GetString( "The amount for the Re-allocation must be between 0 and the positive total for this period.{0}" + "Please re-enter the amount."), "\n\n"), txtFromTransactionAmount, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(txtFromTransactionAmount, VerificationResult, null); } } else if (rbtFromPercentageOption.Checked) { // Validate txtFromPercentage if ((Convert.ToDecimal(txtFromPercentage.NumberValueDecimal) == 0) || (Convert.ToDecimal(txtFromPercentage.NumberValueDecimal) > 100)) { if (string.IsNullOrEmpty(txtFromPercentage.Text)) { txtFromPercentage.NumberValueDecimal = 0; } // Percentage must not be 0 or greater than 100 VerificationResult = new TScreenVerificationResult(this, null, string.Format(Catalog.GetString( "The percentage for the Re-allocation must be between 1% and 100%.{0}Please re-enter the percentage."), "\n\n"), txtFromPercentage, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(txtFromPercentage, VerificationResult, null); } } // Validate To Allocations' amounts if (rbtAmountOption.Checked) { if (GetAmountTotal() != Convert.ToDecimal(txtFromTransactionAmount.Text)) { VerificationResult = new TScreenVerificationResult(this, null, Catalog.GetString( "The 'To' amounts entered do not match the total amount of the Allocation. Please check the amounts entered."), txtDetailTransactionAmount, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(txtDetailTransactionAmount, VerificationResult, null); } } // Validate Allocations' percentages else { if (GetPercentageTotal() != 100) { VerificationResult = new TScreenVerificationResult(this, null, Catalog.GetString("The 'To' percentages entered must add up to 100%."), txtDetailPercentage, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(txtDetailPercentage, VerificationResult, null); } } if (grdDetails.Rows.Count <= 1) { VerificationResult = new TScreenVerificationResult(this, null, Catalog.GetString("You must include at least 1 destination allocation."), btnNew, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(btnNew, VerificationResult, null); } else if (grdDetails.Rows.Count > 11) { VerificationResult = new TScreenVerificationResult(this, null, Catalog.GetString("You must include no more than 10 destination allocations."), btnDeleteReallocation, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(btnDeleteReallocation, VerificationResult, null); } if (!FAnalysisAttributesLogic.AccountAnalysisAttributeCountIsCorrect(FJournal.LastTransactionNumber + 1, FPreviouslySelectedAccountsRow[AGeneralLedgerMasterTable.GetAccountCodeDBName()].ToString(), FTempFromDS)) { VerificationResult = new TScreenVerificationResult(this, null, String.Format(Catalog.GetString( "A value must be entered for the 'Analysis Attribute' for the 'From Allocation's' Account Code {0}."), FPreviouslySelectedAccountsRow[AGeneralLedgerMasterTable.GetAccountCodeDBName()].ToString()), grdFromAnalAttributes, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(grdFromAnalAttributes, VerificationResult, null); } String ValueRequiredForType; if (!FAnalysisAttributesLogic.AccountAnalysisAttributesValuesExist( FJournal.LastTransactionNumber + 1, FPreviouslySelectedAccountsRow[AGeneralLedgerMasterTable.GetAccountCodeDBName()].ToString(), FTempFromDS, out ValueRequiredForType)) { VerificationResult = new TScreenVerificationResult(this, null, String.Format(Catalog.GetString( "A value must be entered for the 'Analysis code {0} for Account Code {1}."), ValueRequiredForType, FPreviouslySelectedAccountsRow[AGeneralLedgerMasterTable.GetAccountCodeDBName()].ToString()), grdFromAnalAttributes, TResultSeverity.Resv_Critical); // Handle addition/removal to/from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(grdFromAnalAttributes, VerificationResult, null); } }
/// <summary> /// Creates a Data Validation *Error* for Phone ComboBoxes. /// </summary> private void ValidationPhoneNrSetButNoPhoneNrAvailable(TOverallContactComboType AContactComboType) { const string ResCont = "ContactDetails_Phone_Set_But_No_Phone_Nr_Available"; TScreenVerificationResult VerificationResult; TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; string ErrorCode; TCmbAutoComplete ComboBoxForContactComboType; string ComboTypeStr; // Ignored, but needed as this is an out Argument of GetDataAccordingToContactComboType... if (AContactComboType == TOverallContactComboType.occtPrimaryPhone) { ErrorCode = PetraErrorCodes.ERR_PRIMARY_PHONE_NR_SET_DESIPITE_NO_PHONE_NR_AVAIL; } else if (AContactComboType == TOverallContactComboType.occtPhoneWithinOrganisation) { ErrorCode = PetraErrorCodes.ERR_OFFICE_PHONE_NR_SET_DESIPITE_NO_PHONE_NR_AVAIL; } else { throw new EOPAppException("AContactComboType Argument must designate a Phone ComboBox"); } GetDataAccordingToContactComboType(AContactComboType, out ComboBoxForContactComboType, out ComboTypeStr); VerificationResult = new TScreenVerificationResult( new TVerificationResult((object)ResCont, ErrorCodes.GetErrorInfo(ErrorCode), FPetraUtilsObject.VerificationResultCollection.CurrentDataValidationRunID), null, ComboBoxForContactComboType, FPetraUtilsObject.VerificationResultCollection.CurrentDataValidationRunID); VerificationResultCollection.Remove(ResCont); if (VerificationResult != null) { VerificationResultCollection.Add(VerificationResult); } }
private void ValidateDataDetailsManual(PcDiscountRow ARow) { if (txtDetailDiscount.Text == "") { ARow.Discount = 0; } // check that default data exists in database TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; TValidationControlsData ValidationControlsData; TScreenVerificationResult VerificationResult = null; DataColumn ValidationColumn; if (ARow.RowState != DataRowState.Deleted) { if (!TRemote.MConference.Conference.WebConnectors.CheckDiscountCriteriaCodeExists(new string[] { ARow.DiscountCriteriaCode })) { ValidationColumn = ARow.Table.Columns[PcDiscountTable.ColumnDiscountCriteriaCodeId]; // displays a warning message VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo( PetraErrorCodes.ERR_DISCOUNT_CRITERIA_CODE_DOES_NOT_EXIST)), ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } if (!TRemote.MConference.Conference.WebConnectors.CheckCostTypeExists(ARow.CostTypeCode)) { ValidationColumn = ARow.Table.Columns[PcDiscountTable.ColumnCostTypeCodeId]; // displays a warning message VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo( PetraErrorCodes.ERR_COST_TYPE_CODE_DOES_NOT_EXIST)), ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn); } } EnableOrDisableCmb(ARow); }
/// <summary> /// Constructor /// </summary> /// <remarks>'Downgrades' a <see cref="TScreenVerificationResult" /> to a <see cref="TVerificationResult" />.</remarks> /// <param name="AScreenVerificationResult">A <see cref="TScreenVerificationResult" />.</param> public TVerificationResult(TScreenVerificationResult AScreenVerificationResult) { FResultContext = AScreenVerificationResult.ResultContext; FResultText = AScreenVerificationResult.ResultText; FResultTextCaption = AScreenVerificationResult.ResultTextCaption; FResultCode = AScreenVerificationResult.ResultCode; FResultSeverity = AScreenVerificationResult.ResultSeverity; FDataValidationRunID = AScreenVerificationResult.DataValidationRunID; }
/// <summary> /// Checks whether the date is not undefined. DateTime.MinValue is seen as undefined by this Method. /// Null values are accepted. /// </summary> /// <param name="ADate">The date to check.</param> /// <param name="ADescription">The name of the date value.</param> /// <param name="AResultContext">Context of verification (can be null).</param> /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param> /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null).</param> /// <param name="AAlternativeFirstDayOfPeriod"></param> /// <remarks>Usage in the Data Validation Framework: rather than using this Method, use Method /// 'TSharedValidationControlHelper.IsNotInvalidDate' for checking the validity of dates as the latter can deal not only with /// empty dates, but dates that are invalid in other respects (e.g. exceeding a valid date range)!!!</remarks> /// <returns>Null if validation succeeded, otherwise a <see cref="TVerificationResult" /> is /// returned that contains details about the problem.</returns> public static TVerificationResult IsNotCorporateDateTime(DateTime? ADate, String ADescription, object AResultContext = null, System.Data.DataColumn AResultColumn = null, System.Windows.Forms.Control AResultControl = null, int AAlternativeFirstDayOfPeriod = 1) { TVerificationResult ReturnValue; DateTime TheDate = TSaveConvert.ObjectToDate(ADate); DateTime FirstOfMonth; DateTime FirstOfMonthAlternative; String Description = THelper.NiceValueDescription(ADescription); if (!ADate.HasValue) { return null; } FirstOfMonth = new DateTime(TheDate.Year, TheDate.Month, 1); FirstOfMonthAlternative = new DateTime(TheDate.Year, TheDate.Month, AAlternativeFirstDayOfPeriod); // Checks if ((TheDate == FirstOfMonth) || (TheDate == FirstOfMonthAlternative)) { //MessageBox.Show('Date <> DateTime.MinValue'); ReturnValue = null; } else { if (AAlternativeFirstDayOfPeriod == 1) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_INVALIDDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateMustNotBeLaterThanFirstDayOfMonth, new string[] { Description })); } else { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_INVALIDDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + String.Format(Catalog.GetString("The first day of the period should be either 1 or {0}."), AAlternativeFirstDayOfPeriod))); } if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl); } } return ReturnValue; }
private void ValidateFeeCode(string AFeeCode, TVerificationResultCollection AVerificationResultCollection) { TScreenVerificationResult result = null; string context = "ReceivableCrossCodeCheck"; if (FExtraDS.AFeesPayable.DefaultView.Find(new object[] { LedgerNumber, AFeeCode }) >= 0) { // oops - we have this code in the other data set result = new TScreenVerificationResult(context, FMainDS.AFeesReceivable.ColumnFeeCode, Catalog.GetString("The Fee Code has already been used as a Fee Code in the 'Payable Administration Grants' screen"), CommonErrorCodes.ERR_DUPLICATE_RECORD, txtDetailFeeCode, TResultSeverity.Resv_Critical); } AVerificationResultCollection.Auto_Add_Or_AddOrRemove(context, result, FMainDS.AFeesReceivable.ColumnFeeCode); }
/// <summary> /// Checks whether the string <paramref name="AString" /> contains a valid DateTime. /// </summary> /// <param name="AString">The date to check.</param> /// <param name="ADescription">The name of the date value.</param> /// <param name="AResultContext">Context of verification (can be null).</param> /// <param name="AResultColumn">Which <see cref="System.Data.DataColumn" /> failed (can be null).</param> /// <param name="AResultControl">Which <see cref="System.Windows.Forms.Control" /> is involved (can be null).</param> /// <returns>Null if <paramref name="AString" /> contains a valid DateTime, otherwise a /// <see cref="TVerificationResult" /> with a message which uses /// <paramref name="ADescription" /> is returned.</returns> public static TVerificationResult IsValidDateTime(String AString, String ADescription, object AResultContext = null, System.Data.DataColumn AResultColumn = null, System.Windows.Forms.Control AResultControl = null) { TVerificationResult ReturnValue = null; String Description = THelper.NiceValueDescription(ADescription); DateTime temp; if (!DateTime.TryParse(AString, out temp)) { ReturnValue = GetInvalidDateVerificationResult(Description, AResultContext); if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl); } } return ReturnValue; }