using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Infragistics.Win.UltraWinGrid;

namespace OPCMonitoring
{
    /// <summary>
    /// Form where you add/edit/delete emails to send when alarm is trigered
    /// </summary>
    public partial class MailEditor : Form
    {

        /// <summary>
        /// Initializes the new form for editing emails
        /// </summary>
        public MailEditor()
        {
            InitializeComponent();
        }

        private void MailEditor_Load(object sender, EventArgs e)
        {
            try
            {
                grdMails.DataSource = MailController.GetAll();
                grdMails.DataBind();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }

        private void grdMails_AfterRowUpdate(object sender, Infragistics.Win.UltraWinGrid.RowEventArgs e)
        {
            try
            {
                MailController.Override((DataTable)grdMails.DataSource);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }

        private void grdMails_AfterRowsDeleted(object sender, EventArgs e)
        {
            try
            {
                MailController.Override((DataTable)grdMails.DataSource);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }

        private void grdMails_AfterRowInsert(object sender, RowEventArgs e)
        {
            try
            {
                MailController.Override((DataTable)grdMails.DataSource);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
    }
}
