/ / DevExpress dateedit customização para permitir apenas datas específicas - .net, vb.net, winforms, devexpress, .net-2.0

DevExpress dataedit customization para permitir apenas datas específicas - .net, vb.net, winforms, devexpress, .net-2.0

Eu usei o exemplo aqui Como criar um descendente do DateEdit que permitirá a seleção da unidade de data e a seleção de várias datas e períodos. Eu queria adicionar mais uma funcionalidade ondeforneceria uma série de datas, apenas aquelas que seriam visíveis Eu modifiquei o código e incluí uma propriedade para aceitar os intervalos de datas, que se fornecidos permitiriam apenas ver e selecionar essas datas, mas não consigo entender qual função devo substituir para realizar a tarefa. O comportamento deve ser como quando o editor é fornecido MaxValue e MinValue

Aqui está meu código

Respostas:

1 para resposta № 1

Dê uma olhada na implementação (padrão) dea classe VistaDateEditInfoArgs. Você pode usar um descompilador de montagem .NET como o .NET Reflector ou ILSpy. Existem alguns métodos virtuais que você pode substituir e retornar nulo se a data e hora relacionada não for visível / permitida. Aqui está o código-fonte desses métodos (observe as verificações baseadas em MinValue / MaxValue "padrão"):

[DevExpress.XtraEditors.ViewInfo.VistaDateEditInfoArgs]

protected virtual DayNumberCellInfo CreateMonthCellInfo(int row, int col)
{
DayNumberCellInfo info;
DateTime date = new DateTime(this.DateTime.Year, (1 + (row * 4)) + col, 1);
if (date > this.Calendar.MaxValue)
{
return null;
}
if ((date < this.Calendar.MinValue) && (date.Month < this.Calendar.MinValue.Month))
{
return null;
}

return new DayNumberCellInfo(date) { Text = this.Calendar.DateFormat.GetAbbreviatedMonthName    (info.Date.Month) };
}

protected virtual DayNumberCellInfo CreateYearCellInfo(int row, int col)
{
int num = ((this.DateTime.Year / 10) * 10) - 1;
int year = (num + (row * 4)) + col;
if ((year <= 0) || (year >= 0x2710))
{
return null;
}
DateTime date = new DateTime(year, 1, 1);
if (date > this.Calendar.MaxValue)
{
return null;
}
if ((date < this.Calendar.MinValue) && (date.Year < this.Calendar.MinValue.Year))
{
return null;
}
DayNumberCellInfo info = new DayNumberCellInfo(date) {
Text = year.ToString()
};
if ((year < ((this.DateTime.Year / 10) * 10)) || (year > (((this.DateTime.Year / 10) * 10) + 1)))
{
info.State = ObjectState.Disabled;
}
return info;
}

protected virtual DayNumberCellInfo CreateYearsGroupCellInfo(int row, int col)
{
int num = ((this.DateTime.Year / 100) * 100) - 10;
int year = num + (((row * 4) + col) * 10);
if ((year < 0) || (year >= 0x2710))
{
return null;
}
int num3 = year + 9;
if (year == 0)
{
year = 1;
}
DateTime date = new DateTime(year, 1, 1);
if (date > this.Calendar.MaxValue)
{
return null;
}
if ((date < this.Calendar.MinValue) && (num3 < this.Calendar.MinValue.Year))
{
return null;
}
return new DayNumberCellInfo(date) { Text = year.ToString() + "-n" + num3.ToString() };
}

Eu sugiro que você substitua esses métodos em sua classe descendente e adicione suas verificações personalizadas. Por exemplo, você pode substituir o método CreateMonthCellInfo de alguma forma assim:

protected override DayNumberCellInfo CreateMonthCellInfo(int row, int col)
{
DateTime date = new DateTime(this.DateTime.Year, (1 + (row * 4)) + col, 1);

if (!IsDateAvailable(date))
{
return null;
}

return base.CreateMonthCellInfo(row, col);
}

// Your date availibility check implementation here
private bool IsDateAvailable(DateTime date)
{
// TODO provide implementation
throw new NotImplementedException();
}