fix date selection range issue
This commit is contained in:
@ -14,6 +14,17 @@ using Resource = Billing.Languages.Resource;
|
||||
|
||||
namespace Billing.Views
|
||||
{
|
||||
public enum DateType : int
|
||||
{
|
||||
Monthly = 0,
|
||||
Today,
|
||||
PastMonth,
|
||||
PastQuarter,
|
||||
PastSixMonths,
|
||||
PastYear,
|
||||
Total
|
||||
}
|
||||
|
||||
public partial class RankPage : BillingPage
|
||||
{
|
||||
private static readonly DateTime today = DateTime.Today;
|
||||
@ -53,13 +64,13 @@ namespace Billing.Views
|
||||
}
|
||||
private static void OnSegmentDateChanged(RankPage page, int old, int @new)
|
||||
{
|
||||
page.OnDateTypeCommand(@new);
|
||||
page.OnDateTypeCommand((DateType)@new);
|
||||
}
|
||||
private static void OnDateChanged(RankPage page, DateTime old = default, DateTime @new = default)
|
||||
{
|
||||
page.isLocked = true;
|
||||
page.StartPickerDate = page.StartDate;
|
||||
page.EndPickerDate = page.EndDate;
|
||||
page.StartPickerDate = page.StartDate.Date;
|
||||
page.EndPickerDate = page.EndDate.Date;
|
||||
page.isLocked = false;
|
||||
if (!page.isFreezed)
|
||||
{
|
||||
@ -73,7 +84,7 @@ namespace Billing.Views
|
||||
if (!page.isLocked)
|
||||
{
|
||||
page.SegmentDate = -1;
|
||||
page.StartDate = @new;
|
||||
page.StartDate = @new.Date;
|
||||
}
|
||||
}
|
||||
private static void OnPickerEndDateChanged(RankPage page, DateTime _, DateTime @new)
|
||||
@ -81,7 +92,7 @@ namespace Billing.Views
|
||||
if (!page.isLocked)
|
||||
{
|
||||
page.SegmentDate = -1;
|
||||
page.EndDate = @new;
|
||||
page.EndDate = @new.Date.LastMoment();
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,7 +197,7 @@ namespace Billing.Views
|
||||
OnDateChanged(this);
|
||||
}
|
||||
|
||||
private void OnDateTypeCommand(int index)
|
||||
private void OnDateTypeCommand(DateType index)
|
||||
{
|
||||
if (index < 0)
|
||||
{
|
||||
@ -200,31 +211,31 @@ namespace Billing.Views
|
||||
var today = DateTime.Today;
|
||||
switch (index)
|
||||
{
|
||||
case 0: // monthly
|
||||
case DateType.Monthly:
|
||||
StartDate = today.AddDays(1 - today.Day);
|
||||
EndDate = today.AddDays(DateTime.DaysInMonth(today.Year, today.Month) - today.Day).LastMoment();
|
||||
break;
|
||||
case 1: // today
|
||||
case DateType.Today:
|
||||
StartDate = today;
|
||||
EndDate = today.LastMoment();
|
||||
break;
|
||||
case 2: // past month
|
||||
case DateType.PastMonth:
|
||||
StartDate = today.AddMonths(-1).AddDays(1);
|
||||
EndDate = today.LastMoment();
|
||||
break;
|
||||
case 3: // past quarter
|
||||
case DateType.PastQuarter:
|
||||
StartDate = today.AddMonths(-3).AddDays(1);
|
||||
EndDate = today.LastMoment();
|
||||
break;
|
||||
case 4: // past six months
|
||||
case DateType.PastSixMonths:
|
||||
StartDate = today.AddMonths(-6).AddDays(1);
|
||||
EndDate = today.LastMoment();
|
||||
break;
|
||||
case 5: // past year
|
||||
case DateType.PastYear:
|
||||
StartDate = today.AddYears(-1).AddDays(1);
|
||||
EndDate = today.LastMoment();
|
||||
break;
|
||||
case 6: // total
|
||||
case DateType.Total:
|
||||
//StartDate = App.Bills.Min(b => b.CreateTime).Date;
|
||||
//EndDate = App.Bills.Max(b => b.CreateTime).Date.LastMoment();
|
||||
DateTime min = DateTime.MaxValue;
|
||||
@ -257,6 +268,11 @@ namespace Billing.Views
|
||||
|
||||
private void OnLeftCommand()
|
||||
{
|
||||
var type = (DateType)SegmentDate;
|
||||
if (type < DateType.Monthly || type >= DateType.Total)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (scroller.ScrollY > 0)
|
||||
{
|
||||
scroller.ScrollToAsync(0, 0, true);
|
||||
@ -264,11 +280,31 @@ namespace Billing.Views
|
||||
isFreezed = true;
|
||||
var start = StartDate;
|
||||
var end = EndDate;
|
||||
if (IsPreset(start, end))
|
||||
if (type == DateType.Monthly || IsPreset(start, end))
|
||||
{
|
||||
start = start.AddMonths(-1);
|
||||
end = start.AddDays(DateTime.DaysInMonth(start.Year, start.Month) - 1).LastMoment();
|
||||
}
|
||||
else if (type == DateType.PastMonth)
|
||||
{
|
||||
start = start.AddMonths(-1);
|
||||
end = end.AddMonths(-1);
|
||||
}
|
||||
else if (type == DateType.PastQuarter)
|
||||
{
|
||||
start = start.AddMonths(-3);
|
||||
end = end.AddMonths(-3);
|
||||
}
|
||||
else if (type == DateType.PastSixMonths)
|
||||
{
|
||||
start = start.AddMonths(-6);
|
||||
end = end.AddMonths(-6);
|
||||
}
|
||||
else if (type == DateType.PastYear)
|
||||
{
|
||||
start = start.AddYears(-1);
|
||||
end = end.AddYears(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
var days = (end.Date - start.Date).TotalDays + 1;
|
||||
@ -288,6 +324,11 @@ namespace Billing.Views
|
||||
|
||||
private void OnRightCommand()
|
||||
{
|
||||
var type = (DateType)SegmentDate;
|
||||
if (type < DateType.Monthly || type >= DateType.Total)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (scroller.ScrollY > 0)
|
||||
{
|
||||
scroller.ScrollToAsync(0, 0, true);
|
||||
@ -295,11 +336,31 @@ namespace Billing.Views
|
||||
isFreezed = true;
|
||||
var start = StartDate;
|
||||
var end = EndDate;
|
||||
if (IsPreset(start, end))
|
||||
if (type == DateType.Monthly || IsPreset(start, end))
|
||||
{
|
||||
start = start.AddMonths(1);
|
||||
end = start.AddDays(DateTime.DaysInMonth(start.Year, start.Month) - 1).LastMoment();
|
||||
}
|
||||
else if (type == DateType.PastMonth)
|
||||
{
|
||||
start = start.AddMonths(1);
|
||||
end = end.AddMonths(1);
|
||||
}
|
||||
else if (type == DateType.PastQuarter)
|
||||
{
|
||||
start = start.AddMonths(3);
|
||||
end = end.AddMonths(3);
|
||||
}
|
||||
else if (type == DateType.PastSixMonths)
|
||||
{
|
||||
start = start.AddMonths(6);
|
||||
end = end.AddMonths(6);
|
||||
}
|
||||
else if (type == DateType.PastYear)
|
||||
{
|
||||
start = start.AddYears(1);
|
||||
end = end.AddYears(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
var days = (end.Date - start.Date).TotalDays + 1;
|
||||
|
Reference in New Issue
Block a user