using PCHMI;
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace CowainHmi.Alarm
{
    public partial class FrmEditAlarmRecord : Form
    {
        PLCInfoModel.PLCAlarmInfo dataRow;
        List<AlarmExcelHelper.EnumItemModel<AlarmType>> alarmType;
        public FrmEditAlarmRecord(PLCInfoModel.PLCAlarmInfo _dataRow)
        {
            InitializeComponent();
            this.MaximizeBox = false;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.StartPosition = FormStartPosition.CenterScreen;
            this.dataRow = _dataRow;
        }

        private void FrmEditAlarmRecord_Load(object sender, EventArgs e)
        {
            alarmType = AlarmExcelHelper.GetEnumItems<AlarmType>();
            SetComboBox();
            SetValue();
        }
        private void SetValue()
        {
            PLC.Text= dataRow.PLC;
            地址.Text = dataRow.地址;
            类型.Text = dataRow.类型;
            触发条件.Text = dataRow.触发条件;
            代码.Text = dataRow.代码;
            报警组.Text = dataRow.报警组;
            //等级.Text = alarmType.Where(item => item.EnumValue == dataRow.等级).FirstOrDefault().EnumName;
            等级.Text= dataRow.等级;
            语言1.Text = dataRow.语言1;
            语言2.Text = dataRow.语言2;
            语言3.Text = dataRow.语言3;
            语言4.Text = dataRow.语言4;
            语言5.Text = dataRow.语言5;
            语言6.Text = dataRow.语言6;
            语言7.Text = dataRow.语言7;
            语言8.Text = dataRow.语言8;
        }
        private void SetComboBox()
        {
            var dataType = AlarmExcelHelper.GetEnumItems<DataType>();
            类型.DataSource = new BindingSource(dataType.Select(item => item.EnumName), null);
            类型.DisplayMember = "Value";

            等级.DataSource = new BindingSource(alarmType.Select(item => item.EnumName), null);
            等级.DisplayMember = "Value";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dataRow.PLC = PLC.Text;
            dataRow.地址 = 地址.Text;
            dataRow.类型 = 类型.Text;
            dataRow.触发条件 = 触发条件.Text;
            dataRow.代码 = 代码.Text;
            dataRow.报警组 = 报警组.Text;
            //dataRow.等级 = alarmType.Where(item => item.EnumName == 等级.Text).FirstOrDefault().EnumValue;
            dataRow.等级 = 等级.Text;
            dataRow.语言1 = 语言1.Text;
            dataRow.语言2 = 语言2.Text;
            dataRow.语言3 = 语言3.Text;
            dataRow.语言4 = 语言4.Text;
            dataRow.语言5 = 语言5.Text;
            dataRow.语言6 = 语言6.Text;
            dataRow.语言7 = 语言7.Text;
            dataRow.语言8 = 语言8.Text;
            this.Close();
        }
    }
}
