using System;
using System.Windows.Forms;

namespace HwComWrapperNETGui.UserControls
{
    public partial class MsgCat02 : UserControl
    {
        #region Constructors and Destructors

        public MsgCat02()
        {
            this.InitializeComponent();

            this.button01.Click += (sender, args) => this.HandleButtonClick(this.ButtonDownloadClicked);
            this.btnDownloadTo.Click += (sender, args) => this.HandleButtonClick(this.ButtonDownloadDestClicked);
            
            this.button02.Click += (sender, args) => this.HandleButtonClick(this.ButtonDownloadFPGAClicked);
        }

        #endregion

        #region Public Events

        /// <summary>
        ///     Occurs when the get button for COM_DownloadReq was clicked. 
        /// </summary>
        public event EventHandler ButtonDownloadClicked;

        /// <summary>
        ///     Occurs when the get button for COM_Download_Dest was clicked. 
        /// </summary>
        public event EventHandler<DownloadDestinationEventArgs> ButtonDownloadDestClicked;

        /// <summary>
        ///     Occurs when the get button for COM_Download_FPGAReq was clicked. 
        /// </summary>
        public event EventHandler ButtonDownloadFPGAClicked;

        #endregion

        #region Methods

        private void HandleButtonClick(EventHandler handler)
        {
            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }

        private void HandleButtonClick(EventHandler<DownloadDestinationEventArgs> handler)
        {
            if (handler != null)
            {
                handler(this, new DownloadDestinationEventArgs(this.tbDownloadTo.Text));
            }
        }

        #endregion
    }
}