You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
7.1 KiB
C#

// ***********************************************************************
// Assembly : Construction
// Author : flythink
// Created : 05-21-2020
//
// Last Modified By : flythink
// Last Modified On : 09-01-2020
// ***********************************************************************
// <copyright file="DlgWait.cs" company="jindongfang">
// Copyright (c) jindongfang. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
namespace WellWorkDataUI
{
using DevExpress.XtraSplashScreen;
using DevExpress.XtraWaitForm;
using System;
using System.Windows.Forms;
using static WellWorkDataUI.SplashHelper;
/// <summary>
/// Class DlgWait.
/// Implements the <see cref="DevExpress.XtraWaitForm.WaitForm" />
/// </summary>
/// <seealso cref="DevExpress.XtraWaitForm.WaitForm" />
public partial class DlgWait : WaitForm
{
private static DlgWait instance;
private static SplashScreenManager splashScreenManager;
private static string description = string.Empty;
/// <summary>
/// Gets or sets a value indicating whether [enable close].
/// </summary>
public static bool EnableClose { get; set; } = true;
/// <summary>
/// Initializes a new instance of the <see cref="DlgWait" /> class.
/// </summary>
public DlgWait()
{
this.InitializeComponent();
this.progressPanel1.AutoHeight = true;
this.ShowOnTopMode = ShowFormOnTopMode.ObsoleteAboveParent;
}
/// <summary>
/// Enum WaitFormCommand
/// </summary>
public enum WaitFormCommand
{
/// <summary>
/// The message box
/// </summary>
MessageBox,
ShowOnTopMode,
}
/// <summary>
/// 单例
/// </summary>
/// <value>The instance.</value>
public static DlgWait Instance
{
get
{
if (instance == null)
{
instance = new DlgWait();
}
return instance;
}
}
/// <summary>
/// Shows the window.
/// </summary>
/// <param name="parent">The parent.</param>
/// <param name="action">The action.</param>
/// <returns>IAsyncResult.</returns>
public static IAsyncResult ShowWindow(Control parent, Action action)
{
IAsyncResult result = parent.BeginInvoke(new Action(() =>
{
if (splashScreenManager == null)
{
splashScreenManager = new SplashScreenManager(parent.FindForm(), typeof(global::WellWorkDataUI.DlgWait), true, false);
splashScreenManager.ShowWaitForm();
splashScreenManager.SetWaitFormDescription(description);
}
// EnableClose = false;
action();
// splashScreenManager.CloseWaitForm();
// splashScreenManager = null;
// EnableClose = true;
}));
return result;
}
/// <summary>
/// Closes the window.
/// </summary>
public static void CloseWindow()
{
if (splashScreenManager == null || EnableClose == false)
{
return;
}
if (splashScreenManager.IsSplashFormVisible)
{
description = string.Empty;
splashScreenManager.CloseWaitForm();
splashScreenManager = null;
}
}
/// <summary>
/// Sets the wait caption.
/// </summary>
/// <param name="msg">The MSG.</param>
public static void SetWaitCaption(string msg)
{
if (splashScreenManager == null)
{
return;
}
splashScreenManager.SetWaitFormCaption(msg);
}
/// <summary>
/// Sets the wait description.
/// </summary>
/// <param name="msg">The MSG.</param>
public static void SetWaitDescription(string msg)
{
description = msg;
if (splashScreenManager == null)
{
return;
}
splashScreenManager.SetWaitFormDescription(msg);
}
/// <summary>
/// Appends the description.
/// </summary>
/// <param name="msg">The MSG.</param>
public static void AppendDescription(string msg)
{
description += msg;
if (splashScreenManager == null)
{
return;
}
splashScreenManager.SetWaitFormDescription(description);
}
/// <summary>
/// 移除提示信息
/// </summary>
/// <param name="msg">信息内容</param>
public static void RemoveDescription(string msg)
{
if (splashScreenManager == null)
{
return;
}
description = description.Replace(msg, string.Empty);
splashScreenManager.SetWaitFormDescription(description);
}
/// <summary>
/// When overridden, the method allows you to process commands received from a <see cref="T:DevExpress.XtraSplashScreen.SplashScreenManager" /> via the <see cref="M:DevExpress.XtraSplashScreen.SplashScreenManager.SendCommand" /> method.
/// </summary>
/// <param name="cmd">An enumeration value that identifies the received command.</param>
/// <param name="arg">The received command's parameter.</param>
public override void ProcessCommand(Enum cmd, object arg)
{
if (cmd.Equals(WaitFormCommand.MessageBox) && arg is MessageBoxData data)
{
data.Result = MessageBox.Show(this, data.Text, data.Title, data.Buttons, data.Icon);
return;
}
else if (cmd.Equals(this.ShowOnTopMode))
{
this.ShowOnTopMode = (ShowFormOnTopMode)arg;
}
base.ProcessCommand(cmd, arg);
}
/// <summary>
/// Sets the <see cref="T:DevExpress.XtraWaitForm.WaitForm" />'s caption to the specified value.
/// </summary>
/// <param name="caption">A string that is the new value for the <see cref="T:DevExpress.XtraWaitForm.WaitForm" />'s caption.</param>
public override void SetCaption(string caption)
{
base.SetCaption(caption);
this.progressPanel1.Caption = caption;
}
/// <summary>
/// Sets the <see cref="T:DevExpress.XtraWaitForm.WaitForm" />'s description to the specified value.
/// </summary>
/// <param name="description">A string that is the new value for the <see cref="T:DevExpress.XtraWaitForm.WaitForm" />'s description.</param>
public override void SetDescription(string description)
{
base.SetDescription(description);
this.progressPanel1.Description = description;
}
}
}