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;
using System.Diagnostics;

namespace GcDevicePc.CK_UI
{
    public partial class InfoBarUser : UserControl
    {
        public InfoBarUser()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 状态信息更新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                //温度显示
                Color zcolor = Color.White;
                Color waringcolor = Color.Coral;
               
               
               //前进样口

                    if (globaldata.m_dpbuffer.ShowList.showtemp.FPSetTemp == 0.0f)
                    {
                        textBoxport.Text = globaldata.m_dpbuffer.ShowList.showtemp.FPActualTemp.ToString("#0.00")+"℃";
                        textBoxport.BackColor = waringcolor;
                    }
                    else
                    {
                         textBoxport.Text = globaldata.m_dpbuffer.ShowList.showtemp.FPActualTemp.ToString("#0.00")+"℃";

                         if (Math.Abs(globaldata.m_dpbuffer.ShowList.showtemp.FPSetTemp - globaldata.m_dpbuffer.ShowList.showtemp.FPActualTemp) <= 0.1)
                         {
                             textBoxport.BackColor = zcolor;

                         }
                         else
                             textBoxport.BackColor = waringcolor;
                       
                    }     
                
              
                //柱箱
               

                    if (globaldata.m_dpbuffer.ShowList.showtemp.ColSetTemp == 0.0f)
                    {
                        textBoven.Text=globaldata.m_dpbuffer.ShowList.showtemp.ColActualTemp.ToString("#0.00")+"℃";
                        textBoven.BackColor = waringcolor;
                    }
                       
                    else
                    {
                         textBoven.Text =globaldata.m_dpbuffer.ShowList.showtemp.ColActualTemp.ToString("#0.00")+"℃";
                        
                         if (Math.Abs(globaldata.m_dpbuffer.ShowList.showtemp.ColSetTemp- globaldata.m_dpbuffer.ShowList.showtemp.ColActualTemp)<=0.1)
                         {
                             textBoven.BackColor = zcolor;

                         }
                         else
                             textBoven.BackColor = waringcolor;                      
                    }
                     
                //阀箱
                    if (globaldata.m_dpbuffer.ShowList.showtemp.AuxSetTemp1 == 0.0f)
                    {

                        textBmanifold.Text = globaldata.m_dpbuffer.ShowList.showtemp.AuxActualTemp1.ToString("#0.00") + "℃";
                        textBmanifold.BackColor = waringcolor;
                    }
                       
                    else
                    {
                        textBmanifold.Text = globaldata.m_dpbuffer.ShowList.showtemp.AuxActualTemp1.ToString("#0.00") + "℃";
                        if (Math.Abs(globaldata.m_dpbuffer.ShowList.showtemp.AuxSetTemp1 - globaldata.m_dpbuffer.ShowList.showtemp.AuxActualTemp1)<=0.1)
                        {
                            textBmanifold.BackColor = zcolor;

                        }
                        else
                            textBmanifold.BackColor = waringcolor;                    
                    }
                
                //Fid
                if (globaldata.m_dpbuffer.ShowList.showtemp.fDetSetTemp == 0.0f)
                {

                    textBFid.Text = globaldata.m_dpbuffer.ShowList.showtemp.fDetActualTemp.ToString("#0.00") + "℃";
                    textBFid.BackColor = waringcolor;
                }

                else
                {
                    textBFid.Text = globaldata.m_dpbuffer.ShowList.showtemp.fDetActualTemp.ToString("#0.00") + "℃";
                    if (Math.Abs(globaldata.m_dpbuffer.ShowList.showtemp.fDetSetTemp- globaldata.m_dpbuffer.ShowList.showtemp.fDetActualTemp)<=0.1)
                    {
                        textBFid.BackColor = zcolor;

                    }
                    else
                        textBFid.BackColor = waringcolor;
                }
               

                     
                   
                //点火状态
                switch (globaldata.m_dpbuffer.ShowList.showDet.fDetStatue)
                {
                    case 0:
                        textBFIDState.Text = "未点火";
                        break;
                    case 1:
                        textBFIDState.Text = "点火中";
                        break;
                    case 2:
                        textBFIDState.Text = "点火成功";
                        break;
                    case 3:
                        textBFIDState.Text = "点火失败";
                        break;
                    case 4:
                        textBFIDState.Text = "火焰熄灭";
                        break;
                    case 5:
                        textBFIDState.Text = "重新点火";
                        break;
                    default:
                        textBFIDState.Text = "状态错误";
                        break;
                }
                do
                {
                    if (globaldata.m_dpbuffer.ShowList.showDet.fDetStatue==2)
                    {
                        textBFIDState.BackColor = zcolor;
                        break;
                    }
                    if (globaldata.m_dpbuffer.ShowList.showDet.fDetStatue != 2)
                    {
                        textBFIDState.BackColor = waringcolor;
                        break;
                    }
                    
                } while (true);
                textBoxRun.Text = (globaldata.m_dpbuffer.ShowList.showtime.alltime / 60.0f).ToString("0.0"); //运行周期时间
                //运行进度条
                if (globaldata.MethodRun_Statue == 4 || globaldata.MethodRun_Statue == 5)
                {
                    progressBarRun.Maximum = globaldata.m_dpbuffer.ShowList.showtime.alltime;
                    if (globaldata.m_dpbuffer.ShowList.showtime.runtimenow < globaldata.m_dpbuffer.ShowList.showtime.alltime)
                    {
                        progressBarRun.Value = globaldata.m_dpbuffer.ShowList.showtime.runtimenow;
                    }
                    else
                    {
                        progressBarRun.Value = globaldata.m_dpbuffer.ShowList.showtime.alltime;
                    }

                }
                else
                {
                    progressBarRun.Value = 0;
                }
                string strtext=null;
                Color bkcolor=Color.Wheat;
                setStatus(ref strtext, ref bkcolor);
                labelStart.Text = strtext;
                labelStart.BackColor = bkcolor;
                
            }catch(Exception ex)
            {
                Trace.Write(ex);
            }
        }

        private void setStatus(ref string status_text, ref Color bkcolor)
        {
            try
            {
                ushort flag = 10;
                if(globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.system_Statue)
                {
                    flag = globaldata.m_hmibuffer.gcinfo.methodstatus;  //获取系统状态
                }
                if(globaldata.m_hmibuffer.gcinfo.hmioffline)
                {
                    flag = 9;
                }
                bkcolor = Color.Wheat;
                switch (flag)
                {
                    case 0:
                    case 1:
                        status_text = "空闲中...";
                        break;
                    case 2:
                        status_text = "仪器平衡中...";
                        break;
                    case 3:
                        status_text = "已就绪...";
                        break;
                    case 4:
                    case 5:
                        if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue == 1)
                            status_text = "方法运行中...";
                        else if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue == 2)
                            status_text = "方法运行中...";
                        else if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue == 3)
                            status_text = "方法运行中...";
                        else
                            status_text = "方法运行中...";
                        break;
                    case 6:
                        if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue == 1)
                           
                        status_text = "后处理...";
                        break;
                    case 7:
                        if (globaldata.m_pcbuffer.gcpcinfo.pcworkinfo.work_Statue == 1)
                           
                        status_text = "后处理完毕...";
                        break;
                    case 8:
                        status_text = "信号稳定中...";
                        break;
                    case 9:
                        status_text = "设备断开";
                        bkcolor = Color.LightCoral;
                        break;
                    default:
                        status_text = "设备连接";

                        break;
                }


            }
            catch(Exception ex)
            {
                Trace.Write(ex);
            }
        }
    }
}
