Ejemplo n.º 1
0
        internal string UlozDoXml(string filePath, string fileName, SeznamKouli sk)
        {
            StreamWriter sw = null;

            try
            {
                sw = new StreamWriter(Path.Combine(filePath, fileName), false, Encoding.Default);
                XElement seznamKouli = new XElement("Seznam_kouli");
                for (int i = 0; i < sk.list_SeznamKouli.Count; i++)
                {
                    XElement koule = new XElement("Koule");
                    koule.SetAttributeValue("Cislo", sk.list_SeznamKouli[i].cislo);
                    koule.SetAttributeValue("Polomer", sk.list_SeznamKouli[i].polomer);
                    koule.SetAttributeValue("Popis", sk.list_SeznamKouli[i].popis);
                    seznamKouli.Add(koule);
                }
                sw.WriteLine(seznamKouli);
            }
            catch (IOException ex)
            {
                return(String.Format("{0}\n\n{1}", "Při uložení došlo k chybě: ", ex.Message));
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
            }
            return("Soubor " + fileName + " je úspěšne uložen.");
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        internal string UlozDoCsv(SeznamKouli seznamKouli, string filePath, string fileName)
        {
            StreamWriter sw = null;

            fileName += ".csv";
            try
            {
                sw = new StreamWriter(Path.Combine(filePath, fileName), false, Encoding.Default);
                for (int i = 0; i < seznamKouli.list_SeznamKouli.Count; i++)
                {
                    sw.WriteLine(seznamKouli.list_SeznamKouli[i].ToString());
                }
            }
            catch (IOException ex)
            {
                return(String.Format("{0}\n\n{1}", "Při uložení došlo k chybě: ", ex.Message));
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
            }
            return("Soubor " + fileName + " je úspěšně uložen.");
        }
Ejemplo n.º 4
0
 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.");
 }
Ejemplo n.º 5
0
        internal string ImortujZCsv(SeznamKouli seznamKouli, string filePath, string fileName)
        {
            StreamReader sr = null;
            string       ln;

            try
            {
                sr = new StreamReader(Path.Combine(filePath, fileName), Encoding.Default);
                seznamKouli.OdstranitKoule();
                while ((ln = sr.ReadLine()) != null)
                {
                    zpracujRadek(ln, seznamKouli);
                }
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
            return("Soubor " + fileName + " je naimportován.");
        }
Ejemplo n.º 6
0
Archivo: Form1.cs Proyecto: novak55/PDA
        string filePath        = "";// Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);


        public Form1()
        {
            InitializeComponent();
            seznamKouli = new SeznamKouli();
        }