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

namespace GcDevicePc.Controls
{
    public partial class HMIStatus : UserControl
    {
        System.DateTime startTime, endTime;
        System.TimeSpan time;

        private bool changed = true;

        private string showtext = "未连接";
        [Description("修改此值，可修改文字"), Category("自定义属性")]
        public string ShowText
        {
            get
            {
                return showtext;
            }
            set
            {
                showtext = value;
                changed = true;
                this.Invalidate();
            }
        }

        private Boolean waingcolor = true;
        [Description("修改此值，可修改背景颜色"), Category("自定义属性")]
        public Boolean WaingColor
        {
            get
            {
                return waingcolor;
            }
            set
            {
                waingcolor = value;
                changed = true;
                this.Invalidate();
            }
        }

        public HMIStatus()
        {
            InitializeComponent();
            startTime = System.DateTime.Now;
            this.sfstatus.Enabled = false;
        }

        private void pctimer_Tick(object sender, EventArgs e)
        {
            endTime = System.DateTime.Now;
            time = endTime - startTime;
            this.pctimes.Text = time.Days.ToString() + "d " + time.Hours.ToString() + "h " + time.Minutes.ToString() + "m " + time.Seconds.ToString() + "s";

            if(changed)
            {
                this.sfstatus.Text = showtext;
                if (!waingcolor)
                {
                    this.sfstatus.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(149)))), ((int)(((byte)(237)))));
                }
                else
                {
                    this.sfstatus.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(254)))), ((int)(((byte)(185)))), ((int)(((byte)(16)))));
                }
                changed = false;
            }
            

        }
    }
}
