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 ColumnBox : Form
    {
        #region 私有变量
        private HWConfig hWConfig;
        #endregion

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

        public ColumnBox(ref HWConfig hwconfig)
        {
            InitializeComponent();
            this.hWConfig = hwconfig;
        }
        #endregion

        #region 窗口事件
        private void ColumnBox_Load(object sender, EventArgs e)
        {
            if (hWConfig != null)
            {
                this.Col.Checked = this.hWConfig.hwconfiginfo.u16Col == 1 ? true : false;
                this.ColType.SelectedIndex = this.hWConfig.hwconfiginfo.u16ColType;
                this.ColPTemp.Text = this.hWConfig.hwconfiginfo.u16ColPTemp.ToString();

                this.ChromNum.SelectedIndex = this.hWConfig.hwconfiginfo.u16ChromNum;
                this.ChromFront.Checked = this.hWConfig.hwconfiginfo.u16ChromFront == 1 ? true: false;
                this.ChromFrontType.SelectedIndex = this.hWConfig.hwconfiginfo.u16ChromFrontType;
                this.ChromFront_Length.Text = this.hWConfig.hwconfiginfo.u16ChromFront_Length.ToString();
                this.ChromFront_Caliber.Text = this.hWConfig.hwconfiginfo.u16ChromFront_Caliber.ToString();
                this.ChromFront_Thickness.Text = this.hWConfig.hwconfiginfo.u16ChromFront_Thickness.ToString();

                this.ChromBehind.Checked = this.hWConfig.hwconfiginfo.u16ChromBehind == 1 ? true : false;
                this.ChromBehindType.SelectedIndex = this.hWConfig.hwconfiginfo.u16ChromBehindType;
                this.ChromBehind_Length.Text = this.hWConfig.hwconfiginfo.u16ChromBehind_Length.ToString();
                this.ChromBehind_Caliber.Text = this.hWConfig.hwconfiginfo.u16ChromBehind_Caliber.ToString();
                this.ChromBehind_Thickness.Text = this.hWConfig.hwconfiginfo.u16ChromBehind_Thickness.ToString();
            }

        }
        #endregion


        #region 控件事件
        private void okbtn_Click(object sender, EventArgs e)
        {
            if (hWConfig != null)
            {

                this.hWConfig.hwconfiginfo.u16Col = this.Col.Checked ? 1:0;
                this.hWConfig.hwconfiginfo.u16ColType = this.ColType.SelectedIndex;
                this.hWConfig.hwconfiginfo.u16ColPTemp = int.Parse(this.ColPTemp.Text);

                this.hWConfig.hwconfiginfo.u16ChromNum = (this.ChromFront.Checked ? 1 : 0) + (this.ChromBehind.Checked ? 1 : 0);

                this.hWConfig.hwconfiginfo.u16ChromFront = this.ChromFront.Checked ? 1: 0;
                this.hWConfig.hwconfiginfo.u16ChromFrontType = this.ChromFrontType.SelectedIndex;
                this.hWConfig.hwconfiginfo.u16ChromFront_Length = int.Parse(this.ChromFront_Length.Text);
                this.hWConfig.hwconfiginfo.u16ChromFront_Caliber = int.Parse(this.ChromFront_Caliber.Text);
                this.hWConfig.hwconfiginfo.u16ChromFront_Thickness = int.Parse(this.ChromFront_Thickness.Text);

                this.hWConfig.hwconfiginfo.u16ChromBehind  = this.ChromBehind.Checked ? 1 : 0;
                this.hWConfig.hwconfiginfo.u16ChromBehindType = this.ChromBehindType.SelectedIndex;
                this.hWConfig.hwconfiginfo.u16ChromBehind_Length = int.Parse(this.ChromBehind_Length.Text); 
                this.hWConfig.hwconfiginfo.u16ChromBehind_Caliber = int.Parse(this.ChromBehind_Caliber.Text);
                this.hWConfig.hwconfiginfo.u16ChromBehind_Thickness = int.Parse(this.ChromBehind_Thickness.Text);
            }
            this.Close();
        }

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