private async void btnOK_Click(object sender, EventArgs e) { btnOK.Enabled = false; if (!txtMobile.MaskCompleted) { ToastNotification.Show(this, "请输入正确的手机号", Properties.Resources.cou_16_clock); btnOK.Enabled = true; return; } ToastNotification.Show(this, "正在提交新手机号...", Properties.Resources.xfsm_switch, -1); var result = await _service.ChangeMobileAsync(txtMobile.Text); ToastNotification.Close(this); if (result.IsNullOrEmpty()) { this.Information("手机号修改成功。双向验证模式下,在核验之前,账户资料里的手机号不会变化。"); Session.UserKeyData.MobileNumber = txtMobile.Text; DialogResult = DialogResult.OK; Close(); } else { ToastNotification.Show(this, result, Properties.Resources.block_16, 2500); } btnOK.Enabled = true; }
/// <summary> /// 异步调用 /// </summary> protected void AsynInvoked(Func <Object> beginInvoke, Action <Object> endInvoke) { try { if (beginInvoke != null) { ToastNotification.Show(this, "数据正在处理中,请等待...", efwplusWinform.Common.CommonResource.load, 0, (eToastGlowColor)(eToastGlowColor.Blue), (eToastPosition)(eToastPosition.TopCenter)); this.Enabled = false; using (BackgroundWorker bw = new BackgroundWorker()) { bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted); bw.DoWork += new DoWorkEventHandler(bw_DoWork); bw.RunWorkerAsync(new object[] { beginInvoke, endInvoke }); } } } catch (Exception e) { ToastNotification.Close(this); this.Enabled = true; throw e; } }
private async void BtnTest_Click(object sender, EventArgs e) { var notifier = new WebNotifier(); this.ShowToast("正在发送通知...", Assets.FreeWp8Icons_White.FreeWp8IconsWhite_Refresh, timeout: int.MaxValue); try { var result = await notifier.SendAsync(WebNotifyConfiguration.Instance.UrlTemplate, WebNotifyConfiguration.Instance.Body).ConfigureAwait(true); ToastNotification.Close(this); if (result.IsNullOrEmpty()) { this.ShowToast("发送成功", Assets.FreeWp8Icons_White.FreeWp8IconsWhite_Apply, Color.ForestGreen, timeout: 2000); } else { this.ShowToast($"发送失败:{result}", Assets.FreeWp8Icons_White.FreeWp8IconsWhite_Delete, Color.DarkRed, timeout: 2000); } } catch (ArgumentException argumentException) { this.Error($"未能发送请求,错误:{argumentException.Message}。请检查相关设置,如果有非英文字符,请尝试转义。"); } catch (Exception ex) { this.Error($"未能发送请求,错误:{ex.Message}"); } }
void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { ToastNotification.Close(this); this.Enabled = true; object[] rst = (object[])e.Result; Action <Object> endInvoke = (Action <Object>)rst[0]; object result = rst[1]; endInvoke(result); //这时后台线程已经完成,并返回了主线程,所以可以直接使用UI控件了 }
private void FinalizeDownload(bool success) { ToastNotification.Close(this, _toast); _views.Items.Clear(); if (success) { _source.Text = Source; // ReSharper disable once CoVariantArrayConversion _views.Items.AddRange(_threatSource.Views.ToArray()); _views.SelectedIndex = 0; } _download.Enabled = !success; }
async void Refresh() { btnApply.Enabled = false; btnGetCode.Enabled = false; btnModify.Enabled = false; btnGetCode.Visible = false; ToastNotification.Show(this, "正在刷新手机号核验状态,请稍等...", Properties.Resources.xfsm_switch, -1); if (!await _service.RefreshStatusAsync()) { ToastNotification.Close(this); this.Information("未能刷新状态,请重试。"); Close(); } ToastNotification.Close(this); if (Session.IsMobileChecked == true) { lblStatus.Text = "已通过核验"; lblStatus.ForeColor = Color.Green; return; } lblStatus.ForeColor = Color.Red; lblStatus.Text = "未通过核验或状态未知"; btnModify.Enabled = true; ToastNotification.Show(this, "正在初始化手机号核验,请稍等...", Properties.Resources.xfsm_switch, -1); var result = await _service.GetMobileCheckIsDoubleAsync(); ToastNotification.Close(this); if (result == null) { this.Information("貌似出现了网络错误,请重试。"); Close(); } if (result == true) { pDesc.Text = "当前验证模式为双向验证模式。<br />请使用您的手机编辑短信 <font color='red'><b>999</b></font> 至 <font color='red'><b>12306</b></font>,<br />在12306回复您的短信后,将收到的短信验证码填入下面的编辑框中。"; } else { btnGetCode.Visible = true; } btnApply.Enabled = true; }
/// <summary> /// Updates the Dock property of SideNav control since when Close/Maximize/Splitter functionality is enabled /// the Dock cannot be set to fill since control needs ability to resize itself. /// </summary> private void UpdateSideNavDock() { if (sideNav1.EnableClose || sideNav1.EnableMaximize || sideNav1.EnableSplitter) { if (sideNav1.Dock != DockStyle.Left) { sideNav1.Dock = DockStyle.Left; sideNav1.Width = this.ClientRectangle.Width - 32; ToastNotification.Close(this); // Closes any toast messages if already open ToastNotification.Show(this, "With current settings SideNav control must be able to resize itself so its Dock is set to Left.", 4000); } } else if (sideNav1.Dock != DockStyle.Fill) { sideNav1.Dock = DockStyle.Fill; ToastNotification.Close(this); // Closes any toast messages if already open ToastNotification.Show(this, "SideNav control Dock is set to Fill.", 2000); } }
private async void lnkGetMobileCode_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { lnkGetMobileCode.Enabled = false; ToastNotification.Show(this, "正在获得手机验证码,请稍等", Properties.Resources.xfsm_switch, 0); var result = await Session.NetClient.GetMobileCode4EmailPwdAsync().ConfigureAwait(true); ToastNotification.Close(this); if (result.IsNullOrEmpty()) { ToastNotification.Show(this, "验证码发送成功", Properties.Resources.tick_16, 1500); lnkGetMobileCode.Enabled = false; _nextTime = DateTime.Now.AddSeconds(120); codeTimer.Start(); } else { lnkGetMobileCode.Enabled = true; ToastNotification.Show(this, result, Properties.Resources.warning_16, 1500); } }
async void SendTestEmail() { btnTest.Enabled = false; //发送测试邮件 ToastNotification.Show(this, "正在发送测试邮件中...", Properties.Resources.xfsm_switch, int.MaxValue); var title = "这是来自于订票助手.NET的一封测试邮件"; var body = "这是来自于订票助手.NET的一封测试邮件。如果您能正常读取到这里,说明您在订票助手.NET中的设置是正确的。"; var cfg = MailConfiguration.Instance; var err = ""; err = await MailSender.Instance.SendEmailAsync(title, body, cfg.Receivers).ConfigureAwait(true); ToastNotification.Close(this); if (!string.IsNullOrEmpty(err)) { HandleError(err); } else { Information("测试邮件发送成功。"); } btnTest.Enabled = true; }
/// <summary> /// 关闭Toast提示 /// </summary> /// <param name="control"></param> /// <param name="intPtr"></param> public static void CloseToast(this Control control, IntPtr?intPtr = null) { ToastNotification.Close(control, intPtr ?? IntPtr.Zero); }
public AccountMobileCheck(Session session) { InitializeComponent(); Icon = Properties.Resources.icon_mobile; InitSession(session); txtMobile.Text = session.UserKeyData.MobileNumber; btnModify.Click += (s, e) => { using (var dlg = new ModifyMobileCode(session)) { if (dlg.ShowDialog(this) != DialogResult.OK) { return; } txtMobile.Text = dlg.MobileNo; } Refresh(); }; btnGetCode.Click += async(s, e) => { btnGetCode.Enabled = false; ToastNotification.Show(this, "正在请求发送验证码...", Properties.Resources.xfsm_switch, -1); var success = await _service.GetMobileCodeAsync(txtMobile.Text); ToastNotification.Close(this); if (success.IsNullOrEmpty()) { DelayButton(); } else { ToastNotification.Show(this, $"操作失败:{success}", Properties.Resources.cou_16_block); } }; btnApply.Click += async(s, e) => { if (txtCode.Text.IsNullOrEmpty()) { ToastNotification.Show(this, "请输入验证码", Properties.Resources.cou_16_block); return; } btnApply.Enabled = false; ToastNotification.Show(this, "正在提交核验...", Properties.Resources.xfsm_switch, -1); var success = await _service.CheckMobileCodeAsync(txtMobile.Text, txtCode.Text); ToastNotification.Close(this); if (success.IsNullOrEmpty()) { this.Information("手机号核验成功!"); DialogResult = DialogResult.OK; Close(); return; } ToastNotification.Show(this, $"操作失败:{success}", Properties.Resources.cou_16_block); btnApply.Enabled = true; }; }
/// <summary> /// 初始化查询参数 /// </summary> void InitQuery() { var param = QueryParam; qp.Init(param); qs.Init(param); qr.Init(param); sellTimeTip.AttachQuery(param); alternativeDateSetting.InitQuery(param); qr.RequestSubmitOrder += (s, e) => HandleOrderRequest(e.Data1, e.Data2); _worker = new TicketQueryWorker(Session, param); _worker.EnableTimeoutService = true; _worker.EnableSystemBusyService = true; _worker.QueryTimeoutWarningService.TimeoutWarning += (s, e) => { this.Invoke(new Action(() => { var cfg = ApiConfiguration.Instance; var qcfg = TOBA.Configuration.QueryConfiguration.Current; AppContext.MainForm.ShowBalloonTip(3000, "查询超时警告", $"在过去的 {cfg.TimeoutRecordCount} 次查询中发生了至少 {cfg.TimeoutWarningLimit} 次查询超时,{(qcfg.TimeoutAutoIncreaseSetting ? "已自动增加超时设置," : "")}请留意", ToolTipIcon.Warning); })); }; _worker.SystemBusyWarningService.SystemBusyWarning += (s, e) => { this.Invoke(new Action(() => { var cfg = ApiConfiguration.Instance; var qcfg = TOBA.Configuration.QueryConfiguration.Current; AppContext.MainForm.ShowBalloonTip(3000, "系统繁忙警告", $"在过去的 {cfg.SystemBusyRecordCount} 次查询中发生了至少 {cfg.SystemBusyRecordCount} 次系统繁忙,频繁繁忙可能意味着当前IP或账户已受限,请尽量放慢查询。", ToolTipIcon.Warning); })); }; _worker.IsBusyChanged += (s, e) => { QueryParam.QueryState = _worker.IsBusy ? QueryState.Query : QueryState.None; ShowQueryStatus(); }; _worker.TicketQuerySuccess += (s, e) => HandleQuerySuccess(); _worker.TicketQueryFailed += (s, e) => HandleQueryFailed(); QueryParam.RequestQuery += (s, e) => { if (QueryParam.EnableAutoPreSubmit && !QueryParam.AutoPreSubmitConfig.AllSetOk && IsControlVisible) { this.ShowToast("自动预定未启用或未设置完成,查票有票后将无法自动提交,请确认车次、联系人和席别均设置正确", Properties.Resources.warning_16, Color.DarkRed, timeout: 5000); } Debug.WriteLine($"请求刷新....当前Worker状态:{_worker.IsBusy}"); _worker.RunQuery(); MainForm.Instance.StopPlayTicketMusic(); }; //停止查询的时候,清空所有的toast param.StatusChanged += this.SafeInvoke((s, e) => { if (QueryParam.QueryState != QueryState.None) { ToastNotification.Close(this); } }); QueryParam.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(QueryParam.EnableAutoPreSubmit)) { if (!QueryParam.EnableAutoPreSubmit) { this.ShowWarningToast("自动预定已关闭!如果刷票,将不会按照要求过滤并自动提交!"); } else { this.ShowSuccessToast("自动预定已开启,请注意是否设置完成,否则无法起效。"); } } }; //查询设置 var qc = new QueryConfiguration(Session); qc.QueryParam = param; btnConfig.PopupControl = qc; //匿名查询,禁用刷票,禁用自动预定 if (!Session.IsLogined) { //chkEnableAutoSubmit.Hide(); //chkEnableAutoSubmit.Value = false; param.EnableAutoPreSubmit = false; qs.Enabled = false; btnDateLoop.Hide(); btnConfig.Hide(); } //刷新界面 QueryParam.SelectedSeatClassChanged += (s, e) => { qr.LoadTrainResult(null); qr.RefreshColumnVisibility(); RefreshList(); }; QueryParam.SelecteTrainClassChanged += (s, e) => { RefreshList(); }; var refreshedProps = new HashSet <string>() { nameof(QueryParam.DepartureTimeFrom), nameof(QueryParam.DepartureTimeTo), nameof(QueryParam.ArriveTimeFrom), nameof(QueryParam.ArriveTimeTo), nameof(QueryParam.PassType), nameof(QueryParam.HideNoNeedTicket), nameof(QueryParam.HideFromNotSame), nameof(QueryParam.HideNoTicket), nameof(QueryParam.HideToNotSame) }; QueryParam.PropertyChanged += (s, e) => { if (refreshedProps.Contains(e.PropertyName)) { RefreshList(); } }; }