using PCHMI;
using System;
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;

namespace CowainHmi.Alarm
{
    public partial class DlgAlarmNow : Form
    {
        public DlgAlarmNow(DataTable dt)
        {
            InitializeComponent();
            this.dgvErr.AutoGenerateColumns = false;
            this.dgvErr.DataSource = dt;
        }

        private void dgvErr_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            Color color = Color.Black;
            string type = dgvErr.Rows[e.RowIndex].Cells[1].Value.ToString();
            AlarmType alarmType = (AlarmType)Enum.Parse(typeof(AlarmType), type);
            switch (alarmType)
            {
                case AlarmType.错误: //错误
                    color = Color.Red;
                    break;
                case AlarmType.警告: //警告
                   //color = Color.DarkOrange;
                   //color = Color.OrangeRed;
                    color = Color.Black;

                    break;
                case AlarmType.信息: //提示
                    color = Color.Black;
                    break;
                default:
                    color = Color.Black;
                    break;
            }
            dgvErr.Rows[e.RowIndex].DefaultCellStyle.ForeColor = color;
            new DataGridViewStyle().DgvRowPostPaint(dgvErr, e);
        }

        private void dgvErr_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            e.CellStyle.SelectionForeColor = e.CellStyle.ForeColor;
        }

        private void DlgAlarmNow_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }

        private void DlgAlarmNow_Load(object sender, EventArgs e)
        {

        }
    }
}
