using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace WPF_TtreeView
{
	public class Organization : INotifyPropertyChanged
	{
		private static int uid = 0;
		private string name;
		private string id;
		private bool select;

		public Organization(string name, bool isSelected)
		{
			Name = name;
			ID = (++uid).ToString();
			this.Select = isSelected;
			batteryList = new List<Department>();
		}
		public string Name
		{
			get { return this.name; }

			set
			{
				if (value != this.name)
				{
					this.name = value;
					this.NotifyPropertyChanged("Name");
				}
			}
		}

		public string ID
		{
			get { return id; }

			set
			{
				if (value != id)
				{
					id = value;
					this.NotifyPropertyChanged("ID");
				}
			}
		}

		public bool Select
		{
			get { return select; }

			set
			{
				if (value != select)
				{
					select = value;
					this.NotifyPropertyChanged("Select");
				}
			}
		}
		public List<Department> batteryList { get; set; }

		public event PropertyChangedEventHandler PropertyChanged;

		private void NotifyPropertyChanged(string info)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(info));
			}
		}
	}


	public class Department : INotifyPropertyChanged
	{
		private string name;
		private string id;
		private static int uid = 0;
		private bool select;
		public Department(string name,bool select)
		{
			Name = name;
			ID = (++uid).ToString();
			this.Select = select;
			wellList = new List<Person>();
		}
		public string Name
		{
			get { return this.name; }

			set
			{
				if (value != this.name)
				{
					this.name = value;
					this.NotifyPropertyChanged("Name");
				}
			}
		}

		public bool Select
		{
			get { return select; }

			set
			{
				if (value != select)
				{
					select = value;
					this.NotifyPropertyChanged("Select");
				}
			}
		}

		public string ID
		{
			get { return id; }

			set
			{
				if (value != id)
				{
					id = value;
					this.NotifyPropertyChanged("ID");
				}
			}
		}
		public List<Person> wellList { get; set; }

		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;

		private void NotifyPropertyChanged(string info)
		{
		if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
		}

		#endregion
	}
	public class Person : INotifyPropertyChanged
	{
		private string name;
		private string id;
		private static int uid = 0;
		public Person(string name)
		{
			
			Name = name;
			ID = (++uid).ToString();
			
		}
		
		public string Name
		{
			get { return this.name; }

			set
			{
				if (value != this.name)
				{
					this.name = value;
					this.NotifyPropertyChanged("Name");
				}
			}
		}
		public string ID
		{
			get { return id; }

			set
			{
				if (value != id)
				{
					id = value;
					this.NotifyPropertyChanged("ID");
				}
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;
		private void NotifyPropertyChanged(string info)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(info));
			}
		}
	}
	public class TreeDataSource : ObservableCollection<Organization>
	{
		public TreeDataSource()
		{
			Organization treeArea;
			Department d;
			Add(treeArea = new Organization("Organization  A-B",true));
			treeArea.batteryList.Add((d = new Department("Department  A",false)));
			d.wellList.Add(new Person("John"));
			d.wellList.Add(new Person("Ben"));
			d.wellList.Add(new Person("George"));
			d.wellList.Add(new Person("Peter"));
			d.wellList.Add(new Person("Ann"));
			treeArea.batteryList.Add((d = new Department("Department  B",true)));
			d.wellList.Add(new Person("Katy"));
			d.wellList.Add(new Person("Karoline"));
			d.wellList.Add(new Person("Simone"));
			d.wellList.Add(new Person("Eduard"));
			d.wellList.Add(new Person("Steave"));
			Add(treeArea = new Organization("Organization  B-C", true));
			treeArea.batteryList.Add((d = new Department("Department  C",false)));
			d.wellList.Add(new Person("Bob"));
			d.wellList.Add(new Person("Smith"));
			d.wellList.Add(new Person("Alex"));
			treeArea.batteryList.Add((d = new Department("Department  D",true)));
			d.wellList.Add(new Person("Katya"));
			d.wellList.Add(new Person("Robert"));
		}
	}
}
