FrmLedTest.cs 4.5 KB
using System; 
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Linq;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
using TSA_V.LoadCSVLibrary;

namespace TSA_V
{
    public partial class FrmLedTest : FrmBase
    {
        public FrmLedTest()
        {
            InitializeComponent();
        }


        private void Frm1_Load(object sender, EventArgs e)
        {
            List<TSAVPosition> allList = CSVPositionReader<TSAVPosition>.getPositionList();
            List<TSAVPosition> list = (from m in allList where m.PositionType.Equals(2) select m).ToList();
            cmbLed.DataSource = list;
            cmbLed.DisplayMember = "PositionName";
            cmbLed.ValueMember = "PositionName";
            if (list.Count > 0)
            {
                cmbLed.SelectedIndex = 0;
            }
        }
         
        private void clearLog_btn_Click(object sender, EventArgs e)
        {
            LogUtil.ClearLogBoxText();
        } 

        private void btnInStore_Click(object sender, EventArgs e)
        {
            string ip = FormUtil.getValue(txtIp);
            int index = FormUtil.GetIntValue(txtLed);
            LEDModule led = LedManager.GetLEDModule(ip);
            led.AllLightOn(Light.GreenLight(0));
        }

        private void btnOutStore_Click(object sender, EventArgs e)
        {
            string ip = FormUtil.getValue(txtIp);
            int index = FormUtil.GetIntValue(txtLed);
            LEDModule led = LedManager.GetLEDModule(ip);
            led.AllLightOff();
        }
        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            string ip = FormUtil.getValue(txtIp);
            int index = FormUtil.GetIntValue(txtLed);
            LEDModule led = LedManager.GetLEDModule(ip);
            led.LightOff();
        }
        private void btnExit_Click(object sender, EventArgs e)
        { 
            this.Close();
        }

        private void buttonOpenOne_Click(object sender, EventArgs e)
        {

            string ip = FormUtil.getValue(txtIp);
            int index = FormUtil.GetIntValue(txtLed);
            LEDModule led = LedManager.GetLEDModule(ip);
            try
            {
                int lightIndex = FormUtil.GetIntValue(txtLed);
                led.LightOn(Light.BlueLight(lightIndex));
            }
            catch (Exception ex)
            {
                LogUtil.error("打开灯失败:" + ex.ToString());
            } 
        }

        private void buttonCloseOne_Click(object sender, EventArgs e)
        {

            string ip = FormUtil.getValue(txtIp);
            int index = FormUtil.GetIntValue(txtLed);
            LEDModule led = LedManager.GetLEDModule(ip);
            try
            {
                int lightIndex = FormUtil.GetIntValue(txtLed);
                led.LightOff(lightIndex); 
            }
            catch (Exception ex)
            {
                LogUtil.error("关闭灯失败:" + ex.ToString());
            } 
        }

        private void cmbLed_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbLed.SelectedIndex >= 0)
            {
                TSAVPosition Select = (TSAVPosition)cmbLed.SelectedItem;
                txtIp.Text = Select.DeviceIP.ToString();
                txtLeds.Text = Select.Leds; 
            }
        }

        private void button_LedOn_Click(object sender, EventArgs e)
        {
            if (cmbLed.SelectedIndex >= 0)
            {
                TSAVPosition Select = (TSAVPosition)cmbLed.SelectedItem;
                LEDModule led = LedManager.GetLEDModule(Select.DeviceIP);
                Light[] lights = new Light[Select.getLedList().Count];
                int index = 0;
                foreach (int i in Select.getLedList())
                {
                    lights[index] = (Light.GreenLight(i));
                    index++;
                }
                led.LightOn(lights);
            }
        }

        private void button_LedOff_Click(object sender, EventArgs e)
        {
            if (cmbLed.SelectedIndex >= 0)
            {
                TSAVPosition Select = (TSAVPosition)cmbLed.SelectedItem;
                LEDModule led = LedManager.GetLEDModule(Select.DeviceIP);

                int[] lights = new int[Select.getLedList().Count];
                int index = 0;
                foreach (int i in Select.getLedList())
                {
                    lights[index] = i;
                    index++;
                }
                led.LightOff(lights);
            }
        }
    }
}