using Microsoft.AspNetCore.Components;
using PrintBarCode.Business;
using PrintBarCode.Helper;
using PrintBarCode.Model;
using SlnMesnac.Redis;
using static PrintBarCode.MessageClient;

namespace PrintBarCode
{
    public partial class MainForm : Form
    {
        private DebugConfig debugConfig = DebugConfig.Instance;

        public MainForm()
        {
            MessageClient.addLogEvent += addLog;
            InitializeComponent();

            addLog("启动监听打印服务成功......");

            BlankFlag.Text = debugConfig.BlankFlag=="1"?"是":"否";

        }


        private void addLog(string logInfo)
        {
            try
            {

                // 如果当前调用线程不是创建窗体的线程，使用 Invoke 
                if (this.logList.InvokeRequired)
                {
                    this.logList.Invoke(new Action<string>(addLog), logInfo);
                }
                else
                {
                    this.logList.Items.Add($"{DateTime.Now}==>{logInfo}");
                }

            }
            catch (Exception ex)
            {

            }
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            // 取消关闭操作
            e.Cancel = true;
            // 将窗口状态设置为最小化
            this.WindowState = FormWindowState.Minimized;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            debugConfig.BlankFlag = debugConfig.BlankFlag == "1" ? "0" : "1";
            BlankFlag.Text = debugConfig.BlankFlag == "1" ? "是" : "否";
        }
    }
}