using HKLib.Dto;
using HKLib.Interfaces;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BPA.Helper;

namespace HKCardManager.UserPages
{
    public partial class CancellationPage : UserControl
    {
        public CancellationPage()
        {
            InitializeComponent();
            //this.SizeChanged += CancellationPage_SizeChanged;
        }

        //private void CancellationPage_SizeChanged(object? sender, EventArgs e)
        //{
        //    panel1.Left = (this.Width - panel1.Width) / 2;
        //    panel1.Top = (this.Height - panel1.Height) / 2;
        //}

        private void button2_Click(object sender, EventArgs e)
        {

            string name = textBox1.Text.Trim();
            if (string.IsNullOrEmpty(name))
            {
                MessageLogNotify.GetInstance.ShowWarning("请输入用户名");
                return;
            }
            string TagName = this.Tag.ToString();
            if (string.IsNullOrEmpty(TagName))
            {
                MessageLogNotify.GetInstance.ShowError("功能名称为空，操作失败，请重试");
            }
            else
            {
                int status = 0;
                if (TagName == "销户") status = 3;
                else if (TagName == "挂失") status = 2;
                else if (TagName == "解挂") status = 1;
                Task.Factory.StartNew(() =>
                {
                    this.Invoke(() => { button2.Enabled = false; });
                    var res = HKLibHelper.CardStutasChange(new CardStutasDto()
                    {
                        keywrod = name,
                        Stutas = status
                    });
                    if (res) MessageLogNotify.GetInstance.Show($"用户 {TagName} 成功");
                    else MessageLogNotify.GetInstance.ShowError($"用户 {TagName} 失败，请重试");
                    this.Invoke(() => { button2.Enabled = true; });
                });
            }
        }
    }
}
