using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace MeterVision.Dlg
{
    /// <summary>
    /// PatchTaskDlg.xaml 的交互逻辑
    /// </summary>
    public partial class PatchTaskDlg : Window
    {
        public event Action OnStopTask; // 用于通知任务被停止

        public PatchTaskDlg()
        {
            InitializeComponent();
            progressText.Text = "等待处理...";
        }

        public void UpdateProgress(int currentNum, int totalNum)
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {
                double progress = (double)currentNum / totalNum * 100;
                progressBar.Value = progress;
                progressText.Text = $"正在处理：{currentNum}/{totalNum}";
            }));
        }

        //点击停止按钮时，停止处理
        private void StopButton_Click(object sender, RoutedEventArgs e)
        {
            stopButton.IsEnabled = false;   //防止连续点击
            // 触发停止任务事件
            OnStopTask?.Invoke();
            // 可选：更新状态，提示任务已停止
            progressText.Text = "任务已停止";
        }

        // 在关闭对话框时恢复主界面的操作
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);

            // 恢复主界面操作
            Application.Current.MainWindow.IsEnabled = true;
        }
        //--------------------------------------------
    }
}
