private async void OnDBTapped(object sender, TappedRoutedEventArgs args) { if (sender == exportDB) { try { var ret = DictService.Export(); hudPopup.Show(msg: "导出中"); byte[] data = await ret; //Logger($"before save {data.Length} bytes data"); if (await imgUtil.SaveImage(data)) { hudPopup.Show(HUDType.Success, "导出成功"); } else { hudPopup.Show(HUDType.Fail, "导出失败"); } } catch (Exception e) { e.CopeWith("exportDB"); } } else if (sender == importDB) { try { var pic = imgUtil.GetImage(); if ((await pic) != null) { bool?confirm = await ImportChoose(); if (confirm.HasValue) { var ret = DictService.Import(pic.Result, confirm.Value); hudPopup.Show(msg: "导入中"); if (await ret) { hudPopup.Show(HUDType.Success, "导入成功"); } else { hudPopup.Show(HUDType.Fail, "导入失败"); } RefreshWords(); } } } catch (Exception e) { e.CopeWith("importDB"); } } else if (sender == clearDB) { if (await clearConfirm()) { DictService.Clear(); RefreshWords(); } } }
private async void OnDBCellTapped(object sender, EventArgs args) { if (sender == exportCell) { try { var ret = DictService.Export(); hudPopup.Show(msg: "导出中"); byte[] data = await ret; if (await imgUtil.SaveImage(data)) { hudPopup.Show(HUDType.Success, "导出成功"); } else { hudPopup.Show(HUDType.Fail, "导出失败"); } } catch (Exception e) { e.CopeWith("exportDB"); } } else if (sender == importCell) { try { var pic = imgUtil.GetImage(); if ((await pic) != null) { bool?confirm = await ImportChoose(); if (confirm.HasValue) { bool isImWCnt = false; if (confirm.Value) { isImWCnt = await DisplayAlert("导入单词本", "是否一并导入测验数据?", "好的", "不了"); } var ret = DictService.Import(pic.Result, confirm.Value, isImWCnt); hudPopup.Show(msg: "导入中"); if (await ret) { hudPopup.Show(HUDType.Success, "导入成功"); } else { hudPopup.Show(HUDType.Fail, "导入失败"); } RefreshWords(); } } } catch (Exception e) { e.CopeWith("importDB"); } } else if (sender == clearCell) { var ret = await DisplayAlert("清空单词本", "此操作无法恢复", "确认", "不了"); if (ret) { DictService.Clear(); RefreshWords(); } } else if (sender == debugCell) { var str = DictService.debugInfo(); Navigation.PushAsync(new DebugPage("DBstat", str)); } else if (sender == updCell) { DictService.updateDB(); } }