using System;
using System.Windows.Forms;

namespace MeterModuleLibrary.uc
{
    public partial class ucBusinessType : UserControl
    {
        public ucBusinessType()
        {
            InitializeComponent();
            btnContext.Enabled = false;
            btnPurchase.Enabled = false;
        }

        public string _code = "";
        public string _bussiness = "";

        //private Form _frm { get; set; }
        public event EventHandler ucEvent;

        /// <summary>
        /// 计量类型
        /// </summary>
        /// <param name="purchase">内倒  采购  销售</param>
        /// <param name="context">说明</param>
        /// <param name="code">001006003内倒  001006001采购  001006002销售</param>
        /// <param name="frm">调用的窗口</param>
        public void setControl(string purchase, string context, string code)//, Form frm)
        {
            btnPurchase.Text = purchase;
            btnContext.Text = context;
            _bussiness = purchase;
            _code = code;
            //_frm = frm;
        }

        public bool bcEnable = false;

        public void setControlEnable(bool bEnable)
        {
            setPurchase(bEnable);
            setContext(bEnable);
            bcEnable = bEnable;
        }

        private void setPurchase(bool bEnable)
        {
            if (btnPurchase.InvokeRequired)
            {
                Action<bool> action = new Action<bool>(setControlEnable);
                Invoke(action, new object[] { bEnable });
            }
            else
            {
                btnPurchase.Enabled = bEnable;
            }
        }

        private void setContext(bool bEnable)
        {
            if (btnContext.InvokeRequired)
            {
                Action<bool> action = new Action<bool>(setControlEnable);
                Invoke(action, new object[] { bEnable });
            }
            else
            {
                btnContext.Enabled = bEnable;
            }
        }

        private void btnPurchase_Click(object sender, EventArgs e)
        {
            //001006001 内倒
            //_frm.ShowDialog();
            //*
            EventArgs arg = new EventArgs();
            if (ucEvent != null)
            {
                ucEvent(sender, arg);
            }
            //*/
        }
    }
}