public MainWindow() { InitializeComponent(); Auditories = new ObservableCollection <Auditory>(); foreach (var aud in Auditories) { AuditoryRowVaiew rowControl = this.FindName($"Row{aud.DayPeople}") as AuditoryRowVaiew; if (rowControl != null) { var property = rowControl.GetType().GetProperty($"AudCell{aud.Pair - 1}"); property.SetValue(rowControl, aud); } } Loaded += MainWindow_Loaded; }
void LoadAudInfo(string audTitle) { string sqlExpression = string.Format("SELECT day, everyweek, para," + " rtrim(p.preps) as prep," + "rtrim(vp.pred) as pred," + "rtrim(nt.repvrnt) as nt," + "rtrim(coalesce(pl.konts, kg.obozn, kk.obozn)) as kont," + "coalesce(pl.stud, kg.students, kk.stud) as stud " + "FROM raspis r " + "LEFT JOIN auditories a ON r.aud = a.id_60 " + "LEFT JOIN raspnagr rn ON rn.id_51 = r.raspnagr " + "LEFT JOIN prepods p ON rn.prep = p.id_61 " + "LEFT JOIN vacpred vp ON rn.pred = vp.id_15 " + "LEFT JOIN kontgrp kg ON kg.id_7 = rn.kontid " + "LEFT JOIN kontkurs kk ON kk.id_1 = rn.kont " + "LEFT JOIN potoklist pl ON pl.op = rn.op " + "LEFT JOIN normtime nt ON nt.id_40 = rn.nt " + $"WHERE rtrim(a.obozn) = '{audTitle}' " + "ORDER BY day, para "); var sqlCommand = new SqlCommand(sqlExpression, connection); using (var dataAdapter = new SqlDataAdapter(sqlCommand)) { DataTable dt = new DataTable(); dataAdapter.Fill(dt); var fetchedPersons = dt.AsEnumerable() .Select(x => new Auditory { Group = x.Field <String>("kont"), Pair = x.Field <Int16>("para"), Discipline = x.Field <String>("pred"), Day = x.Field <Int16>("day"), Count = x.Field <int>("stud"), DayPeople = (x.Field <Int16>("day") - 1) % 7 + 1, Type = x.Field <String>("nt"), Teacher = x.Field <String>("prep"), Is_everyweek = x.Field <Int16>("everyweek") == 2 }); this.Auditories = new ObservableCollection <Auditory>(fetchedPersons); } var groupAud = from a in Auditories group a by new { a.DayPeople, a.Pair, a.Is_everyweek }; var groupList = new List <FullAuditory>(); foreach (var g in groupAud) { var list = g.ToList(); var fAud = new FullAuditory { Pair = g.Key.Pair, DayPeople = g.Key.DayPeople, Is_everyweek = g.Key.Is_everyweek }; if (list[0].Day >= 8) { fAud.Even = list[0]; } else { fAud.Odd = list[0]; } if (g.Count() == 2) { if (list[1].Day >= 8) { fAud.Even = list[1]; } else { fAud.Odd = list[1]; } } groupList.Add(fAud); } foreach (var aud in groupList) { AuditoryRowVaiew rowControl = this.FindName($"Row{aud.DayPeople}") as AuditoryRowVaiew; if (rowControl != null) { var property = rowControl.GetType().GetProperty($"AudCell{aud.Pair - 1}"); property.SetValue(rowControl, aud); } } }