Exemple #1
0
        private static List <SuperGroupExcell> getSuperGroups(string filename)
        {
            ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @$ "{filename}.xlsm");

            using (var package = new ExcelPackage(new FileInfo(path)))
            {
                var sheetTeacher = package.Workbook.Worksheets["По класове"];
                var sheetSubject = package.Workbook.Worksheets["ХЕИ"];

                Dictionary <SuperGroupExcell, List <SuperGroupExcell> > superGroups = new Dictionary <SuperGroupExcell, List <SuperGroupExcell> >();
                for (int l = 1; l <= 7; l++)
                {
                    for (int day = 1; day <= workDays; day++)
                    {
                        List <SuperGroupExcell> currSuperGroups = new List <SuperGroupExcell>();
                        for (int g = 0; g < groupsCnt; g++)
                        {
                            string        subject  = sheetSubject.Cells[20 + g * 9 + l - 1, 3 + day - 1].Text;
                            List <string> teachers = sheetTeacher.Cells[2 + g * 9 + l, 3 * day].Text.Split('/').ToList();

                            if (subject == "")
                            {
                                continue;
                            }
                            if (subject == "0")
                            {
                                continue;
                            }
                            if (subject == "ИТ")
                            {
                                subject = "ИТ/ИТ";
                            }

                            SuperGroupExcell sg = new SuperGroupExcell(sheetTeacher.Cells[2 + g * 9, 1].Text, subject, teachers, Tuple.Create(g, l, day));
                            int ind             = currSuperGroups.FindIndex(x => x.isIntersecting(sg) == true);

                            if (ind == -1)
                            {
                                currSuperGroups.Add(sg);
                            }
                            else
                            {
                                currSuperGroups[ind] = merge(currSuperGroups[ind], sg);
                            }
                        }

                        foreach (var x in currSuperGroups.Where(x => x.isSuper() == true))
                        {
                            if (superGroups.ContainsKey(x) == false)
                            {
                                superGroups.Add(x, new List <SuperGroupExcell>());
                            }
                            superGroups[x].Add(x);
                        }
                    }
                }

                List <SuperGroupExcell> output = new List <SuperGroupExcell>();
                foreach (var item in superGroups)
                {
                    SuperGroupExcell x = item.Value[0];
                    for (int i = 1; i < item.Value.Count; i++)
                    {
                        x = merge(x, item.Value[i]);
                    }

                    output.Add(x);
                }

                return(output);
            }
        }
Exemple #2
0
 private static SuperGroupExcell merge(SuperGroupExcell A, SuperGroupExcell B)
 {
     return(new SuperGroupExcell(A.teachers.Concat(B.teachers).Distinct().ToList(),
                                 A.groups.Concat(B.groups).Distinct().ToList(),
                                 A.positions.Concat(B.positions).Distinct().ToList()));
 }