using MeasureThread;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace HOZProject
{
    public class MeasureMsgManage
    {
        /// <summary>
        /// 线程消息处理，显示内容
        /// </summary>
        /// <param name="formHOZ">主窗体对象</param>
        /// <param name="args">消息对象</param>
        public static void ShowMsgContent(FormHOZMain formHOZ, ThreadStatusEventArgs args)
        {
            switch (args.Step_Code)
            {
                case "1-3":
                    //设置图像
                    FileStream fileStream = new FileStream(args.Picture_Information.Picture_FullPath, FileMode.Open, FileAccess.Read);
                    formHOZ.pbImage.Image = Image.FromStream(fileStream);
                    fileStream.Close();
                    fileStream.Dispose();
                    //流程内容
                    string semParaContent = "电压:"+args.Picture_Information.Work_Voltage;
                    semParaContent += "  放大倍数：" + args.Picture_Information.Magnification;
                    semParaContent += "  工作距离:" + args.Picture_Information.Work_Distance;
                    formHOZ.lblFlowContent.Text = semParaContent;
                    break;
                default:
                    ////设置图像
                    //formHOZ.pbImage.Image = null;
                    ////流程内容
                    //formHOZ.lblFlowContent.Text = "1";
                    break;

            }
            //修改切孔中流程状态
            ChageCutHoleFlowNodeState(formHOZ, args);
        }

        #region 修改切孔中流程状态
        /// <summary>
        /// 修改切孔中流程状态
        /// </summary>
        /// <param name="formHOZ">主窗体对象</param>
        /// <param name="cutHoleName">切孔名称</param>
        /// <param name="Code">流程编号</param>
        /// <param name="state">状态</param>
        /// <returns></returns>
        public static bool ChageCutHoleFlowNodeState(FormHOZMain formHOZ, ThreadStatusEventArgs args)
        {
            if (formHOZ.plPrarInfo.Controls.Count > 0)
            {
                foreach (Control item in formHOZ.plPrarInfo.Controls)
                {
                    if (item is UserControl)
                    {
                        if (item.Name == args.HoleName)
                        {
                            UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
                            TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
                            foreach (TimeLineItem tlItem in ParaItem)
                            {
                                if (tlItem.Code == args.Step_Code)
                                {
                                    tlItem.State = Convert.ToInt32(args.State);
                                    break;
                                }
                            }
                            //重新绘制
                            uControl_ParaInfo.TimeLineInvalidate();
                            return true;
                        }
                    }
                }
            }
            return false;
        }
        #endregion
    }
}
