using Common;
using System;
using System.Drawing;
using System.Media;
using System.Windows.Forms;

namespace StorageMeterSystem
{
    public partial class frmHotDeliveryBeltWarn : Form
    {
        private static frmHotDeliveryBeltWarn frm = null;
        private static frmHotDeliveryBelt frmP;
        private static frmHotDeliveryScale frmScale;
        private static frmHotDeliveryScaleCar40 frmScale40;
        private static frmHotDeliveryScaleCar41 frmScale41;
        private static frmHotDeliveryScaleCar42 frmScale42;
        private static frmHotDeliveryScaleCar43 frmScale43;
        private static frmHotDeliveryScaleCar44 frmScale44;

        private static frmHotDeliveryWeightWarn frmWeightWarn;

        /// <summary>
        /// 热送磅计量主界面预警
        /// </summary>
        /// <param name="frmHotDeliveryBelting"></param>
        /// <returns></returns>
        public static frmHotDeliveryBeltWarn CreateInstrance(frmHotDeliveryBelt frmHotDeliveryBelting)
        {
            if (frm == null)
            {
                frm = new frmHotDeliveryBeltWarn();
            }
            frmP = frmHotDeliveryBelting;
            return frm;
        }

        /// <summary>
        /// 预报界面预警
        /// </summary>
        /// <param name="frmHotDeliveryScaleing"></param>
        /// <returns></returns>
        public static frmHotDeliveryBeltWarn CreateInstrance(frmHotDeliveryScale frmHotDeliveryScaleing)
        {
            if (frm == null)
            {
                frm = new frmHotDeliveryBeltWarn();
            }
            frmScale = frmHotDeliveryScaleing;
            return frm;
        }


        /// <summary>
        /// 预报界面预警40
        /// </summary>
        /// <param name="frmHotDeliveryScaleing"></param>
        /// <returns></returns>
        public static frmHotDeliveryBeltWarn CreateInstrance(frmHotDeliveryScaleCar40 frmHotDeliveryScale40ing)
        {
            if (frm == null)
            {
                frm = new frmHotDeliveryBeltWarn();
            }
            frmScale40 = frmHotDeliveryScale40ing;
            return frm;
        }

        /// <summary>
        /// 预报界面预警41
        /// </summary>
        /// <param name="frmHotDeliveryScale41ing"></param>
        /// <returns></returns>
        public static frmHotDeliveryBeltWarn CreateInstrance(frmHotDeliveryScaleCar41 frmHotDeliveryScale41ing)
        {
            if (frm == null)
            {
                frm = new frmHotDeliveryBeltWarn();
            }
            frmScale41 = frmHotDeliveryScale41ing;
            return frm;
        }

        /// <summary>
        /// 预报界面预警41
        /// </summary>
        /// <param name="frmHotDeliveryScale42ing"></param>
        /// <returns></returns>
        public static frmHotDeliveryBeltWarn CreateInstrance(frmHotDeliveryScaleCar42 frmHotDeliveryScale42ing)
        {
            if (frm == null)
            {
                frm = new frmHotDeliveryBeltWarn();
            }
            frmScale42 = frmHotDeliveryScale42ing;
            return frm;
        }

        /// <summary>
        /// 预报界面预警41
        /// </summary>
        /// <param name="frmHotDeliveryScale41ing"></param>
        /// <returns></returns>
        public static frmHotDeliveryBeltWarn CreateInstrance(frmHotDeliveryScaleCar43 frmHotDeliveryScale43ing)
        {
            if (frm == null)
            {
                frm = new frmHotDeliveryBeltWarn();
            }
            frmScale43 = frmHotDeliveryScale43ing;
            return frm;
        }


        /// <summary>
        /// 预报界面预警41
        /// </summary>
        /// <param name="frmHotDeliveryScale41ing"></param>
        /// <returns></returns>
        public static frmHotDeliveryBeltWarn CreateInstrance(frmHotDeliveryScaleCar44 frmHotDeliveryScale44ing)
        {
            if (frm == null)
            {
                frm = new frmHotDeliveryBeltWarn();
            }
            frmScale44 = frmHotDeliveryScale44ing;
            return frm;
        }


