/// <summary> /// 完成初始化 /// </summary> protected virtual void PostInitialize() { if (ProgramConfiguration.Instance.OrderDlgCenterMainform) { UiUtility.PlaceFormAtCenter(this, show: false); } else { StartPosition = FormStartPosition.CenterScreen; } FormPlacementManager.Instance.Control(this); Layer = new MsgLayer(); Controls.Add(Layer); Layer.BringToFront(); //空格键快速提交 KeyDown += (s, e) => { if (SubmitButton?.Enabled == true && !InQueue) { if (e.KeyCode == Keys.Space || e.KeyCode == Keys.Enter) { SubmitButton.PerformClick(); e.Handled = true; } } }; KeyPreview = true; }
/// <summary> /// 订单提交已成功 /// </summary> /// <param name="orderid"></param> /// <returns></returns> protected virtual async Task QueueSucceedAsync(string orderid) { PreventCloseFlag = false; //new OrderSuccess(orderid.DefaultForEmpty("(不知道..T_T)")) { Session = Session }.Show(); UiUtility.PlaceFormAtCenter(new OrderNotification(Session, Query, Train, PassengerInTickets, null, orderid)); Session.OnRequestShowPanel(PanelIndex.NotComplete); if (Query.Resign) { Query.IsLoaded = false; } if (OrderEventArgs != null) { OrderEventArgs.OrderSubmitContext.OrderID = orderid ?? ""; OrderEventArgs.OrderSubmitContext.Message = ""; Session.OnOrderSubmitSuccess(OrderEventArgs.OrderSubmitContext.Session, OrderEventArgs); } if (AutoResumeAttached) { Controller.Instance[Session].GetContext(this).IsSubmitSuccess = true; } Close(); }
/// <summary> /// 要求显示 /// </summary> /// <param name="queueInfo"></param> public void Show(OrderCacheItem queueInfo) { lock (_lockObject) { if (_queueDlg == null) { _queueDlg = new OrderQueue(Session, queueInfo); _queueDlg.Closed += (s, e) => { _queueDlg = null; }; UiUtility.PlaceFormAtCenter(_queueDlg, AppContext.HostForm); } } }
/// <summary> /// 重试登录 /// </summary> /// <param name="owner"></param> /// <returns></returns> public Task <bool> ReloginCore(Form owner) { var tcs = new TaskCompletionSource <bool>(); var loginDlg = new Login(); loginDlg.PreSelectUser = _session.UserName; loginDlg.Session = _session; loginDlg.FormClosed += (s, e) => { tcs.TrySetResult(loginDlg.DialogResult == DialogResult.OK); }; UiUtility.PlaceFormAtCenter(loginDlg, owner); return(tcs.Task); }
public OrderNotification(Session session, QueryParam query, QueryResultItem train, IEnumerable <PassengerInTicket> passengers, string error, string orderid) { _query = query; _train = train; _passengers = passengers; _error = error; _orderid = orderid; InitializeComponent(); InitSession(session); Icon = Properties.Resources.icon_warning; imglist.Images.Add(UiUtility.Get24PxImageFrom16PxImg(Properties.Resources.user_16)); lblTrainCode.Text = train.Code; lblDate.Text = train.FromStation.DepartureTime.Value.ToString("M月d日"); lblFrom.Text = train.FromStation.StationName; lblTo.Text = train.ToStation.StationName; lblTimeInfo.Text = lblTimeInfo.Text.FormatWith( train.FromStation.DepartureTime.Value.ToString("HH:mm"), train.ToStation.ArriveTime.Value.ToString("HH:mm"), train.ElapsedTime.ToString("dd'天'hh'时'mm'分'")); if (passengers != null) { lstPas.Items.AddRange(passengers.Select(s => new ListViewItem(new[] { ParamData.GetTicketType(s.TicketType).DisplayName, ParamData.SeatTypeFull[s.SeatType], s.Name, ParamData.PassengerIdType[s.IdType], s.IdNo }) { ImageIndex = 0 }).ToArray()); } if (string.IsNullOrEmpty(error)) { Gif.SetSuccessImage(pbAnimate); lblError.ForeColor = Color.RoyalBlue; lblError.Text = "订票成功!订单号为:" + orderid.DefaultForEmpty("<未知>") + ",请尽快付款!如果订单没有立刻查询到,请刷新订单列表!"; btnOK.Click += btnOK_Click; btnOK.Text = "乖~~戳我去付款啦~~要截图留念请速度并打码哦 ლ(^o^ლ) "; Operation.Instance.PlayMusicForSuccess(); } else { lblError.Text = error; btnOK.Text = "同学不哭,站起来擦干眼泪继续刷 ლ(╹◡╹ლ)"; Gif.SetFailedImage(pbAnimate); btnOK.Click += (s, e) => Close(); if (error.IndexOf("未完成") != -1) { session.OnRequestShowPanel(PanelIndex.Orders); session.OnOrderChanged(); } } if (ProgramConfiguration.Instance.OrderDlgCenterMainform) { UiUtility.PlaceFormAtCenter(this, show: false); } else { StartPosition = FormStartPosition.CenterScreen; } FormPlacementManager.Instance.Control(this); Load += async(s, e) => { WindowState = FormWindowState.Normal; BringToFront(); Activate(); if (_error.IsNullOrEmpty()) { await CheckNotification().ConfigureAwait(true); await SendWebNotification().ConfigureAwait(true); } }; }
/// <summary> /// 订票失败 /// </summary> /// <param name="error">错误信息</param> /// <param name="isQueue">是排队后的信息还是排队前信息</param> protected virtual async Task OrderFailedAsync(string error, bool isQueue) { PreventCloseFlag = false; if (OrderEventArgs != null) { OrderEventArgs.OrderSubmitContext.OrderID = null; OrderEventArgs.OrderSubmitContext.Message = error; Session.OnOrderSubmitFailed(OrderEventArgs.OrderSubmitContext.Session, OrderEventArgs); } LastErrorMessage = error; if (error?.IndexOf("出票失败") >= 0) { ApiConfiguration.Instance.MinimalVcWaitTimeRunTime += 100; Trace.TraceInformation($"Increase MinimalVcWaitTimeRunTime to {ApiConfiguration.Instance.MinimalVcWaitTimeRunTime}"); } var ma = new MessageAnalyzer(error); if (ma.NeedRelogin) { if (await OnReloginAsync().ConfigureAwait(true)) { await OnOrderContextInitializeAsync().ConfigureAwait(true); await PrepareOrderAsync().ConfigureAwait(true); } else { Close(); } return; } if (ma.NeedVc) { this.ShowToast("请输入验证码"); await SetAllowOperationAsync(false, true).ConfigureAwait(true); VerifyCodeBox.SetIfNeedVc(SubmitOrderWorker.NeedVc); return; } if (ma.CaptchaError) { await OnCaptchaErrorAsync().ConfigureAwait(true); return; } if (ma.NeedRetry && AutoRetryCount++ < OrderConfiguration.Instance.AutoRetryCountLimit) { await OnOrderContextInitializeAsync().ConfigureAwait(true); await OnRequireRetryAsync().ConfigureAwait(true); return; } if (ma.TicketNotEnough) { //排队人数过多/排队人数已超过剩余票数 //余票不足 //没有足够的票 RecentlySubmitFailedTokenStorageProvider.Instance.AddDisableTicketData(Train); } if (ma.NeedRollbackOrderCommitMethod) { Query.TemporaryDisableFastSubmitOrder = !Query.TemporaryDisableFastSubmitOrder; } if (ma.TicketNotEnough || ma.ErrorElse || ma.NeedRetry) { //订单提交失败 if (AutoResumeAttached) { if (ma.TicketNotEnough) { if (isQueue) { OnQueueFailedNoTicket(); } else { OnSubmitFailed(); } } else { if (isQueue) { OnQueueFailedElse(); } else { OnSubmitFailed(); } } if (BreakOperation) { return; } } if (ma.NeedRollbackOrderCommitMethod) { await OnInformationAsync("当前订单提交已失效,请返回后重试。").ConfigureAwait(true); Close(); return; } //请求确认 if (await OnOrderResubmitAsync(error).ConfigureAwait(true)) { await PrepareOrderAsync().ConfigureAwait(true); } else { Close(); } return; } //身份信息有误/账户信息有误/订单要处理/订单排队中 UiUtility.PlaceFormAtCenter(new OrderNotification(Session, Query, Train, PassengerInTickets, ma.Message, null)); Close(); }
/// <summary> /// 登录用户 /// </summary> public void Login() { UiUtility.PlaceFormAtCenter(new Login()); }