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); }
private void button_UpravitKouli_Click(object sender, EventArgs e) { if (listBox_SeznamKouli.SelectedIndex == -1) { MessageBox.Show("Nebyla zvolena žádná koule pro úpravy!", "Chybové hlášení", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } selectedInxedKoule = listBox_SeznamKouli.SelectedIndex; Koule k = seznamKouli.GetKouleByIndex(selectedInxedKoule); textBox_Popis.Text = k.popis; textBox_Cislo.Text = k.cislo.ToString(); textBox_Polomer.Text = k.polomer.ToString(); ZpristupnitPolozkyKoule(false, "Upravit kouli"); }
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."); }
public void VlozitKouli(Koule k) { bool existuje = false; for (int i = 0; i < list_SeznamKouli.Count; i++) { if (list_SeznamKouli[i].cislo == k.cislo) { existuje = true; break; } } // existuje = list_SeznamKouli.Contains(k); // nevím proč ale nefunguje if (existuje == false) { list_SeznamKouli.Add(k); } else { throw new MyException_KouleExistujiciCislo("Nelze vložit kouli se stejným pořadovým číslem!"); } }
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); } }