/ / Dostosowanie DevExpress dateedit, aby umożliwić tylko określone daty - .net, vb.net, winforms, devexpress, .net-2.0

Dostosowanie dateedit DevExpress, aby umożliwić tylko określone daty - .net, vb.net, winforms, devexpress, .net-2.0

Skorzystałem z przykładu tutaj Jak utworzyć potomka DateEdit, który umożliwi wybór jednostki daty oraz wybór wielu dat i okresów?. Chciałem dodać jeszcze jedną funkcjonalność, w którejdostarczy tablicę dat, tylko te będą widoczne. Zmodyfikowałem kod i dołączyłem właściwość do akceptowania zakresów dat, które, jeśli zostaną podane, pozwolą tylko zobaczyć i wybrać te daty, ale nie jestem w stanie zrozumieć, którą funkcję należy przesłonić, aby wykonać zadanie. Zachowanie powinno wyglądać tak, jak kiedy edytor jest dostarczany MaxValue i MinValue

Oto mój kod

Odpowiedzi:

1 dla odpowiedzi № 1

Zobacz (standardową) implementacjęklasa VistaDateEditInfoArgs. Możesz użyć dekompilatora zestawu .NET, takiego jak .NET Reflector lub ILSpy. Istnieje kilka wirtualnych metod, które możesz zastąpić i zwrócić null, jeśli powiązana data i godzina nie powinna być widoczna/dozwolona. Oto kod źródłowy tych metod (proszę zwrócić uwagę na "standardowe" kontrole oparte na wartości MinValue / MaxValue):

[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() };
}

Proponuję zastąpić te metody w swojej klasie potomnej i dodać własne kontrole. Na przykład możesz przesłonić metodę CreateMonthCellInfo w taki sposób:

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();
}