| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- using GSG.NET.Utils;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Controls;
- using System.Windows.Threading;
- namespace OHV.Module.Interactivity.PopUp
- {
- public class BusyBarViewModel : BindableBase, IDialogAware
- {
- private DelegateCommand<string> _closeDialogCommand;
- public event Action<IDialogResult> RequestClose;
- public DelegateCommand<string> CloseDialogCommand =>
- _closeDialogCommand ?? (_closeDialogCommand = new DelegateCommand<string>(CloseDialog));
- //public string Title => throw new NotImplementedException();
- #region Property
- private string text = "Waiting. . .";
- public string Text
- {
- get { return text; }
- set { SetProperty(ref this.text, value); }
- }
- private string title = "Device";
- public string Title
- {
- get { return title; }
- set { SetProperty(ref this.title, value); }
- }
- private bool isBusy;
- public bool IsBusy
- {
- get { return isBusy; }
- set { SetProperty(ref this.isBusy , value); }
- }
- #endregion
- public BusyBarViewModel()
- {
- }
- public void Init() { }
-
- #region Dialog Function
- public bool CanCloseDialog()
- {
- return true;
- }
- private int progressValue;
- public int ProgressValue
- {
- get { return progressValue; }
- set { SetProperty(ref this.progressValue , value); }
- }
- public void OnDialogClosed()
- {
- }
- DispatcherTimer busyTimer;
- public void OnDialogOpened(IDialogParameters parameters)
- {
- //this.ConfigListProperty = sql.ConfigDal.GetAll().ToList();
- this.Title = parameters.GetValue<string>("Title");
- this.Text = parameters.GetValue<string>("Text");
- var sw = SwUtils.CurrentTimeMillis;
- busyTimer = new DispatcherTimer();
- busyTimer.Tick += (object sender, EventArgs e) =>
- {
- if (SwUtils.Gt(sw, 10000))
- {
- this.IsBusy = false;
- this.CloseDialog("");
- }
- if (this.IsBusy)
- {
- this.IsBusy = false;
- this.CloseDialog("");
- }
- this.ProgressValue += 5;
- };
- busyTimer.Interval = TimeSpan.FromMilliseconds(200);
- busyTimer.Start();
- }
- private void CloseDialog(string parameter)
- {
- ButtonResult result = ButtonResult.None;
- if (parameter?.ToLower() == "true")
- result = ButtonResult.OK;
- else if (parameter?.ToLower() == "false")
- result = ButtonResult.Cancel;
- result = ButtonResult.OK;
- RaiseRequestClose(new DialogResult(result));
- }
- public virtual void RaiseRequestClose(IDialogResult dialogResult)
- {
- this.busyTimer.Stop();
- this.busyTimer = null;
- RequestClose?.Invoke(dialogResult);
- }
- #endregion
- }
- }
|