using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AIRS.usercontrol
{
    /// <summary>
    /// inclusion.xaml 的交互逻辑
    /// </summary>
    public partial class Inclusion : UserControl
    {
        public List<String> inclusion = new List<string>();

        public delegate void inc_changeEvent(List<string> incl);
        public static event inc_changeEvent inc_change;

        private Boolean isall = false;

        public Inclusion()
        {
            InitializeComponent();

            isall = true;
            inclusion.Clear();
            inclusion.Add("a");
            inclusion.Add("b");
            inclusion.Add("c");
            chbA.IsChecked = true;
            chbB.IsChecked = true;
            chbC.IsChecked = true;
            isall = false;
        }

        private void chbA_Checked(object sender, RoutedEventArgs e)
        {
            if(isall)
            {
                return;
            }
            if(inclusion.IndexOf("a")==-1)
            {
                inclusion.Add("a");
            }
            isall = true;
            if (inclusion.Count == 5)
            {
                chbAll.IsChecked = true;
            }
            else
            {
                chbAll.IsChecked = false;
            }
            isall = false;
            inc_change(inclusion);
        }

        private void chbA_Unchecked(object sender, RoutedEventArgs e)
        {
            if (isall)
            {
                return;
            }
            inclusion.Remove("a");
            isall = true;
            chbAll.IsChecked = false;
            isall = false;
            inc_change(inclusion);
        }

        private void chbB_Checked(object sender, RoutedEventArgs e)
        {
            if (isall)
            {
                return;
            }
            if (inclusion.IndexOf("b") == -1)
            {
                inclusion.Add("b");
            }
            isall = true;
            if (inclusion.Count == 5)
            {
                chbAll.IsChecked = true;
            }
            else
            {
                chbAll.IsChecked = false;
            }
            isall = false;
            inc_change(inclusion);
        }

        private void chbB_Unchecked(object sender, RoutedEventArgs e)
        {
            if (isall)
            {
                return;
            }
            inclusion.Remove("b");
            isall = true;
            chbAll.IsChecked = false;
            isall = false;
            inc_change(inclusion);
        }

        private void chbC_Checked(object sender, RoutedEventArgs e)
        {
            if (isall)
            {
                return;
            }
            if (inclusion.IndexOf("c") == -1)
            {
                inclusion.Add("c");
            }
            isall = true;
            if (inclusion.Count == 5)
            {
                chbAll.IsChecked = true;
            }
            else
            {
                chbAll.IsChecked = false;
            }
            isall = false;
            inc_change(inclusion);
        }

        private void chbC_Unchecked(object sender, RoutedEventArgs e)
        {
            if (isall)
            {
                return;
            }
            inclusion.Remove("c");
            isall = true;
            chbAll.IsChecked = false;
            isall = false;
            inc_change(inclusion);
        }

        private void chbD_Checked(object sender, RoutedEventArgs e)
        {
            if (isall)
            {
                return;
            }
            if (inclusion.IndexOf("d") == -1)
            {
                inclusion.Add("d");
            }
            isall = true;
            if (inclusion.Count == 5)
            {
                chbAll.IsChecked = true;
            }
            else
            {
                chbAll.IsChecked = false;
            }
            isall = false;
            inc_change(inclusion);
        }

        private void chbD_Unchecked(object sender, RoutedEventArgs e)
        {
            if (isall)
            {
                return;
            }
            inclusion.Remove("d");
            isall = true;
            chbAll.IsChecked = false;
            isall = false;
            inc_change(inclusion);
        }

        private void chbDS_Checked(object sender, RoutedEventArgs e)
        {
            if (isall)
            {
                return;
            }
            if (inclusion.IndexOf("ds") == -1)
            {
                inclusion.Add("ds");
            }
            isall = true;
            if (inclusion.Count == 5)
            {
                chbAll.IsChecked = true;
            }
            else
            {
                chbAll.IsChecked = false;
            }
            isall = false;
            inc_change(inclusion);
        }

        private void chbDS_Unchecked(object sender, RoutedEventArgs e)
        {
            if (isall)
            {
                return;
            }
            inclusion.Remove("ds");
            isall = true;
            chbAll.IsChecked = false;
            isall = false;
            inc_change(inclusion);
        }

        private void chbAll_Checked(object sender, RoutedEventArgs e)
        {
            if(isall)
            {
                return;
            }
            isall = true;
            inclusion.Clear();
            inclusion.Add("a");
            inclusion.Add("b");
            inclusion.Add("c");
            inclusion.Add("d");
            inclusion.Add("ds");
            chbA.IsChecked = true;
            chbB.IsChecked = true;
            chbC.IsChecked = true;
            chbD.IsChecked = true;
            chbDS.IsChecked = true;
            isall = false;
            inc_change(inclusion);
        }

        private void chbAll_Unchecked(object sender, RoutedEventArgs e)
        {
            if (isall)
            {
                return;
            }
            isall = true;
            inclusion.Clear();
            chbA.IsChecked = false;
            chbB.IsChecked = false;
            chbC.IsChecked = false;
            chbD.IsChecked = false;
            chbDS.IsChecked = false;
            isall = false;
            inc_change(inclusion);
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            
        }
    }
}
