using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Project.Dialog
{
    public partial class fLog : Form
    {
        public fLog()
        {
            InitializeComponent();
            PUB.log.RaiseMsg += log_RaiseMsg;
            PUB.logFlag.RaiseMsg += LogFlag_RaiseMsg;
            PUB.logILock.RaiseMsg += LogILock_RaiseMsg;
            PUB.logKeyence.RaiseMsg += LogKeyence_RaiseMsg;
			PUB.logILStop.RaiseMsg += LogIL_RaiseMsg;
			PUB.logDbg.RaiseMsg += LogDebug_RaiseMsg;
			PUB.logVision.RaiseMsg += LogVision_RaiseMsg;
			//this.FormClosed += (s1, e1) => { this.timer1.Stop(); };
        }

		private void LogVision_RaiseMsg(DateTime LogTime, string TypeStr, string Message)
		{
			if (this.chkVision.Checked) this.logTextBox1.AddMsg(LogTime, "DEBUG", TypeStr + ":" + Message);
		}

		private void fLog_Load(object sender, EventArgs e)
        {
            this.logTextBox1.ColorList = new arCtl.sLogMessageColor[] {
                new arCtl.sLogMessageColor("FLAG",Color.SkyBlue),
                new arCtl.sLogMessageColor("ILOCK", Color.Gold),
                new arCtl.sLogMessageColor("ERR",Color.Red),
                new arCtl.sLogMessageColor("ATT", Color.Tomato),
                new arCtl.sLogMessageColor("NORM", Color.WhiteSmoke),
            };
			//timer1.Start();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            var od = new OpenFileDialog();
            od.InitialDirectory = PUB.log.BaseDirectory;
            if (od.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.logTextBox1.Text = System.IO.File.ReadAllText(od.FileName, System.Text.Encoding.Default);
            }
        }

        private void chkMain_Click(object sender, EventArgs e)
        {

        }
		private void LogDebug_RaiseMsg(DateTime LogTime, string TypeStr, string Message)
		{
			if (this.chkDebug.Checked) this.logTextBox1.AddMsg(LogTime, "DEBUG", TypeStr + ":" + Message);
		}

		private void LogIL_RaiseMsg(DateTime LogTime, string TypeStr, string Message)
		{
			if (this.chkILStop.Checked) this.logTextBox1.AddMsg(LogTime, "IL-STOP", TypeStr + ":" + Message);
		}

		private void LogFlag_RaiseMsg(DateTime LogTime, string TypeStr, string Message)
        {
            if (this.chkFlag.Checked) this.logTextBox1.AddMsg(LogTime, "FLAG", TypeStr + ":" + Message);
        }

        private void LogILock_RaiseMsg(DateTime LogTime, string TypeStr, string Message)
        {
            if (this.chkILock.Checked) this.logTextBox1.AddMsg(LogTime, "ILCK", TypeStr + ":" + Message);
        }

        private void LogKeyence_RaiseMsg(DateTime LogTime, string TypeStr, string Message)
        {
            if (this.chkKen.Checked) this.logTextBox1.AddMsg(LogTime, "KEYE", TypeStr + ":" + Message);
        }


        void log_RaiseMsg(DateTime LogTime, string TypeStr, string Message)
        {
            if (this.chkMain.Checked) this.logTextBox1.AddMsg(LogTime, TypeStr, Message);
        }

		private void timer1_Tick(object sender, EventArgs e)
		{
			//this.textBox1.Text =
			//	"PX:" + Pub.WaitMessage[(int)eWaitMessage.PX] + "\r\n" +
			//	"PZ:" + Pub.WaitMessage[(int)eWaitMessage.PZ] + "\r\n" +
			//	"LMOVE:" + Pub.WaitMessage[(int)eWaitMessage.LMOVE] + "\r\n" +
			//	"LUPDN:" + Pub.WaitMessage[(int)eWaitMessage.LUPDN] + "\r\n" +
			//	"RMOVE:" + Pub.WaitMessage[(int)eWaitMessage.RMOVE] + "\r\n" +
			//	"RUPDN:" + Pub.WaitMessage[(int)eWaitMessage.RUPDN] + "\r\n" +
			//	"LPRINT:" + Pub.WaitMessage[(int)eWaitMessage.LPRINT] + "\r\n" +
			//	"RPRINT:" + Pub.WaitMessage[(int)eWaitMessage.RPRINT] + "\r\n" +
			//	"VIS0:" + Pub.WaitMessage[(int)eWaitMessage.VIS0] + "\r\n" +
			//	"VIS1:" + Pub.WaitMessage[(int)eWaitMessage.VIS1] + "\r\n" +
			//	"VIS2:" + Pub.WaitMessage[(int)eWaitMessage.VIS2];
		}
	}
}
