/// <summary> /// check the validity of each location and update the icon of each location (current address, old address, future address) /// </summary> /// <param name="APartnerLocationsDT">the datatable to check</param> /// <param name="ADateToCheck"></param> public static void DeterminePartnerLocationsDateStatus(DataTable APartnerLocationsDT, DateTime ADateToCheck) { System.DateTime pDateEffective; System.DateTime pDateGoodUntil; /* * Add custom DataColumn if its not part of the DataTable yet */ if (!APartnerLocationsDT.Columns.Contains(PARTNERLOCATION_ICON_COLUMN)) { APartnerLocationsDT.Columns.Add(new System.Data.DataColumn(PARTNERLOCATION_ICON_COLUMN, typeof(Int32))); } /* * Loop over all DataRows and determine their 'Date Status'. The result is then * stored in the 'Icon' DataColumn. */ foreach (DataRow pRow in APartnerLocationsDT.Rows) { if (pRow.RowState != DataRowState.Deleted) { bool Unchanged = pRow.RowState == DataRowState.Unchanged; pDateEffective = TSaveConvert.ObjectToDate(pRow[PPartnerLocationTable.GetDateEffectiveDBName()]); pDateGoodUntil = TSaveConvert.ObjectToDate( pRow[PPartnerLocationTable.GetDateGoodUntilDBName()], TNullHandlingEnum.nhReturnHighestDate); // Current Address: Icon = 1, // Future Address: Icon = 2, // Expired Address: Icon = 3. if ((pDateEffective <= ADateToCheck) && ((pDateGoodUntil >= ADateToCheck) || (pDateGoodUntil == new DateTime(9999, 12, 31)))) { pRow[PartnerEditTDSPPartnerLocationTable.GetIconDBName()] = ((object)1); } else if (pDateEffective > ADateToCheck) { pRow[PartnerEditTDSPPartnerLocationTable.GetIconDBName()] = ((object)2); } else { pRow[PartnerEditTDSPPartnerLocationTable.GetIconDBName()] = ((object)3); } if (Unchanged) { // We do not want changing the Icon column to enable save. So revert row status to original. pRow.AcceptChanges(); } } } }
/// <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="AAlternativeFirstDayOfPeriod"></param> /// <remarks>Usage in the Data Validation Framework: rather than using this Method, use Method /// 'TValidationControlHelper.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, 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); } } return(ReturnValue); }
/// <summary> /// todoComment /// </summary> /// <param name="e"></param> /// <param name="AVerificationResultCollection"></param> /// <param name="AVerificationResult"></param> public static void VerifyDates(DataColumnChangeEventArgs e, TVerificationResultCollection AVerificationResultCollection, out TVerificationResult AVerificationResult) { AVerificationResult = null; DateTime DateGoodUntil = new DateTime(); DateTime DateEffective = new DateTime(); try { if (e.Column.ColumnName == PPartnerLocationTable.GetDateEffectiveDBName()) { // MessageBox.Show('p_date_effective_d: ' + e.Row['p_date_effective_d', DataRowVersion.Current].ToString); DateEffective = TSaveConvert.ObjectToDate(e.ProposedValue); DateGoodUntil = TSaveConvert.ObjectToDate(e.Row[PPartnerLocationTable.GetDateGoodUntilDBName()]); } else if (e.Column.ColumnName == PPartnerLocationTable.GetDateGoodUntilDBName()) { DateEffective = TSaveConvert.ObjectToDate(e.Row[PPartnerLocationTable.GetDateEffectiveDBName()]); DateGoodUntil = TSaveConvert.ObjectToDate(e.ProposedValue); } // MessageBox.Show('p_date_effective_d: ' + DateEffective.ToString + Environment.NewLine + // 'p_date_good_until_d: ' + DateGoodUntil.ToString); if (e.Column.ColumnName == PPartnerLocationTable.GetDateEffectiveDBName()) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateEffective, DateGoodUntil, "Valid From", "Valid To"); } else { AVerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(DateGoodUntil, DateEffective, "Valid To", "Valid From"); } if (e.Column.ColumnName == PPartnerLocationTable.GetDateEffectiveDBName()) { // delete any error that might have been there from a verification of the other column AVerificationResultCollection.Remove(PPartnerLocationTable.GetDateGoodUntilDBName()); } else { // delete any error that might have been there from a verification of the other column AVerificationResultCollection.Remove(PPartnerLocationTable.GetDateEffectiveDBName()); } } catch (Exception Exp) { MessageBox.Show("Exception occured in TPartnerAddressVerification.VerifyDates: " + Exp.ToString()); } }
/// <summary> /// 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> /// Search in each row for the smallest "created" field /// and the biggest "modified" field. /// Update these values: CreatedBy, DateCreated, DateModified, ModifiedBy. /// </summary> /// <param name="ADataTable">The data table to retrieve the modified and created values.</param> private void UpdateFields_SearchDate(DataTable ADataTable) { System.DateTime TempCreatedDate = new System.DateTime(System.DateTime.MinValue.Ticks); System.DateTime TempModifiedDate = new System.DateTime(System.DateTime.MaxValue.Ticks); System.DateTime TempDate = new System.DateTime(2000, 1, 1); String TempCreatedBy = StrUnknown; String TempModifiedBy = StrUnknown; // search for the smallest / biggest field for (int Counter = 0; Counter < ADataTable.Rows.Count; ++Counter) { System.Data.DataRow CurrentRow = ADataTable.Rows[Counter]; if (Counter == 0) { TempCreatedDate = TSaveConvert.ObjectToDate(CurrentRow[UNIT_DATE_CREATED_COL]); TempModifiedDate = TSaveConvert.ObjectToDate(CurrentRow[UNIT_DATE_MODIFIED_COL]); TempCreatedBy = System.Convert.ToString(CurrentRow[UNIT_CREATED_BY_COL]); TempModifiedBy = System.Convert.ToString(CurrentRow[UNIT_MODIFIED_BY_COL]); } else { TempDate = TSaveConvert.ObjectToDate(CurrentRow[UNIT_DATE_CREATED_COL]); if (TempDate.CompareTo(TempCreatedDate) < 0) { TempCreatedDate = TempDate; TempCreatedBy = System.Convert.ToString(CurrentRow[UNIT_CREATED_BY_COL]); } TempDate = TSaveConvert.ObjectToDate(CurrentRow[UNIT_DATE_MODIFIED_COL]); if (TempDate.CompareTo(TempModifiedDate) > 0) { TempModifiedDate = TempDate; TempModifiedBy = System.Convert.ToString(CurrentRow[UNIT_MODIFIED_BY_COL]); } } } // update the control DateCreated = TempCreatedDate; DateModified = TempModifiedDate; CreatedBy = TempCreatedBy; ModifiedBy = TempModifiedBy; this.tipFields.SetToolTip(this, this.FToolTipString); }
/// <summary> /// This procedure updates the following fields in the TbtnButton class: /// CreatedBy, DateCreated, DateModified, ModifiedBy. /// The <see cref="DataRow"/> passed in with <paramref name="ARow"/> is used for this. /// </summary> /// <param name="ARow">A <see cref="DataRow"/> which holds the data.</param> public void UpdateFields(DataRow ARow) { DateTime DateCreated; DateTime DateModified; // A null date is transformed to the 1st January 0001 DateCreated = TSaveConvert.ObjectToDate(ARow[UNIT_DATE_CREATED_COL]); DateModified = TSaveConvert.ObjectToDate(ARow[UNIT_DATE_MODIFIED_COL]); this.DateCreated = DateCreated; CreatedBy = ARow[UNIT_CREATED_BY_COL].ToString() != String.Empty ? System.Convert.ToString(ARow[UNIT_CREATED_BY_COL]) : StrUnknown; this.DateModified = DateModified; ModifiedBy = ARow[UNIT_MODIFIED_BY_COL].ToString() != String.Empty ? System.Convert.ToString(ARow[UNIT_MODIFIED_BY_COL]) : StrUnknown; this.tipFields.SetToolTip(this, this.FToolTipString); }
/// <summary> /// This procedure updates the following fields in the TbtnButton class: /// CreatedBy, DateCreated, DateModified, ModifiedBy. /// </summary> /// <param name="ATable">A table to which this control referes.</param> /// <param name="ARow">A row in the table which holds the data /// </param> /// <returns>void</returns> public void UpdateFields(System.Data.DataTable ATable, System.Int32 ARow) { System.Data.DataRow mDataRow; System.DateTime mDateCreated; System.DateTime mDateModified; if (ATable.Rows.Count > 0) { // Get a DataRow mDataRow = ATable.Rows[ARow]; // A null date is transformed to the 1st January 0001 mDateCreated = TSaveConvert.ObjectToDate(mDataRow[UNIT_DATE_CREATED_COL]); mDateModified = TSaveConvert.ObjectToDate(mDataRow[UNIT_DATE_MODIFIED_COL]); DateCreated = mDateCreated; CreatedBy = System.Convert.ToString(mDataRow[UNIT_CREATED_BY_COL]); DateModified = mDateModified; ModifiedBy = System.Convert.ToString(mDataRow[UNIT_MODIFIED_BY_COL]); this.tipFields.SetToolTip(this, this.FToolTipString); } }
/// <summary> /// Checks whether the date is today or in the future. Null values are accepted. /// </summary> /// <param name="ADate">Date to check.</param> /// <param name="ADescription">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> /// <returns>Null if the date <paramref name="ADate" /> is today or in the future, /// otherwise a verification result with a message that uses <paramref name="ADescription" />. /// </returns> public static TVerificationResult IsCurrentOrFutureDate(DateTime?ADate, String ADescription, object AResultContext = null, System.Data.DataColumn AResultColumn = null) { TVerificationResult ReturnValue; DateTime TheDate = TSaveConvert.ObjectToDate(ADate); String Description = THelper.NiceValueDescription(ADescription); if (!ADate.HasValue) { return(null); } // Check if (TheDate >= DateTime.Today) { //MessageBox.Show('Date >= Today'); ReturnValue = null; } else { if (TheDate != DateTime.MinValue) { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOPASTDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateMustNotBePastDate, new string[] { Description })); if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn); } } else { ReturnValue = null; } } return(ReturnValue); }
/// <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> /// <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) { TVerificationResult ReturnValue; DateTime TheDate = TSaveConvert.ObjectToDate(ADate); DateTime FirstOfMonth; String Description = THelper.NiceValueDescription(ADescription); if (!ADate.HasValue) { return(null); } FirstOfMonth = new DateTime(TheDate.Year, TheDate.Month, 1); // Checks if (TheDate == FirstOfMonth) { //MessageBox.Show('Date <> DateTime.MinValue'); ReturnValue = null; } else { ReturnValue = new TVerificationResult(AResultContext, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_INVALIDDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + StrDateMustNotBeLaterThanFirstDayOfMonth, new string[] { Description })); if (AResultColumn != null) { ReturnValue = new TScreenVerificationResult(ReturnValue, AResultColumn, AResultControl); } } return(ReturnValue); }
/// <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> /// <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) { 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); } } else { ReturnValue = null; } return(ReturnValue); }
/// <summary> /// todoComment /// </summary> /// <param name="e"></param> /// <param name="AVerificationResultCollection"></param> /// <param name="AVerificationResult"></param> /// <param name="FDataColumnComparedTo"></param> public static void VerifySubscriptionDates(DataColumnChangeEventArgs e, TVerificationResultCollection AVerificationResultCollection, out TVerificationResult AVerificationResult, out DataColumn FDataColumnComparedTo) { FDataColumnComparedTo = null; AVerificationResult = null; DateTime DateStarted = new DateTime(); DateTime DateExpired = new DateTime(); DateTime DateRenewed = new DateTime(); DateTime DateNoticeSent = new DateTime(); DateTime DateEnded = new DateTime(); DateTime DateFirstSent = new DateTime(); DateTime DateLastSent = new DateTime(); Boolean Completed; Completed = false; if (e.Column.ColumnName == PSubscriptionTable.GetStartDateDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.ProposedValue); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetExpiryDateDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.ProposedValue); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetSubscriptionRenewalDateDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.ProposedValue); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetDateNoticeSentDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.ProposedValue); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetDateCancelledDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.ProposedValue); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetFirstIssueDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.ProposedValue); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetLastIssueDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.ProposedValue); } while (!Completed) { // when the StartDate has changed, do this: if (e.Column.ColumnName == PSubscriptionTable.GetStartDateDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } } if (e.Column.ColumnName == PSubscriptionTable.GetExpiryDateDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } } if (e.Column.ColumnName == PSubscriptionTable.GetSubscriptionRenewalDateDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateTime.Today, "Date Renewed", "Today") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateTime.Today, "DateRenewed", "Today"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateExpired, "Date Renewed", "Date Expired") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateExpired, "Date Renewed", "Date Expired"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateNoticeSent, "Date Renewed", "Date Notice Sent") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateNoticeSent, "Date Renewed", "Date Notice Sent"); Completed = true; break; } } if (e.Column.ColumnName == PSubscriptionTable.GetDateNoticeSentDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } } if (e.Column.ColumnName == PSubscriptionTable.GetDateCancelledDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } if (TDateChecks.FirstLesserThanSecondDate(DateTime.Today, DateEnded, "Today", "Cancelled") != null) { AVerificationResult = TDateChecks.FirstLesserThanSecondDate(DateTime.Today, DateEnded, "Today", "Cancelled"); Completed = true; break; } } if (e.Column.ColumnName == PSubscriptionTable.GetFirstIssueDBName()) { FDataColumnComparedTo = e.Column; if (TDateChecks.FirstGreaterOrEqualThanSecondDate(DateLastSent, DateFirstSent, "Last Sent", "First Sent") != null) { AVerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(DateLastSent, DateFirstSent, "Last Sent", "First Sent"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateFirstSent, "Date Started", "First Sent") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateFirstSent, "Date Started", "First Sent"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateTime.Today, "First Sent", "today") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateTime.Today, "First Sent", "today"); Completed = true; break; } } if (e.Column.ColumnName == PSubscriptionTable.GetLastIssueDBName()) { FDataColumnComparedTo = e.Column; if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateLastSent, "First Sent", "Last Sent") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateLastSent, "First Sent", "Last Sent"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateLastSent, DateTime.Today, "Last Sent", "today") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateLastSent, DateTime.Today, "Last Sent", "today"); Completed = true; break; } } Completed = true; } }
/// <summary> /// Determines which address is the 'Best Address' of a Partner, and marks it in the DataColumn 'BestAddress'. /// </summary> /// <remarks>There are convenient overloaded server-side Methods, Ict.Petra.Server.MPartner.ServerCalculations.DetermineBestAddress, /// which work by specifying the PartnerKey of a Partner in an Argument.</remarks> /// <param name="APartnerLocationsDT">DataTable containing the addresses of a Partner.</param> /// <returns>A <see cref="TLocationPK" /> which points to the 'Best Address'. If no 'Best Address' was found, /// SiteKey and LocationKey of this instance will be both -1.</returns> public static TLocationPK DetermineBestAddress(DataTable APartnerLocationsDT) { TLocationPK ReturnValue; DataRow[] OrderedRows; System.Int32 CurrentRow; System.Int32 BestRow; System.Int16 FirstRowAddrOrder; bool FirstRowMailingAddress; System.DateTime BestRowDate; System.DateTime TempDate; CurrentRow = 0; BestRow = 0; bool Unchanged = false; TLogging.LogAtLevel(8, "Calculations.DetermineBestAddress: processing " + APartnerLocationsDT.Rows.Count.ToString() + " rows..."); if (APartnerLocationsDT == null) { throw new ArgumentException("Argument APartnerLocationsDT must not be null"); } if (!APartnerLocationsDT.Columns.Contains(PARTNERLOCATION_BESTADDR_COLUMN)) { DeterminePartnerLocationsDateStatus(APartnerLocationsDT, DateTime.Today); } /* * Add custom DataColumn if its not part of the DataTable yet */ if (!APartnerLocationsDT.Columns.Contains(PARTNERLOCATION_BESTADDR_COLUMN)) { APartnerLocationsDT.Columns.Add(new System.Data.DataColumn(PARTNERLOCATION_BESTADDR_COLUMN, typeof(Boolean))); } /* * Order tables' rows: first all records with p_send_mail_l = true, these are ordered * ascending by Icon, then all records with p_send_mail_l = false, these are ordered * ascending by Icon. */ OrderedRows = APartnerLocationsDT.Select(APartnerLocationsDT.DefaultView.RowFilter, PPartnerLocationTable.GetSendMailDBName() + " DESC, " + PartnerEditTDSPPartnerLocationTable.GetIconDBName() + " ASC", DataViewRowState.CurrentRows); if (OrderedRows.Length > 1) { FirstRowAddrOrder = Convert.ToInt16(OrderedRows[0][PartnerEditTDSPPartnerLocationTable.GetIconDBName()]); FirstRowMailingAddress = Convert.ToBoolean(OrderedRows[0][PPartnerLocationTable.GetSendMailDBName()]); // determine pBestRowDate if (FirstRowAddrOrder != 3) { BestRowDate = TSaveConvert.ObjectToDate(OrderedRows[CurrentRow][PPartnerLocationTable.GetDateEffectiveDBName()]); } else { BestRowDate = TSaveConvert.ObjectToDate(OrderedRows[CurrentRow][PPartnerLocationTable.GetDateGoodUntilDBName()]); } // iterate through the sorted rows for (CurrentRow = 0; CurrentRow <= OrderedRows.Length - 1; CurrentRow += 1) { Unchanged = OrderedRows[CurrentRow].RowState == DataRowState.Unchanged; // reset any row that might have been marked as 'best' before OrderedRows[CurrentRow][PartnerEditTDSPPartnerLocationTable.GetBestAddressDBName()] = ((object)0); // We do not want changing the BestAddress column to enable save. So revert row status to original. if (Unchanged) { OrderedRows[CurrentRow].AcceptChanges(); } // determine pTempDate if (FirstRowAddrOrder != 3) { TempDate = TSaveConvert.ObjectToDate(OrderedRows[CurrentRow][PPartnerLocationTable.GetDateEffectiveDBName()]); } else { TempDate = TSaveConvert.ObjectToDate(OrderedRows[CurrentRow][PPartnerLocationTable.GetDateGoodUntilDBName()]); } // still the same ADDR_ORDER than the ADDR_ORDER of the first row and // still the same Mailing Address than the Mailing Address flag of the first row > proceed if ((Convert.ToInt16(OrderedRows[CurrentRow][PartnerEditTDSPPartnerLocationTable.GetIconDBName()]) == FirstRowAddrOrder) && (Convert.ToBoolean(OrderedRows[CurrentRow][PPartnerLocationTable.GetSendMailDBName()]) == FirstRowMailingAddress)) { switch (FirstRowAddrOrder) { case 1: case 3: // find the Row with the highest p_date_effective_d (or p_date_good_until_d) date if (TempDate > BestRowDate) { BestRowDate = TempDate; BestRow = CurrentRow; } break; case 2: // find the Row with the lowest p_date_effective_d date if (TempDate < BestRowDate) { BestRowDate = TempDate; BestRow = CurrentRow; } break; } } } Unchanged = OrderedRows[0].RowState == DataRowState.Unchanged; // mark the location that was determined to be the 'best' OrderedRows[BestRow][PartnerEditTDSPPartnerLocationTable.GetBestAddressDBName()] = ((object)1); // We do not want changing the BestAddress column to enable save. So revert row status to original. if (Unchanged) { OrderedRows[0].AcceptChanges(); } ReturnValue = new TLocationPK(Convert.ToInt64(OrderedRows[BestRow][PLocationTable.GetSiteKeyDBName()]), Convert.ToInt32(OrderedRows[BestRow][PLocationTable.GetLocationKeyDBName()])); } else { if (OrderedRows.Length == 1) { Unchanged = OrderedRows[0].RowState == DataRowState.Unchanged; // mark the only location to be the 'best' OrderedRows[0][PartnerEditTDSPPartnerLocationTable.GetBestAddressDBName()] = ((object)1); // We do not want changing the BestAddress column to enable save. So revert row status to original. if (Unchanged) { OrderedRows[0].AcceptChanges(); } ReturnValue = new TLocationPK(Convert.ToInt64(OrderedRows[0][PLocationTable.GetSiteKeyDBName()]), Convert.ToInt32(OrderedRows[0][PLocationTable.GetLocationKeyDBName()])); } else { ReturnValue = new TLocationPK(); } } return(ReturnValue); }
/// <summary> /// get the details of the last gift of the partner /// </summary> /// <param name="APartnerKey"></param> /// <param name="ALastGiftDate"></param> /// <param name="AGiftInfo"></param> public static void GetLastGiftDetails(Int64 APartnerKey, out DateTime ALastGiftDate, out String AGiftInfo) { Boolean LastGiftAvailable; DateTime LastGiftDate; decimal LastGiftAmount; Int64 LastGiftGivenToPartnerKey; Int64 LastGiftRecipientLedger; String LastGiftCurrencyCode; String LastGiftDisplayFormat; String LastGiftGivenToShortName; String LastGiftRecipientLedgerShortName; Boolean RestrictedGiftAccessDenied; AGiftInfo = ""; ALastGiftDate = DateTime.MinValue; LastGiftAvailable = GetLastGiftDetails(APartnerKey, out LastGiftDate, out LastGiftAmount, out LastGiftGivenToPartnerKey, out LastGiftRecipientLedger, out LastGiftCurrencyCode, out LastGiftDisplayFormat, out LastGiftGivenToShortName, out LastGiftRecipientLedgerShortName, out RestrictedGiftAccessDenied); if (LastGiftAvailable) { ALastGiftDate = LastGiftDate; if (TSystemDefaultsCache.GSystemDefaultsCache.GetStringDefault(SharedConstants.SYSDEFAULT_DISPLAYGIFTAMOUNT) == "true") { if ((UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE1)) || (UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE2)) || (UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE3)) || (UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_DEVUSER))) { if (LastGiftCurrencyCode != "") { AGiftInfo = LastGiftCurrencyCode + ' ' + StringHelper.FormatCurrency(LastGiftAmount, LastGiftDisplayFormat) + " "; } else { AGiftInfo = LastGiftAmount.ToString() + " "; } } } if (LastGiftGivenToPartnerKey == -1) { // Split Gift if ((TSystemDefaultsCache.GSystemDefaultsCache.GetBooleanDefault(SharedConstants.SYSDEFAULT_DISPLAYGIFTRECIPIENT)) || (TSystemDefaultsCache.GSystemDefaultsCache.GetBooleanDefault(SharedConstants.SYSDEFAULT_DISPLAYGIFTFIELD))) { AGiftInfo = AGiftInfo + StrSplitGift; } } else { // Not a Split Gift if (TSystemDefaultsCache.GSystemDefaultsCache.GetBooleanDefault(SharedConstants.SYSDEFAULT_DISPLAYGIFTRECIPIENT)) { if (LastGiftGivenToPartnerKey != -1) { AGiftInfo = AGiftInfo + LastGiftGivenToShortName; } else { AGiftInfo = AGiftInfo + LastGiftGivenToPartnerKey.ToString(); } } if (TSystemDefaultsCache.GSystemDefaultsCache.GetBooleanDefault(SharedConstants.SYSDEFAULT_DISPLAYGIFTFIELD)) { if (LastGiftRecipientLedger != -1) { AGiftInfo = AGiftInfo + " (" + LastGiftRecipientLedgerShortName + ')'; } else { AGiftInfo = AGiftInfo + " (" + LastGiftRecipientLedger.ToString() + ')'; } } } } else { if (!RestrictedGiftAccessDenied) { ALastGiftDate = TSaveConvert.ObjectToDate(LastGiftDate); AGiftInfo = ""; } else { AGiftInfo = Catalog.GetString("** confidential **"); } } }