using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Rfid;
using SlnMesnac.WPF.Attribute;
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 SlnMesnac.WPF.Page.IndexPage
{
    /// <summary>
    /// SetPower.xaml 的交互逻辑
    /// </summary>
    [RegisterAsSingletonAttribute]
    public partial class SetPower : Window
    {
        public List<RfidAbsractFactory> rfidList;
        private string _combineID;

        public SetPower(string combineID)
        {
            _combineID = combineID;
            InitializeComponent();
        }
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                rfidList = App.ServiceProvider.GetRequiredService<List<RfidAbsractFactory>>();
                int DB = await rfidList.Find(x => x.ConfigKey == _combineID).Get_Rf();
                textBox.Text = DB.ToString();
            }
            catch (Exception ex)
            {

            }
        }

        private async void button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int DB = await rfidList.Find(x => x.ConfigKey == _combineID).Get_Rf();
                textBox.Text = DB.ToString();

            }
            catch (Exception ex)
            {

            }
        }

        private async void button复制__C__Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(textBox复制__C_.Text))
                {
                    MessageBox.Show("写入功率不能为空！","注意",MessageBoxButton.OK,MessageBoxImage.Warning);
                    return;
                }
                bool iflag = await rfidList.Find(x => x.ConfigKey == _combineID).Set_Rf(int.Parse(textBox复制__C_.Text));
                if (iflag)
                {
                    MessageBox.Show("功率修改成功!");
                }
            }
            catch (Exception ex)
            {

            }
        }
    }
}
