需要在列表之间提供主/子关系
Product empID Project Emp1D projectID taskname taskID
abc 1 xyz 1 10 we 23
sfv 1 10 rr 56
ooo 1 1
abc 2 xyz 2 11 we 33
sfv 3 11 rr 44
sfv 3 11 rr 55
我有来自webservice的数据comin,然后将所有数据转换为列表。 现在从列表中需要提供它们之间的关系
公共类SampleProjectData { public static ObservableCollection GetSampleData() { DateTime dtS = DateTime.Now;
ObservableCollection<Product> teams = new ObservableCollection<Product>();
teams.Add(new Product() { PDName = "Product1", OverallStartTime = dtS, OverallEndTime = dtS + TimeSpan.FromDays(3), });
Project emp = new Project() { PName = "Project1", OverallStartTime = dtS + TimeSpan.FromDays(1), OverallEndTime = dtS + TimeSpan.FromDays(6) };
emp.Tasks.Add(new Task() { StartTime = dtS, EndTime = dtS + TimeSpan.FromDays(2), TaskName = "John's Task 3" });
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(3), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "John's Task 2" });
teams[0].Projects.Add(emp);
emp = new Project() { PName = "Project2", OverallStartTime = dtS + TimeSpan.FromDays(1.5), OverallEndTime = dtS + TimeSpan.FromDays(5.5) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "Victor's Task" });
teams[0].Projects.Add(emp);
emp = new Project() { PName = "Project3", OverallStartTime = dtS + TimeSpan.FromDays(2), OverallEndTime = dtS + TimeSpan.FromDays(5) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "Jason's Task 1" });
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(7), EndTime = dtS + TimeSpan.FromDays(9), TaskName = "Jason's Task 2" });
teams[0].Projects.Add(emp);
teams.Add(new Product() { PDName = "Product2", OverallStartTime = dtS, OverallEndTime = dtS + TimeSpan.FromDays(3) });
emp = new Project() { PName = "Project4", OverallStartTime = dtS + TimeSpan.FromDays(0.5), OverallEndTime = dtS + TimeSpan.FromDays(3.5) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1.5), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "Vicky's Task" });
teams[1].Projects.Add(emp);
emp = new Project() { PName = "Project5", OverallStartTime = dtS + TimeSpan.FromDays(2), OverallEndTime = dtS + TimeSpan.FromDays(6) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(2.2), EndTime = dtS + TimeSpan.FromDays(3.8), TaskName = "Oleg's Task 1" });
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(5), EndTime = dtS + TimeSpan.FromDays(6), TaskName = "Oleg's Task 2" });
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(8), EndTime = dtS + TimeSpan.FromDays(9.6), TaskName = "Oleg's Task 3" });
teams[1].Projects.Add(emp);
emp = new Project() { PName = "Project6", OverallStartTime = dtS + TimeSpan.FromDays(2.5), OverallEndTime = dtS + TimeSpan.FromDays(4.5) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(0.8), EndTime = dtS + TimeSpan.FromDays(2), TaskName = "Kim's Task" });
teams[1].Projects.Add(emp);
teams.Add(new Product() { PDName = "Product3", OverallStartTime = dtS, OverallEndTime = dtS + TimeSpan.FromDays(3) });
emp = new Project() { PName = "Project7", OverallStartTime = dtS + TimeSpan.FromDays(5), OverallEndTime = dtS + TimeSpan.FromDays(7.5) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1.5), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "Balaji's Task 1" });
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(5), EndTime = dtS + TimeSpan.FromDays(8), TaskName = "Balaji's Task 2" });
teams[2].Projects.Add(emp);
emp = new Project() { PName = "Project8", OverallStartTime = dtS + TimeSpan.FromDays(3), OverallEndTime = dtS + TimeSpan.FromDays(6.3) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1.75), EndTime = dtS + TimeSpan.FromDays(2.25), TaskName = "Li's Task" });
teams[2].Projects.Add(emp);
emp = new Project() { PName = "Project9", OverallStartTime = dtS + TimeSpan.FromDays(2), OverallEndTime = dtS + TimeSpan.FromDays(6) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(2), EndTime = dtS + TimeSpan.FromDays(3), TaskName = "Stacy's Task" });
teams[2].Projects.Add(emp);
return teams;
}
}
上面是一个示例数据,我将它们与静态数据分组,就像我需要来处理来自DB的cmg数据一样,我需要存储它们列表
所有这三个数据都来自不同的服务。我将它们存储在一个列表中
现在我有三个表数据
产品,
项目,
任务。
所有数据都来自webservies。
我创建了三个列表,我将数据存储在列表中。
Listobjpro = new List(); Listobjproduct = new List(); LIstobjTask = new List();
现在我需要做的是我需要在这些表之间进行映射。 如果你看到上面的话。我有产品的对象产品我添加了项目的对象 然后在项目对象下我添加了任务对象。 现在从上面存储在列表中的数据我需要在类之间做相同的映射。
并对数据进行分组。
public class Product : INotifyPropertyChanged
{
public Product()
{
this.Projects = new ObservableCollection<Project>();
}
public string PDName { get; set; }
public ObservableCollection<Project> Projects { get; set; }
private DateTime _st;
public DateTime OverallStartTime
{
get { return _st; }
set
{
if (this._st != value)
{
TimeSpan dur = this._et - this._st;
this._st = value;
this.OnPropertyChanged("OverallStartTime");
this.OverallEndTime = value + dur;
}
}
}
private DateTime _et;
public DateTime OverallEndTime
{
get { return _et; }
set
{
if (this._et != value)
{
this._et = value;
this.OnPropertyChanged("OverallEndTime");
}
}
}
#region INotifyPropertyChanged Members
protected void OnPropertyChanged(string name)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(name));
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
public class Project : INotifyPropertyChanged
{
public Project() { this.Tasks = new ObservableCollection<Task>(); }
public string PName { get; set; }
public ObservableCollection<Task> Tasks { get; set; }
DateTime _st;
public DateTime OverallStartTime
{
get { return _st; }
set
{
if (this._st != value)
{
TimeSpan dur = this._et - this._st;
this._st = value;
this.OnPropertyChanged("OverallStartTime");
this.OverallEndTime = value + dur;
}
}
}
DateTime _et;
public DateTime OverallEndTime
{
get { return _et; }
set
{
if (this._et != value)
{
this._et = value;
this.OnPropertyChanged("OverallEndTime");
}
}
}
#region INotifyPropertyChanged Members
protected void OnPropertyChanged(string name)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(name));
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
public class Task : INotifyPropertyChanged
{
public string TaskName { get; set; }
DateTime _st;
public DateTime StartTime
{
get { return _st; }
set
{
if (this._st != value)
{
TimeSpan dur = this._et - this._st;
this._st = value;
this.OnPropertyChanged("StartTime");
this.EndTime = value + dur;
}
}
}
private DateTime _et;
public DateTime EndTime
{
get { return _et; }
set
{
if (this._et != value)
{
this._et = value;
this.OnPropertyChanged("EndTime");
}
}
}
#region INotifyPropertyChanged Members
protected void OnPropertyChanged(string name)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(name));
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}