private async Task QueryByIntervalAsync() { var dateStart = DateTimeViewModelStart.ToDateTime(); var dateEnd = DateTimeViewModelEnd.ToDateTime(); if (!dateStart.HasValue || !dateEnd.HasValue) { PromptUser("Invalid date"); return; } if (dateEnd.Value <= dateStart.Value) { PromptUser("Datetime end should greater than datetime start."); return; } if ((dateEnd.Value - dateStart.Value).TotalDays > 31) { PromptUser("Can not query more than 31 days"); return; } if (ProductType == ProductType.Mtm) { var output = await FaiCollectionHelper.SelectByIntervalAsync <FaiCollectionMtm>(ProductType, NameConstants.SqlConnectionString, dateStart.Value, dateEnd.Value); DatabaseBuffer.FaiCollectionBuffers = new List <IFaiCollection>(output); } else { var output = await FaiCollectionHelper.SelectByIntervalAsync <FaiCollectionAlps>(ProductType, NameConstants.SqlConnectionString, dateStart.Value, dateEnd.Value); DatabaseBuffer.FaiCollectionBuffers = new List <IFaiCollection>(output); } DatabaseBuffer.NavigateToPage(0); // Activate related controls CommandManager.InvalidateRequerySuggested(); }
private async Task DeleteSelection() { CurrentDialogType = DatabaseViewDialogType.WaitingDialog; // Delete in database await FaiCollectionHelper.DeleteByDateTimeAsync(SelectedCollections, NameConstants.SqlConnectionString); // Get last index in buffer before selections var indexOfFirstSelectedCollections = DatabaseBuffer.FaiCollectionBuffers.IndexOf(SelectedCollections[0]); var lastIndexBeforeSelections = indexOfFirstSelectedCollections == 0 ? 0 : indexOfFirstSelectedCollections - 1; // Calculate the page index of lastIndexBeforeSelection var pageIndex = (int)Math.Floor(lastIndexBeforeSelections / (double)DatabaseBuffer.RowsPerPage); // Remove selections from buffer DatabaseBuffer.Remove(SelectedCollections); // Navigate to page where the first selection is deleted DatabaseBuffer.NavigateToPage(pageIndex); ShouldDisplayDialog = false; }