BoxResetControl.cs 3.3 KB
using DeviceLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AutoCountMachine
{
    public partial class BoxResetControl : UserControl
    {
        System.Timers.Timer timer;
        public BoxResetControl()
        {
            InitializeComponent();
            if (GetIsDesignMode())
                return;
            RobotManage.LoadFinishEvent += RobotManage_LoadFinishEvent;
            timer = new System.Timers.Timer();            
            timer.Interval = 1000;
            timer.AutoReset = true;
            timer.Elapsed += Timer_Elapsed;
            timer.Enabled = false;
            GC.KeepAlive(timer);
        }
        private bool GetIsDesignMode()
        {
            return (this.GetService(typeof(System.ComponentModel.Design.IDesignerHost)) != null
                || LicenseManager.UsageMode == LicenseUsageMode.Designtime);
        }

        private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            this.Invoke((EventHandler)delegate {
                NgCountBar.ForeColor = Color.MediumSeaGreen;
                MsdCountBar.ForeColor = Color.MediumSeaGreen;
                PaperCountBar.ForeColor = Color.MediumSeaGreen;
                if (RobotManage.filterMachine.NGBox_Count > RobotManage.filterMachine.Config.NG_BOX_MAXCOUNT * 0.8)
                    NgCountBar.ForeColor = Color.Red;
                if (RobotManage.filterMachine.MSDBox_Count > RobotManage.filterMachine.Config.MSD_BOX_MAXCOUNT * 0.8)
                    MsdCountBar.ForeColor = Color.Red;
                if (RobotManage.filterMachine.PaperBox_Count > RobotManage.filterMachine.Config.PAPER_BOX_MAXCOUNT * 0.8)
                    PaperCountBar.ForeColor = Color.Red;
                NgCountBar.Value = RobotManage.filterMachine.NGBox_Count;
                MsdCountBar.Value = RobotManage.filterMachine.MSDBox_Count;
                PaperCountBar.Value = RobotManage.filterMachine.PaperBox_Count;
            });            
        }

        private void RobotManage_LoadFinishEvent(bool state, string msg)
        {
            if (state)
            {
                this.Invoke((EventHandler)delegate
                {
                    NgCountBar.Maximum = RobotManage.filterMachine.Config.NG_BOX_MAXCOUNT;
                    MsdCountBar.Maximum = RobotManage.filterMachine.Config.MSD_BOX_MAXCOUNT;
                    PaperCountBar.Maximum = RobotManage.filterMachine.Config.PAPER_BOX_MAXCOUNT;

                    MsdCountBar.ForeColor = Color.MediumSeaGreen;
                    PaperCountBar.ForeColor = Color.MediumSeaGreen;
                    timer.Enabled = true;
                    timer.Start();
                });
            }
        }

        private void btn_NGClear_Click(object sender, EventArgs e)
        {
            RobotManage.filterMachine.NGBox_Count = 0;
        }

        private void btn_MSDClear_Click(object sender, EventArgs e)
        {
            RobotManage.filterMachine.MSDBox_Count = 0;
        }

        private void btn_PaperClear_Click(object sender, EventArgs e)
        {
            RobotManage.filterMachine.PaperBox_Count = 0;
        }
    }
}