コード例 #1
0
        private Soutez LoadSoutez(FileInfo fileInfo)
        {
            using (var package = new ExcelPackage(fileInfo))
            {
                var worksheet           = package.Workbook.Worksheets[1];
                var pocetTridObj        = worksheet.Cells[1, 3].Value;
                var pocetZakuNaTriduObj = worksheet.Cells[1, 4].Value;
                if (pocetTridObj == null || pocetZakuNaTriduObj == null || !int.TryParse(pocetTridObj.ToString(), out var pocetTrid) || !int.TryParse(pocetZakuNaTriduObj.ToString(), out var pocetZakuNaTridu))
                {
                    return(null);
                }

                var localZaci = new List <Zak>();
                for (var i = 3; i <= pocetTrid * pocetZakuNaTridu + 3 + pocetTrid * 2; i++)
                {
                    var id        = worksheet.Cells["A" + i].Value;
                    var jmeno     = worksheet.Cells["B" + i].Value;
                    var kategorie = worksheet.Cells["C" + i].Value;
                    var skola     = worksheet.Cells["D" + i].Value;
                    if (jmeno == null || kategorie == null || skola == null || id == null)
                    {
                        continue;
                    }
                    try
                    {
                        var zak = new Zak(jmeno.ToString(), Konstanty.RomanToInteger(kategorie.ToString()), char.ToUpper(Convert.ToChar(skola)))
                        {
                            Id = Convert.ToInt32(id)
                        };
                        localZaci.Add(zak);
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }
                var soutez = new Soutez(localZaci, pocetTrid, pocetZakuNaTridu);

                return(soutez);
            }
        }
コード例 #2
0
        private void buttonSort_Click(object sender, EventArgs e)
        {
            if (numericUpDownPupils.Value % 6 != 0)
            {
                MessageBox.Show(@"Počet žáků na třídu musí být dělitelný 6", @"ERROR", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            var soutez = new Soutez(_zaci, (int)numericUpDownClasses.Value, (int)numericUpDownPupils.Value);

            for (var i = 0; i < _config.Pokusy; i++)
            {
                if (soutez.Rozrad())
                {
                    var path = soutez.CreateXlxsFile();
                    if (!path.Equals(string.Empty))
                    {
                        Task.Run(() => Process.Start(path));
                    }
                    MessageBox.Show(@"Úspěšně rozřazeno!");
                    break;
                }
            }
        }