Example #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);
            }
        }
Example #2
0
        public void LoadData(FileInfo fileinfo)
        {
            var jmenoRow     = ';';
            var kategorieRow = ';';
            var skolaRow     = ';';

            using (var package = new ExcelPackage(fileinfo))
            {
                var worksheet = package.Workbook.Worksheets[1];
                for (var i = 65; i < 91; i++)
                {
                    var value = worksheet.Cells[((char)i).ToString() + _config.HeaderRow].Value;
                    if (value == null)
                    {
                        continue;
                    }
                    if (value.Equals(_config.Jmeno))
                    {
                        jmenoRow = (char)i;
                    }
                    else if (value.Equals(_config.Kategorie))
                    {
                        kategorieRow = (char)i;
                    }
                    else if (value.Equals(_config.Skola))
                    {
                        skolaRow = (char)i;
                    }
                }

                if (jmenoRow == ';' || kategorieRow == ';' || skolaRow == ';')
                {
                    MessageBox.Show(@"Hlavičky sloupců nenalezeny!", @"ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                listViewPupils.View = View.Details;
                listViewPupils.Columns.Add("Jméno", 150, HorizontalAlignment.Left);
                listViewPupils.Columns.Add("Kategorie", 60, HorizontalAlignment.Left);
                listViewPupils.Columns.Add("Škola", 50, HorizontalAlignment.Left);
                var index = 2;
                while (true)
                {
                    var jmeno     = worksheet.Cells[jmenoRow.ToString() + index].Value;
                    var kategorie = worksheet.Cells[kategorieRow.ToString() + index].Value;
                    var skola     = worksheet.Cells[skolaRow.ToString() + index].Value;
                    if (jmeno == null || kategorie == null || skola == null)
                    {
                        break;
                    }
                    try
                    {
                        var zak = new Zak(jmeno.ToString(), Konstanty.RomanToInteger(kategorie.ToString()), char.ToUpper(Convert.ToChar(skola)));
                        listViewPupils.Items.Add(new ListViewItem(new[] { zak.Jmeno, zak.Kategorie.ToRoman(), zak.Skola.ToString() }));
                        _zaci.Add(zak);
                    }
                    catch (Exception)
                    {
                        // ignored
                    }

                    index++;
                }
                numericUpDownClasses.Value = Math.Ceiling(listViewPupils.Items.Count / numericUpDownPupils.Value);
            }
        }
Example #3
0
 private void listViewPupils_KeyDown(object sender, KeyEventArgs e)
 {
     if (Keys.Delete == e.KeyCode)
     {
         foreach (ListViewItem listViewItem in ((ListView)sender).SelectedItems)
         {
             listViewItem.Remove();
             var zak = _zaci.Find(x => x.Jmeno == listViewItem.SubItems[0].Text && x.Kategorie == Convert.ToByte(Konstanty.RomanToInteger(listViewItem.SubItems[1].Text)) && x.Skola == Convert.ToChar(listViewItem.SubItems[2].Text));
             _zaci.Remove(zak);
         }
     }
 }