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;
using GcDevicePc.IniParam;

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.White;


                //前进样口
                if (CProfileDevice.m_DevParam.syspara.u16InjPortFront == 1)
                {
                    if (globaldata.m_dpbuffer.ShowList.showtemp.FPSetTemp == 0.0f)
                    {
                        if (globaldata.m_dpbuffer.ShowList.showtemp.FPActualTemp >= 1001.0f)
                        {
                            textBoxport.Text = "铂电阻断开";
                        }
                        else
                        {
                            textBoxport.Text = globaldata.m_dpbuffer.ShowList.showtemp.FPActualTemp.ToString("#0.00") +
                                               "℃";
                        }

                        textBoxport.BackColor = waringcolor;
                    }
                    else
                    {
                        if (globaldata.m_dpbuffer.ShowList.showtemp.FPActualTemp >= 1001.0f)
                        {
                            textBoxport.Text = "铂电阻断开";
                        }
                        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;

                    }
                }
                else
                {
                    textBoxport.Text = "0.0/0";
                    textBoxport.BackColor = waringcolor; ;
                }



                //柱箱


                if (globaldata.m_dpbuffer.ShowList.showtemp.ColSetTemp == 0.0f)
                {
                    if (globaldata.m_dpbuffer.ShowList.showtemp.ColActualTemp >= 1001.0f)
                    {
                        textBoven.Text = "铂电阻断开";
                    }
                    else
                    {
                        textBoven.Text = globaldata.m_dpbuffer.ShowList.showtemp.ColActualTemp.ToString("#0.0") + "/" + globaldata.m_dpbuffer.ShowList.showtemp.ColSetTemp.ToString("#0");
                    }

                    textBoven.BackColor = waringcolor;
                }

                else
                {
                    if (globaldata.m_dpbuffer.ShowList.showtemp.ColActualTemp >= 1001.0f)
                    {
                        textBoven.Text = "铂电阻断开";
                    }
                    else
                    {
                        textBoven.Text = globaldata.m_dpbuffer.ShowList.showtemp.ColActualTemp.ToString("#0.0") + "/" + globaldata.m_dpbuffer.ShowList.showtemp.ColSetTemp.ToString("#0");
                    }


                    if (Math.Abs(globaldata.m_dpbuffer.ShowList.showtemp.ColSetTemp - globaldata.m_dpbuffer.ShowList.showtemp.ColActualTemp) <= 0.1)
                    {
                        textBoven.BackColor = zcolor;
                    }
                    else
                        textBoven.BackColor = waringcolor;
                }
                textBoven.BackColor = waringcolor;
                //阀箱
                if (globaldata.m_dpbuffer.ShowList.showtemp.AuxSetTemp1 == 0.0f)
                {
                    if (globaldata.m_dpbuffer.ShowList.showtemp.AuxActualTemp1 >= 1001.0f)
                    {
                        textBmanifold.Text = "铂电阻断开";
                    }
                    else
                    {
                        textBmanifold.Text = globaldata.m_dpbuffer.ShowList.showtemp.AuxActualTemp1.ToString("#0.0") + "/" + globaldata.m_dpbuffer.ShowList.showtemp.AuxSetTemp1.ToString("#0");
                    }

                    textBmanifold.BackColor = waringcolor;
                }

                else
                {

                    if (globaldata.m_dpbuffer.ShowList.showtemp.AuxActualTemp1 >= 1001.0f)
                    {
                        textBmanifold.Text = "铂电阻断开";
                    }
                    else
                    {

                        textBmanifold.Text =
                            globaldata.m_dpbuffer.ShowList.showtemp.AuxActualTemp1.ToString("#0.0") + "/" + globaldata.m_dpbuffer.ShowList.showtemp.AuxSetTemp1.ToString("#0");
                    }

                    if (Math.Abs(globaldata.m_dpbuffer.ShowList.showtemp.AuxSetTemp1 - globaldata.m_dpbuffer.ShowList.showtemp.AuxActualTemp1) <= 0.1)
                    {
                        textBmanifold.BackColor = zcolor;
                    }
                    else
                        textBmanifold.BackColor = waringcolor;
                }
                textBmanifold.BackColor = waringcolor;
                //Fid
                if (globaldata.m_dpbuffer.ShowList.showtemp.fDetSetTemp == 0.0f)
                {
                    if (globaldata.m_dpbuffer.ShowList.showtemp.fDetActualTemp >= 1001.0f)
                    {
                        textBFid.Text = "铂电阻断开";
                    }
                    else
                    {
                        textBFid.Text = globaldata.m_dpbuffer.ShowList.showtemp.fDetActualTemp.ToString("#0.0") + "/" + globaldata.m_dpbuffer.ShowList.showtemp.fDetSetTemp.ToString("#0");
                    }
                    textBFid.BackColor = waringcolor;

                }

                else
                {

                    if (globaldata.m_dpbuffer.ShowList.showtemp.fDetActualTemp >= 1001.0f)
                    {
                        textBFid.Text = "铂电阻断开";
                    }
                    else
                    {

                        textBFid.Text = globaldata.m_dpbuffer.ShowList.showtemp.fDetActualTemp.ToString("#0.0") + "/" + globaldata.m_dpbuffer.ShowList.showtemp.fDetSetTemp.ToString("#0");
                    }

                    if (Math.Abs(globaldata.m_dpbuffer.ShowList.showtemp.fDetSetTemp - globaldata.m_dpbuffer.ShowList.showtemp.fDetActualTemp) <= 0.1)
                    {
                        textBFid.BackColor = zcolor;

                    }
                    else
                        textBFid.BackColor = waringcolor;
                }
                textBFid.BackColor = waringcolor;
                //epc

                if (globaldata.m_hwconfig.hwconfiginfo.u16StartType != 2)
                {
                    hflow.Text = (globaldata.m_dpbuffer.ShowList.showepc.EPC1_2_Cur / 10.0f).ToString("#0.0") + "/" + (globaldata.m_dpbuffer.ShowList.showepc.EPC1_2_Set / 10.0f).ToString("#0");
                    hflow.BackColor = waringcolor;
                    airflow.Text = (globaldata.m_dpbuffer.ShowList.showepc.EPC1_3_Cur / 10.0f).ToString("#0.0") + "/" + (globaldata.m_dpbuffer.ShowList.showepc.EPC1_3_Set / 10.0f).ToString("#0");
                    airflow.BackColor = waringcolor;
                    foneflow.Text = (globaldata.m_dpbuffer.ShowList.showepc.EPC2_1_Cur / 10.0f).ToString("#0.0") + "/" + (globaldata.m_dpbuffer.ShowList.showepc.EPC2_1_Set / 10.0f).ToString("#0");
                    foneflow.BackColor = waringcolor;
                    ftwoflow.Text = (globaldata.m_dpbuffer.ShowList.showepc.EPC2_2_Cur / 10.0f).ToString("#0.0") + "/" + (globaldata.m_dpbuffer.ShowList.showepc.EPC2_2_Set / 10.0f).ToString("#0");
                    ftwoflow.BackColor = waringcolor;
                }
                else
                {
                    hflow.Enabled = false;
                    airflow.Enabled = false;
                    foneflow.Enabled = false;
                    ftwoflow.Enabled = false;
                    //hflow.BackColor = waringcolor;
                    //airflow.BackColor = waringcolor;
                    //foneflow.BackColor = waringcolor;
                    //ftwoflow.BackColor = waringcolor;
                }



                fidsingnal.Text = globaldata.m_dpbuffer.ShowList.showDet.fDetValue.ToString("#0.000") + " mV";
                fidsingnal.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);

                textBFIDState.BackColor = waringcolor;

                if (globaldata.MethodRun_Statue == 4 || globaldata.MethodRun_Statue == 5)
                    textBoxRun.Text = (globaldata.m_dpbuffer.ShowList.showtime.runtimenow / 60.0f).ToString("0.00") + "/" + (globaldata.m_dpbuffer.ShowList.showtime.alltime / 60.0f).ToString("0.0"); //运行周期时间
                else
                    textBoxRun.Text = "0.00 /" + (globaldata.m_dpbuffer.ShowList.showtime.alltime / 60.0f).ToString("0.0"); //运行周期时间


                textBoxRun.BackColor = waringcolor;
                //运行进度条
                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);
                //txtstats.Text = strtext;
                //txtstats.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;
                    case 10:
                        if (globaldata.m_hwconfig.hwconfiginfo.u16StartType == 0)
                        {
                            status_text = "设备等待";
                        }
                        else
                        {
                            status_text = "气路压力流量稳定中";
                         }
                        break;
                    default:
                        status_text = "设备连接";

                        break;
                }


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

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }
    }
}
