using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace Project
{
    public partial class fMain
    {
        void gridView2_ItemClick(object sender, arFrame.Control.GridView.ItemClickEventArgs e)
        {
            //메인화면 하단의 플래그 상태창에서 클릭된 경우
            var  gv = sender as arFrame.Control.GridView;
            //var flagIndex = gv.getNameItem(e.idx);
            //if(flagIndex != "")
            //{
            //    var fidx = int.Parse(flagIndex);
            //    var flag = (eFlag)fidx;
            //    var curValue = Pub.flag.get(flag);
            //    Pub.flag.set(flag, !curValue);
            //}
        }
        

        void flag_ValueChanged(object sender, Device.Flag.ValueEventArgs e)
        {
            var flag = (eFlag)e.ArrIDX;
            if (e.ArrIDX >= FlagMapValue.Length) return;
            var gridItemIndex = FlagMapValue[e.ArrIDX];
            Pub.log.Add(string.Format("Flag:{0}({2}) Changed = {1}", flag, e.NewValue,e.ArrIDX));
            if(gridItemIndex != -1)
            {
                this.IOState.setValue(gridItemIndex, e.NewValue);
                this.IOState.Invalidate();
            }
        }

        void dio_Message(object sender, arDev.ProPLC.MemoryAccess.MessageEventArgs e)
        {
            if(e.IsError)
            {
                Pub.log.Add("ERROR-DIO", e.Message);
            }
            else Pub.log.Add("DIO", e.Message);
        }

        private void Dio_ValueChanged(object sender, arDev.ProPLC.MemoryAccess.IOValueEventArgs e)
        {
            var diName = (eDIName)e.ArrIDX;

            if(diName == eDIName.MC_START)
            {
                if(e.NewValue ==true)
                {
                    func_sw_start();
                }   
            }
            else if(diName == eDIName.MC_LOTEND)
            {
                //lot가 활성화된 경우
                if(e.NewValue == true)
                {
                   
                }
                
            }
            //throw new NotImplementedException();
            Console.WriteLine(string.Format("[{1}]{0}=>{2}", diName,e.ArrIDX,e.NewValue));
        }

        void dio_Message2(object sender, arDev.ProPLC.MemoryAccess.MessageEventArgs e)
        {
            if (e.IsError)
            {
                Pub.log.Add("ERROR-DIO", e.Message);
            }
            else Pub.log.Add("DIO", e.Message);
        }

        private void Dio_ValueChanged2(object sender, arDev.ProPLC.MemoryAccess.IOValueEventArgs e)
        {
            var diName = (eDIName)e.ArrIDX;

            if (diName == eDIName.MC_START)
            {
                if (e.NewValue == true)
                {
                    func_sw_start();
                }
            }
            else if (diName == eDIName.MC_LOTEND)
            {
                //lot가 활성화된 경우
                if (e.NewValue == true)
                {

                }

            }
            //throw new NotImplementedException();
            Console.WriteLine(string.Format("[{1}]{0}=>{2}", diName, e.ArrIDX, e.NewValue));
        }

    }
}
