private async Task GetRecords(DateTime start, DateTime end, bool isSwiped) { RefreshIndicator.IsVisible = !isSwiped; Promption.IsVisible = false; string id = Application.Current.Properties["Ecard.id"] as string; string password = Application.Current.Properties["Ecard.password"] as string; try { EcardSystem ecardSystem = new EcardSystem(id, password, start, end); await ecardSystem.Login(); var detail = await ecardSystem.GetDetail(); detail.Sort((x, y) => y.OperatingDate.CompareTo(x.OperatingDate)); records.Clear(); foreach (var item in detail) { records.Add(item); } EcardRecordsList.IsVisible = true; } catch (AuthenticationFailedException) { EcardRecordsList.IsVisible = false; Promption.Text = strings.LoginFailed; Promption.IsVisible = true; } catch (System.Net.Http.HttpRequestException) { EcardRecordsList.IsVisible = false; Promption.Text = strings.NetworkError; Promption.IsVisible = true; } catch (TaskCanceledException) { EcardRecordsList.IsVisible = false; Promption.Text = strings.NetworkTimeout; Promption.IsVisible = true; } RefreshIndicator.IsVisible = false; EcardRecordsList.IsRefreshing = false; }
private async Task GetRecords(DateTime startQueryTime, DateTime endQueryTime) { //TODO AuthenticationFailedException will not be thrown in Android. LoadingIndicator.IsVisible = true; this.Promotion.IsVisible = false; string id = Application.Current.Properties["Ecard.id"] as string; string password = Application.Current.Properties["Ecard.password"] as string; try { EcardSystem ecardSystem = new EcardSystem(id, password, startQueryTime, endQueryTime); await ecardSystem.Login(); var detail = await ecardSystem.GetDetail(); Dictionary <DateTime, double> dailyRecords = new Dictionary <DateTime, double>(); for (DateTime date = startQueryTime; date <= endQueryTime; date = date.AddDays(1)) { dailyRecords.Add(date, 0); } foreach (var item in detail) { double amount = double.Parse(item.Amount); DateTime date = item.OperatingDate.Date; if (dailyRecords.ContainsKey(date)) { dailyRecords[date] += amount; } else { dailyRecords.Add(date, amount); } } records.Clear(); foreach (var item in dailyRecords) { records.Add(new ChartDataPoint(item.Key, item.Value)); } DataChart.IsVisible = true; } catch (AuthenticationFailedException) { this.Promotion.IsVisible = true; this.Promotion.Text = strings.LoginFailed; DataChart.IsVisible = false; //await CrossPlatformFeatures.Toast(this, strings.Alert, strings.LoginFailed, strings.OK); } catch (System.Net.Http.HttpRequestException) { this.Promotion.IsVisible = true; this.Promotion.Text = strings.NetworkError; DataChart.IsVisible = false; //await CrossPlatformFeatures.Toast(this, strings.Alert, strings.NetworkError, strings.OK); } catch (TaskCanceledException) { this.Promotion.IsVisible = true; this.Promotion.Text = strings.NetworkTimeout; DataChart.IsVisible = false; } LoadingIndicator.IsVisible = false; }