FrmDbLineIO.cs 7.2 KB
using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
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 OnlineStore.DoubleLineClient
{
    public partial class FrmDbLineIO : FrmBase
    {
        public FrmDbLineIO()
        {
            InitializeComponent();
        }
        private List<Control> DILabel = new List<Control>();
        private List<Control> doList = new List<Control>();
        private List<Control> rfidList = new List<Control>();
        private void FrmDbLineIO_Load(object sender, EventArgs e)
        {

        }

        private void FrmDbLineIO_Shown(object sender, EventArgs e)
        {
            if (DILabel.Count <= 0)
            {
                DILabel = new List<Control>();
                doList = new List<Control>();
                rfidList = new List<Control>();
                foreach (Control con in this.Controls)
                {
                    if (con is GroupBox)
                    {
                        foreach (Control c in con.Controls)
                        {
                            if (c is Label)
                            {
                                if (LineManager.Line.Config.DIList.ContainsKey(c.Name))
                                {
                                    DILabel.Add(c);
                                }
                                else if( c.Tag !=null && LineManager.Line.RfidIpList.Contains(c.Tag.ToString()))
                                {
                                    rfidList.Add(c);
                                }
                            }
                            else if (c is Button)
                            {
                                if (LineManager.Line.Config.DOList.ContainsKey(c.Name))
                                {
                                    doList.Add(c);
                                }
                            }
                        }
                    }
                }
            }
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!this.Visible)
            {
                return;
            }
            //Task.Factory.StartNew();
            this.Invoke(new Action(() =>
            {
                if (!lblA5State.Text.Equals(LineManager.packageLine.A5_State))
                    lblA5State.Text = LineManager.packageLine.A5_State;
                if (!lblA6State.Text.Equals(LineManager.packageLine.A6_State))
                    lblA6State.Text = LineManager.packageLine.A6_State;
            }));
            foreach (Control labl in DILabel)
            {
                IO_VALUE value = LineManager.Line.IOValue(labl.Name);
                if (value.Equals(IO_VALUE.HIGH))
                {
                    labl.BackColor = Color.LawnGreen;
                }
                else if (value.Equals(IO_VALUE.LOW))
                {
                    labl.BackColor = Color.LightGray;
                }
            }
            foreach (Control labl in doList)
            {
                IO_VALUE value = LineManager.Line.IOValue(labl.Name);
                if (value.Equals(IO_VALUE.HIGH))
                {
                    labl.BackColor = Color.LawnGreen;
                }
                else if (value.Equals(IO_VALUE.LOW))
                {
                    labl.BackColor = labl.Parent.BackColor;
                    //labl.BackColor = Color.LightGray;
                }
            }
            foreach (Control lbl in rfidList)
            {
                string tmpRfid = RFIDManager.ReadRFID(lbl.Tag.ToString()).NumStr();
                if(!tmpRfid.Equals(lbl.Text))
                {
                    lbl.Text = string.Format("{0}:{1}", lbl.Tag.ToString(), tmpRfid);
                }
            }
        }

        private void Line_StopCylinder_Click(object sender, EventArgs e)
        {
            Control c = (Control)sender;
            string ioType = c.Name;
            IO_VALUE value = LineManager.Line.IOValue(c.Name);
            if (value.Equals(IO_VALUE.LOW))
            {
                LineManager.Line.IOMove(ioType, IO_VALUE.HIGH);
                c.BackColor = Color.LawnGreen;
            }
            else
            {
                LineManager.Line.IOMove(ioType, IO_VALUE.LOW);
                c.BackColor = c.Parent.BackColor;
            }
        }

        private void btnS1Up_Click(object sender, EventArgs e)
        {
            LineManager.Line.CylinderMove(null, IO_Type.S1_TopCylinderDown, IO_Type.S1_TopCylinderUp);
        }

        private void btnS1Down_Click(object sender, EventArgs e)
        {

            LineManager.Line.CylinderMove(null, IO_Type.S1_TopCylinderUp, IO_Type.S1_TopCylinderDown);
        }

        private void btnLUp_Click(object sender, EventArgs e)
        {
            LineManager.Line.CylinderMove(null, IO_Type.L_Updown_Down, IO_Type.L_Updown_Up);
        }

        private void btnLDown_Click(object sender, EventArgs e)
        {
            LineManager.Line.CylinderMove(null, IO_Type.L_Updown_Up, IO_Type.L_Updown_Down);
        }

        private void btnMUp_Click(object sender, EventArgs e)
        {
            LineManager.Line.CylinderMove(null, IO_Type.M_Updown_Down, IO_Type.M_Updown_Up);

        }

        private void btnMDown_Click(object sender, EventArgs e)
        {
            LineManager.Line.CylinderMove(null, IO_Type.M_Updown_Up, IO_Type.M_Updown_Down);

        }

        private void btnS2Up_Click(object sender, EventArgs e)
        {

            // LineManager.Line.CylinderMove(null, IO_Type.S2_TopCylinderDown, IO_Type.S2_TopCylinderUp);
        }

        private void btnS2Down_Click(object sender, EventArgs e)
        {

            // LineManager.Line.CylinderMove(null, IO_Type.S2_TopCylinderUp, IO_Type.S2_TopCylinderDown);
        }

        private void btnRUp_Click(object sender, EventArgs e)
        {
            LineManager.Line.CylinderMove(null, IO_Type.R_Updown_Down, IO_Type.R_Updown_Up);

        }

        private void btnRDown_Click(object sender, EventArgs e)
        {

            LineManager.Line.CylinderMove(null, IO_Type.R_Updown_Up, IO_Type.R_Updown_Down);
        }

        private void btnS1StopDown_Click(object sender, EventArgs e)
        {
            LineManager.Line.S1_StopMove(null, IO_VALUE.LOW, true);
        }

        private void S1StopDown_Click(object sender, EventArgs e)
        {

            LineManager.Line.S1_StopMove(null, IO_VALUE.HIGH, true);
        }

        private void btnS1Stop_Click(object sender, EventArgs e)
        {
            LineManager.Line.IOMove(IO_Type.S1_LineBackRun, IO_VALUE.LOW);
            LineManager.Line.IOMove(IO_Type.S1_LineRun, IO_VALUE.LOW);
        }

        private void btnOpenRFID_Click(object sender, EventArgs e)
        {
            RFIDManager.Open(LineManager.Line.RfidIpList.ToArray());
            Common.LogUtil.info("手动开启RFID");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            RFIDManager.Close();
            Common.LogUtil.info("手动关闭RFID");
        }
    }
}