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 GcDevicePc.GCBuffer;

namespace GcDevicePc.DeviceConfigUI
{
    public partial class Device : Form
    {
        #region 私有变量
        private HWConfig hWConfig;
        #endregion

        #region 构造函数
        public Device()
        {
            InitializeComponent();
        }

        public Device(ref HWConfig hwconfig)
        {
            InitializeComponent();

            hWConfig = hwconfig;
        }
        #endregion

        #region 窗口事件
        private void Device_Load(object sender, EventArgs e)
        {
            try
            {
                if (hWConfig != null)
                {
                    this.GCNum.Text = ((globaldata.DeviceInfo)globaldata.DeviceList[0]).MacAddr;
                    this.GCName.Text = this.hWConfig.hwconfiginfo.GCName;

                    switch (this.hWConfig.hwconfiginfo.u16StartType)
                    {
                        case 1:
                            this.radioButton1.Checked = true;
                            break;
                        case 2:
                            this.radioButton2.Checked = true;
                            break;
                        case 3:
                            this.radioButton3.Checked = true;
                            break;
                        default:
                            this.radioButton2.Checked = true;
                            break;
                    }
                }
            }
            catch 
            {
                
            }

        }
        #endregion

        #region 控件事件
        private void okbtn_Click(object sender, EventArgs e)
        {
            if (hWConfig != null)
            {
                this.hWConfig.hwconfiginfo.GCNum = this.GCNum.Text;
                this.hWConfig.hwconfiginfo.GCName = this.GCName.Text;

                if (this.radioButton1.Checked)
                {
                    this.hWConfig.hwconfiginfo.u16StartType = 1;
                }
                else if (this.radioButton2.Checked)
                {
                    this.hWConfig.hwconfiginfo.u16StartType = 2;
                }
                else if (this.radioButton3.Checked)
                {
                    this.hWConfig.hwconfiginfo.u16StartType = 3;
                }
            }
            this.Close();
        }

        private void cancelbtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion
    }
}
