using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.ComponentModel;
using IReaper.Category;
namespace IReaper.CourseData{
public abstract class CourseVectorBase:IVector<Course>
{
static List<CourseVectorBase> list = new List<CourseVectorBase>();
protected CourseCollection all;
protected IWebcastNode<Course> node;
protected CourseVectorBase(CourseCollection courses)
{
this.all = courses;
}
//
protected abstract void AddCourse(Course course);
/// <summary>
///
/// </summary>
/// <param name="course"></param>
protected abstract void RemoveCourse(Course course);
/// <summary>
///
/// </summary>
private void RefreshVector()
{
int i = 0;
if (node != null)
node.SetRoot(this.all);
for (i = 0; i < this.all.Count; i++)//this.allCoursesCollection
{
Course course = this.all[i];
this.AddCourse(course);
}
}
public void SetWebcastNode(IWebcastNode<Course> Node)
{
this.node = Node;
if (this.all != null)
this.all.ResetBindings();
}
/// <summary>
///
/// NotifyRemove
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DataChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
{
if (e.ListChangedType == ListChangedType.ItemAdded)
{
Course course = this.all[e.NewIndex];
this.AddCourse(course);
}
else if (e.ListChangedType == ListChangedType.Reset)
{
this.RefreshVector();
}
}
private void NotifyRemove(int index)
{
Course course = this.all[index];
this.RemoveCourse(course);
}
/// <summary>
/// CoursesCollection
/// </summary>
internal static CourseVectorBase GetCoursVector(CourseCollection courses)
{
CourseVectorBase vector = new CourseCategoryVector(courses);
courses.ListChanged += vector.DataChanged;
courses.NotifyRemove += vector.NotifyRemove;
list.Add(vector);
return vector;
}
public static void RefreshAll()
{
foreach (CourseCategoryVector vector in list)
{
vector.RefreshVector();
}
}
}
}
|