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

namespace OutlookExpress_V1._._
{
    public partial class AddTasks : Form
    {
        public DataSet ds;
        private DataTable dt;
        private string Type;
        private int ItemNumber;
        public AddTasks()
        {
            InitializeComponent();
            ds = new DataSet();
            dt = new DataTable();
        }
        public AddTasks(DataSet d, string type, int item)
        {
            InitializeComponent();
            ds = d;
            dt = new DataTable();
            dt = ds.Tables[0];
            Type = type;
            ItemNumber = item;
        }
        private void AddTasks_Load(object sender, EventArgs e)
        {
            if (Type == "Add")
            {
                btnApply.Text = "Save New";
            }
            if (Type == "Update")
            {
                btnApply.Text = "Update";
                FName.Text = dt.Rows[ItemNumber][0].ToString();
                LName.Text = dt.Rows[ItemNumber][1].ToString();
                Email.Text = dt.Rows[ItemNumber][2].ToString();
                PhoneNumber.Text = dt.Rows[ItemNumber][3].ToString();
            }

        }

        private void btnApply_Click(object sender, EventArgs e)
        {
            Boolean IsComplete = true;
            if (FName.Text == string.Empty || LName.Text == string.Empty || Email.Text == string.Empty)
            {
                IsComplete = false;
                MessageBox.Show("Add Date, Time and Description then click Apply");
            }
            if (IsComplete == true && Type == "Add")
            {
                dt.Rows.Add(FName.Text, LName.Text, Email.Text, PhoneNumber.Text);
                ds.WriteXml(@"PerlLookUpTask.xml");
                MessageBox.Show("Task added successfully");
                this.Close();
            }
            if (IsComplete == true && Type == "Update")
            {
                dt.Rows[ItemNumber][0] = FName.Text;
                dt.Rows[ItemNumber][1] = LName.Text;
                dt.Rows[ItemNumber][2] = Email.Text;
                dt.Rows[ItemNumber][3] = PhoneNumber.Text;
                ds.WriteXml(@"PerlLookUpTask.xml");
                MessageBox.Show("Task updated successfully");
                this.Close();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}