        /// <summary>
        /// 重量预警界面报警
        /// </summary>
        /// <param name="frmHotDeliveryWeightWarning"></param>
        /// <returns></returns>
        public static frmHotDeliveryBeltWarn CreateInstrance(frmHotDeliveryWeightWarn frmHotDeliveryWeightWarning)
        {
            if (frm == null)
            {
                frm = new frmHotDeliveryBeltWarn();
            }
            frmWeightWarn = frmHotDeliveryWeightWarning;
            return frm;
        }


        public frmHotDeliveryBeltWarn()
        {
            InitializeComponent();
        }

        private string rk_CurPath = Application.StartupPath;  //System.Environment.CurrentDirectory;//获取到当前路径
        private SoundPlayer play_ls = null;

        public void setLbTxt(string pointName)
        {
            if (pointName.Contains("10") && pointName.Contains("支"))
            {
                lbPoint.ForeColor = Color.Lime;
            }
            lbPoint.Text = pointName;
        }

        /// <summary>
        /// 加载界面的时候就播放语音
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmMsgInfo_Load(object sender, EventArgs e)
        {
            try
            {
                if (frmWeightWarn!=null)
                {
                    play_ls = new SoundPlayer(rk_CurPath + "\\Sound\\cc.wav");
                }
                else
                {
                    play_ls = new SoundPlayer(rk_CurPath + "\\Sound\\7887.wav");
                }
               
            }
            catch (Exception ex) { }
            finally
            {
                timer1.Start();
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            play_ls.Play();
        }

        private void frmMsgInfo_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (play_ls != null)
                {
                    play_ls.Stop();
                }
            }
            catch (Exception ex) { }
            finally
            {
                if (frmP != null) //计量主界面
                {
                    frmP.bMsgOpen = false;
                }
                if (frmScale != null) //预报界面
                {
                    frmScale.bMsgOpen = false;
                }
                if (frmScale40 != null) //预报界面:优钢热送
                {
                    frmScale40.bMsgOpen = false;
                }
                if (frmScale41 != null) //预报界面:热送磅
                {
                    frmScale41.bMsgOpen = false;
                }
                if (frmScale42 != null) //预报界面:热送磅
                {
                    frmScale42.bMsgOpen = false;
                }
                if (frmScale43 != null) //预报界面:热送磅
                {
                    frmScale43.bMsgOpen = false;
                }
                if (frmScale44 != null) //预报界面:热送磅 
                {
                    frmScale44.bMsgOpen = false;
                }
                if (frmWeightWarn != null) //预报界面:热送磅 frmWeightWarn
                {
                    frmWeightWarn.bMsgOpen = false;
                }
                frm = null;
                timer1.Stop();

                PbCacheMonitor.frmMsgClosingTime = DateTime.Now;
            }
        }

        public void CloseFrm()
        {
            this.Close();
        }

        public void setFrmNull()
        {
            setFormInfo(frm);
        }

        public void setFormInfo(Form fm)
        {
            setFormMsg(fm);
        }

        /// <summary>
        /// 如果ResultMessage为true或者false，则sType 为0的时候readonly  1为enable  2为visable  3为check
        /// </summary>
        /// <param name="control"></param>
        /// <param name="ResultMessage"></param>
        /// <param name="sType"></param>
        private void setFormMsg(Form fm)
        {
            if (fm.InvokeRequired)
            {
                Action<Form> action = new Action<Form>(setFormInfo);
                Invoke(action, new object[] { fm });
            }
            else
            {
                fm.Close();
            }
        }

        protected override void OnVisibleChanged(EventArgs e)
        {
            base.OnVisibleChanged(e);
            if (!IsHandleCreated)
            {
                this.Close();
            }
        }
    }
}