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;

namespace Project.Dialog
{
    public partial class fLog : Form
    {
        public fLog()
        {
            InitializeComponent();
            this.FormClosed += FLog_FormClosed;
        }

        private void FLog_FormClosed(object sender, FormClosedEventArgs e)
        {
            PUB.log.RaiseMsg -= Log_RaiseMsg;
            PUB.logagv.RaiseMsg -= Log_RaiseMsgagv;
            PUB.logplc.RaiseMsg -= Log_RaiseMsgplc;
            PUB.logbms.RaiseMsg -= Log_RaiseMsgbms;
            PUB.logxbee.RaiseMsg -= Log_RaiseMsgcal;
        }

        private void fLog_Load(object sender, EventArgs e)
        {

            var colorlist = new arCtl.sLogMessageColor[]
            {
                new arCtl.sLogMessageColor("NOR",Color.Black),
                new arCtl.sLogMessageColor("NORM",Color.Black),
                new arCtl.sLogMessageColor("NORMAL",Color.Black),
                new arCtl.sLogMessageColor("ERR",Color.Red),
                new arCtl.sLogMessageColor("FLAG",Color.Magenta),
                new arCtl.sLogMessageColor("TX",Color.SkyBlue),
                new arCtl.sLogMessageColor("SETUP",Color.Gold),
                new arCtl.sLogMessageColor("MFLAG",Color.BlueViolet),
            };
            this.rtsys.ColorList = colorlist;
            this.rtTx.ColorList = colorlist;
            this.rtAGV.ColorList = colorlist;

            PUB.log.RaiseMsg += Log_RaiseMsg;
            PUB.logagv.RaiseMsg += Log_RaiseMsgagv;
            PUB.logplc.RaiseMsg += Log_RaiseMsgplc;
            PUB.logbms.RaiseMsg += Log_RaiseMsgbms;
            PUB.logxbee.RaiseMsg += Log_RaiseMsgcal;
        }

        private void Log_RaiseMsg(DateTime LogTime, string TypeStr, string Message)
        {
            showlog(rtsys,LogTime, TypeStr, Message);
        }
        private void Log_RaiseMsgagv(DateTime LogTime, string TypeStr, string Message)
        {
            showlog(rtAGV, LogTime, TypeStr, Message);
        }
        private void Log_RaiseMsgplc(DateTime LogTime, string TypeStr, string Message)
        {
            showlog(rtPLC, LogTime, TypeStr, Message);
        }
        private void Log_RaiseMsgbms(DateTime LogTime, string TypeStr, string Message)
        {
            showlog(rtBMS, LogTime, TypeStr, Message);
        }
        private void Log_RaiseMsgcal(DateTime LogTime, string TypeStr, string Message)
        {
            showlog(rtCAL, LogTime, TypeStr, Message);
        }
        void showlog(arCtl.LogTextBox rtRx, DateTime LogTime, string TypeStr, string Message)
        {
            if (rtRx.Visible)
            {
                rtRx.AddMsg(LogTime, TypeStr, Message);
            }
        }
    }
}
