﻿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;

namespace jarvis
{
    public partial class FilterTasksDialog : Form
    {
        private Dictionary<string, object> filters = null;
        public FilterTasksDialog()
        {
            InitializeComponent();
        }

        public DialogResult ShowDialog(Dictionary<string,object> filters) {
            cmbStatus.SelectedIndex = 0;
            cmbPriority.SelectedIndex = 0;
            if (filters.ContainsKey("COMPLETE"))
            {
                cmbStatus.Text = Convert.ToInt32(filters["COMPLETE"]) == 0 ? "Incomplete" : "Complete" ;
            }
            else if (filters.ContainsKey("PRIORITY")) {
                cmbPriority.Text = filters["PRIORITY"].ToString();
            }
            this.filters = filters;
            return this.ShowDialog();
        }

        private void cmdOkay_Click(object sender, EventArgs e)
        {
            //STATUS
            if (cmbStatus.Text == "All")
            {
                if (filters.ContainsKey("COMPLETE")) filters.Remove("COMPLETE");
            }
            else
            {
                int nstatus = cmbStatus.Text == "Incomplete" ? 0 : 1;
                if (filters.ContainsKey("COMPLETE"))
                    filters["COMPLETE"] = nstatus;
                else
                    filters.Add("COMPLETE", nstatus);
            }

            //PRIORITY
            if (cmbPriority.Text == "All")
            {
                if (filters.ContainsKey("PRIORITY")) filters.Remove("PRIORITY");
            }
            else
            {
                string npriority = cmbPriority.Text;
                if (filters.ContainsKey("PRIORITY"))
                    filters["PRIORITY"] = npriority;
                else
                    filters.Add("PRIORITY", npriority);
            }

            //INSERT FILTERS TO DATBASE
            //cmd.CommandText = @"INSERT INTO FILTERS VALUES ('COMPLETE', 0);";
            //cmd.ExecuteNonQuery();
            Database.StoreFilters(filters);
        }
    }
}
