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

namespace Mesnac.Action.ChemicalWeighing.Sys
{
    public partial class FrmNotify : Form
    {
        private string _notifyText;
        private int _value;

        private FrmNotify()
        {
            InitializeComponent();
            this._value = 0;
        }

        /// <summary>
        /// 提示文本
        /// </summary>
        public string NotifyText
        {
            get { return this._notifyText; }
            set { this._notifyText = value; }
        }

        /// <summary>
        /// 进度值,最大值为100
        /// </summary>
        public int Value
        {
            get { return this._value; }
            set
            {
                if (value > 100)
                {
                    value = 100;
                }
                this._value = value;
                this.SetProgreccBar(this._value, this._notifyText);
                //向网络发送进度
                //string netMsg = "{0}:{1}/";
                //netMsg = String.Format(netMsg, Global.ProtocalHeader.ReceiveRecipeDownLoadStatu, value.ToString());
                //Mesnac.Communication.TcpService.Instance.NetSendMsg(netMsg);

            }
        }
        /// <summary>
        /// 显示进度条的信息
        /// </summary>
        /// <param name="value">进度条的当前值</param>
        /// <param name="strInfor">当前提示信息</param>
        public void SetProgreccBar(int value, string strInfor)
        {
            this.labInfor.Text = strInfor;
            this.pbInfor.Value = value;
            this.labInfor.Refresh();
        }

        #region 单例实现

        private static FrmNotify _instance = null;

        public static FrmNotify Instance
        {
            get
            {
                if (_instance == null || _instance.IsDisposed)
                {
                    _instance = new FrmNotify();
                    _instance.Show();
                }
                return _instance;
            }
        }

        public void Destory()
        {
            if (_instance != null && !_instance.IsDisposed)
            {
                _instance.Close();
                _instance = null;
            }
        }
        #endregion
    }
}