private void zpracujRadek(string ln, SeznamKouli seznamKouli) { string[] radek = ln.Split(';'); Koule k = new Koule(Convert.ToDouble(radek[1]), radek[2], Convert.ToUInt32(radek[0])); seznamKouli.VlozitKouli(k); }
internal string ImortujZXml(SeznamKouli seznamKouli, string filePath, string fileName) { using (XmlReader reader = XmlReader.Create(@Path.Combine(filePath, fileName))) { while (reader.Read()) { if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "Koule")) { if (reader.HasAttributes) { Koule k = new Koule(Convert.ToDouble(reader.GetAttribute("Polomer")), reader.GetAttribute("Popis"), Convert.ToUInt32(reader.GetAttribute("Cislo"))); seznamKouli.VlozitKouli(k); } } } } return("Soubor " + fileName + " je naimportován."); }
private void button_PridatKouli_Click(object sender, EventArgs e) { string popis; double polomer; uint cislo; if (selectedInxedKoule > -1) { seznamKouli.OdstranitKouli(selectedInxedKoule); ZpristupnitPolozkyKoule(true); selectedInxedKoule = -1; } try { polomer = Convert.ToDouble(textBox_Polomer.Text); cislo = Convert.ToUInt32(textBox_Cislo.Text); popis = textBox_Popis.Text.Trim(); if (popis == string.Empty) { throw new FormatException("Nebyl zadán žádný popis!"); } Koule k = new Koule(polomer, popis, cislo); seznamKouli.VlozitKouli(k); refresh_SeznamKouli(); MessageBox.Show("Koule byla úspěšně vložena", "Informace", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFormulareKoule(); } catch (FormatException ex) { MessageBox.Show(String.Format("{0}\n{1}", "Chybně zadaná data", ex.Message), "Neúspěšné zadání", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (MyException_KouleExistujiciCislo ex) { MessageBox.Show(String.Format("{0}\n{1}", "Duplicitně zadaná data", ex.Message), "Neúspěšné zadání", MessageBoxButtons.OK, MessageBoxIcon.Error); } }