How to prevent entering previous date

StatusIDPriorityType
Closed24771MajorQuestion
ProfileReply
doorscomputersClient

Hi, May I kindly ask a solution on this,
I am struggling to get the previous value on a previous record. The reason why I am doing this is to be able to validate entering of new record on a date field prior to the latest transaction date.
for example on the previous record the transaction date is 12/3/2015, when I enter a new record, I should not be able to enter 12/2/2015, I should allow the user to enter same date or future date only and not to allow previous date based on the latest date entered on the last record .
Thanks very much!

Replies

UserDescriptionPosted On
Sasha (Xafari Support)Client

Hi,

The resolve of the ticket depends on the Web or Win version of your application.
To Web you can read next documentation: DateEditProperties.MinDate Property, DateEditProperties.MaxDate Property.
To Win you can read next documentation: How to: Restrict User Input in Date Editor, RepositoryItemDateEdit.MinValue Property, RepositoryItemDateEdit.MaxValue Property.
I hope you find this information helpful.

Feel free to contact us if you have any questions.
Regards,
Sasha.

doorscomputers

Thanks for the reply. The minimum date should be dynamically coming from a table record in a class, and this is what I am struggling to do.
what could be wrong with this code below, I dont know how to get the maximum value of records based on transaction date and loan no

public long LoanNo
{
get
{
return _LoanNo;
}
set
{
SetPropertyValue("LoanNo", ref _LoanNo, value);
}
}

public DateTime TransactionDate
{
get
{
return _TransactionDate;
}
set
{
SetPropertyValue("TransactionDate", ref _TransactionDate, value);
}
}

[RuleFromBoolProperty("DateIsValid", UsedProperties="TransactionDate", SkipNullOrEmptyValues=false)]
public bool IsDateValid
{
get
{
if (!Session.IsNewObject(this)) //Only check this property if this is a new record
return true;

DateTime mostrecent = A query here to get the most recent transaction date and the parameter value of a loan number here //Get the highest TransactionDate from the collection of transactions within the current class
return TransactionDate > mostrecent; //This object is valid if the TransactionDate is larger than or equal the most recent
}
}

I want to restrict the loan no to the value in the current class, the transaction date will get the max Date within the class, but it seems that my xpo knowledge is not sufficient, I know this is not a xafari issue but I hope somebody from your tech supposr tcan help me on this, hope there are paid services by Xafari on Xaf training.Thanks very much!

This reply has been deleted 9 years ago.
Sasha (Xafari Support)Client

Hi,

To resolve your issue you can test the following code for the IsDateValid property:

[RuleFromBoolProperty(CustomMessageTemplate = "DateIsValid", UsedProperties = "TransactionDate", SkipNullOrEmptyValues = false)]
public bool IsDateValid
{
get
{
if (!Session.IsNewObject(this))
return true;var dt = DateTime.Today;
/*
//You can set your filter
var criteria = CriteriaOperator.Parse("TransactionDate < ?", dt);
*/
var list = new XPCollection<TestClass>(Session, null,
new SortProperty("TransactionDate", SortingDirection.Ascending));
//var list = new XPCollection<TestClass>(Session, criteria,
//                                        new SortProperty("TransactionDate", SortingDirection.Ascending));var mostrecent = (DateTime)list[list.Count - 1].GetMemberValue("TransactionDate");
var loanNo = list[list.Count - 1].GetMemberValue("LoanNo");

if (TransactionDate >= mostrecent && TransactionDate >= dt) return true;

var message = "Please, enter correct date";
throw new UserFriendlyException(message);
}
}

I hope you find this information helpful.

Feel free to contact us if you have any questions.
Regards,
Sasha.

doorscomputers

Thanks so much for the reply!

× This ticket is closed.

Write US