From the question it appears that the ClassRoom, Subjects, DayTable and ClassHours are basically used as look up tables to get the full description of the corresponding id. The Cst and newTimeTable are the main data tables for constructing the time table as required. The DataTables can be populated from the database and then the LINQ to DataSet can be used to create the Time Table as shown below
void Main()
{
DataTable cst = new DataTable();
cst.Columns.Add("CstId",typeof(string),null);
cst.Columns.Add("ClassId",typeof(string),null);
cst.Columns.Add("SubjectId",typeof(string),null);
DataTable newTimeTable = new DataTable();
newTimeTable.Columns.Add("Id",typeof(string),null);
newTimeTable.Columns.Add("CstId",typeof(string),null);
newTimeTable.Columns.Add("HourId",typeof(string),null);
newTimeTable.Columns.Add("DayId",typeof(string),null);
cst.Rows.Add("cs1","C1","Eng");
cst.Rows.Add("cs2","C1","Sci");
cst.Rows.Add("cs3","C1","Mat");
cst.Rows.Add("cs1","C2","Eng");
cst.Rows.Add("cs2","C2","Sci");
cst.Rows.Add("cs3","C2","Mat");
DataTable subjects = new DataTable();
subjects.Columns.Add("SubjectId",typeof(string),null);
subjects.Columns.Add("SubjectName",typeof(string),null);
subjects.PrimaryKey = new DataColumn[]{subjects.Columns[0]};
subjects.Rows.Add("Eng","English");
subjects.Rows.Add("Sci","Science");
subjects.Rows.Add("mat","Mathematics");
newTimeTable.Rows.Add("N1","cs1", "Hour1","D1");
newTimeTable.Rows.Add("N2","cs2","Hour2","D4");
newTimeTable.Rows.Add("N3","cs3","Hour4","D2");
DataTable classTimeTable = new DataTable();
classTimeTable.Columns.Add("DayId",typeof(string),null);
classTimeTable.Columns.Add("DayName",typeof(string),null);
classTimeTable.Columns.Add("Hour1",typeof(string),null);
classTimeTable.Columns.Add("Hour2",typeof(string),null);
classTimeTable.Columns.Add("Hour3",typeof(string),null);
classTimeTable.Columns.Add("Hour4",typeof(string),null);
classTimeTable.Columns[1].DefaultValue="";
classTimeTable.Columns[2].DefaultValue="Na";
classTimeTable.Columns[3].DefaultValue="Na";
classTimeTable.Columns[4].DefaultValue="Na";
classTimeTable.Columns[5].DefaultValue="Na";
classTimeTable.Rows.Add("D1","Monday");
classTimeTable.Rows.Add("D2","Tuesday");
classTimeTable.Rows.Add("D3","Wednesday");
classTimeTable.Rows.Add("D4","Thursday");
classTimeTable.Rows.Add("D5","Friday");
classTimeTable.Rows.Add("D6","Saturday");
classTimeTable.PrimaryKey= new DataColumn[]{ classTimeTable.Columns[0]};
var ct = cst.AsEnumerable().Where (c =>c.Field<string>("ClassId")=="C1" ).
Join(newTimeTable.AsEnumerable(), cs => cs.Field<string>("CstId"),
nt => nt.Field<string>("CstId"),
(cs, nt) => {DataRow row = classTimeTable.Rows.Find(nt.Field<string>("DayId"));
row[nt.Field<string>("HourId")]=
subjects.Rows.Find(cs.Field<string>("SubjectId")).
Field<string>("SubjectName");
return row;}).Count ();
for(int i=1; i<6; i++)
{
Console.Write("{0,-20}",classTimeTable.Columns[i].ColumnName);
}
Console.WriteLine ("\n{0}",new string('-',80));
foreach(DataRow row in classTimeTable.Rows){
for(int i=1; i<6; i++)
Console.Write("{0,-20}",row[i].ToString());
Console.WriteLine ();
}
}