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 BulkTap3
{
    public partial class FilrerbyDate : Form
    {
        TreeView Filtertree;
        string filename;
        public void TreeNode(TreeView Filtertreenode, string Opened_filename)
        {
            Filtertree = Filtertreenode;
            filename = Opened_filename;
        }
        public FilrerbyDate()
        {
            InitializeComponent();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

            SDatetime.Enabled = StartChb.Checked;
            SHour.Enabled = StartChb.Checked;
            SMin.Enabled = StartChb.Checked;
            SSec.Enabled = StartChb.Checked;
            
        }

        private void EndChb_CheckedChanged(object sender, EventArgs e)
        {
            EDatetime.Enabled = EndChb.Checked;
            EHour.Enabled = EndChb.Checked;
            EMin.Enabled = EndChb.Checked;
            ESec.Enabled = EndChb.Checked;
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string SDate="";
            string EDate="";
            if (StartChb.Checked)
            {
                
                SDate = SDatetime.Value.ToString("yyyyMMdd");
                if (SHour.Text != "HH")
                    SDate += SHour.Text;
                else
                    SDate += "00";
                if (SMin.Text != "MM")
                    SDate += SMin.Text;
                else
                    SDate += "00";
                if (SSec.Text != "SS")
                    SDate += SSec.Text;
                else
                    SDate += "00";
            }
            if (EndChb.Checked)
            {
                
                EDate = EDatetime.Value.ToString("yyyyMMdd");
                if (EHour.Text != "HH")
                    EDate += EHour.Text;
                else
                    EDate += "00";
                if (EMin.Text != "MM")
                    EDate += EMin.Text;
                else
                    EDate += "00";
                if (ESec.Text != "SS")
                    EDate += ESec.Text;
                else
                    EDate += "00";
            }

            if (StartChb.Checked && EndChb.Checked)
            {
                TreeNode[] filtered_node = functions.Filter_Between_timeStamp(Filtertree.Nodes[0].Nodes[3], 16, SDate, EDate, filename);
                if (filtered_node.Length > 0)
                {
                    Filtertree.Nodes[0].Nodes[3].Nodes.Clear();
                    Filtertree.Nodes[0].Nodes[3].Nodes.AddRange(filtered_node);
                }
                this.Close();
            }
            else if (StartChb.Checked )
            {
                TreeNode[] filtered_node = functions.Filter_Greater_Less_timeStamp(Filtertree.Nodes[0].Nodes[3], 16, SDate, filename, 1);
                
                if (filtered_node.Length > 0)
                {
                    Filtertree.Nodes[0].Nodes[3].Nodes.Clear();
                    Filtertree.Nodes[0].Nodes[3].Nodes.AddRange(filtered_node);
                }
                this.Close();
            }
            else if (EndChb.Checked)
            {
                TreeNode[] filtered_node = functions.Filter_Greater_Less_timeStamp(Filtertree.Nodes[0].Nodes[3], 16, EDate, filename, 2);

                if (filtered_node.Length > 0)
                {
                    Filtertree.Nodes[0].Nodes[3].Nodes.Clear();
                    Filtertree.Nodes[0].Nodes[3].Nodes.AddRange(filtered_node);
                }
                this.Hide();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void FilrerbyDate_Load(object sender, EventArgs e)
        {

        }
    }
}
